Information Technology Reference
In-Depth Information
view_type => 'HostSystem',
begin_entity => $clusterView,
# limit the properties returned for performance
properties => [ 'name' ]
);
# print a simple newline delimited list of the found hosts
foreach my $host (@{$hostViews}) {
print $host->name . ″\n″;
}
# and destroy the session with the server
Util::disconnect();
Executing our script, you see the following results:
vi-admin@vma01:~> getClusterHosts.pl --server vCenter01 cluster01
Enter username: administrator
Enter password:
vSphere01.vSphere.local
vSphere02.vSphere.local
Notice that we were prompted for the username and password. This is a feature of using the
VIRuntime library. VMware has simplii ed things for developers by providing default options.
These are the same as for all of the vCLI scripts, so --username and --password apply regard-
less of whether you are using a vCLI script or one that you created. If you pass the username
and password arguments to the script via the command line, it will not prompt for them.
Alternatively, using fastpass will also eliminate the need for a username and password to be
supplied.
You can now combine your Perl script with bash and fastpass to coni gure an entire cluster
with a new portgroup quickly and efi ciently.
vi-admin@vma01:~> vifptarget -s vCenter01
vi-admin@vma01:~[vCenter01.vSphere.local]> for server in
'getClusterHosts.pl cluster01'; do
> echo ″$server is being configured...″
> vicfg-vswitch -h $server -A VLAN100 vSwitch0
> vicfg-vswitch -h $server -v 100 -p VLAN100 vSwitch0
> done
vSphere01.vSphere.local is being configured...
vSphere02.vSphere.local is being configured...
vi-admin@vma01:~[vCenter01.get-admin.com]> vifptarget -c
This example is just a tiny portion of what can be done with the Perl toolkit. The vCLI does
not include functionality for managing virtual servers; however, you can leverage the Perl tool-
kit and the SDK to manage VMs just as you can PowerCLI. Using the SDK, you can accomplish
any task that can be done through the VI Client or PowerCLI; the difference is the level of effort
Search WWH ::




Custom Search