Esempio n. 1
0
def check_cinder_exists():
    service_type = 'volumev2'
    try:
        base.url_for(context.current().service_catalog, service_type,
                     endpoint_type=CONF.cinder.endpoint_type)
        return True
    except ex.SystemError:
        return False
Esempio n. 2
0
def check_cinder_exists():
    service_type = 'volumev2'
    try:
        base.url_for(context.current().service_catalog,
                     service_type,
                     endpoint_type=CONF.cinder.endpoint_type)
        return True
    except keystone_exceptions.EndpointNotFound:
        return False
Esempio n. 3
0
def check_cinder_exists():
    if CONF.cinder.api_version == 1:
        service_type = 'volume'
    else:
        service_type = 'volumev2'
    try:
        base.url_for(context.current().service_catalog, service_type)
        return True
    except ex.SystemError:
        return False
Esempio n. 4
0
def check_cinder_exists():
    if CONF.cinder.api_version == 1:
        service_type = 'volume'
    else:
        service_type = 'volumev2'
    try:
        base.url_for(context.current().service_catalog, service_type)
        return True
    except ex.SystemError:
        return False
Esempio n. 5
0
def check_cinder_exists():
    if CONF.cinder.api_version == 2:
        service_type = 'volumev2'
    else:
        service_type = 'volumev3'
    try:
        base.url_for(context.current().service_catalog, service_type,
                     endpoint_type=CONF.cinder.endpoint_type)
        return True
    except keystone_exceptions.EndpointNotFound:
        return False
Esempio n. 6
0
def client():
    ctx = context.current()
    if CONF.cinder_api_version == 1:
        volume_url = base.url_for(ctx.service_catalog, 'volume')
        cinder = cinder_client_v1.Client(ctx.username, ctx.auth_token,
                                         ctx.tenant_id, volume_url)
    else:
        volume_url = base.url_for(ctx.service_catalog, 'volumev2')
        cinder = cinder_client_v2.Client(ctx.username, ctx.auth_token,
                                         ctx.tenant_id, volume_url)

    cinder.client.auth_token = ctx.auth_token
    cinder.client.management_url = volume_url

    return cinder
Esempio n. 7
0
def client():
    ctx = context.current()
    if CONF.cinder_api_version == 1:
        volume_url = base.url_for(ctx.service_catalog, 'volume')
        cinder = cinder_client_v1.Client(ctx.username, ctx.token,
                                         ctx.tenant_id, volume_url)
    else:
        volume_url = base.url_for(ctx.service_catalog, 'volumev2')
        cinder = cinder_client_v2.Client(ctx.username, ctx.token,
                                         ctx.tenant_id, volume_url)

    cinder.client.auth_token = ctx.token
    cinder.client.management_url = volume_url

    return cinder
Esempio n. 8
0
def client():
    ctx = context.ctx()
    session = sessions.cache().get_heat_session()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration',
                            endpoint_type=CONF.heat.endpoint_type)
    return heat_client.Client(
        '1', endpoint=heat_url, session=session, auth=keystone.auth(),
        region_name=CONF.os_region_name)
Esempio n. 9
0
def client():
    ctx = context.ctx()
    session = sessions.cache().get_heat_session()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration',
                            endpoint_type=CONF.heat.endpoint_type)
    return heat_client.Client(
        '1', endpoint=heat_url, session=session, auth=keystone.auth(),
        region_name=CONF.os_region_name)
Esempio n. 10
0
def client():
    ctx = context.current()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration')
    return heat_client.Client('1',
                              heat_url,
                              token=ctx.auth_token,
                              cert_file=CONF.heat.ca_file,
                              insecure=CONF.heat.api_insecure)
Esempio n. 11
0
def client():
    ctx = context.current()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration',
                            endpoint_type=CONF.heat.endpoint_type)
    return heat_client.Client('1', heat_url, token=ctx.auth_token,
                              cert_file=CONF.heat.ca_file,
                              insecure=CONF.heat.api_insecure,
                              username=ctx.username,
                              include_pass=True)
Esempio n. 12
0
def client():
    ctx = context.current()
    args = {
        'insecure': CONF.cinder.api_insecure,
        'cacert': CONF.cinder.ca_file
    }
    if CONF.cinder.api_version == 1:
        volume_url = base.url_for(ctx.service_catalog, 'volume')
        cinder = cinder_client_v1.Client(ctx.username, ctx.auth_token,
                                         ctx.tenant_id, volume_url, **args)
    else:
        volume_url = base.url_for(ctx.service_catalog, 'volumev2')
        cinder = cinder_client_v2.Client(ctx.username, ctx.auth_token,
                                         ctx.tenant_id, volume_url, **args)

    cinder.client.auth_token = ctx.auth_token
    cinder.client.management_url = volume_url

    return cinder
Esempio n. 13
0
def client():
    ctx = context.ctx()
    args = {
        'username': ctx.username,
        'tenant_name': ctx.tenant_name,
        'tenant_id': ctx.tenant_id,
        'token': ctx.token,
        'endpoint_url': base.url_for(ctx.service_catalog, 'network')
    }
    return neutron_cli.Client('2.0', **args)
Esempio n. 14
0
def client():
    ctx = context.ctx()
    args = {
        'username': ctx.username,
        'tenant_name': ctx.tenant_name,
        'tenant_id': ctx.tenant_id,
        'token': ctx.token,
        'endpoint_url': base.url_for(ctx.service_catalog, 'network')
    }
    return neutron_cli.Client('2.0', **args)
Esempio n. 15
0
def client():
    ctx = context.current()
    args = {
        'insecure': CONF.cinder.api_insecure,
        'cacert': CONF.cinder.ca_file
    }
    if CONF.cinder.api_version == 1:
        volume_url = base.url_for(ctx.service_catalog, 'volume')
        cinder = cinder_client_v1.Client(ctx.username, ctx.auth_token,
                                         ctx.tenant_id, volume_url, **args)
    else:
        volume_url = base.url_for(ctx.service_catalog, 'volumev2')
        cinder = cinder_client_v2.Client(ctx.username, ctx.auth_token,
                                         ctx.tenant_id, volume_url, **args)

    cinder.client.auth_token = ctx.auth_token
    cinder.client.management_url = volume_url

    return cinder
Esempio n. 16
0
def client():
    ctx = context.ctx()
    args = {
        'username': ctx.username,
        'tenant_name': ctx.tenant_name,
        'tenant_id': ctx.tenant_id,
        'token': ctx.auth_token,
        'endpoint_url': base.url_for(ctx.service_catalog, 'network'),
        'ca_cert': CONF.neutron.ca_file,
        'insecure': CONF.neutron.api_insecure
    }
    return neutron_cli.Client('2.0', **args)
Esempio n. 17
0
def _etc_hosts_for_services(hosts):
    # add alias for keystone and swift
    for service in ["identity", "object-store"]:
        try:
            hostname = parse.urlparse(
                auth_base.url_for(service_type=service,
                                  endpoint_type="publicURL")).hostname
        except keystone_ex.EndpointNotFound:
            LOG.debug("Endpoint not found for service: \"%s\"", service)
            continue
        hosts += "%s %s\n" % (socket.gethostbyname(hostname), hostname)
    return hosts
Esempio n. 18
0
File: heat.py Progetto: uladz/sahara
def client():
    ctx = context.current()
    heat_url = base.url_for(ctx.service_catalog,
                            'orchestration',
                            endpoint_type=CONF.heat.endpoint_type)
    return heat_client.Client('1',
                              heat_url,
                              token=context.get_auth_token(),
                              cert_file=CONF.heat.ca_file,
                              insecure=CONF.heat.api_insecure,
                              username=ctx.username,
                              include_pass=True)
Esempio n. 19
0
def client():
    ctx = context.current()
    volume_url = base.url_for(ctx.service_catalog, 'volume')

    cinder = cinder_client.Client(ctx.username,
                                  ctx.token,
                                  ctx.tenant_id, volume_url)

    cinder.client.auth_token = ctx.token
    cinder.client.management_url = volume_url

    return cinder
Esempio n. 20
0
def client_from_token(token):
    '''return a Swift client authenticated from a token.'''
    return swiftclient.Connection(auth_version='2.0',
                                  cacert=CONF.swift.ca_file,
                                  insecure=CONF.swift.api_insecure,
                                  preauthurl=base.url_for(
                                      service_type="object-store"),
                                  preauthtoken=token,
                                  retries=CONF.retries.retries_number,
                                  retry_on_ratelimit=True,
                                  starting_backoff=CONF.retries.retry_after,
                                  max_backoff=CONF.retries.retry_after)
Esempio n. 21
0
    def get_neutron_info(self):
        neutron_info = h.HashableDict()
        neutron_info['network'] = (
            self.instance.node_group.cluster.neutron_management_network)
        ctx = context.current()
        neutron_info['uri'] = base.url_for(ctx.service_catalog, 'network')
        neutron_info['token'] = ctx.token
        neutron_info['tenant'] = ctx.tenant_name
        neutron_info['host'] = self.instance.management_ip

        LOG.debug('Returning neutron info: {0}'.format(neutron_info))
        return neutron_info
Esempio n. 22
0
    def get_neutron_info(self):
        neutron_info = h.HashableDict()
        neutron_info['network'] = (
            self.instance.node_group.cluster.neutron_management_network)
        ctx = context.current()
        neutron_info['uri'] = base.url_for(ctx.service_catalog, 'network')
        neutron_info['token'] = ctx.token
        neutron_info['tenant'] = ctx.tenant_name
        neutron_info['host'] = self.instance.management_ip

        LOG.debug('Returning neutron info: {0}'.format(neutron_info))
        return neutron_info
Esempio n. 23
0
def client():
    ctx = context.ctx()
    args = {
        'username': ctx.username,
        'tenant_name': ctx.tenant_name,
        'tenant_id': ctx.tenant_id,
        'token': ctx.auth_token,
        'endpoint_url': base.url_for(ctx.service_catalog, 'network'),
        'ca_cert': CONF.neutron.ca_file,
        'insecure': CONF.neutron.api_insecure
    }
    return neutron_cli.Client('2.0', **args)
Esempio n. 24
0
def client():
    ctx = context.ctx()
    args = {
        'username': ctx.username,
        'project_name': ctx.tenant_name,
        'project_id': ctx.tenant_id,
        'input_auth_token': ctx.auth_token,
        'auth_url': base.retrieve_auth_url(),
        'service_catalog_url': base.url_for(ctx.service_catalog, 'share'),
        'ca_cert': CONF.manila.ca_file,
        'insecure': CONF.manila.api_insecure
    }
    return manila_client.Client(CONF.manila.api_version, **args)
Esempio n. 25
0
    def get_neutron_info(self, instance=None):
        if not instance:
            instance = self.instance
        neutron_info = h.HashableDict()
        neutron_info['network'] = instance.cluster.neutron_management_network
        ctx = context.current()
        neutron_info['uri'] = base.url_for(ctx.service_catalog, 'network')
        neutron_info['token'] = ctx.auth_token
        neutron_info['tenant'] = ctx.tenant_name
        neutron_info['host'] = instance.management_ip

        LOG.debug('Returning neutron info: {0}'.format(neutron_info))
        return neutron_info
Esempio n. 26
0
    def get_neutron_info(self, instance=None):
        if not instance:
            instance = self.instance
        neutron_info = h.HashableDict()
        neutron_info['network'] = instance.cluster.neutron_management_network
        ctx = context.current()
        neutron_info['uri'] = base.url_for(ctx.service_catalog, 'network')
        neutron_info['token'] = ctx.auth_token
        neutron_info['tenant'] = ctx.tenant_name
        neutron_info['host'] = instance.management_ip

        LOG.debug('Returning neutron info: {info}'.format(info=neutron_info))
        return neutron_info
Esempio n. 27
0
def client():
    ctx = context.ctx()
    args = {
        'username': ctx.username,
        'project_name': ctx.tenant_name,
        'project_id': ctx.tenant_id,
        'input_auth_token': ctx.auth_token,
        'auth_url': base.retrieve_auth_url(),
        'service_catalog_url': base.url_for(ctx.service_catalog, 'share'),
        'ca_cert': CONF.manila.ca_file,
        'insecure': CONF.manila.api_insecure
    }
    return manila_client.Client(CONF.manila.api_version, **args)
Esempio n. 28
0
def client():
    ctx = context.current()
    auth_url = base.retrieve_auth_url()
    compute_url = base.url_for(ctx.service_catalog, 'compute')

    nova = nova_client.Client(username=ctx.username,
                              api_key=None,
                              project_id=ctx.tenant_id,
                              auth_url=auth_url)

    nova.client.auth_token = ctx.token
    nova.client.management_url = compute_url
    nova.images = images.SaharaImageManager(nova)
    return nova
Esempio n. 29
0
    def test_url_for_regions(self):
        service_catalog = ('[{"endpoints": '
                           '  [{"adminURL": "http://192.168.0.5:8774/v2", '
                           '    "region": "RegionOne", '
                           '    "id": "83d12c9ad2d647ecab7cbe91adb8666b", '
                           '    "internalURL": "http://192.168.0.5:8774/v2", '
                           '    "publicURL": "http://172.18.184.5:8774/v2"}, '
                           '   {"adminURL": "http://192.168.0.6:8774/v2", '
                           '    "region": "RegionTwo", '
                           '    "id": "07c5a555176246c783d8f0497c98537b", '
                           '    "internalURL": "http://192.168.0.6:8774/v2", '
                           '    "publicURL": "http://172.18.184.6:8774/v2"}], '
                           '  "endpoints_links": [], '
                           '  "type": "compute", '
                           '  "name": "nova"}]')

        self.override_config("os_region_name", "RegionOne")
        self.assertEqual("http://172.18.184.5:8774/v2",
                         base.url_for(service_catalog, "compute"))

        self.override_config("os_region_name", "RegionTwo")
        self.assertEqual("http://172.18.184.6:8774/v2",
                         base.url_for(service_catalog, "compute"))
Esempio n. 30
0
def client_from_token(token=None):
    if not token:
        token = context.get_auth_token()
    '''return a Swift client authenticated from a token.'''
    return swiftclient.Connection(auth_version='3',
                                  cacert=CONF.swift.ca_file,
                                  insecure=CONF.swift.api_insecure,
                                  preauthurl=base.url_for(
                                      service_type="object-store",
                                      endpoint_type=CONF.swift.endpoint_type),
                                  preauthtoken=token,
                                  retries=CONF.retries.retries_number,
                                  retry_on_ratelimit=True,
                                  starting_backoff=CONF.retries.retry_after,
                                  max_backoff=CONF.retries.retry_after)
Esempio n. 31
0
    def test_url_for_regions(self):
        service_catalog = (
            '[{"endpoints": '
            '  [{"adminURL": "http://192.168.0.5:8774/v2", '
            '    "region": "RegionOne", '
            '    "id": "83d12c9ad2d647ecab7cbe91adb8666b", '
            '    "internalURL": "http://192.168.0.5:8774/v2", '
            '    "publicURL": "http://172.18.184.5:8774/v2"}, '
            '   {"adminURL": "http://192.168.0.6:8774/v2", '
            '    "region": "RegionTwo", '
            '    "id": "07c5a555176246c783d8f0497c98537b", '
            '    "internalURL": "http://192.168.0.6:8774/v2", '
            '    "publicURL": "http://172.18.184.6:8774/v2"}], '
            '  "endpoints_links": [], '
            '  "type": "compute", '
            '  "name": "nova"}]')

        self.override_config("os_region_name", "RegionOne")
        self.assertEqual("http://172.18.184.5:8774/v2",
                         b.url_for(service_catalog, "compute"))

        self.override_config("os_region_name", "RegionTwo")
        self.assertEqual("http://172.18.184.6:8774/v2",
                         b.url_for(service_catalog, "compute"))
Esempio n. 32
0
def client_from_token(token=None):
    if not token:
        token = context.get_auth_token()
    '''return a Swift client authenticated from a token.'''
    return swiftclient.Connection(auth_version='3',
                                  cacert=CONF.swift.ca_file,
                                  insecure=CONF.swift.api_insecure,
                                  preauthurl=base.url_for(
                                      service_type="object-store",
                                      endpoint_type=CONF.swift.endpoint_type),
                                  preauthtoken=token,
                                  retries=CONF.retries.retries_number,
                                  retry_on_ratelimit=True,
                                  starting_backoff=CONF.retries.retry_after,
                                  max_backoff=CONF.retries.retry_after)
Esempio n. 33
0
def etc_hosts_entry_for_service(service):
    result = ""
    try:
        hostname = parse.urlparse(
            auth_base.url_for(service_type=service,
                              endpoint_type="publicURL")).hostname
    except keystone_ex.EndpointNotFound:
        LOG.debug("Endpoint not found for service: '{}'".format(service))
        return result
    try:
        result = "%s %s\n" % (socket.gethostbyname(hostname), hostname)
    except socket.gaierror:
        LOG.warning(
            "Failed to resolve hostname of service: '{}'".format(service))
        result = "# Failed to resolve {} during deployment\n".format(hostname)
    return result
Esempio n. 34
0
def generate_etc_hosts(cluster):
    hosts = "127.0.0.1 localhost\n"
    for node_group in cluster.node_groups:
        for instance in node_group.instances:
            hosts += "%s %s %s\n" % (instance.internal_ip, instance.fqdn(),
                                     instance.hostname())
    # add alias for keystone and swift
    for service in ["identity", "object-store"]:
        try:
            hostname = parse.urlparse(
                auth_base.url_for(service_type=service,
                                  endpoint_type="publicURL")).hostname
        except keystone_ex.EndpointNotFound:
            LOG.debug("Endpoint not found for service: \"%s\"", service)
            continue
        hosts += "%s %s\n" % (socket.gethostbyname(hostname), hostname)

    return hosts
Esempio n. 35
0
def retrieve_auth_url():
    """This function returns auth url v2.0 api.

    Hadoop Swift library doesn't support keystone v3 api.
    """
    auth_url = clients_base.url_for(context.current().service_catalog,
                                    'identity')
    info = urlparse.urlparse(auth_url)

    if CONF.use_domain_for_proxy_users:
        url = 'v3/auth'
    else:
        url = 'v2.0'

    return '{scheme}://{hostname}:{port}/{url}/'.format(scheme=info.scheme,
                                                        hostname=info.hostname,
                                                        port=info.port,
                                                        url=url)
Esempio n. 36
0
def retrieve_auth_url():
    """This function returns auth url v2.0 api.

    Hadoop Swift library doesn't support keystone v3 api.
    """
    auth_url = clients_base.url_for(context.current().service_catalog,
                                    'identity')
    info = urlparse.urlparse(auth_url)

    if CONF.use_domain_for_proxy_users:
        url = 'v3/auth'
    else:
        url = 'v2.0'

    return '{scheme}://{hostname}:{port}/{url}/'.format(scheme=info.scheme,
                                                        hostname=info.hostname,
                                                        port=info.port,
                                                        url=url)
Esempio n. 37
0
def generate_etc_hosts(cluster):
    hosts = "127.0.0.1 localhost\n"
    for node_group in cluster.node_groups:
        for instance in node_group.instances:
            hosts += "%s %s %s\n" % (instance.internal_ip,
                                     instance.fqdn(),
                                     instance.hostname())
    # add alias for keystone and swift
    for service in ["identity", "object-store"]:
        try:
            hostname = parse.urlparse(
                auth_base.url_for(service_type=service,
                                  endpoint_type="publicURL")).hostname
        except keystone_ex.EndpointNotFound:
            LOG.debug("Endpoint not found for service: \"%s\"", service)
            continue
        hosts += "%s %s\n" % (socket.gethostbyname(hostname), hostname)

    return hosts
Esempio n. 38
0
def etc_hosts_entry_for_service(service):
    result = ""
    try:
        hostname = parse.urlparse(
            auth_base.url_for(service_type=service,
                              endpoint_type="publicURL")).hostname
    except keystone_ex.EndpointNotFound:
        LOG.debug("Endpoint not found for service: '{}'".format(service))
        return result

    overridden_ip = (getattr(CONF,
                             "%s_ip_accessible" % service.replace('-', '_'),
                             None))
    if overridden_ip is not None:
        return "%s %s\n" % (overridden_ip, hostname)

    try:
        result = "%s %s\n" % (socket.gethostbyname(hostname), hostname)
    except socket.gaierror:
        LOG.warning(
            "Failed to resolve hostname of service: '{}'".format(service))
        result = "# Failed to resolve {} during deployment\n".format(hostname)
    return result
Esempio n. 39
0
def etc_hosts_entry_for_service(service):
    result = ""
    try:
        hostname = parse.urlparse(
            auth_base.url_for(service_type=service,
                              endpoint_type="publicURL")).hostname
    except keystone_ex.EndpointNotFound:
        LOG.debug("Endpoint not found for service: '{}'".format(service))
        return result

    overridden_ip = (
        getattr(CONF, "%s_ip_accessible" % service.replace('-', '_'), None)
    )
    if overridden_ip is not None:
        return "%s %s\n" % (overridden_ip, hostname)

    try:
        result = "%s %s\n" % (socket.gethostbyname(hostname), hostname)
    except socket.gaierror:
        LOG.warning("Failed to resolve hostname of service: '{}'"
                    .format(service))
        result = "# Failed to resolve {} during deployment\n".format(hostname)
    return result
Esempio n. 40
0
def client():
    ctx = context.current()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration')
    return heat_client.Client('1', heat_url, token=ctx.token)
Esempio n. 41
0
def client():
    ctx = context.current()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration')
    return heat_client.Client('1', heat_url, token=ctx.auth_token,
                              cert_file=CONF.heat.ca_file,
                              insecure=CONF.heat.api_insecure)
Esempio n. 42
0
def client():
    ctx = context.current()
    heat_url = base.url_for(ctx.service_catalog, 'orchestration')
    return heat_client.Client('1', heat_url, token=ctx.token)
Esempio n. 43
0
def _get_service_address(service_type):
    ctx = context.current()
    identity_url = base.url_for(ctx.service_catalog, service_type)
    address_regexp = r"^\w+://(.+?)/"
    identity_host = re.search(address_regexp, identity_url).group(1)
    return identity_host
Esempio n. 44
0
def _get_service_address(service_type):
    ctx = context.current()
    identity_url = base.url_for(ctx.service_catalog, service_type)
    address_regexp = r"^\w+://(.+?)/"
    identity_host = re.search(address_regexp, identity_url).group(1)
    return identity_host