예제 #1
0
def delete_vmdk_if_exist(client, soap_stub, datacenter_name, datastore_name,
                         datastore_path):
    if detect_vmdk(client, soap_stub, datacenter_name, datastore_name,
                   datastore_path):
        print("Detected VMDK '{}' {}".format(datastore_name, datastore_path))
        delete_vmdk(service_instance, datacenter_mo, datastore_path)
        print("Deleted VMDK '{}'".format(datastore_path))
예제 #2
0
def cleanup():
    # Clean up the saved disk from the update sample
    vmdk_file = saved_disk_info.backing.vmdk_file
    print("\n# Cleanup: Delete VMDK '{}'".format(vmdk_file))
    delete_vmdk(service_instance, datacenter_mo, vmdk_file)

    # List all Disks for a VM
    disk_summaries = client.vcenter.vm.hardware.Disk.list(vm=vm)
    print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries))

    print('\n# Cleanup: Delete VM Disks that were added')
    for disk in disks_to_delete:
        disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk)
        print('vm.hardware.Disk.get({}, {}) -> {}'.format(
            vm, disk, pp(disk_info)))
        vmdk_file = disk_info.backing.vmdk_file

        client.vcenter.vm.hardware.Disk.delete(vm, disk)
        print('vm.hardware.Disk.delete({}, {})'.format(vm, disk))

        print("\n# Cleanup: Delete VMDK '{}'".format(vmdk_file))
        delete_vmdk(service_instance, datacenter_mo, vmdk_file)

    print('\n# Cleanup: Remove SATA controller')
    print('vm.hardware.adapter.Sata.delete({}, {})'.format(vm, sata))
    client.vcenter.vm.hardware.adapter.Sata.delete(vm, sata)

    disk_summaries = client.vcenter.vm.hardware.Disk.list(vm)
    print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries))
    if set(orig_disk_summaries) != set(disk_summaries):
        print(
            'vm.hardware.Disk WARNING: Final Disk info does not match original'
        )