Exemplo n.º 1
0
    def _execute(self):
        # Get the identifiers
        vm_id = get_vm(self.vsphere_client, self.vm_name)
        assert vm_id
        resource_pool_id = get_resource_pool(self.vsphere_client,
                                             self.datacenter_name,
                                             self.resource_pool_name)
        assert resource_pool_id

        # Create a library
        storage_backings = self.helper.create_storage_backings(
            self.servicemanager, self.datastore_name)
        self.library_id = self.helper.create_local_library(
            storage_backings, self.library_name)

        # Build the create specification
        create_spec = VmtxLibraryItem.CreateSpec()
        create_spec.source_vm = vm_id
        create_spec.library = self.library_id
        create_spec.name = self.item_name
        create_spec.placement = VmtxLibraryItem.CreatePlacementSpec(
            resource_pool=resource_pool_id)

        # Create a new library item from the source VM
        self.item_id = self.client.vmtx_service.create(create_spec)
        print("Created VM template item '{0}' with ID: {1}".format(
            self.item_name, self.item_id))

        # Retrieve the library item info
        info = self.client.vmtx_service.get(self.item_id)
        print('VM template guest OS: {0}'.format(info.guest_os))
 def create_vmtx_item_from_vm(self, library_id, source_vm_id,
                              vmtx_item_name):
     # Create a VMTX item using the given VM as source
     create_spec = VmtxLibraryItem.CreateSpec()
     create_spec.source_vm = source_vm_id
     create_spec.library = library_id
     create_spec.name = vmtx_item_name
     create_spec.description = 'sample-vmtx-description'
     create_spec.placement = VmtxLibraryItem.CreatePlacementSpec()
     create_spec.placement.resource_pool = self.resource_pool_id
     vmtx_item_id = self.client.vmtx_service.create(create_spec)
     print("VMTX item created id: {0}".format(vmtx_item_id))
     return vmtx_item_id