¡@

Home 

OpenStack Study: api.py

OpenStack Index

**** CubicPower OpenStack Study ****

def configure_registry_client():

    """

    Sets up a registry client for use in registry lookups

    """

    global _CLIENT_KWARGS, _CLIENT_HOST, _CLIENT_PORT, _METADATA_ENCRYPTION_KEY

    try:

        host, port = CONF.registry_host, CONF.registry_port

    except cfg.ConfigFileValueError:

        msg = _("Configuration option was not valid")

        LOG.error(msg)

        raise exception.BadRegistryConnectionConfiguration(reason=msg)

    except IndexError:

        msg = _("Could not find required configuration option")

        LOG.error(msg)

        raise exception.BadRegistryConnectionConfiguration(reason=msg)

    _CLIENT_HOST = host

    _CLIENT_PORT = port

    _METADATA_ENCRYPTION_KEY = CONF.metadata_encryption_key

    _CLIENT_KWARGS = {

        'use_ssl': CONF.registry_client_protocol.lower() == 'https',

        'key_file': CONF.registry_client_key_file,

        'cert_file': CONF.registry_client_cert_file,

        'ca_file': CONF.registry_client_ca_file,

        'insecure': CONF.registry_client_insecure,

        'timeout': CONF.registry_client_timeout,

    }

    if not CONF.use_user_token:

        configure_registry_admin_creds()

**** CubicPower OpenStack Study ****

def configure_registry_admin_creds():

    global _CLIENT_CREDS

    if CONF.auth_url or os.getenv('OS_AUTH_URL'):

        strategy = 'keystone'

    else:

        strategy = CONF.auth_strategy

    _CLIENT_CREDS = {

        'user': CONF.admin_user,

        'password': CONF.admin_password,

        'username': CONF.admin_user,

        'tenant': CONF.admin_tenant_name,

        'auth_url': CONF.auth_url,

        'strategy': strategy,

        'region': CONF.auth_region,

    }

**** CubicPower OpenStack Study ****

def get_registry_client(cxt):

    global _CLIENT_CREDS, _CLIENT_KWARGS, _CLIENT_HOST, _CLIENT_PORT

    global _METADATA_ENCRYPTION_KEY

    kwargs = _CLIENT_KWARGS.copy()

    if CONF.use_user_token:

        kwargs['auth_tok'] = cxt.auth_tok

    if _CLIENT_CREDS:

        kwargs['creds'] = _CLIENT_CREDS

    if CONF.send_identity_headers:

        identity_headers = {

            'X-User-Id': cxt.user,

            'X-Tenant-Id': cxt.tenant,

            'X-Roles': ','.join(cxt.roles),

            'X-Identity-Status': 'Confirmed',

            'X-Service-Catalog': jsonutils.dumps(cxt.service_catalog),

        }

        kwargs['identity_headers'] = identity_headers

    return client.RegistryClient(_CLIENT_HOST, _CLIENT_PORT,

                                 _METADATA_ENCRYPTION_KEY, **kwargs)

**** CubicPower OpenStack Study ****

def get_images_list(context, **kwargs):

    c = get_registry_client(context)

    return c.get_images(**kwargs)

**** CubicPower OpenStack Study ****

def get_images_detail(context, **kwargs):

    c = get_registry_client(context)

    return c.get_images_detailed(**kwargs)

**** CubicPower OpenStack Study ****

def get_image_metadata(context, image_id):

    c = get_registry_client(context)

    return c.get_image(image_id)

**** CubicPower OpenStack Study ****

def add_image_metadata(context, image_meta):

    LOG.debug(_("Adding image metadata..."))

    c = get_registry_client(context)

    return c.add_image(image_meta)

**** CubicPower OpenStack Study ****

def update_image_metadata(context, image_id, image_meta,

                          purge_props=False, from_state=None):

    LOG.debug(_("Updating image metadata for image %s..."), image_id)

    c = get_registry_client(context)

    return c.update_image(image_id, image_meta, purge_props=purge_props,

                          from_state=from_state)

**** CubicPower OpenStack Study ****

def delete_image_metadata(context, image_id):

    LOG.debug(_("Deleting image metadata for image %s..."), image_id)

    c = get_registry_client(context)

    return c.delete_image(image_id)

**** CubicPower OpenStack Study ****

def get_image_members(context, image_id):

    c = get_registry_client(context)

    return c.get_image_members(image_id)

**** CubicPower OpenStack Study ****

def get_member_images(context, member_id):

    c = get_registry_client(context)

    return c.get_member_images(member_id)

**** CubicPower OpenStack Study ****

def replace_members(context, image_id, member_data):

    c = get_registry_client(context)

    return c.replace_members(image_id, member_data)

**** CubicPower OpenStack Study ****

def add_member(context, image_id, member_id, can_share=None):

    c = get_registry_client(context)

    return c.add_member(image_id, member_id, can_share=can_share)

**** CubicPower OpenStack Study ****

def delete_member(context, image_id, member_id):

    c = get_registry_client(context)

    return c.delete_member(image_id, member_id)