def do_host_bulk_export(cc, args): """Export host bulk configurations.""" result = cc.ihost.bulk_export() xml_content = result['content'] config_filename = './hosts.xml' if hasattr(args, 'filename') and args.filename: config_filename = args.filename try: with open(config_filename, 'wb') as fw: fw.write(xml_content) print(_('Export successfully to %s') % config_filename) except IOError: print(_('Cannot write to file: %s') % config_filename) return
'num_cores_on_processor2', 'num_cores_on_processor3' ] PLATFORM_CPU_TYPE = "Platform" VSWITCH_CPU_TYPE = "Vswitch" SHARED_CPU_TYPE = "Shared" APPLICATION_CPU_TYPE = "Application" ISOLATED_CPU_TYPE = "Application-isolated" NONE_CPU_TYPE = "None" CPU_TYPE_LIST = [ PLATFORM_CPU_TYPE, VSWITCH_CPU_TYPE, SHARED_CPU_TYPE, APPLICATION_CPU_TYPE, ISOLATED_CPU_TYPE, NONE_CPU_TYPE ] PLATFORM_CPU_TYPE_FORMAT = _("Platform") VSWITCH_CPU_TYPE_FORMAT = _("vSwitch") SHARED_CPU_TYPE_FORMAT = _("Shared") APPLICATION_CPU_TYPE_FORMAT = _("Application") ISOLATED_CPU_TYPE_FORMAT = _("Application-isolated") NONE_CPU_TYPE_FORMAT = _("None") CPU_TYPE_FORMATS = { PLATFORM_CPU_TYPE: PLATFORM_CPU_TYPE_FORMAT, VSWITCH_CPU_TYPE: VSWITCH_CPU_TYPE_FORMAT, SHARED_CPU_TYPE: SHARED_CPU_TYPE_FORMAT, APPLICATION_CPU_TYPE: APPLICATION_CPU_TYPE_FORMAT, ISOLATED_CPU_TYPE: ISOLATED_CPU_TYPE_FORMAT, NONE_CPU_TYPE: NONE_CPU_TYPE_FORMAT }
def get_client(api_version, **kwargs): """Get an authenticated client, based on the credentials in the keyword args. :param api_version: the API version to use ('1' or '2') :param kwargs: keyword args containing credentials, either: * os_auth_token: pre-existing token to re-use * system_url: system API endpoint or: * os_username: name of user * os_password: user's password * os_auth_url: endpoint to authenticate against * insecure: allow insecure SSL (no cert verification) * os_tenant_{name|id}: name or ID of tenant * os_region_name: region of the service * os_project_name: name of a project * os_project_id: ID of a project * os_user_domain_name: name of a domain the user belongs to * os_user_domain_id: ID of a domain the user belongs to * os_project_domain_name: name of a domain the project belongs to * os_project_domain_id: ID of a domain the project belongs to """ if kwargs.get('os_auth_token') and kwargs.get('system_url'): token = kwargs.get('os_auth_token') endpoint = kwargs.get('system_url') auth_ref = None elif (kwargs.get('os_username') and kwargs.get('os_password') and kwargs.get('os_auth_url') and (kwargs.get('os_project_id') or kwargs.get('os_project_name'))): ks_kwargs = { 'username': kwargs.get('os_username'), 'password': kwargs.get('os_password'), 'project_id': kwargs.get('os_project_id'), 'project_name': kwargs.get('os_project_name'), 'user_domain_id': kwargs.get('os_user_domain_id'), 'user_domain_name': kwargs.get('os_user_domain_name'), 'project_domain_id': kwargs.get('os_project_domain_id'), 'project_domain_name': kwargs.get('os_project_domain_name'), 'auth_url': kwargs.get('os_auth_url'), 'service_type': kwargs.get('os_service_type'), 'endpoint_type': kwargs.get('os_endpoint_type'), 'insecure': kwargs.get('insecure'), 'os_cacert': kwargs.get('ca_file') } _ksclient = _get_ksclient(**ks_kwargs) token = kwargs.get('os_auth_token') if kwargs.get( 'os_auth_token') else _ksclient.auth_ref.auth_token ep_kwargs = { 'service_type': kwargs.get('os_service_type'), 'endpoint_type': kwargs.get('os_endpoint_type'), 'os_region_name': kwargs.get('os_region_name'), } endpoint = kwargs.get('system_url') or \ _get_endpoint(_ksclient, **ep_kwargs) auth_ref = _ksclient.auth_ref else: e = (_('Must provide Keystone credentials or user-defined endpoint ' 'and token')) raise exc.AmbigiousAuthSystem(e) try: smapi_endpoint = _get_sm_endpoint(_ksclient, **ep_kwargs) except Exception: # Could be invoked during controller bootstrap where smapi # endpoint is not yet available. smapi_endpoint = None cli_kwargs = { 'token': token, 'insecure': kwargs.get('insecure'), 'cacert': kwargs.get('cacert'), 'timeout': kwargs.get('timeout'), 'ca_file': kwargs.get('ca_file'), 'cert_file': kwargs.get('cert_file'), 'key_file': kwargs.get('key_file'), 'auth_ref': auth_ref, 'auth_url': kwargs.get('os_auth_url'), 'smapi_endpoint': smapi_endpoint, } return Client(api_version, endpoint, **cli_kwargs)