def create_client(self, args): created_client = None endpoint_filter_kwargs = self._get_endpoint_filter_kwargs(args) api_version = args.os_identity_api_version if args.no_auth and args.os_auth_url: raise Exception( 'ERROR: argument --os-auth-url/-A: not allowed ' 'with argument --no-auth/-N' ) if args.no_auth: if not all([args.endpoint, args.os_tenant_id or args.os_project_id]): raise Exception( 'ERROR: please specify --endpoint and ' '--os-project-id (or --os-tenant-id)') created_client = client.Client( endpoint=args.endpoint, project_id=args.os_tenant_id or args.os_project_id, verify=not args.insecure, **endpoint_filter_kwargs ) # Token-based authentication elif args.os_auth_token: if not args.os_auth_url: raise Exception('ERROR: please specify --os-auth-url') token_kwargs = { 'auth_url': args.os_auth_url, 'token': args.os_auth_token } session = self.create_keystone_session( args, api_version, token_kwargs, auth_type='token' ) created_client = client.Client( session=session, endpoint=args.endpoint, **endpoint_filter_kwargs ) # Password-based authentication elif args.os_auth_url: password_kwargs = { 'auth_url': args.os_auth_url, 'password': args.os_password, 'user_id': args.os_user_id, 'username': args.os_username, } session = self.create_keystone_session( args, api_version, password_kwargs, auth_type='password' ) created_client = client.Client( session=session, endpoint=args.endpoint, **endpoint_filter_kwargs ) else: raise Exception('ERROR: please specify authentication credentials') return created_client
def main(): session = ksession.Session(auth=v3.Password(**CORIOLIS_CONNECTION_INFO)) coriolis = coriolis_client.Client(session=session) barbican = barbican_client.Client(session=session) # fetch and validate options for Azure: azure_schema = get_schema_for_plugin('coriolis', 'azure', 'source') # NOTE: this parameter validation is also done in any API # call involving the Azure source options: jsonschema.validate(AZURE_SOURCE_OPTIONS, azure_schema) # fetch and validate options schema for OCI: oci_schema = get_schema_for_plugin('coriolis', 'oci', 'destination') # NOTE: this parameter validation is also done in any API # call involving the OCI destination options: jsonschema.validate(OCI_DESTINATION_OPTIONS, oci_schema) # list all available options on source or target: azure_options = coriolis.endpoint_source_options.list( AZURE_ENDPOINT_ID, environment=AZURE_SOURCE_OPTIONS) print("Avaialble Azure options are: ", json.dumps(azure_options, indent=4)) oci_options = coriolis.endpoint_destination_options.list( OCI_ENDPOINT_ID, environment=OCI_DESTINATION_OPTIONS) print("Avaialble OCI options are: ", json.dumps(oci_options, indent=4)) # check all mapped networks and storage exist: check_mapped_networks_exist( coriolis, OCI_ENDPOINT_ID, NETWORK_MAP, destination_environment=OCI_DESTINATION_OPTIONS) check_mapped_storage_exists( coriolis, OCI_ENDPOINT_ID, NETWORK_MAP, destination_environment=OCI_DESTINATION_OPTIONS) # get list of Linux VMs off of Azure: azure_linux_vms = get_linux_vms_for_endpoint( coriolis, AZURE_ENDPOINT_ID, source_options=AZURE_SOURCE_OPTIONS) print("Linux VMs currently on Azure: %s" % azure_linux_vms) # check network mapping: if azure_linux_vms: vm_name = azure_linux_vms[0].instance_name check_vm_network_mapping(coriolis, AZURE_ENDPOINT_ID, vm_name, NETWORK_MAP, source_options=AZURE_SOURCE_OPTIONS)
def main(): session = ksession.Session( auth=v3.Password(**CORIOLIS_CONNECTION_INFO)) coriolis = coriolis_client.Client(session=session) # see how may Replicas from Azure we already have: azure_replicas = get_replicas_for_endpoint( coriolis, AZURE_ENDPOINT_ID, as_source=True, as_target=False) print( "Existing Azure Replicas for endpoint '%s': %s" % ( AZURE_ENDPOINT_ID, azure_replicas)) # create a Replica: replicas = create_vm_replicas( coriolis, AZURE_ENDPOINT_ID, OCI_ENDPOINT_ID, AZURE_SOURCE_OPTIONS, OCI_DESTINATION_OPTIONS, NETWORK_MAP, STORAGE_MAPPINGS, [SOURCE_VM_NAME]) # execute the Replica: test_replica = replicas[0] execution = coriolis.replica_executions.create( test_replica, shutdown_instances=True) # wait for execution to finish: wait_for_replica_execution(coriolis, test_replica, execution) # create a Migration from the Replica: migration = coriolis.migrations.create_from_replica( test_replica.id, clone_disks=True, skip_os_morphing=False) migration = wait_for_replica_migration(coriolis, migration) print("Migrated VM info is: %s" % ( json.dumps(migration.transfer_result.to_dict(), indent=4))) # delete the Migration (this has *NO* effect on the migrated VM(s)) coriolis.migrations.delete(migration) # delete the Replica once done: delete_replica(coriolis, test_replica, delete_replica_disks=True)
def get_coriolis_client(): conn_info = get_conn_info_for_group(constants.CORIOLIS_OPT_GROUP_NAME) session = openstack_client.create_keystone_session(conn_info) return coriolis_client.Client(session=session)