def main(): """ Simple command-line program for creating a first class disk. """ args = get_args() try: if args.disable_ssl_verification: service_instance = connect.SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) else: service_instance = connect.SmartConnect(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(connect.Disconnect, service_instance) content = service_instance.RetrieveContent() # Connect to SPBM Endpoint pbmSi = pbmhelper.create_pbm_session(service_instance._stub) pbmContent = pbmSi.RetrieveContent() # Retrieving Storage Policy if args.policy: policy = pbmhelper.retrieve_storage_policy(pbmContent, args.policy) else: policy = None # Retrieve Datastore Object datastore = disk.get_obj(content, [vim.Datastore], args.datastore) # Setting FCD Specifications spec = vim.vslm.CreateSpec() spec.name = args.name spec.capacityInMB = args.capacityInGB * 1024 if args.keepAfterDeleteVm: spec.keepAfterDeleteVm = True spec.backingSpec = vim.vslm.CreateSpec.DiskFileBackingSpec() spec.backingSpec.provisioningType = "thin" spec.backingSpec.datastore = datastore if policy: spec.profile = [ vim.vm.DefinedProfileSpec(profileId=policy.profileId.uniqueId) ] # Create FCD storage = content.vStorageObjectManager task = storage.CreateDisk_Task(spec) tasks.wait_for_tasks(service_instance, [task]) except vmodl.MethodFault as error: print("Caught vmodl fault : " + error.msg) return -1 return 0
def main(): """ Simple command-line program for creating a first class disk. """ args = get_args() try: if args.disable_ssl_verification: service_instance = connect.SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) else: service_instance = connect.SmartConnect(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(connect.Disconnect, service_instance) content = service_instance.RetrieveContent() # Connect to SPBM Endpoint pbmSi = pbmhelper.create_pbm_session(service_instance._stub) pbmContent = pbmSi.RetrieveContent() # Retrieving Storage Policy if args.policy: policy = pbmhelper.retrieve_storage_policy(pbmContent, args.policy) else: policy = None # Retrieve Datastore Object datastore = disk.get_obj(content, [vim.Datastore], args.datastore) # Setting FCD Specifications spec = vim.vslm.CreateSpec() spec.name = args.name spec.capacityInMB = args.capacityInGB * 1024 if args.keepAfterDeleteVm: spec.keepAfterDeleteVm = True spec.backingSpec = vim.vslm.CreateSpec.DiskFileBackingSpec() spec.backingSpec.provisioningType = "thin" spec.backingSpec.datastore = datastore if policy: spec.profile = [vim.vm.DefinedProfileSpec( profileId=policy.profileId.uniqueId)] # Create FCD storage = content.vStorageObjectManager task = storage.CreateDisk_Task(spec) tasks.wait_for_tasks(service_instance, [task]) except vmodl.MethodFault as error: print("Caught vmodl fault : " + error.msg) return -1 return 0
def main(): """ Simple command-line program for creating a new vdisk from a snapshot """ args = get_args() try: if args.disable_ssl_verification: service_instance = connect.SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) else: service_instance = connect.SmartConnect(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(connect.Disconnect, service_instance) content = service_instance.RetrieveContent() # Connect to SPBM Endpoint pbmSi = pbmhelper.create_pbm_session(service_instance._stub) pbmContent = pbmSi.RetrieveContent() # Retrieving Storage Policy if args.policy: p = pbmhelper.retrieve_storage_policy(pbmContent, args.policy) policy = [ vim.vm.DefinedProfileSpec(profileId=p.profileId.uniqueId) ] else: policy = None # Retrieve Source Datastore Object source_datastore = disk.get_obj(content, [vim.Datastore], args.source_datastore) # Retrieve Source FCD Object source_vdisk = disk.retrieve_fcd(content, source_datastore, args.source_vdisk) # Retrieve Snapshot Object snapshot = disk.retrieve_fcd_snapshot(content, source_datastore, source_vdisk, args.snapshot) # Retrieve Destination Datastore Object dest_datastore = disk.get_obj(content, [vim.Datastore], args.dest_datastore) # Create FCD from Snapshot storage = content.vStorageObjectManager if policy: task = storage.CreateDiskFromSnapshot_Task(source_vdisk.config.id, dest_datastore, snapshot, args.dest_vdisk, policy) else: task = storage.CreateDiskFromSnapshot_Task(source_vdisk.config.id, dest_datastore, snapshot, args.dest_vdisk) tasks.wait_for_tasks(service_instance, [task]) except vmodl.MethodFault as error: print("Caught vmodl fault : " + error.msg) return -1 return 0
def main(): """ Simple command-line program for creating a first class disk. """ parser = cli.Parser() parser.add_required_arguments(cli.Argument.DATASTORE_NAME, cli.Argument.FIRST_CLASS_DISK_NAME) parser.add_optional_arguments(cli.Argument.STORAGE_POLICY_NAME) parser.add_custom_argument('--capacityInGB', required=True, action='store', type=int, help='Size in GB of the First Class Disk.') parser.add_custom_argument( '--keepAfterDeleteVm', action='store_true', help='Keep after VM deletion. Choice of the ' 'deletion behavior of this virtual storage object. ' 'If not set, the default value is false.') args = parser.get_args() si = service_instance.connect(args) try: content = si.RetrieveContent() # Connect to SPBM Endpoint pbm_si = pbmhelper.create_pbm_session(si._stub) pbm_content = pbm_si.RetrieveContent() # Retrieving Storage Policy if args.storage_policy_name: policy = pbmhelper.retrieve_storage_policy( pbm_content, args.storage_policy_name) else: policy = None # Retrieve Datastore Object datastore = pchelper.get_obj(content, [vim.Datastore], args.datastore_name) # Setting FCD Specifications spec = vim.vslm.CreateSpec() spec.name = args.fcd_name spec.capacityInMB = args.capacityInGB * 1024 if args.keepAfterDeleteVm: spec.keepAfterDeleteVm = True spec.backingSpec = vim.vslm.CreateSpec.DiskFileBackingSpec() spec.backingSpec.provisioningType = "thin" spec.backingSpec.datastore = datastore if policy: spec.profile = [ vim.vm.DefinedProfileSpec(profileId=policy.profileId.uniqueId) ] # Create FCD storage = content.vStorageObjectManager task = storage.CreateDisk_Task(spec) tasks.wait_for_tasks(si, [task]) print("FCD created!") except vmodl.MethodFault as error: print("Caught vmodl fault : " + error.msg) return -1 return 0
def main(): """ Simple command-line program for creating a new vdisk from a snapshot """ parser = cli.Parser() parser.add_required_arguments(cli.Argument.SNAPSHOT_NAME) parser.add_optional_arguments(cli.Argument.STORAGE_POLICY_NAME) parser.add_custom_argument( '--source_datastore', required=True, action='store', help='Datastore name where source disk is located') parser.add_custom_argument( '--source_vdisk', required=True, action='store', help='First Class Disk name with specified snapshot') parser.add_custom_argument('--dest_datastore', required=True, action='store', help='Datastore name where new disk is located') parser.add_custom_argument('--dest_vdisk', required=True, action='store', help='First Class Disk name to be created') args = parser.get_args() si = service_instance.connect(args) try: content = si.RetrieveContent() # Connect to SPBM Endpoint pbm_si = pbmhelper.create_pbm_session(si._stub) pbm_content = pbm_si.RetrieveContent() # Retrieving Storage Policy if args.storage_policy_name: storage_policy = pbmhelper.retrieve_storage_policy( pbm_content, args.storage_policy_name) policy = [ vim.vm.DefinedProfileSpec( profileId=storage_policy.profileId.uniqueId) ] else: policy = None # Retrieve Source Datastore Object source_datastore = pchelper.get_obj(content, [vim.Datastore], args.source_datastore) # Retrieve Source FCD Object source_vdisk = disk.retrieve_fcd(content, source_datastore, args.source_vdisk) # Retrieve Snapshot Object snapshot = disk.retrieve_fcd_snapshot(content, source_datastore, source_vdisk, args.snapshot_name) # Retrieve Destination Datastore Object dest_datastore = pchelper.get_obj(content, [vim.Datastore], args.dest_datastore) # Create FCD from Snapshot storage = content.vStorageObjectManager if policy: task = storage.CreateDiskFromSnapshot_Task(source_vdisk.config.id, dest_datastore, snapshot, args.dest_vdisk, policy) else: task = storage.CreateDiskFromSnapshot_Task(source_vdisk.config.id, dest_datastore, snapshot, args.dest_vdisk) tasks.wait_for_tasks(si, [task]) print("FCD created from snapshot!") except vmodl.MethodFault as error: print("Caught vmodl fault : " + error.msg) return -1 return 0