Beispiel #1
0
def _delete_tunnels(tunnels, region_name=None):
    endpoint = ks_client.get_endpoint(region_name, "network")
    auth_token = ks_client.get_token()
    path = "%s/v2.0/uos_resources/%s/remove_tunnel.json" % (endpoint.rstrip("/"), "%s")
    for tunnel in tunnels:
        url = path % tunnel
        try:
            requests.put(url, headers={"X-Auth-Token": auth_token})
        except Exception as e:
            LOG.error("Fail to delete tunnel: %s, as: %s" % (tunnel, e))
Beispiel #2
0
def _delete_tunnels(tunnels, region_name=None):
    endpoint = ks_client.get_endpoint(region_name, 'network')
    auth_token = ks_client.get_token()
    path = "%s/v2.0/uos_resources/%s/remove_tunnel.json" % (
        endpoint.rstrip('/'), '%s')
    for tunnel in tunnels:
        url = path % tunnel
        try:
            requests.put(url, headers={'X-Auth-Token': auth_token})
        except Exception as e:
            LOG.error('Fail to delete tunnel: %s, as: %s' % (tunnel, e))
Beispiel #3
0
def request_to_lotus(method, api_url, body=None, headers=None):
    service_url = cfg.CONF.lotus_endpoint
    if not service_url:
        return

    auth_token = keystone.get_token()
    client = lotus_client()
    if headers:
        client.headers.update(headers)
    client.headers.update({'X-Auth-Token': auth_token})
    client.request(method, service_url.rstrip('/') + api_url, data=body)
Beispiel #4
0
def get_manilaclient(region_name=None):
    ks_cfg = cfg.CONF.keystone_authtoken
    endpoint = ks_client.get_endpoint(region_name, 'share')
    auth_token = ks_client.get_token()
    auth_url = ks_client.get_auth_url()
    c = manila_client.Client(ks_cfg.admin_user,
                             ks_cfg.admin_password,
                             None,
                             auth_url=auth_url)
    c.client.auth_token = auth_token
    c.client.management_url = endpoint
    return c
Beispiel #5
0
def get_manilaclient(region_name=None):
    ks_cfg = cfg.CONF.keystone_authtoken
    endpoint = ks_client.get_endpoint(region_name, 'share')
    auth_token = ks_client.get_token()
    auth_url = ks_client.get_auth_url()
    c = manila_client.Client(ks_cfg.admin_user,
                             ks_cfg.admin_password,
                             None,
                             auth_url=auth_url)
    c.client.auth_token = auth_token
    c.client.management_url = endpoint
    return c
Beispiel #6
0
def request_to_lotus(method, api_url, body=None, headers=None):
    service_url = cfg.CONF.lotus_endpoint
    if not service_url:
        return

    auth_token = keystone.get_token()
    client = lotus_client()
    if headers:
        client.headers.update(headers)
    client.headers.update({'X-Auth-Token': auth_token})
    client.request(method,
                   service_url.rstrip('/') + api_url,
                   data=body)
Beispiel #7
0
def troveclient(region_name=None):
    ks_cfg = cfg.CONF.keystone_authtoken
    endpoint = ks_client.get_endpoint(region_name, 'database')
    auth_token = ks_client.get_token()
    auth_url = ks_client.get_auth_url()

    tc = trove_client.Client(ks_cfg.admin_user,
                             ks_cfg.admin_password,
                             auth_url=auth_url)

    tc.client.auth_token = auth_token
    tc.client.management_url = endpoint
    return tc
Beispiel #8
0
def get_uos_user(user_id):
    # NOTE(chengkun): Now The user's detail info is stored in kunkka,
    # so we should use kunkka api to get user info.
    ks_cfg = cfg.CONF.keystone_authtoken
    auth_url = '%s://%s' % (ks_cfg.auth_protocol, ks_cfg.auth_host)
    url = auth_url + '/api/v1/user/%s' % user_id
    r = requests.get(url,
                     headers={'Content-Type': 'application/json',
                              'X-Auth-Token': keystone.get_token()})
    if r.status_code == 404:
        LOG.warn("can't not find user %s from kunkka" % user_id)
        raise exception.NotFound()
    return r.json()
Beispiel #9
0
def troveclient(region_name=None):
    ks_cfg = cfg.CONF.keystone_authtoken
    endpoint = ks_client.get_endpoint(region_name, 'database')
    auth_token = ks_client.get_token()
    auth_url = ks_client.get_auth_url()

    tc = trove_client.Client(ks_cfg.admin_user,
                             ks_cfg.admin_password,
                             auth_url=auth_url)

    tc.client.auth_token = auth_token
    tc.client.management_url = endpoint
    return tc
Beispiel #10
0
def get_uos_user(user_id):
    # NOTE(chengkun): Now The user's detail info is stored in kunkka,
    # so we should use kunkka api to get user info.
    ks_cfg = cfg.CONF.keystone_authtoken
    auth_url = '%s://%s' % (ks_cfg.auth_protocol, ks_cfg.auth_host)
    url = auth_url + '/api/v1/user/%s' % user_id
    r = requests.get(url,
                     headers={
                         'Content-Type': 'application/json',
                         'X-Auth-Token': keystone.get_token()
                     })
    if r.status_code == 404:
        LOG.warn("can't not find user %s from kunkka" % user_id)
        raise exception.NotFound()
    return r.json()
Beispiel #11
0
def get_novaclient(region_name=None):
    ks_cfg = cfg.CONF.keystone_authtoken
    endpoint = ks_client.get_endpoint(region_name, 'compute')
    auth_token = ks_client.get_token()
    auth_url = ks_client.get_auth_url()

    # Actually, there is no need to give any params to novaclient,
    # but it requires parameters.
    c = nova_client.Client(ks_cfg.admin_user,
                           ks_cfg.admin_password,
                           None, # project_id is not required
                           auth_url=auth_url)

    # Give auth_token and management_url directly to avoid authenticate again.
    c.client.auth_token = auth_token
    c.client.management_url = endpoint
    return c
Beispiel #12
0
def get_neutronclient(region_name=None):
    endpoint = ks_client.get_endpoint(region_name, 'network')
    auth_token = ks_client.get_token()
    c = neutron_client.Client(token=auth_token, endpoint_url=endpoint)
    return c
Beispiel #13
0
def get_glanceclient(region_name=None):
    endpoint = ks_client.get_endpoint(region_name, 'image')
    if endpoint[-1] != '/':
        endpoint += '/'
    auth_token = ks_client.get_token()
    return glanceclient.Client('2', endpoint, token=auth_token)
Beispiel #14
0
def get_neutronclient(region_name=None):
    endpoint = ks_client.get_endpoint(region_name, "network")
    auth_token = ks_client.get_token()
    c = neutron_client.Client(token=auth_token, endpoint_url=endpoint)
    return c
Beispiel #15
0
def get_cmclient(region_name=None):
    endpoint = ks_client.get_endpoint(region_name, "metering")
    auth_token = ks_client.get_token()
    return cmclient.get_client(2, os_auth_token=(lambda: auth_token), ceilometer_url=endpoint)
Beispiel #16
0
def get_cmclient(region_name=None):
    endpoint = ks_client.get_endpoint(region_name, 'metering')
    auth_token = ks_client.get_token()
    return cmclient.get_client(2,
                               os_auth_token=(lambda: auth_token),
                               ceilometer_url=endpoint)