def _get_vnic_profile_mappings(module): vnicProfileMappings = list() for vnicProfileMapping in module.params['vnic_profile_mappings']: vnicProfileMappings.append( otypes.VnicProfileMapping( source_network_name=vnicProfileMapping['source_network_name'], source_network_profile_name=vnicProfileMapping[ 'source_profile_name'], target_vnic_profile=otypes.VnicProfile( id=vnicProfileMapping['target_profile_id'], ) if vnicProfileMapping['target_profile_id'] else None, )) return vnicProfileMappings
# the action methods are defined: storage_domain_service = storage_domains_service.storage_domain_service(sd.id) # Locate the service that manages the VMs in storage domain: vms_service = storage_domain_service.vms_service() # Find the the unregistered VM we want to register: vms = vms_service.list(unregistered=True) vm = next((v for v in vms if v.name == 'myvm'), None) # Locate the service that manages virtual machine in the storage domain, # as that is where the action methods are defined: vm_service = vms_service.vm_service(vm.id) # Register the VM into the system: vm = vm_service.register( cluster=types.Cluster(name='mycluster', ), vm=types.Vm(name='exported_myvm', ), vnic_profile_mappings=[ types.VnicProfileMapping( source_network_name='mynetwork', source_network_profile_name='mynetwork', target_vnic_profile=types.VnicProfile(name='mynetwork', ), ), ], reassign_bad_macs=True, ) # Close the connection to the server: connection.close()