def __init__(self, service_manager): # Client for all the services on a management node. self.service_manager = service_manager # Returns the service which provides support for generic functionality # which can be applied equally to all types of libraries self.library_service = Library(self.service_manager.stub_config) # Returns the service for managing local libraries self.local_library_service = LocalLibrary(self.service_manager.stub_config) # Returns the service for managing subscribed libraries self.subscribed_library_service = SubscribedLibrary(self.service_manager.stub_config) # Returns the service for managing library items self.library_item_service = Item(self.service_manager.stub_config) # Returns the service for managing sessions to update or delete content self.upload_service = UpdateSession(self.service_manager.stub_config) # Returns the service for managing files within an update session self.upload_file_service = UpdateSessionFile(self.service_manager.stub_config) # Returns the service for managing sessions to download content self.download_service = DownloadSession(self.service_manager.stub_config) # Returns the service for managing files within a download session self.download_file_service = DownloadSessionFile(self.service_manager.stub_config) # Returns the service for deploying virtual machines from OVF library items self.ovf_lib_item_service = LibraryItem(self.service_manager.stub_config) # Returns the service for mount and unmount of an iso file on a VM self.iso_service = Image(self.service_manager.stub_config) # Returns the service for managing subscribed library items self.subscribed_item_service = SubscribedItem(self.service_manager.stub_config) # Returns the service for managing library items containing virtual # machine templates self.vmtx_service = VmtxLibraryItem(self.service_manager.stub_config) # Returns the service for managing subscription information of # the subscribers of a published library. self.subscriptions = Subscriptions(self.service_manager.stub_config) # Creates the service that communicates with virtual machines self.vm_service = VM(self.service_manager.stub_config) # Returns the service for managing checkouts of a library item containing # a virtual machine template self.check_outs_service = CheckOuts(self.service_manager.stub_config) # Returns the service for managing the live versions of the virtual machine # templates contained in a library item self.versions_service = Versions(self.service_manager.stub_config) # Returns the service for managing the history of content changes made # to a library item self.changes_service = Changes(self.service_manager.stub_config)
def __init__(self, service_manager): # Client for all the services on a management node. self.service_manager = service_manager # Returns the service which provides support for generic functionality # which can be applied equally to all types of libraries self.library_service = Library(self.service_manager.stub_config) # Returns the service for managing local libraries self.local_library_service = LocalLibrary( self.service_manager.stub_config) # Returns the service for managing subscribed libraries self.subscribed_library_service = SubscribedLibrary( self.service_manager.stub_config) # Returns the service for managing library items self.library_item_service = Item(self.service_manager.stub_config) # Returns the service for managing sessions to update or delete content self.upload_service = UpdateSession(self.service_manager.stub_config) # Returns the service for managing files within an update session self.upload_file_service = UpdateSessionFile( self.service_manager.stub_config) # Returns the service for managing sessions to download content self.download_service = DownloadSession( self.service_manager.stub_config) # Returns the service for managing files within a download session self.download_file_service = DownloadSessionFile( self.service_manager.stub_config) # Returns the service for deploying virtual machines from OVF library items self.ovf_lib_item_service = LibraryItem( self.service_manager.stub_config) # Returns the service for mount and unmount of an iso file on a VM self.iso_service = Image(self.service_manager.stub_config) # Returns the service for managing subscribed library items self.subscribed_item_service = SubscribedItem( self.service_manager.stub_config) # Returns the service for managing library items containing virtual # machine templates self.vmtx_service = VmtxLibraryItem(self.service_manager.stub_config) # Creates the service that communicates with virtual machines self.vm_service = VM(self.service_manager.stub_config)
def deployVM(self, sddcName=None, templateName='centos_master', vmName='centos', datastoreName='WorkloadDatastore', resourcePoolName='Compute-ResourcePool', folderName='Workloads', ipAddress='192.168.2.4', subnetMask='255.255.255.0', gateway='192.168.2.1'): if not sddcName: raise ValueError('You must supply an SDDC name') if not templateName: raise ValueError('You must supply a Template name') if not vmName: raise ValueError('You must supply a VM name') if not datastoreName: raise ValueError('You must supply a Datastore name') if not resourcePoolName: raise ValueError('You must supply a Resource Pool name') if not folderName: raise ValueError('You must supply a Folder name') #podNumber = re.sub(r'^[^0-9]*(.*)',r'\1',sddcName) datastore = self.getDatastore(datastoreName)._moId resourcePool = self.getResourcePool(resourcePoolName)._moId folder = self.getFolder(folderName)._moId deploymentTarget = LibraryItem.DeploymentTarget( resource_pool_id=resourcePool, folder_id=folder) findSpec = Item.FindSpec(name=templateName) libraryItemService = Item(self.stub_config) ovfLibraryItemService = LibraryItem(self.stub_config) itemIDs = libraryItemService.find(findSpec) libItemID = itemIDs[0] if itemIDs else None print('Library item ID: {0}'.format(libItemID)) ovfSummary = ovfLibraryItemService.filter( ovf_library_item_id=libItemID, target=deploymentTarget) print('Found an OVF template: {0} to deploy.'.format(ovfSummary.name)) adaptermap = vim.vm.customization.AdapterMapping() adaptermap.adapter = vim.vm.customization.IPSettings( ip=vim.vm.customization.FixedIp(ipAddress=ipAddress), subnetMask=subnetMask, gateway=gateway) globalip = vim.vm.customization.GlobalIPSettings( dnsServerList=self.org.config['WorkshopConfig']['DnsConfig']) ident = vim.vm.customization.LinuxPrep( domain='domain.local', hostName=vim.vm.customization.FixedName(name=vmName)) customspec = vim.vm.customization.Specification( nicSettingMap=[adaptermap], globalIPSettings=globalip, identity=ident) deploymentSpec = LibraryItem.ResourcePoolDeploymentSpec( name='centos', annotation=ovfSummary.annotation, accept_all_eula=True, network_mappings=None, storage_mappings=None, storage_provisioning=None, storage_profile_id=None, locale=None, flags=None, additional_parameters=None, default_datastore_id=None) result = ovfLibraryItemService.deploy(libItemID, deploymentTarget, deploymentSpec, client_token=str(uuid.uuid4())) # The type and ID of the target deployment is available in the deployment result. if result.succeeded: print( 'Deployment successful. Result resource: {0}, ID: {1}'.format( result.resource_id.type, result.resource_id.id)) vm_id = result.resource_id.id error = result.error if error is not None: for warning in error.warnings: print('OVF warning: {}'.format(warning.message)) # Power on the VM and wait for the power on operation to be completed vm_obj = None container = self.content.viewManager.CreateContainerView( self.content.rootFolder, [vim.VirtualMachine], True) for c in container.view: if c._GetMoId() == vm_id: vm_obj = c break assert vm_obj is not None self.wait_for_tasks(self.content, [vm_obj.Customize(spec=customspec)]) self.wait_for_tasks(self.content, [vm_obj.PowerOn()]) else: print('Deployment failed.') for error in result.error.errors: print('OVF error: {}'.format(error.message))