def neutronclient(request): insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) LOG.debug('neutronclient connection created using token "%s" and url "%s"' % (request.user.hp_attr.token.id, base.url_for(request, 'network'))) LOG.debug('user_id=%(user)s, tenant_id=%(tenant)s' % {'user': request.user.id, 'tenant': request.user.hp_attr.tenant_id}) c = neutron_client.Client(token=request.user.hp_attr.token.id, endpoint_url=base.url_for(request, 'network'), insecure=insecure, ca_cert=cacert) return c
def novaclient(request): insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) LOG.debug('novaclient connection created using token "%s" and url "%s"' % (request.user.hp_attr.token.id, base.url_for(request, 'compute'))) c = nova_client.Client(request.user.username, request.user.hp_attr.token.id, project_id=request.user.hp_attr.tenant_id, auth_url=base.url_for(request, 'compute'), insecure=insecure, cacert=cacert, http_log_debug=settings.DEBUG) c.client.auth_token = request.user.hp_attr.token.id c.client.management_url = base.url_for(request, 'compute') return c
def glanceclient(request): o = urlparse.urlparse(base.url_for(request, 'image')) url = "://".join((o.scheme, o.netloc)) insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) LOG.debug('glanceclient connection created using token "%s" and url "%s"' % (request.user.hp_attr.token.id, url)) return glance_client.Client('1', url, token=request.user.hp_attr.token.id, insecure=insecure, cacert=cacert)
def swift_api(request): endpoint = base.url_for(request, 'object-store') cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) LOG.debug('Swift connection created using token "%s" and url "%s"' % (request.user.hp_attr.token.id, endpoint)) return swiftclient.client.Connection(None, request.user.username, None, preauthtoken=request.user.hp_attr.token.id, preauthurl=endpoint, cacert=cacert, auth_version="2.0")
def ceilometerclient(request): """ Initialization of Ceilometer client. """ endpoint = base.url_for(request, 'metering') insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) LOG.debug('ceilometerclient connection created using token "%s" ' 'and endpoint "%s"' % (request.user.hp_attr.token.id, endpoint)) return ceilometer_client.Client('2', endpoint, token=(lambda: request.user.hp_attr.token.id), insecure=insecure, ca_file=cacert)
def swift_api(request): endpoint = base.url_for(request, 'object-store') cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) LOG.debug('Swift connection created using token "%s" and url "%s"' % (request.user.hp_attr.token.id, endpoint)) return swiftclient.client.Connection( None, request.user.username, None, preauthtoken=request.user.hp_attr.token.id, preauthurl=endpoint, cacert=cacert, 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. bits = urlparse.urlparse(url) root = "://".join((bits.scheme, bits.netloc)) url = "%s/v%s" % (root, VERSIONS.active) return url
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') LOG.debug('heatclient connection created using token "%s" and url "%s"' % (request.user.hp_attr.token.id, endpoint)) kwargs = { 'token': request.user.hp_attr.token.id, 'insecure': insecure, 'ca_file': cacert, 'username': request.user.username, 'password': password } client = heat_client.Client(api_version, endpoint, **kwargs) client.format_parameters = format_parameters return client
def cinderclient(request): insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) cinder_url = "" try: cinder_url = base.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.hp_attr.token.id, cinder_url)) c = cinder_client.Client(request.user.username, request.user.hp_attr.token.id, project_id=request.user.hp_attr.tenant_id, auth_url=cinder_url, insecure=insecure, cacert=cacert, http_log_debug=settings.DEBUG) c.client.auth_token = request.user.hp_attr.token.id c.client.management_url = cinder_url return c