def _create(self): endpoint_type = self._get_client_option('nova', 'endpoint_type') management_url = self.url_for(service_type='compute', endpoint_type=endpoint_type) computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions(NOVACLIENT_VERSION) args = { 'project_id': self.context.tenant, 'auth_url': self.context.auth_url, 'service_type': 'compute', 'username': None, 'api_key': None, 'extensions': extensions, 'endpoint_type': endpoint_type, 'http_log_debug': self._get_client_option('nova', 'http_log_debug'), 'cacert': self._get_client_option('nova', 'ca_file'), 'insecure': self._get_client_option('nova', 'insecure') } client = nc.Client(**args) client.client.auth_token = self.auth_token client.client.management_url = management_url return client
def nova(self, service_type='compute'): if service_type in self._nova: return self._nova[service_type] con = self.context computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions("1.1") endpoint_type = self._get_client_option('nova', 'endpoint_type') args = { 'project_id': con.tenant, 'auth_url': con.auth_url, 'service_type': service_type, 'username': None, 'api_key': None, 'extensions': extensions, 'endpoint_type': endpoint_type, 'cacert': self._get_client_option('nova', 'ca_file'), 'insecure': self._get_client_option('nova', 'insecure') } client = novaclient.Client(1.1, **args) management_url = self.url_for(service_type=service_type, endpoint_type=endpoint_type) client.client.auth_token = self.auth_token client.client.management_url = management_url self._nova[service_type] = client return client
def nova(self, service_type='compute'): if service_type in self._nova: return self._nova[service_type] con = self.context if self.auth_token is None: logger.error("Nova connection failed, no auth_token!") return None computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions("1.1") args = { 'project_id': con.tenant_id, 'auth_url': con.auth_url, 'service_type': service_type, 'username': None, 'api_key': None, 'extensions': extensions } client = novaclient.Client(1.1, **args) management_url = self.url_for(service_type=service_type, attr='region', filter_value='RegionTwo') client.client.auth_token = self.auth_token client.client.management_url = management_url self._nova[service_type] = client return client
def _create(self): endpoint_type = self._get_client_option('nova', 'endpoint_type') management_url = self.url_for(service_type=self.COMPUTE, endpoint_type=endpoint_type) if hasattr(nc, 'discover_extensions'): extensions = nc.discover_extensions(NOVACLIENT_VERSION) else: # TODO(lyj): The else condition is for backward compatibility, # once novaclient bump to a newer version with # discover_extensions exists, this should be safely # removed. from novaclient import shell as novashell computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions(NOVACLIENT_VERSION) args = { 'project_id': self.context.tenant, 'auth_url': self.context.auth_url, 'service_type': self.COMPUTE, 'username': None, 'api_key': None, 'extensions': extensions, 'endpoint_type': endpoint_type, 'http_log_debug': self._get_client_option('nova', 'http_log_debug'), 'cacert': self._get_client_option('nova', 'ca_file'), 'insecure': self._get_client_option('nova', 'insecure') } client = nc.Client(NOVACLIENT_VERSION, **args) client.client.auth_token = self.auth_token client.client.management_url = management_url return client
def is_available(self): try: # Just see that we can import. from novaclient import shell shell.OpenStackComputeShell()._discover_extensions("1.1") return True except ImportError: return False
def novaclient(request): insecure = getattr(api.settings, 'OPENSTACK_SSL_NO_VERIFY', False) api.LOG.debug('novaclient connection created using token "%s" and url "%s"' % (request.user.token.id, api.url_for(request, 'compute'))) extensions = shell.OpenStackComputeShell()._discover_extensions("1.1") c = client.Client(request.user.username, request.user.token.id, extensions=extensions, project_id=request.user.tenant_id, auth_url=api.url_for(request, 'compute'), insecure=insecure) c.client.auth_token = request.user.token.id c.client.management_url = api.url_for(request, 'compute') return c
def novaclient(self): from novaclient import shell from novaclient.v1_1.client import Client as NovaClient if self._client is None: extensions = shell.OpenStackComputeShell()._discover_extensions( "1.1") self._client = NovaClient(self.username, self.password, self.tenant_name, self.auth_url, region_name=self.region_name, service_type="compute", extensions=extensions) return self._client
def is_available(self): try: from novaclient import shell # Fetch a list of extension names. extension_names = [ extension.name for extension in shell.OpenStackComputeShell()._discover_extensions("1.1") ] # Check that the cobalt extension is installed. return ("cobalt" in extension_names or "cobalt_python_novaclient_ext" in extension_names) except ImportError: return False
def create_nova_client(config): '''Creates a nova Client from the environment variables.''' from novaclient import shell extensions = shell.OpenStackComputeShell()._discover_extensions("1.1") if not set([ 'gridcentric', 'cobalt', 'gridcentric_python_novaclient_ext', 'cobalt_python_novaclient_ext' ]) & set([e.name for e in extensions]): raise Exception("You don\'t have the gridcentric extension installed." \ "Try 'pip install gridcentric-python-novaclient-ext'.") from novaclient.v1_1.client import Client return Client(extensions=extensions, username=config.os_username, api_key=config.os_password, project_id=config.os_tenant_name, auth_url=config.os_auth_url, region_name=config.os_region_name, no_cache=os.environ.get('OS_NO_CACHE', 0) and True, http_log_debug=config.http_log_debug)
def _connect_nova_region(self, region_name): """Get an OpenStack Nova (compute) client object.""" # Force reauthentication with Keystone self._cached_keystone_session = None api_version = self._get_config_value( 'os_compute_api_version', get_env('OS_COMPUTE_API_VERSION', 2)) service_name = self._get_config_value( 'nova_service_name', get_env('NOVA_SERVICE_NAME', None)) if self.config.debug_mode: nova_shell.OpenStackComputeShell().setup_debugging(True) nova = nova_client.Client( api_version, session=self._keystone_session, auth_url=self.auth_url, region_name=region_name, service_name=service_name, http_log_debug=True if self.config.debug_mode else False) return nova
def _get_nova(self, username, password, project, auth_url, auth_token, insecure, keystone): computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions("1.1") args = { 'project_id': project, 'auth_url': auth_url, 'service_type': 'compute', 'username': None, 'api_key': None, 'extensions': extensions, 'insecure': insecure } nova = nova_client.Client(**args) management_url =\ keystone.service_catalog.url_for(service_type='compute', endpoint_type='publicURL') nova.client.auth_token = auth_token nova.client.management_url = management_url return nova
def nova(self, service_type='compute'): if service_type in self._nova: return self._nova[service_type] con = self.context if self.auth_token is None: logger.error("Nova connection failed, no auth_token!") return None computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions("1.1") args = { 'project_id': con.tenant, 'auth_url': con.auth_url, 'service_type': service_type, 'username': con.username, 'insecure': True, 'api_key': con.password, 'region_name': con.region_name, 'extensions': extensions, 'timeout': 180 } if con.password is not None: if self.context.region_name is None: management_url = self.url_for(service_type=service_type) else: management_url = self.url_for( service_type=service_type, attr='region', filter_value=self.context.region_name) else: management_url = con.nova_url + '/' + con.tenant_id client = novaclient.Client(2, **args) client.client.auth_token = self.auth_token client.client.management_url = management_url self._nova[service_type] = client return client
def __init__(self): from novaclient import shell self.nova = shell.OpenStackComputeShell() self.base_argv = copy.deepcopy(sys.argv[1:]) self.nova.parser = self.nova.get_base_parser() self.add_argument = self.nova.parser.add_argument
def test_shell(self): '''Test to make sure this plugin integrates with novaclient''' fake_tenant_id = "123456" fake_token = format(random.randint(0, 2**(32 * 4)), 'x') import os shell.os.environ.update({ "OS_USERNAME": "******", "OS_TENANT_NAME": "mock_id", "OS_AUTH_URL": "https://identity.api.rackspacecloud.com/v2.0/", "OS_PASSWORD": "******" }) def identity_callback(request, uri, headers): ''' This callback mocks the identity response with total success ''' identity_response_dict = { "access": # Randomly pick a token for authentication { 'token': { 'id': fake_token, 'RAX-AUTH:authenticatedBy': ['APIKEY'], 'expires': '2014-01-08T18:07:22.007Z', 'tenant': { 'id': fake_tenant_id, 'name': fake_tenant_id } }, "serviceCatalog": [ { u'endpoints': [ { u'publicURL': u'https://dfw.mock.api.rackspacecloud.com/v2/' + fake_tenant_id, u'region': u'DFW', u'tenantId': fake_tenant_id, u'versionId': u'2', u'versionInfo': u'https://dfw.mock.api.rackspacecloud.com/v2', u'versionList': u'https://dfw.mock.api.rackspacecloud.com/' }, ], u'name': u'mockCompute', u'type': u'compute' }, ], # Data not being used for these little tests "user": {} } } identity_response = json.dumps(identity_response_dict) return (200, headers, identity_response) httpretty.register_uri( httpretty.POST, "https://identity.api.rackspacecloud.com/v2.0/tokens", body=identity_callback, content_type="application/json") oscs = shell.OpenStackComputeShell() oscs.main(["endpoints"])