コード例 #1
0
def getVirtualNWDeviceSpec(content, nw_spec_list, template):
    # this if can be removed, also "content" will be removed as it won't be used
    # motivation: we don't check for VM name when doing custom config, so why check if the network exists?
    # Leave it to the user or move it out to another function
    for nw_spec in nw_spec_list:
        target_network=nw_spec['name']
        if target_network:
            networkObject = getObject(content, [vim.Network], target_network)
            if networkObject:
                # New object which defines network backing for a virtual Ethernet card
                ## In case of several network device settings, we need to change the backing here to loop through the XML options
                ## otherwise all network devices will bind to target_network
                virtual_device_backing_info = vim.VirtualEthernetCardNetworkBackingInfo(network=networkObject,deviceName=target_network)
            else:
                print "Network name '" + target_network + "' not found."
                return None
        else:
            print "No network name was specified in the XML file or definition is invalid. . . ."
            return None

    # New object which contains information about connectable virtual devices
    # TODO: allowGuestControl and connected to be collected from XML?
    vdev_connect_info = vim.VirtualDeviceConnectInfo(startConnected=str2bool(nw_spec['startConnected']),allowGuestControl=False,connected=True)

    # get a list object containing the device key of all network devices associated with the VM
    networkDevkey_List = getNICDeviceKeyList(template)

    if networkDevkey_List:
        print "Found " + str(len(networkDevkey_List)) + " network device(s) in the template VM '" + template.name + "'"
    else:
        print "Couldn't find any network device from " + template.name + " attached to " + target_network

    networkSpec = []
############ DEV
    # returns a list of Specs of devices to be deleted from the template  (if effectively removes all network devices)
    networkSpec_Remove = [deviceConfigSpecRemoveNIC(template,device_key) for device_key in networkDevkey_List]

    # add N network devices, N being the number of custom spec defined in the XML. This must match
    # loop through nw_spec_list, even if not using it (may be useful in the future)
    # there is no control here if the Network exists - nw_spec is taken directly from the XML file
    # TODO: check if all networks specified in the XML are indeed valid/existent networks
    networkSpec_Add = [deviceConfigSpecAddNIC(template, nw_spec['name']) for nw_spec in nw_spec_list]

    networkSpec = networkSpec_Remove + networkSpec_Add

############ WORKING - translated from PERL
#    # New object which define virtual device
#    print "debugging networkDevkey_List" + str(networkDevkey_List)
#    networkDevice_List = []
#    for device_key in networkDevkey_List:
#        networkDevice_List.append(vim.VirtualVmxnet3(key=device_key,
#                                        backing=virtual_device_backing_info,
#                                        connectable=vdev_connect_info))
#
#    # New object which encapsulates change specifications for an individual virtual device

#    for network_device in networkDevice_List:
#        networkSpec.append(vim.VirtualDeviceConfigSpec(operation=vim.VirtualDeviceConfigSpecOperation('edit'),device=network_device))

    return networkSpec
コード例 #2
0
def customSystemPreparation(os_spec):
    """
    TODO: this is the hostname, valid for Linux and Windows
    create a condition, if the
    """
    if "SAME_AS_VM" == os_spec['hostName']:
            cust_name = vim.CustomizationVirtualMachineName()
    else:
            cust_name = vim.CustomizationFixedName(name=os_spec['hostName'])

    # test for Linux or Windows customization
    if (os_spec['custType'].lower() == "linux") or (os_spec['custType'].lower() == "lin"):
            cust_prep = vim.CustomizationLinuxPrep(domain=os_spec['joinDomain'],
                                                    hostName=cust_name);

    elif (os_spec['custType'].lower() == "windows") or (os_spec['custType'].lower() == "win"):
            customization_identity_settings = vim.CustomizationIdentitySettings()
            customLicenseDataMode = vim.CustomizationLicenseDataMode(os_spec['autoMode'])

            cust_gui_unattended = vim.CustomizationGuiUnattended(autoLogon=str2bool(os_spec['autoLogon']),
                                                                autoLogonCount=0,
                                                                timeZone=int(os_spec['timeZone']));


            password = vim.CustomizationPassword(plainText=True, value=os_spec['domainAdminPassword'])
            cust_identification = vim.CustomizationIdentification(domainAdmin=os_spec['domainAdmin'],
                                                                    domainAdminPassword=password,
                                                                    joinDomain=os_spec['joinDomain'],
                                                                    joinWorkgroup=os_spec['joinWorkgroup'])

            licenseFilePrintData = vim.CustomizationLicenseFilePrintData(autoMode=customLicenseDataMode,
                                                                            autoUsers=int(os_spec['autoUsers']))

            cust_user_data = vim.CustomizationUserData(fullName=os_spec['fullName'],
                                                        orgName=os_spec['orgName'],
                                                        computerName=cust_name,
                                                        productId=os_spec['productId'])

            cust_prep = vim.CustomizationSysprep(guiUnattended=cust_gui_unattended,
                                                    identification=cust_identification,
                                                    licenseFilePrintData=licenseFilePrintData,
                                                    userData=cust_user_data);
    else:
            print "The custType " + os_spec['custType'] + " is not suported. Quitting.."
            exit

    return cust_prep
コード例 #3
0
def getVirtualNWDeviceSpec(content, nw_spec_list, template):
    # this if can be removed, also "content" will be removed as it won't be used
    # motivation: we don't check for VM name when doing custom config, so why check if the network exists?
    # Leave it to the user or move it out to another function
    for nw_spec in nw_spec_list:
        target_network = nw_spec['name']
        if target_network:
            networkObject = getObject(content, [vim.Network], target_network)
            if networkObject:
                # New object which defines network backing for a virtual Ethernet card
                ## In case of several network device settings, we need to change the backing here to loop through the XML options
                ## otherwise all network devices will bind to target_network
                virtual_device_backing_info = vim.VirtualEthernetCardNetworkBackingInfo(
                    network=networkObject, deviceName=target_network)
            else:
                print "Network name '" + target_network + "' not found."
                return None
        else:
            print "No network name was specified in the XML file or definition is invalid. . . ."
            return None

    # New object which contains information about connectable virtual devices
    # TODO: allowGuestControl and connected to be collected from XML?
    vdev_connect_info = vim.VirtualDeviceConnectInfo(startConnected=str2bool(
        nw_spec['startConnected']),
                                                     allowGuestControl=False,
                                                     connected=True)

    # get a list object containing the device key of all network devices associated with the VM
    networkDevkey_List = getNICDeviceKeyList(template)

    if networkDevkey_List:
        print "Found " + str(
            len(networkDevkey_List)
        ) + " network device(s) in the template VM '" + template.name + "'"
    else:
        print "Couldn't find any network device from " + template.name + " attached to " + target_network

    networkSpec = []
    ############ DEV
    # returns a list of Specs of devices to be deleted from the template  (if effectively removes all network devices)
    networkSpec_Remove = [
        deviceConfigSpecRemoveNIC(template, device_key)
        for device_key in networkDevkey_List
    ]

    # add N network devices, N being the number of custom spec defined in the XML. This must match
    # loop through nw_spec_list, even if not using it (may be useful in the future)
    # there is no control here if the Network exists - nw_spec is taken directly from the XML file
    # TODO: check if all networks specified in the XML are indeed valid/existent networks
    networkSpec_Add = [
        deviceConfigSpecAddNIC(template, nw_spec['name'])
        for nw_spec in nw_spec_list
    ]

    networkSpec = networkSpec_Remove + networkSpec_Add

    ############ WORKING - translated from PERL
    #    # New object which define virtual device
    #    print "debugging networkDevkey_List" + str(networkDevkey_List)
    #    networkDevice_List = []
    #    for device_key in networkDevkey_List:
    #        networkDevice_List.append(vim.VirtualVmxnet3(key=device_key,
    #                                        backing=virtual_device_backing_info,
    #                                        connectable=vdev_connect_info))
    #
    #    # New object which encapsulates change specifications for an individual virtual device

    #    for network_device in networkDevice_List:
    #        networkSpec.append(vim.VirtualDeviceConfigSpec(operation=vim.VirtualDeviceConfigSpecOperation('edit'),device=network_device))

    return networkSpec