Creating a New Virtual MachineThe first step in creating a new virtual machine is to create a blank virtual machine and register it with the Parallels Service. A blank virtual machine is an equivalent of a hardware box with no operating system installed on the hard drive. Once a blank virtual machine is created and registered, it can be powered on and an operating system can be installed on it. In this section, we will discuss how to create a typical virtual machine for a particular OS type using a sample configuration. By using this approach, you can easily create a virtual machine without knowing all of the little details about configuring a virtual machine for a particular operating system type. The steps involved in creating a typical virtual machine are:
Sample """ Create a new virtual machine. """ def create_vm(server):
# Obtain the prlsdkapi.ServerConfig object. # The object contains the host machine configuration # information. try: result = server.get_srv_config().wait() except prlsdkapi.PrlSDKError, e: print "Error: %s" % e
srv_config = result.get_param()
# Obtain a new prlsdkapi.Vm object. vm = server.create_vm()
# Obtain a prlsdkapi.VmConfig object. # The new virtual machine configuration will be performed # using this object. At this time the object will be empty. vm_config = vm.get_config()
# Use the default configuration. # Parameters of the set_default_config method: # param_1: The host machine configuration object. # param_2: Target OS type and version. # param_3: Specifies to create the virtual machine devices using # default values (the settings can be modified later if needed). vm_config.set_default_config(srv_config, \ consts.PVS_GUEST_VER_WIN_XP, True)
# Set the virtual machine name and description. vm_config.set_name("My New XP machine") vm_config.set_description("Parallels Python API sample")
# Modify the default RAM size and HDD size. # These two steps are optional. If you omit them, the # default values will be used. vm_config.set_ram_size(256) # Set HDD size to 10 gig. # The get_device method obtains a prlsdkapi.VmHardDisk object. # The index 0 is used because the default configuration has a # single hard disk. dev_hdd = vm.get_hard_disk(0) dev_hdd.set_disk_size(10000)
# Register the virtual machine with the Parallels Service. # The first parameter specifies to create the machine in the # default directory on the host computer. # The second parameter specifies that non-interactive mode # should be used. print "Creating a virtual machine..." try: vm.reg("", True).wait() except prlsdkapi.PrlSDKError, e: print "Error: %s" % e return
print "Virtual machine was created successfully." |
||||
|