For example, to power on a virtual machine using the vmcontrol.pl utility application, you must specify the name of the virtual machine to power on, as follows:
Run any application or sample without any options or with --help to see its parameters and execution examples. Information about common and script-specific options is included.
The save_session.pl script in the
apps/session directory illustrates how to create a session file. You can modify the script and include it in your own application, or create a session file using the script on the command line, and then pass in that session file when running vSphere SDK for Perl commands. See
Saving Sessions.
You can use the code in the \apps\session\save_session.pl utility application inside your own vSphere SDK for Perl application. If a call to the server throws an exception, your application should terminate the session to avoid session leaks. You could do this with an error handler that runs
disconnect() or
logout(), for example:
You can also use the _END_ pseudo-signal handler to perform a disconnect, as follows:
The following example connects to the server as user snow-white with password
dwarf$. The first example (Linux) uses an escape character before each special character, the other examples use single quotes (Linux) and double quotes (Windows).
You can set environment variables in a Linux profile, in the Environment properties dialog box of the Microsoft Windows System control panel, or, for the current session, at the command line. Environment variables are listed when you run a command with
--help.
The following example shows the contents of a /root/.visdkrc file that uses environment variables:
A configuration file is a text file that contains variable names and settings. Variables corresponding to the connection options are shown in
Options Available for all vSphere SDK for Perl Scripts. Use
--config if the configuration information is saved in a different file than
./visdkrc. If you specify
--config, the system ignores the
./visdkrc settings.
You can use the --config option to run a script with the configuration file, for example:
Using a configuration file is useful for repeatedly entering connection details. If you have multiple vCenter Server or ESX/ESXi systems and you administer each system individually, you can create multiple configuration files with different names. When you want to run a command or a set of commands on a server, you pass in the
--config option with the appropriate filename at the command line.
You can use the --passthroughauth command-line argument to log in to a vCenter Server system (vCenter Server version 2.5 Update 2 or later). Using
--passthroughauth passes the credentials of the executing user to the server. If the executing user is known by both the machine from which you access the vCenter Server system and the machine running the vCenter Server system, no additional authentication is required.
If SDK commands and the vCenter Server system run on the same machine, a local account for the executing user works. If they run on different machines, then the executing user must have an account in a domain trusted by both machines.
SSPI supports a number of protocols. By default, it selects the Negotiate protocol, which indicates that client and server attempt to find a mutually supported protocol. Alternatively, you can use
--passthroughauthpackage to specify another protocol supported by SSPI. Kerberos, the Windows standard for domain-level authentication, is commonly chosen.
If the vCenter Server system is configured to accept only a specific protocol, specifying the protocol to vSphere SDK for Perl commands with
--passthroughauthpackage might be required for successful authentication to the server. If you use
--passthroughauth, you do not have to specify authentication information in any other way. For example, to run
connect.pl on the server, you can use the following command at the command line.
The following example connects to a server that has been set up to use SSPI. When you run the command, the system calls
vminfo.pl with the
--vmname option. The system does not prompt for a user name and password because the current user is known to the server.
Options Available for all vSphere SDK for Perl Scripts lists options that are available for all vSphere SDK for Perl scripts. Use the parameter on the command line and the variable or the parameter in configuration files.