Hello,
Is it possible to create a script using the perl sdk and execute it via apache or IIS ? I wish to create
a script which can be executed via IIS or Apache to deploy a vm from a template via a browser.
regards
newbie
I'm not familiar with that particular appliance, but a standard apache installation typically has the cgi configured. Just need to place the script into the cgi-bin directory.
You'll need to install the VI Perl Toolkit from VMware (Windows or Linux). Be sure to follow the instructions for the dependencies.
Yes, that is possible. Do a search online for Perl and CGI, if you have a vSphere SDK for Perl scrip that already does the VM deployment, then the only piece left is to have it be executed via some webpage of your design.
Here are a bunch of canned VMware scripts that's included with the vSphere SDK for Perl: http://www.vmware.com/support/developer/viperltoolkit/viperl40/doc/vsperl_util_index.html, one that may of be interest is vmclone.pl. If the default scripts don't provide what you need you can always re-write or update the script.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Definitely follow up on the links Iamw provided. But I do this all the time. Just install the VI Perl Toolkit into your web server, then use mod_perl or Perl CGI. Pretty straightforward actually. Just have to format your output as HTML vs text. It's actually lot easier when you start using the Perl CGI/HTML modules.
If you want to get fancy with mod_perl, you can preload the VMware modules as well, but I doubt you'll have a high traffic site that needs that sort of optimization.
Your web server will need to be able to communicate to the ESX host(s) or vCenter servers on 443.
Sure, here's a very basic "Hello VI Perl" type example. It just gets the About info from the Service Content managed object. This is assuming the web server you're on is *Nix based and has cgi-bin and perl installed.
#!/usr/bin/perl use warnings; use strict; use VMware::VIRuntime; Opts::set_option("username", "administrator"); Opts::set_option("password", "VMware1"); Opts::set_option("url", "https://192.168.73.133/sdk"); Opts::parse(); Opts::validate(); Util::connect(); my $service_content = Vim::get_service_content(); my $full_name = $service_content->about->fullName; my $html = "<HTML><BODY>$full_name<BR></BODY></HTML>"; Util::disconnect(); print "Content-type: text/html\n\n"; print $html;
In my case I get back the full name value from the serviceContent->about object.
VMware vCenter Server 4.0.0 build-208111
Note the Opts::set_option lines. In the case of the Service Content, a login isn't required, but you'll need that information for more interesting work. You could also use a configuration file, look through the vSphere SDK for Perl Programming Guide. If you were accepting the login information as a form from a web page, you'd just parse the variables and set_option for simplicity.
Obviously this will get a bit more complex as you do more interesting things, for example, you'll want to use eval { } blocks to catch errors from the SDK and handle them in a HTML safe manner.
Another place you may want to look is the vSphere Client Plugins Documentation. There will be a little more setup work, but you'll be able to integrate your cgi based tools directly into the vCenter UI.
If you want something with embedded perl for doing more complex web pages, look at Perl-Mason. I've used it in the past and it's pretty solid. I know VMware is working on a new plugin framework called Flex I believe. This is supposed to replace web and C# plugins in the future, but I'm not sure when that is slated to be released. I do believe the View 4.5 Beta web UIs use the new Flex framework, so it may be getting close.
thanks for that example. Is this example unix specific? I tried running the script on IIS7.0 using event handlers that point to the perl.exe that shipped with vsphere cli.(perl sdk)
This code works fine:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello world!\n\n";
print "Press the Enter key to exit.\n";
But when I run your .pl script I get the following:
Looks like a problem with your Perl Toolkit installation or your Perl environment. Can you run some of the sample scripts from the Perl Toolkit outside of the IIS CGI (just run them at the command line on the same server)?
Yep definately something wrong there. Im going to drop winblowz for this project. If I download the appliance
http://www.vmware.com/appliances/directory/va/178973/resources
Can I use that appliances webserver to execute the perl scripts. Or can you tell me what your environment
is and I will build that up.
regards
B
I'm not familiar with that particular appliance, but a standard apache installation typically has the cgi configured. Just need to place the script into the cgi-bin directory.
You'll need to install the VI Perl Toolkit from VMware (Windows or Linux). Be sure to follow the instructions for the dependencies.
Thanks I'll try that
kablamo!!!
Got it working wrong paths in environment variables.
My Environemnt:
Windows vista, IIS7, vSphere CLI Perl SDK (which is activeperl from activstate)
Steps to get it working:
configure IIS Event Handliers as per doco but ensure vsphere cli install directory contained no spaces.
set path variables for all paths referenced in the error code posted previously in this article.