def get_auth_params_from_request(request): api_version = VERSIONS.get_active_version() cinder_url = "" auth_url = base.url_for(request, 'identity') try: # The cinder client assumes that the v2 endpoint type will be # 'volumev2'. if api_version['version'] == 2: try: cinder_url = base.url_for(request, 'volumev2') except exceptions.ServiceCatalogException: LOG.warning("Cinder v2 requested but no 'volumev2' service " "type available in Keystone catalog.") except exceptions.ServiceCatalogException: LOG.debug('no volume service configured.') raise return ( api_version, request.user.username, request.user.token.id, request.user.tenant_id, cinder_url, auth_url, )
def get_auth_params_from_request(request): """Extracts the properties from the request object needed by the novaclient call below. These will be used to memoize the calls to novaclient """ return (request.user.username, request.user.token.id, request.user.tenant_id, base.url_for(request, 'compute'), base.url_for(request, 'identity'))
def quantumclient(request): LOG.debug( 'quantumclient connection created using token "%s" and url "%s"' % (request.user.token.id, url_for(request, 'network'))) LOG.debug('user_id=%(user)s, tenant_id=%(tenant)s' % { 'user': request.user.id, 'tenant': request.user.tenant_id }) c = quantum_client.Client(token=request.user.token.id, endpoint_url=url_for(request, 'network')) return c
def novaclient(request): insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) LOG.debug('novaclient connection created using token "%s" and url "%s"' % (request.user.token.id, url_for(request, 'compute'))) c = nova_client.Client(request.user.username, request.user.token.id, project_id=request.user.tenant_id, auth_url=url_for(request, 'compute'), insecure=insecure, http_log_debug=settings.XXX_CLIENT_DEBUG) c.client.auth_token = request.user.token.id c.client.management_url = url_for(request, 'compute') c.client.origin_remote_address = request.META['REMOTE_ADDR'] return c
def _get_endpoint_url(request, endpoint_type, catalog=None): if getattr(request.user, "service_catalog", None): return base.url_for(request, service_type='identity', endpoint_type=endpoint_type) return request.session.get('region_endpoint', getattr(settings, 'OPENSTACK_KEYSTONE_URL'))
def swift_get_container(request, container_name, with_data=True): if with_data: headers, data = swift_api(request).get_object(container_name, "") else: data = None headers = swift_api(request).head_container(container_name) timestamp = None is_public = False public_url = None try: is_public = GLOBAL_READ_ACL in headers.get('x-container-read', '') if is_public: swift_endpoint = base.url_for(request, 'object-store', endpoint_type='publicURL') parameters = urlparse.quote(container_name.encode('utf8')) public_url = swift_endpoint + '/' + parameters ts_float = float(headers.get('x-timestamp')) timestamp = datetime.utcfromtimestamp(ts_float).isoformat() except Exception: pass container_info = { 'name': container_name, 'container_object_count': headers.get('x-container-object-count'), 'container_bytes_used': headers.get('x-container-bytes-used'), 'timestamp': timestamp, 'data': data, 'is_public': is_public, 'public_url': public_url, } return Container(container_info)
def glanceclient(request): o = urlparse.urlparse(url_for(request, 'image')) url = "://".join((o.scheme, o.netloc)) insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) LOG.debug('glanceclient connection created using token "%s" and url "%s"' % (request.user.token.id, url)) return glance_client.Client('1', url, token=request.user.token.id, insecure=insecure)
def glanceclient(request, version='1'): url = base.url_for(request, 'image') insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) return glance_client.Client(version, url, token=request.user.token.id, insecure=insecure, cacert=cacert)
def swift_api(request): endpoint = url_for(request, 'object-store') LOG.debug('Swift connection created using token "%s" and url "%s"' % (request.user.token.id, endpoint)) return swiftclient.client.Connection(None, request.user.username, None, preauthtoken=request.user.token.id, preauthurl=endpoint, auth_version="2.0")
def get_image_name(self): # url = base.url_for(self.auth_ref['catalog'], 'image') url = base.url_for(self.auth_ref['serviceCatalog'], 'image') try: # c = glance_client('1', url, token=self.auth_ref['auth_token']) c = glance_client('1', url, token=self.auth_ref.auth_token) image = c.images.get(self.server.image['id']) return image.name except Exception, e: print e return ""
def swift_api(request): endpoint = base.url_for(request, 'object-store') cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) return swiftclient.client.Connection(None, request.user.username, None, preauthtoken=request.user.token.id, preauthurl=endpoint, cacert=cacert, insecure=insecure, auth_version="2.0")
def _get_endpoint_url(request, endpoint_type, catalog=None): if getattr(request.user, "service_catalog", None): url = base.url_for(request, service_type='identity', endpoint_type=endpoint_type) else: auth_url = getattr(settings, 'OPENSTACK_KEYSTONE_URL') url = request.session.get('region_endpoint', auth_url) # TODO(gabriel): When the Service Catalog no longer contains API versions # in the endpoints this can be removed. url = auth_utils.fix_auth_url_version(url) return url
def cinderclient(request): insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cinder_url = "" try: cinder_url = url_for(request, 'volume') except exceptions.ServiceCatalogException: LOG.debug('no volume service configured.') return None LOG.debug('cinderclient connection created using token "%s" and url "%s"' % (request.user.token.id, cinder_url)) c = cinder_client.Client(request.user.username, request.user.token.id, project_id=request.user.tenant_id, auth_url=cinder_url, insecure=insecure, http_log_debug=settings.XXX_CLIENT_DEBUG) c.client.auth_token = request.user.token.id c.client.management_url = cinder_url return c
def heatclient(request, password=None): api_version = "1" insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) endpoint = base.url_for(request, 'orchestration') kwargs = { 'token': request.user.token.id, 'insecure': insecure, 'ca_file': cacert, 'username': request.user.username, 'password': password # 'timeout': args.timeout, # 'ca_file': args.ca_file, # 'cert_file': args.cert_file, # 'key_file': args.key_file, } client = heat_client.Client(api_version, endpoint, **kwargs) client.format_parameters = format_parameters return client