def create(context, conf, **kwargs): conf.register_opts(manila_client_opts, group=CONFIG_GROUP) client_config = conf[CONFIG_GROUP] url = utils.get_url(SERVICE, context, client_config, append_project_fmt='%(url)s/%(project)s', **kwargs) LOG.debug('Creating manila client with url %s.', url) if kwargs.get('session'): return mc.Client(MANILACLIENT_VERSION, session=kwargs.get('session'), endpoint_override=url) args = { 'input_auth_token': context.auth_token, 'project_id': context.project_id, 'service_catalog_url': url, 'cacert': client_config.manila_ca_cert_file, 'insecure': client_config.manila_auth_insecure, } client = mc.Client(MANILACLIENT_VERSION, **args) client.client.auth_token = context.auth_token client.client.management_url = url return client
def setUpClass(cls): """Run class setup for running tests.""" super(ManilaGaneshaTests, cls).setUpClass() cls.nova_client = ( openstack_utils.get_nova_session_client(cls.keystone_session)) cls.manila_client = manilaclient.Client( session=cls.keystone_session, client_version='2')
def _discover_client(self, current_client, os_api_version, os_endpoint_type, os_service_type, client_args): if os_api_version == manilaclient.API_DEPRECATED_VERSION: discovered_version = manilaclient.API_DEPRECATED_VERSION os_service_type = constants.V1_SERVICE_TYPE else: discovered_version = api_versions.discover_version( current_client, os_api_version ) if not os_endpoint_type: os_endpoint_type = DEFAULT_MANILA_ENDPOINT_TYPE if not os_service_type: os_service_type = self._discover_service_type(discovered_version) if (discovered_version != manilaclient.API_MAX_VERSION or os_service_type != constants.V1_SERVICE_TYPE or os_endpoint_type != DEFAULT_MANILA_ENDPOINT_TYPE): client_args['version'] = discovered_version client_args['service_type'] = os_service_type client_args['endpoint_type'] = os_endpoint_type return (client.Client(discovered_version, **client_args), discovered_version) else: return current_client, discovered_version
def create_manila_client(config_file, version="2.7"): """ Parse config file and create manila client :param string config_file: :return client.Client manila: manila client """ try: parser = configparser.ConfigParser() parser.read(config_file) auth_url = parser.get('keystone_authtoken', 'www_authenticate_uri') username = parser.get('keystone_authtoken', 'username') password = parser.get('keystone_authtoken', 'password') user_domain = parser.get('keystone_authtoken', 'user_domain_name') prj_domain = parser.get('keystone_authtoken', 'project_domain_name') prj_name = parser.get('keystone_authtoken', 'project_name') except Exception as e: print(f"ERROR: Parse {config_file}: " + str(e)) sys.exit(2) auth = v3.Password( username=username, password=password, user_domain_name=user_domain, project_domain_name=prj_domain, project_name=prj_name, auth_url=auth_url, ) sess = session.Session(auth=auth) manila = client.Client(version, session=sess) return manila
def manilaclient(request): insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) manila_url = "" try: manila_url = base.url_for(request, MANILA_SERVICE_TYPE) except exceptions.ServiceCatalogException: LOG.debug('no share service configured.') return None LOG.debug('manilaclient connection created using token "%s" and url "%s"' % (request.user.token.id, manila_url)) c = manila_client.Client( MANILA_VERSION, username=request.user.username, input_auth_token=request.user.token.id, project_id=request.user.tenant_id, service_catalog_url=manila_url, insecure=insecure, cacert=cacert, http_log_debug=settings.DEBUG, user_agent=MANILA_UI_USER_AGENT_REPR, ) c.client.auth_token = request.user.token.id c.client.management_url = manila_url return c
def get_manila_client_from_env(): # We should catch KeyError exception with the purpose of # source or configure openrc file. auth_url = os.environ['OS_AUTH_URL'] username = os.environ['OS_USERNAME'] password = os.environ['OS_PASSWORD'] project_name = os.environ['OS_PROJECT_NAME'] # Either project(user)_domain_name or project(user)_domain_id # would be acceptable. project_domain_name = os.environ.get("OS_PROJECT_DOMAIN_NAME") project_domain_id = os.environ.get("OS_PROJECT_DOMAIN_ID") user_domain_name = os.environ.get("OS_USER_DOMAIN_NAME") user_domain_id = os.environ.get("OS_USER_DOMAIN_ID") auth = identity.Password(auth_url=auth_url, username=username, password=password, project_name=project_name, project_domain_id=project_domain_id, project_domain_name=project_domain_name, user_domain_id=user_domain_id, user_domain_name=user_domain_name) session = ks.Session(auth=auth) return manila_client.Client(session=session, client_version='2')
def __init__(self, client_version: str = '2.0', keystone_version: str = 'v2'): """ Get the Keystone credentials and use them to create the Manila client. :param client_version: The version of the Manila Client to use as a string (e.g. '2.0') :param keystone_version: The version of the Keystone API to use for authentication. """ keystone_credentials = keystone.keystone_retrieve(version=keystone_version) self.manila_session = client.Client(client_version, *keystone_credentials)
def create_client(self, version=None, service_type=None): """Return manila client.""" from manilaclient import client as manila manila_client = manila.Client( self.choose_version(version), session=self.keystone.get_session()[0], service_catalog_url=self._get_endpoint(service_type)) return manila_client
def _create(self): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { 'endpoint_type': endpoint_type, 'service_type': self.SHARE, 'session': self.context.keystone_session } client = manila_client.Client(MANILACLIENT_VERSION, **args) return client
def _create(self): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { 'endpoint_type': endpoint_type, 'service_type': self.SHARE, 'session': self.context.keystone_session, 'connect_retries': cfg.CONF.client_retry_limit, 'region_name': self._get_region_name() } client = manila_client.Client(MANILACLIENT_VERSION, **args) return client
def setUpClass(cls): """Run class setup for running tests.""" super(ManilaBaseTest, cls).setUpClass() cls.nova_client = openstack_utils.get_nova_session_client( session=cls.keystone_session) cls.manila_client = manilaclient.Client(session=cls.keystone_session, client_version='2') cls.share_name = 'test-manila-share' cls.share_type_name = 'default_share_type' cls.share_protocol = 'nfs' cls.mount_dir = '/mnt/manila_share' cls.share_network = None
def _create(self): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') endpoint = self.url_for(service_type=self.SHARE, endpoint_type=endpoint_type) args = { 'service_catalog_url': endpoint, 'input_auth_token': self.auth_token } client = manila_client.Client(MANILACLIENT_VERSION, **args) return client
def setup_ganesha_share_type(manila_client=None): if manila_client is None: keystone_session = openstack_utils.get_overcloud_keystone_session() manila_client = manilaclient.Client(session=keystone_session, client_version='2') manila_client.share_types.create(name="cephfsnfstype", spec_driver_handles_share_servers=False, extra_specs={ 'vendor_name': 'Ceph', 'storage_protocol': 'NFS', 'snapshot_support': False, })
def client(): ctx = context.ctx() args = { 'username': ctx.username, 'project_name': ctx.tenant_name, 'project_id': ctx.tenant_id, 'input_auth_token': ctx.auth_token, 'auth_url': base.retrieve_auth_url(), 'service_catalog_url': base.url_for(ctx.service_catalog, 'share'), 'ca_cert': CONF.manila.ca_file, 'insecure': CONF.manila.api_insecure } return manila_client.Client(CONF.manila.api_version, **args)
def create_client(self, version=None, service_type=None): """Return manila client.""" from manilaclient import client as manila manila_client = manila.Client( self.choose_version(version), region_name=self.credential.region_name, http_log_debug=logging.is_debug(), timeout=CONF.openstack_client_http_timeout, insecure=self.credential.insecure, **self._get_auth_info(password_key="api_key", project_name_key="project_name")) manila_client.client.management_url = self._get_endpoint(service_type) manila_client.client.auth_token = self.keystone.auth_ref.auth_token return manila_client
def setup_ganesha_share_type(manila_client=None): """Create a share type for manila with Ganesha. :param manila_client: Authenticated manilaclient :type manila_client: manilaclient.Client """ if manila_client is None: keystone_session = openstack_utils.get_overcloud_keystone_session() manila_client = manilaclient.Client( session=keystone_session, client_version='2') manila_client.share_types.create( name=MANILA_GANESHA_TYPE_NAME, spec_driver_handles_share_servers=False, extra_specs={ 'vendor_name': 'Ceph', 'storage_protocol': 'NFS', 'snapshot_support': False, })
def manila(self, version="1"): """Return manila client.""" from manilaclient import client as manila manila_client = manila.Client( version, region_name=self.endpoint.region_name, http_log_debug=logging.is_debug(), timeout=CONF.openstack_client_http_timeout, insecure=self.endpoint.insecure, cacert=self.endpoint.cacert, **self._get_auth_info(password_key="api_key", project_name_key="project_name")) kc = self.keystone() manila_client.client.management_url = kc.service_catalog.url_for( service_type="share", endpoint_type=self.endpoint.endpoint_type, region_name=self.endpoint.region_name) manila_client.client.auth_token = kc.auth_token return manila_client
def get_manilaclient(*args, **kwargs): session, auth_plugin = get_keystone_session(config.manila_group.name) return manila_client.Client(session=session, auth=auth_plugin, region_name=CONF.manila.region_name, client_version='2')
def get_manila_client_from_creds(): auth_plugin, session = _get_cloud_config_auth_data() return manila_client.Client(session=session, auth=auth_plugin, client_version='2')
def main(self, argv): # Parse args once to find version and debug settings parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self.setup_debugging(options.debug) # build available subcommands based on version self.extensions = self._discover_extensions( options.os_share_api_version) self._run_extension_hooks('__pre_parse_args__') subcommand_parser = self.get_subcommand_parser( options.os_share_api_version) self.parser = subcommand_parser if options.help or not argv: subcommand_parser.print_help() return 0 args = subcommand_parser.parse_args(argv) self._run_extension_hooks('__post_parse_args__', args) # Short-circuit and deal with help right away. if args.func == self.do_help: self.do_help(args) return 0 elif args.func == self.do_bash_completion: self.do_bash_completion(args) return 0 (os_username, os_password, os_tenant_name, os_auth_url, os_region_name, os_tenant_id, endpoint_type, insecure, service_type, service_name, share_service_name, username, apikey, projectid, url, region_name, cacert) = (args.os_username, args.os_password, args.os_tenant_name, args.os_auth_url, args.os_region_name, args.os_tenant_id, args.endpoint_type, args.insecure, args.service_type, args.service_name, args.share_service_name, args.username, args.apikey, args.projectid, args.url, args.region_name, args.os_cacert) if not endpoint_type: endpoint_type = DEFAULT_MANILA_ENDPOINT_TYPE if not service_type: service_type = DEFAULT_MANILA_SERVICE_TYPE service_type = utils.get_service_type(args.func) or service_type #FIXME(usrleon): Here should be restrict for project id same as # for os_username or os_password but for compatibility it is not. if not utils.isunauthenticated(args.func): if not os_username: if not username: raise exc.CommandError( "You must provide a username " "via either --os-username or env[OS_USERNAME]") else: os_username = username if not os_password: if not apikey: raise exc.CommandError("You must provide a password " "via either --os-password or via " "env[OS_PASSWORD]") else: os_password = apikey if not (os_tenant_name or os_tenant_id): if not projectid: raise exc.CommandError("You must provide a tenant_id " "via either --os-tenant-id or " "env[OS_TENANT_ID]") else: os_tenant_name = projectid if not os_auth_url: if not url: raise exc.CommandError( "You must provide an auth url " "via either --os-auth-url or env[OS_AUTH_URL]") else: os_auth_url = url if not os_region_name and region_name: os_region_name = region_name if not (os_tenant_name or os_tenant_id): raise exc.CommandError( "You must provide a tenant_id " "via either --os-tenant-id or env[OS_TENANT_ID]") if not os_auth_url: raise exc.CommandError( "You must provide an auth url " "via either --os-auth-url or env[OS_AUTH_URL]") self.cs = client.Client(options.os_share_api_version, os_username, os_password, os_tenant_name, os_auth_url, insecure, region_name=os_region_name, tenant_id=os_tenant_id, endpoint_type=endpoint_type, extensions=self.extensions, service_type=service_type, service_name=service_name, share_service_name=share_service_name, retries=options.retries, http_log_debug=args.debug, cacert=cacert) try: if not utils.isunauthenticated(args.func): self.cs.authenticate() except exc.Unauthorized: raise exc.CommandError("Invalid OpenStack Manila credentials.") except exc.AuthorizationFailure: raise exc.CommandError("Unable to authorize user") args.func(self.cs, args)
def _get_manila_client(api_version='2'): kwargs = _get_client_args('sharev2') client = manilaclient.Client(api_version, **kwargs) return client
def main(self, argv): # Parse args once to find version and debug settings parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self.setup_debugging(options.debug) os_api_version = self._validate_input_api_version(options) # build available subcommands based on version args = self._build_subcommands_and_extensions(os_api_version, argv, options) if not args: return 0 # Short-circuit and deal with help right away. if args.func == self.do_help: self.do_help(args) return 0 elif args.func == self.do_bash_completion: self.do_bash_completion(args) return 0 os_service_type = args.service_type os_endpoint_type = args.endpoint_type client_args = dict( username=args.os_username, password=args.os_password, project_name=args.os_project_name or args.os_tenant_name, auth_url=args.os_auth_url, insecure=args.insecure, region_name=args.os_region_name, tenant_id=args.os_project_id or args.os_tenant_id, endpoint_type=DEFAULT_MANILA_ENDPOINT_TYPE, extensions=self.extensions, service_type=constants.V1_SERVICE_TYPE, service_name=args.service_name, retries=options.retries, http_log_debug=args.debug, cacert=args.os_cacert, use_keyring=args.os_cache, force_new_token=args.os_reset_cache, user_id=args.os_user_id, user_domain_id=args.os_user_domain_id, user_domain_name=args.os_user_domain_name, project_domain_id=args.os_project_domain_id, project_domain_name=args.os_project_domain_name, cert=args.os_cert, input_auth_token=args.os_token, service_catalog_url=args.bypass_url, ) # Handle deprecated parameters if args.share_service_name: client_args['share_service_name'] = args.share_service_name self._validate_required_options( args.os_tenant_name, args.os_tenant_id, args.os_project_name, args.os_project_id, args.os_token, args.bypass_url, client_args['auth_url']) # This client is needed to discover the server api version. temp_client = client.Client(manilaclient.API_MAX_VERSION, **client_args) self.cs, discovered_version = self._discover_client(temp_client, os_api_version, os_endpoint_type, os_service_type, client_args) args = self._build_subcommands_and_extensions(discovered_version, argv, options) args.func(self.cs, args)
def setUpClass(cls): """Run class setup for running tests.""" super(ManilaTests, cls).setUpClass() cls.manila_client = manilaclient.Client(session=cls.keystone_session, client_version='2')
def main(self, argv): # Parse args once to find version and debug settings parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self.setup_debugging(options.debug) os_api_version = self._validate_input_api_version(options) # build available subcommands based on version args = self._build_subcommands_and_extensions(os_api_version, argv, options) if not args: return 0 # Short-circuit and deal with help right away. if args.func == self.do_help: self.do_help(args) return 0 elif args.func == self.do_bash_completion: self.do_bash_completion(args) return 0 if not options.os_share_api_version: api_version = api_versions.get_api_version( DEFAULT_MAJOR_OS_SHARE_API_VERSION) else: api_version = api_versions.get_api_version( options.os_share_api_version) major_version_string = six.text_type(api_version.ver_major) os_service_type = args.service_type if not os_service_type: os_service_type = constants.SERVICE_TYPES[major_version_string] os_endpoint_type = args.endpoint_type or DEFAULT_MANILA_ENDPOINT_TYPE client_args = dict( username=args.os_username, password=args.os_password, project_name=args.os_project_name or args.os_tenant_name, auth_url=args.os_auth_url, insecure=args.insecure, region_name=args.os_region_name, tenant_id=args.os_project_id or args.os_tenant_id, endpoint_type=os_endpoint_type, extensions=self.extensions, service_type=os_service_type, service_name=args.service_name, retries=options.retries, http_log_debug=args.debug, cacert=args.os_cacert, use_keyring=args.os_cache, force_new_token=args.os_reset_cache, user_id=args.os_user_id, user_domain_id=args.os_user_domain_id, user_domain_name=args.os_user_domain_name, project_domain_id=args.os_project_domain_id, project_domain_name=args.os_project_domain_name, cert=args.os_cert, input_auth_token=args.os_token, service_catalog_url=args.bypass_url, ) # Handle deprecated parameters if args.share_service_name: client_args['share_service_name'] = args.share_service_name self._validate_required_options(args.os_tenant_name, args.os_tenant_id, args.os_project_name, args.os_project_id, args.os_token, args.bypass_url, client_args['auth_url']) # This client is needed to discover the server api version. temp_client = client.Client(manilaclient.API_MAX_VERSION, **client_args) self.cs, discovered_version = self._discover_client( temp_client, os_api_version, os_endpoint_type, os_service_type, client_args) args = self._build_subcommands_and_extensions(discovered_version, argv, options) profile = osprofiler_profiler and options.profile if profile: osprofiler_profiler.init(options.profile) args.func(self.cs, args) if profile: trace_id = osprofiler_profiler.get().get_base_id() print("Profiling trace ID: %s" % trace_id) print("To display trace use next command:\n" "osprofiler trace show --html %s " % trace_id)
username = user_name user_domain_name = domain_nameks project_name = project_nameks project_domain_name = domain_nameks password = passwordvpc auth = v3.Password(auth_url=auth_url, username=username, password=password, project_domain_name=project_domain_name, project_name=project_name, user_domain_name=user_domain_name) sess = session.Session(auth=auth) keystone = client.Client(session=sess) sess = session.Session(auth=auth) try: manilac = mclient.Client(VERSION, session=sess) print "Checking under Domain " + domain_nameks + " " + project_name + " \n" except: print "\n Note: Domain " + domain_nameks + " " + project_name + " is non expiry! \n " continue def offline_share(netapp_name, manilaid, svmname): umount_cmd = "python " + filepath + "/apitest.py -v " + svmname + " " + netapp_url + " " + netapp_user + " " + netapp_passwd + " volume-unmount force true volume-name " + netapp_name offline_cmd = "python " + filepath + "/apitest.py -v " + svmname + " " + netapp_url + " " + netapp_user + " " + netapp_passwd + " volume-offline name " + netapp_name try: os.system(umount_cmd) os.system(offline_cmd) return "success" except: print "\tError trying to offline Share " + netapp_name + " " + manilaid return "failed"