Previous page

Next page

Locate page in Contents

Print this page

Connecting to Parallels Service and Logging In

The sample program in the previous section provided basic instructions on how to connect and log in to a local or a remote host. In this section, we will discuss these operations in greater detail.

Depending on whether you are using Parallels Server or Parallels Desktop, the login options are different.

Parallels Desktop accepts local connections only. This means that you can only run your client program on the same computer that hosts Parallels Desktop. You cannot run it on a remote client and connect to Parallels Desktop over the network. In addition, Parallels Desktop does not support multiple users, so the only option available is to connect as the current user.

Parallels Server accepts both local and remote connections. This means that your client program can run anywhere on the network and connect to Parallels Server remotely. Parallels Server supports multiple users. If running a client program locally, you have an option to login as the current user or as a specified user. If a program is running on a remote client, you always have to specify the user information.

The prlsdkapi.Server class provides two login methods: login_local() and login() . The login_local() method is used to establish a local connection as a current user .  It can be used with both Parallels Server and Parallels Desktop. The login() method is used to establish a local or a remote connection as a specified user . It can be used with Parallels Server only.

The following tables describe the parameters of the two login methods.

prlsdkapi.Server.login_local

Parameter

Type

Description

port

integer

[optional] Port number at which Parallels Service is listening for incoming requests. To use the default port number, pass 0 . If the default port number was changed by the administrator of your system, specify the correct value.

The default value is 0 .

secur_level

integer

[optional] Communication security level to use for the session. The value must be specified using one of the constants with the PSL_ prefix. The following options are currently available (for possible changes, consult the Parallels Python API Reference guide):

PSL_HIGH_SECURITY - using SSL. PSL_LOW_SECURITY - no encryption. PSL_NORMAL_SECURITY - mixed.

Parallels Service configuration have a setting specifying the minimum security level (the setting can be modified). You must specify here an equal or a higher level to establish a connection. To find out the minimum level, use the min_security_level property of the prlsdkapi.DispConfig object.

The default value is PSL_LOW_SECURITY .

session_uuid

string

[optional] Previous session ID. This parameter can be used in recovering from a lost connection. The ID will be used to restore references to the asynchronous jobs that were started in the previous session and are still running on the server. If you are not restoring a connection, omit this parameter or pass an empty string.

The default value is empty string.

prlsdkapi.Server.login

Parameter

Type

Description

host

string

The IP address or name of the host.

user

User name.

password

User password.

port

integer

[optional] Port number on which Parallels Service is listening for incoming requests. To use the default port number, pass 0 . If the default port number was changed by the administrator, specify the correct value.

The default value is 0 .

secur_level

integer

[optional] Communication security level to use for the session. The value must be specified using one of the constants with the PSL_ prefix. The following options are currently available (for possible changes, consult the Parallels Python API Reference guide):

PSL_HIGH_SECURITY - using SSL. PSL_LOW_SECURITY - no encryption. PSL_NORMAL_SECURITY - mixed.

Parallels Service configuration has a parameter specifying the minimum security level. You must specify an equal or higher level to establish a connection. To find out the minimum level, use the min_security_level property of the prlsdkapi.DispConfig object.

The default value is PSL_LOW_SECURITY .

session_uuid

string

[optional] Previous session ID. This parameter can be used in recovering from a lost connection. The ID will be used to restore references to asynchronous jobs that were started in the previous session and are still running on the server. If you are not restoring a connection, omit this parameter or pass an empty string value.

The default value is empty string.

timeout

integer

Timeout value in milliseconds. The operation will be automatically interrupted if a connection is not established within this timeframe. Specify 0 (zero) for infinite timeout.

The default value is 0 .

Both methods return an instance of the prlsdkapi.LoginResponse class containing some basic information about the host, the new session ID, and the information about the previous session (if applicable).

Example 1 - Connecting to the local host as the current user:

import prlsdkapi

import sys

prlsdk = prlsdkapi.prlsdk

consts = prlsdkapi.prlsdk.consts

class Halt(Exception):

pass

def main():

# Initialize API library using the "Parallels Desktop" mode.

prlsdk.InitializeSDK(consts.PAM_DESKTOP)

# Create a Server object.

server = prlsdkapi.Server()

# Log in.

# The "result" object is an instance of the prlsdkapi.LoginResponse class.

try:

result = server.login_local(0, consts.PSL_NORMAL_SECURITY).wait()

except prlsdkapi.prlsdk.ParallelsError, e:

print "Login error: %s" % e

raise Halt

# Read and display information from the result object.

print ""

print "Login successful"

print "Parallels Desktop version: " + result.product_version

print "Host OS version: " + result.host_os_version

print "Host UUID: " + result.server_uuid

print "Session UUID: " + result.session_uuid

print ""

if __name__ == "__main__":

try:

sys.exit(main())

except Halt:

pass

Example 2 - Connecting to the specified host as a specified user:

Please note that the host in this example can be a local or a remote machine.

import prlsdkapi

import sys

prlsdk = prlsdkapi.prlsdk

consts = prlsdkapi.prlsdk.consts

class Halt(Exception):

pass

def main():

# Initialize API library using the "Parallels Server" mode.

prlsdk.InitializeSDK(consts.PAM_SERVER)

# Create a Server object.

server = prlsdkapi.Server()

# Log in.

# The "result" object is an instance of the prlsdkapi.LoginResponse class.

try:

result = server.login("10.30.19.149", "johndoe", "secret", 0, consts.PSL_NORMAL_SECURITY).wait()

except prlsdkapi.prlsdk.ParallelsError, e:

print "Login error: %s" % e

raise Halt

# Read and display information from the result object.

print ""

print "Login successful"

print "Parallels Server version: " + result.product_version

print "Host OS version: " + result.host_os_version

print "Host UUID: " + result.server_uuid

print "Session UUID: " + result.session_uuid

print ""

if __name__ == "__main__":

try:

sys.exit(main())

except Halt:

pass

Please send us your feedback on this help page