def get_auth_params_from_request(request): """Extracts properties needed by novaclient call from the request object. These will be used to memoize the calls to novaclient. """ return (request.user.username, request.user.token.id, request.user.tenant_id, request.user.token.project.get('domain_id'), base.url_for(request, 'compute'), base.url_for(request, 'identity'))
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 __init__(self, apiresource, request): super(ExternallyUploadedImage, self).__init__(apiresource) image_endpoint = base.url_for(request, 'image', 'publicURL') if VERSIONS.active >= 2: upload_template = "%s/v2/images/%s/file" else: upload_template = "%s/v1/images/%s" self._url = upload_template % (image_endpoint, self.id) self._token_id = request.user.token.id
def get_auth_params_from_request(request): auth_url = base.url_for(request, 'identity') cinder_urls = [] for service_name in ('volumev3', 'volumev2', 'volume'): try: cinder_url = base.url_for(request, service_name) cinder_urls.append((service_name, cinder_url)) except exceptions.ServiceCatalogException: pass if not cinder_urls: raise exceptions.ServiceCatalogException("no volume service configured") cinder_urls = tuple(cinder_urls) # need to make it cacheable return ( request.user.username, request.user.token.id, request.user.tenant_id, cinder_urls, auth_url, )
def get_microversion(request, feature): for service_name in ('volume', 'volumev2', 'volumev3'): try: cinder_url = base.url_for(request, service_name) break except exceptions.ServiceCatalogException: continue else: return None min_ver, max_ver = cinder_client.get_server_version(cinder_url) return (microversions.get_microversion_for_feature('cinder', feature, api_versions.APIVersion, min_ver, max_ver))
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 glanceclient(request, version=None): api_version = VERSIONS.get_active_version() url = base.url_for(request, 'image') insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) # TODO(jpichon): Temporarily keep both till we update the API calls # to stop hardcoding a version in this file. Once that's done we # can get rid of the deprecated 'version' parameter. if version is None: return api_version['client'].Client(url, token=request.user.token.id, insecure=insecure, cacert=cacert) else: return glance_client.Client(version, url, token=request.user.token.id, insecure=insecure, cacert=cacert)
def _get_engine_kwargs(request, connection_str): from openstack_netsec.api import base engines_kwargs = { # NOTE(tsufiev): actually Horizon doesn't use ceilometer backend (too # slow for UI), but since osprofiler still supports it (due to API # deprecation cycle limitations), Horizon also should support this # option 'ceilometer': lambda req: { 'endpoint': base.url_for(req, 'metering'), 'insecure': getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False), 'cacert': getattr(settings, 'OPENSTACK_SSL_CACERT', None), 'token': (lambda: req.user.token.id), 'ceilometer_api_version': '2' } } engine = urlparse(connection_str).scheme return engines_kwargs.get(engine, lambda req: {})(request)
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
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) message = ("The Keystone URL in service catalog points to a v2.0 " "Keystone endpoint, but v3 is specified as the API version " "to use by Horizon. Using v3 endpoint for authentication.") else: auth_url = getattr(settings, 'OPENSTACK_KEYSTONE_URL') url = request.session.get('region_endpoint', auth_url) message = ("The OPENSTACK_KEYSTONE_URL setting points to a v2.0 " "Keystone endpoint, but v3 is specified as the API version " "to use by Horizon. Using v3 endpoint for authentication.") # TODO(gabriel): When the Service Catalog no longer contains API versions # in the endpoints this can be removed. url, url_fixed = auth_utils.fix_auth_url_version_prefix(url) if url_fixed: LOG.warning(message) return url