Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
tvault_configurator / common / clients / os / contego.py
Size: Mime:
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2013 TrilioData, Inc.
# All Rights Reserved.

from novaclient import shell as novashell
from .contegoclient import client as cc
from .contegoclient import exceptions
from oslo_log import log as logging
from novaclient import client as nc

from workloadmgr.common.clients import client_plugin

LOG = logging.getLogger(__name__)

client_retry_limit = 2
max_interface_check_attempts = 2

CONTEGOCLIENT_VERSION = "2"
CLIENT_NAME = 'contego'


class ContegoClientPlugin(client_plugin.ClientPlugin):

    exceptions_module = exceptions

    service_types = [CONTEGO] = ['datamover']

    def _create(self):
        endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')
        management_url = self.url_for(service_type=self.CONTEGO,
                                      endpoint_type=endpoint_type)

        extensions = nc.discover_extensions(CONTEGOCLIENT_VERSION)

        args = {
            'project_id': self.context.tenant_id,
            'auth_url': self.context.auth_url,
            'auth_token': self.auth_token,
            'service_type': self.CONTEGO,
            'username': None,
            'api_key': None,
            'extensions': extensions,
            'endpoint_type': endpoint_type,
            'http_log_debug': self._get_client_option(CLIENT_NAME,
                                                      'http_log_debug'),
            'cacert': self._get_client_option(CLIENT_NAME, 'cafile'),
            'insecure': self._get_client_option(CLIENT_NAME, 'insecure')
        }

        client = cc.Client(CONTEGOCLIENT_VERSION, **args)
        client.client.set_management_url(management_url)
        return client

    def is_not_found(self, ex):
        return isinstance(ex, exceptions.NotFound)

    def is_over_limit(self, ex):
        return isinstance(ex, exceptions.OverLimit)

    def is_bad_request(self, ex):
        return isinstance(ex, exceptions.BadRequest)

    def is_conflict(self, ex):
        return isinstance(ex, exceptions.Conflict)

    def is_unprocessable_entity(self, ex):
        http_status = (getattr(ex, 'http_status', None) or
                       getattr(ex, 'code', None))
        return (isinstance(ex, exceptions.ClientException) and
                http_status == 422)

    def _list_extensions(self):
        extensions = self.client().list_extensions.show_all()
        return set(extension.alias for extension in extensions)

    def has_extension(self, alias):
        """Check if specific extension is present."""
        return alias in self._list_extensions()