Example #1
0
def Client(version=None, endpoint=None, session=None, *args, **kwargs):
    if session and endpoint:
        msg = ("You cannot provide an endpoint URL with the session. The "
               "endpoint will be retrieved from the auth plugin's catalog")
        raise RuntimeError(msg)

    elif not session:
        if version is not None:
            warnings.warn(("`version` keyword is being deprecated. Please pass"
                           " the version as part of the URL. "
                           "http://$HOST:$PORT/v$VERSION_NUMBER"),
                          DeprecationWarning)

        endpoint, url_version = utils.strip_version(endpoint)

        if not url_version and not version:
            msg = ("Please provide either the version or an url with the form "
                   "http://$HOST:$PORT/v$VERSION_NUMBER")
            raise RuntimeError(msg)

        version = int(version or url_version)

    module = utils.import_versioned_module(version, 'client')
    client_class = getattr(module, 'Client')
    return client_class(endpoint, *args, session=session, **kwargs)
Example #2
0
def Client(version=None, endpoint=None, *args, **kwargs):
    """Client for the OpenStack Images API.

    Generic client for the OpenStack Images API. See version classes
    for specific details.

    :param string version: The version of API to use. Note this is
                           deprecated and should be passed as part of the URL
                           (http://$HOST:$PORT/v$VERSION_NUMBER).
    """
    if version is not None:
        warnings.warn(("`version` keyword is being deprecated. Please pass the"
                       " version as part of the URL. "
                       "http://$HOST:$PORT/v$VERSION_NUMBER"),
                      DeprecationWarning)

    endpoint, url_version = utils.strip_version(endpoint)

    if not url_version and not version:
        msg = ("Please provide either the version or an url with the form "
               "http://$HOST:$PORT/v$VERSION_NUMBER")
        raise RuntimeError(msg)

    version = int(version or url_version)

    module = utils.import_versioned_module(version, 'client')
    client_class = getattr(module, 'Client')
    return client_class(endpoint, *args, **kwargs)
Example #3
0
    def get_subcommand_parser(self, version):
        parser = self.get_base_parser()

        self.subcommands = {}
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        submodule = utils.import_versioned_module(version, 'shell')
        self._find_actions(subparsers, submodule)
        self._find_actions(subparsers, self)

        return parser
Example #4
0
    def get_subcommand_parser(self, version):
        parser = self.get_base_parser()

        self.subcommands = {}
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        submodule = utils.import_versioned_module(version, 'shell')
        self._find_actions(subparsers, submodule)
        self._find_actions(subparsers, self)

        return parser
Example #5
0
    def get_subcommand_parser(self, version):
        parser = self.get_base_parser()

        self.subcommands = {}
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        try:
            submodule = utils.import_versioned_module(version, 'shell')
        except ImportError:
            print('"%s" is not a supported API version. Example '
                  'values are "1" or "2".' % version)
            utils.exit()

        self._find_actions(subparsers, submodule)
        self._find_actions(subparsers, self)

        self._add_bash_completion_subparser(subparsers)

        return parser
Example #6
0
    def get_subcommand_parser(self, version):
        parser = self.get_base_parser()

        self.subcommands = {}
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        try:
            submodule = utils.import_versioned_module(version, 'shell')
        except ImportError:
            print('"%s" is not a supported API version. Example '
                  'values are "1" or "2".' % version)
            utils.exit()

        self._find_actions(subparsers, submodule)
        self._find_actions(subparsers, self)

        self._add_bash_completion_subparser(subparsers)

        return parser
Example #7
0
def Client(version=None, endpoint=None, *args, **kwargs):
    if version is not None:
        warnings.warn(("`version` keyword is being deprecated. Please pass the"
                       " version as part of the URL. "
                       "http://$HOST:$PORT/v$VERSION_NUMBER"),
                      DeprecationWarning)

    endpoint, url_version = utils.strip_version(endpoint)

    if not url_version and not version:
        msg = ("Please provide either the version or an url with the form "
               "http://$HOST:$PORT/v$VERSION_NUMBER")
        raise RuntimeError(msg)

    version = int(version or url_version)

    module = utils.import_versioned_module(version, 'client')
    client_class = getattr(module, 'Client')
    return client_class(endpoint, *args, **kwargs)
Example #8
0
def Client(version=None, endpoint=None, session=None, *args, **kwargs):
    """Client for the OpenStack Images API.

    Generic client for the OpenStack Images API. See version classes
    for specific details.

    :param string version: The version of API to use.
    :param session: A keystoneclient session that should be used for transport.
    :type session: keystoneclient.session.Session
    """
    # FIXME(jamielennox): Add a deprecation warning if no session is passed.
    # Leaving it as an option until we can ensure nothing break when we switch.
    if session:
        if endpoint:
            kwargs.setdefault('endpoint_override', endpoint)

            if not version:
                __, version = utils.strip_version(endpoint)

        if not version:
            msg = ("You must provide a client version when using session")
            raise RuntimeError(msg)

    else:
        if version is not None:
            warnings.warn(("`version` keyword is being deprecated. Please pass"
                           " the version as part of the URL. "
                           "http://$HOST:$PORT/v$VERSION_NUMBER"),
                          DeprecationWarning)

        endpoint, url_version = utils.strip_version(endpoint)
        version = version or url_version

        if not version:
            msg = ("Please provide either the version or an url with the form "
                   "http://$HOST:$PORT/v$VERSION_NUMBER")
            raise RuntimeError(msg)

    module = utils.import_versioned_module(int(version), 'client')
    client_class = getattr(module, 'Client')
    return client_class(endpoint, *args, session=session, **kwargs)
def Client(version, *args, **kwargs):
    module = utils.import_versioned_module(version, 'client')
    client_class = getattr(module, 'Client')
    return client_class(*args, **kwargs)