def _old_init(self, username, project_id, auth_url, region_name, password, os_auth_plugin, **kwargs): self.kwargs = kwargs.copy() if not self.extensions: if hasattr(OpenStackComputeShell, '_discover_extensions'): self.extensions = OpenStackComputeShell()._discover_extensions( '2.0') else: self.extensions = client.discover_extensions('2.0') for extension in self.extensions: extension.run_hooks('__pre_parse_args__') self.kwargs['extensions'] = self.extensions self.kwargs['username'] = username self.kwargs['project_id'] = project_id self.kwargs['auth_url'] = auth_url self.kwargs['region_name'] = region_name self.kwargs['service_type'] = 'compute' # used in novaclient extensions to see if they are rackspace or not, to know if it needs to load # the hooks for that extension or not. This is cleaned up by sanatize_novaclient self.kwargs['os_auth_url'] = auth_url if os_auth_plugin is not None: novaclient.auth_plugin.discover_auth_systems() auth_plugin = novaclient.auth_plugin.load_plugin(os_auth_plugin) self.kwargs['auth_plugin'] = auth_plugin self.kwargs['auth_system'] = os_auth_plugin if not self.kwargs.get('api_key', None): self.kwargs['api_key'] = password # This has to be run before sanatize_novaclient before extra variables are cleaned out. if hasattr(self, 'extensions'): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.kwargs) for extension in self.extensions: extension.run_hooks('__post_parse_args__', self.kwargstruct) self.kwargs = self.kwargstruct.__dict__ self.kwargs = sanatize_novaclient(self.kwargs) # Requires novaclient version >= 2.6.1 self.kwargs['version'] = six.text_type(kwargs.get('version', 2)) conn = client.Client(**self.kwargs) try: conn.client.authenticate() except novaclient.exceptions.AmbiguousEndpoints: raise SaltCloudSystemExit( "Nova provider requires a 'region_name' to be specified") self.kwargs['auth_token'] = conn.client.auth_token self.catalog = conn.client.service_catalog.catalog['access'][ 'serviceCatalog'] self._v2_setup(region_name)
def _new_init(self, username, project_id, auth_url, region_name, password, os_auth_plugin, auth=None, verify=True, **kwargs): if auth is None: auth = {} loader = keystoneauth1.loading.get_plugin_loader(os_auth_plugin or 'password') self.client_kwargs = kwargs.copy() self.kwargs = auth.copy() if not self.extensions: if hasattr(OpenStackComputeShell, '_discover_extensions'): self.extensions = OpenStackComputeShell()._discover_extensions('2.0') else: self.extensions = client.discover_extensions('2.0') for extension in self.extensions: extension.run_hooks('__pre_parse_args__') self.client_kwargs['extensions'] = self.extensions self.kwargs['username'] = username self.kwargs['project_name'] = project_id self.kwargs['auth_url'] = auth_url self.kwargs['password'] = password if auth_url.endswith('3'): self.kwargs['user_domain_name'] = kwargs.get('user_domain_name', 'default') self.kwargs['project_domain_name'] = kwargs.get('project_domain_name', 'default') self.client_kwargs['region_name'] = region_name self.client_kwargs['service_type'] = 'compute' if hasattr(self, 'extensions'): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.client_kwargs) for extension in self.extensions: extension.run_hooks('__post_parse_args__', self.kwargstruct) self.client_kwargs = self.kwargstruct.__dict__ # Requires novaclient version >= 2.6.1 self.version = str(kwargs.get('version', 2)) self.client_kwargs = sanatize_novaclient(self.client_kwargs) options = loader.load_from_options(**self.kwargs) self.session = keystoneauth1.session.Session(auth=options, verify=verify) conn = client.Client(version=self.version, session=self.session, **self.client_kwargs) self.kwargs['auth_token'] = conn.client.session.get_token() identity_service_type = kwargs.get('identity_service_type', 'identity') self.catalog = conn.client.session.get('/auth/catalog', endpoint_filter={'service_type': identity_service_type}).json().get('catalog', []) if conn.client.get_endpoint(service_type=identity_service_type).endswith('v3'): self._v3_setup(region_name) else: self._v2_setup(region_name)
def _run_extension_hooks(self, hook_type, *args, **kwargs): """Run hooks for all registered extensions.""" for extension in self.extensions: extension.run_hooks(hook_type, *args, **kwargs)
def _new_init(self, username, project_id, auth_url, region_name, password, os_auth_plugin, auth=None, verify=True, **kwargs): if auth is None: auth = {} loader = keystoneauth1.loading.get_plugin_loader(os_auth_plugin or "password") self.client_kwargs = kwargs.copy() self.kwargs = auth.copy() if not self.extensions: if hasattr(OpenStackComputeShell, "_discover_extensions"): self.extensions = OpenStackComputeShell()._discover_extensions( "2.0") else: self.extensions = client.discover_extensions("2.0") for extension in self.extensions: extension.run_hooks("__pre_parse_args__") self.client_kwargs["extensions"] = self.extensions self.kwargs["username"] = username self.kwargs["project_name"] = project_id self.kwargs["auth_url"] = auth_url self.kwargs["password"] = password if auth_url.endswith("3"): self.kwargs["user_domain_name"] = kwargs.get( "user_domain_name", "default") self.kwargs["project_domain_name"] = kwargs.get( "project_domain_name", "default") self.client_kwargs["region_name"] = region_name self.client_kwargs["service_type"] = "compute" if hasattr(self, "extensions"): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.client_kwargs) for extension in self.extensions: extension.run_hooks("__post_parse_args__", self.kwargstruct) self.client_kwargs = self.kwargstruct.__dict__ # Requires novaclient version >= 2.6.1 self.version = str(kwargs.get("version", 2)) self.client_kwargs = sanatize_novaclient(self.client_kwargs) options = loader.load_from_options(**self.kwargs) self.session = keystoneauth1.session.Session(auth=options, verify=verify) conn = client.Client(version=self.version, session=self.session, **self.client_kwargs) self.kwargs["auth_token"] = conn.client.session.get_token() identity_service_type = kwargs.get("identity_service_type", "identity") self.catalog = (conn.client.session.get("/auth/catalog", endpoint_filter={ "service_type": identity_service_type }).json().get("catalog", [])) if conn.client.get_endpoint( service_type=identity_service_type).endswith("v3"): self._v3_setup(region_name) else: self._v2_setup(region_name)
def __init__(self, username, project_id, auth_url, region_name=None, password=None, os_auth_plugin=None, **kwargs): ''' Set up nova credentials ''' if not HAS_NOVA: return None self.kwargs = kwargs.copy() if not novaclient.base.Manager._hooks_map: self.extensions = self._discover_extensions('1.1') for extension in self.extensions: extension.run_hooks('__pre_parse_args__') self.kwargs['extensions'] = self.extensions self.kwargs['username'] = username self.kwargs['project_id'] = project_id self.kwargs['auth_url'] = auth_url self.kwargs['region_name'] = region_name self.kwargs['service_type'] = 'compute' # used in novaclient extensions to see if they are rackspace or not, to know if it needs to load # the hooks for that extension or not. This is cleaned up by sanatize_novaclient self.kwargs['os_auth_url'] = auth_url if os_auth_plugin is not None: novaclient.auth_plugin.discover_auth_systems() auth_plugin = novaclient.auth_plugin.load_plugin(os_auth_plugin) self.kwargs['auth_plugin'] = auth_plugin self.kwargs['auth_system'] = os_auth_plugin if not self.kwargs.get('api_key', None): self.kwargs['api_key'] = password # This has to be run before sanatize_novaclient before extra variables are cleaned out. if hasattr(self, 'extensions'): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.kwargs) for extension in self.extensions: extension.run_hooks('__post_parse_args__', self.kwargstruct) self.kwargs = self.kwargstruct.__dict__ self.kwargs = sanatize_novaclient(self.kwargs) if not hasattr(client.Client, '__exit__'): raise SaltCloudSystemExit( "Newer version of novaclient required for __exit__.") with client.Client(**self.kwargs) as conn: try: conn.client.authenticate() except novaclient.exceptions.AmbiguousEndpoints: raise SaltCloudSystemExit( "Nova provider requires a 'region_name' to be specified") self.kwargs['auth_token'] = conn.client.auth_token self.catalog = \ conn.client.service_catalog.catalog['access']['serviceCatalog'] if region_name is not None: servers_endpoints = get_entry(self.catalog, 'type', 'compute')['endpoints'] self.kwargs['bypass_url'] = get_entry(servers_endpoints, 'region', region_name)['publicURL'] self.compute_conn = client.Client(**self.kwargs) volume_endpoints = get_entry(self.catalog, 'type', 'volume', raise_error=False).get('endpoints', {}) if volume_endpoints: if region_name is not None: self.kwargs['bypass_url'] = get_entry(volume_endpoints, 'region', region_name)['publicURL'] self.volume_conn = client.Client(**self.kwargs) if hasattr(self, 'extensions'): self.expand_extensions() else: self.volume_conn = None
def __init__( self, username, project_id, auth_url, region_name=None, password=None, os_auth_plugin=None, **kwargs ): ''' Set up nova credentials ''' self.kwargs = kwargs.copy() if not self.extensions: if hasattr(OpenStackComputeShell, '_discover_extensions'): self.extensions = OpenStackComputeShell()._discover_extensions('2.0') else: self.extensions = client.discover_extensions('2.0') for extension in self.extensions: extension.run_hooks('__pre_parse_args__') self.kwargs['extensions'] = self.extensions self.kwargs['username'] = username self.kwargs['project_id'] = project_id self.kwargs['auth_url'] = auth_url self.kwargs['region_name'] = region_name self.kwargs['service_type'] = 'compute' # used in novaclient extensions to see if they are rackspace or not, to know if it needs to load # the hooks for that extension or not. This is cleaned up by sanatize_novaclient self.kwargs['os_auth_url'] = auth_url if os_auth_plugin is not None: novaclient.auth_plugin.discover_auth_systems() auth_plugin = novaclient.auth_plugin.load_plugin(os_auth_plugin) self.kwargs['auth_plugin'] = auth_plugin self.kwargs['auth_system'] = os_auth_plugin if not self.kwargs.get('api_key', None): self.kwargs['api_key'] = password # This has to be run before sanatize_novaclient before extra variables are cleaned out. if hasattr(self, 'extensions'): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.kwargs) for extension in self.extensions: extension.run_hooks('__post_parse_args__', self.kwargstruct) self.kwargs = self.kwargstruct.__dict__ self.kwargs = sanatize_novaclient(self.kwargs) # Requires novaclient version >= 2.6.1 self.kwargs['version'] = str(kwargs.get('version', 2)) conn = client.Client(**self.kwargs) try: conn.client.authenticate() except novaclient.exceptions.AmbiguousEndpoints: raise SaltCloudSystemExit( "Nova provider requires a 'region_name' to be specified" ) self.kwargs['auth_token'] = conn.client.auth_token self.catalog = conn.client.service_catalog.catalog['access']['serviceCatalog'] if region_name is not None: servers_endpoints = get_entry(self.catalog, 'type', 'compute')['endpoints'] self.kwargs['bypass_url'] = get_entry( servers_endpoints, 'region', region_name )['publicURL'] self.compute_conn = client.Client(**self.kwargs) volume_endpoints = get_entry(self.catalog, 'type', 'volume', raise_error=False).get('endpoints', {}) if volume_endpoints: if region_name is not None: self.kwargs['bypass_url'] = get_entry( volume_endpoints, 'region', region_name )['publicURL'] self.volume_conn = client.Client(**self.kwargs) if hasattr(self, 'extensions'): self.expand_extensions() else: self.volume_conn = None
def _new_init(self, username, project_id, auth_url, region_name, password, os_auth_plugin, auth=None, **kwargs): if auth is None: auth = {} ks_version = self._get_version_from_url(auth_url) if not ks_version: ks_version = self._discover_ks_version(auth_url) auth_url = '{0}/{1}'.format(auth_url, ks_version) loader = keystoneauth1.loading.get_plugin_loader(os_auth_plugin or 'password') self.client_kwargs = kwargs.copy() self.kwargs = auth.copy() if not self.extensions: if hasattr(OpenStackComputeShell, "_discover_extensions"): self.extensions = OpenStackComputeShell()._discover_extensions("2.0") else: self.extensions = client.discover_extensions("2.0") for extension in self.extensions: extension.run_hooks('__pre_parse_args__') self.client_kwargs['extensions'] = self.extensions self.kwargs['username'] = username self.kwargs['project_name'] = project_id self.kwargs['auth_url'] = auth_url self.kwargs['password'] = password if ks_version == 'v3': self.kwargs['project_id'] = kwargs.get('project_id') self.kwargs['project_name'] = kwargs.get('project_name') self.kwargs['user_domain_name'] = kwargs.get('user_domain_name', 'default') self.kwargs['project_domain_name'] = kwargs.get('project_domain_name', 'default') self.client_kwargs["region_name"] = region_name self.client_kwargs["service_type"] = "compute" if hasattr(self, "extensions"): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.client_kwargs) for extension in self.extensions: extension.run_hooks("__post_parse_args__", self.kwargstruct) self.client_kwargs = self.kwargstruct.__dict__ # Requires novaclient version >= 2.6.1 self.version = six.text_type(kwargs.get("version", 2)) self.client_kwargs = sanatize_novaclient(self.client_kwargs) options = loader.load_from_options(**self.kwargs) self.session = keystoneauth1.session.Session(auth=options) conn = client.Client(version=self.version, session=self.session, **self.client_kwargs) self.kwargs['auth_token'] = conn.client.session.get_token() identity_service_type = kwargs.get('identity_service_type', 'identity') self.catalog = conn.client.session.get('/' + ks_version + '/auth/catalog', endpoint_filter={'service_type': identity_service_type} ).json().get('catalog', []) for ep_type in self.catalog: if ep_type['type'] == identity_service_type: for ep_id in ep_type['endpoints']: ep_ks_version = self._get_version_from_url(ep_id['url']) if not ep_ks_version: ep_id['url'] = '{0}/{1}'.format(ep_id['url'], ks_version) if ks_version == 'v3': self._v3_setup(region_name) else: self._v2_setup(region_name)
def __init__(self, username, project_id, auth_url, region_name=None, password=None, os_auth_plugin=None, **kwargs): """ Set up nova credentials """ if not HAS_NOVA: return None self.kwargs = kwargs.copy() if not novaclient.base.Manager._hooks_map: self.extensions = self._discover_extensions("1.1") for extension in self.extensions: extension.run_hooks("__pre_parse_args__") self.kwargs["extensions"] = self.extensions self.kwargs["username"] = username self.kwargs["project_id"] = project_id self.kwargs["auth_url"] = auth_url self.kwargs["region_name"] = region_name self.kwargs["service_type"] = "compute" # used in novaclient extensions to see if they are rackspace or not, to know if it needs to load # the hooks for that extension or not. This is cleaned up by sanatize_novaclient self.kwargs["os_auth_url"] = auth_url if os_auth_plugin is not None: novaclient.auth_plugin.discover_auth_systems() auth_plugin = novaclient.auth_plugin.load_plugin(os_auth_plugin) self.kwargs["auth_plugin"] = auth_plugin self.kwargs["auth_system"] = os_auth_plugin if not self.kwargs.get("api_key", None): self.kwargs["api_key"] = password # This has to be run before sanatize_novaclient before extra variables are cleaned out. if hasattr(self, "extensions"): # needs an object, not a dictionary self.kwargstruct = KwargsStruct(**self.kwargs) for extension in self.extensions: extension.run_hooks("__post_parse_args__", self.kwargstruct) self.kwargs = self.kwargstruct.__dict__ self.kwargs = sanatize_novaclient(self.kwargs) if not hasattr(client.Client, "__exit__"): raise SaltCloudSystemExit("Newer version of novaclient required for __exit__.") with client.Client(**self.kwargs) as conn: try: conn.client.authenticate() except novaclient.exceptions.AmbiguousEndpoints: raise SaltCloudSystemExit("Nova provider requires a 'region_name' to be specified") self.kwargs["auth_token"] = conn.client.auth_token self.catalog = conn.client.service_catalog.catalog["access"]["serviceCatalog"] if region_name is not None: servers_endpoints = get_entry(self.catalog, "type", "compute")["endpoints"] self.kwargs["bypass_url"] = get_entry(servers_endpoints, "region", region_name)["publicURL"] self.compute_conn = client.Client(**self.kwargs) if region_name is not None: servers_endpoints = get_entry(self.catalog, "type", "volume")["endpoints"] self.kwargs["bypass_url"] = get_entry(servers_endpoints, "region", region_name)["publicURL"] self.kwargs["service_type"] = "volume" self.volume_conn = client.Client(**self.kwargs) if hasattr(self, "extensions"): self.expand_extensions()