rename neutron to tacker
Change-Id: I1d7c0729d387827e8d4355db9f4dccb265c2ec32
This commit is contained in:
parent
066bddc79f
commit
14eeda8a0b
@ -24,13 +24,13 @@ import os
|
||||
from keystoneclient import access
|
||||
import requests
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.common import utils
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.common import utils
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
if os.environ.get('NEUTRONCLIENT_DEBUG'):
|
||||
if os.environ.get('TACKERCLIENT_DEBUG'):
|
||||
ch = logging.StreamHandler()
|
||||
_logger.setLevel(logging.DEBUG)
|
||||
_logger.addHandler(ch)
|
||||
@ -44,7 +44,7 @@ logging.getLogger("requests").setLevel(_requests_log_level)
|
||||
class HTTPClient(object):
|
||||
"""Handles the REST calls and responses, include authn."""
|
||||
|
||||
USER_AGENT = 'python-neutronclient'
|
||||
USER_AGENT = 'python-tackerclient'
|
||||
|
||||
def __init__(self, username=None, user_id=None,
|
||||
tenant_name=None, tenant_id=None,
|
||||
@ -242,7 +242,7 @@ class HTTPClient(object):
|
||||
try:
|
||||
resp, body = self._cs_request(url, "GET")
|
||||
except exceptions.Unauthorized:
|
||||
# rollback to authenticate() to handle case when neutron client
|
||||
# rollback to authenticate() to handle case when tacker client
|
||||
# is initialized just before the token is expired
|
||||
self.authenticate()
|
||||
return self.endpoint_url
|
@ -15,7 +15,7 @@
|
||||
|
||||
import gettext
|
||||
|
||||
t = gettext.translation('neutronclient', fallback=True)
|
||||
t = gettext.translation('tackerclient', fallback=True)
|
||||
try:
|
||||
ugettext = t.ugettext # Python 2
|
||||
except AttributeError:
|
@ -19,8 +19,8 @@
|
||||
|
||||
import logging
|
||||
|
||||
from neutronclient import client
|
||||
from neutronclient.neutron import client as neutron_client
|
||||
from tackerclient import client
|
||||
from tackerclient.tacker import client as tacker_client
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -44,10 +44,7 @@ class ClientCache(object):
|
||||
class ClientManager(object):
|
||||
"""Manages access to API clients, including authentication.
|
||||
"""
|
||||
neutron = ClientCache(neutron_client.make_client)
|
||||
# Provide support for old quantum commands (for example
|
||||
# in stable versions)
|
||||
quantum = neutron
|
||||
tacker = ClientCache(tacker_client.make_client)
|
||||
|
||||
def __init__(self, token=None, url=None,
|
||||
auth_url=None,
|
@ -15,12 +15,12 @@
|
||||
|
||||
|
||||
EXT_NS = '_extension_ns'
|
||||
XML_NS_V20 = 'http://openstack.org/quantum/api/v2.0'
|
||||
XML_NS_V10 = 'http://openstack.org/tacker/api/v1.0'
|
||||
XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"
|
||||
XSI_ATTR = "xsi:nil"
|
||||
XSI_NIL_ATTR = "xmlns:xsi"
|
||||
TYPE_XMLNS = "xmlns:quantum"
|
||||
TYPE_ATTR = "quantum:type"
|
||||
TYPE_XMLNS = "xmlns:tacker"
|
||||
TYPE_ATTR = "tacker:type"
|
||||
VIRTUAL_ROOT_KEY = "_v_root"
|
||||
ATOM_NAMESPACE = "http://www.w3.org/2005/Atom"
|
||||
ATOM_XMLNS = "xmlns:atom"
|
||||
@ -33,11 +33,6 @@ TYPE_FLOAT = "float"
|
||||
TYPE_LIST = "list"
|
||||
TYPE_DICT = "dict"
|
||||
|
||||
PLURALS = {'networks': 'network',
|
||||
'ports': 'port',
|
||||
'subnets': 'subnet',
|
||||
'dns_nameservers': 'dns_nameserver',
|
||||
'host_routes': 'host_route',
|
||||
'allocation_pools': 'allocation_pool',
|
||||
'fixed_ips': 'fixed_ip',
|
||||
'extensions': 'extension'}
|
||||
PLURALS = {'templates': 'template',
|
||||
'devices': 'device',
|
||||
'services': 'service'}
|
@ -13,24 +13,24 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutronclient.common import _
|
||||
from tackerclient.common import _
|
||||
|
||||
"""
|
||||
Neutron base exception handling.
|
||||
Tacker base exception handling.
|
||||
|
||||
Exceptions are classified into three categories:
|
||||
* Exceptions corresponding to exceptions from neutron server:
|
||||
* Exceptions corresponding to exceptions from tacker server:
|
||||
This type of exceptions should inherit one of exceptions
|
||||
in HTTP_EXCEPTION_MAP.
|
||||
* Exceptions from client library:
|
||||
This type of exceptions should inherit NeutronClientException.
|
||||
This type of exceptions should inherit TackerClientException.
|
||||
* Exceptions from CLI code:
|
||||
This type of exceptions should inherit NeutronCLIError.
|
||||
This type of exceptions should inherit TackerCLIError.
|
||||
"""
|
||||
|
||||
|
||||
class NeutronException(Exception):
|
||||
"""Base Neutron Exception
|
||||
class TackerException(Exception):
|
||||
"""Base Tacker Exception
|
||||
|
||||
To correctly use this class, inherit from it and define
|
||||
a 'message' property. That message will get printf'd
|
||||
@ -52,8 +52,8 @@ class NeutronException(Exception):
|
||||
return self._error_string
|
||||
|
||||
|
||||
class NeutronClientException(NeutronException):
|
||||
"""Base exception which exceptions from Neutron are mapped into.
|
||||
class TackerClientException(TackerException):
|
||||
"""Base exception which exceptions from Tacker are mapped into.
|
||||
|
||||
NOTE: on the client side, we use different exception types in order
|
||||
to allow client library users to handle server exceptions in try...except
|
||||
@ -63,39 +63,39 @@ class NeutronClientException(NeutronException):
|
||||
def __init__(self, message=None, **kwargs):
|
||||
if 'status_code' in kwargs:
|
||||
self.status_code = kwargs['status_code']
|
||||
super(NeutronClientException, self).__init__(message, **kwargs)
|
||||
super(TackerClientException, self).__init__(message, **kwargs)
|
||||
|
||||
|
||||
# Base exceptions from Neutron
|
||||
# Base exceptions from Tacker
|
||||
|
||||
class BadRequest(NeutronClientException):
|
||||
class BadRequest(TackerClientException):
|
||||
status_code = 400
|
||||
|
||||
|
||||
class Unauthorized(NeutronClientException):
|
||||
class Unauthorized(TackerClientException):
|
||||
status_code = 401
|
||||
message = _("Unauthorized: bad credentials.")
|
||||
|
||||
|
||||
class Forbidden(NeutronClientException):
|
||||
class Forbidden(TackerClientException):
|
||||
status_code = 403
|
||||
message = _("Forbidden: your credentials don't give you access to this "
|
||||
"resource.")
|
||||
|
||||
|
||||
class NotFound(NeutronClientException):
|
||||
class NotFound(TackerClientException):
|
||||
status_code = 404
|
||||
|
||||
|
||||
class Conflict(NeutronClientException):
|
||||
class Conflict(TackerClientException):
|
||||
status_code = 409
|
||||
|
||||
|
||||
class InternalServerError(NeutronClientException):
|
||||
class InternalServerError(TackerClientException):
|
||||
status_code = 500
|
||||
|
||||
|
||||
class ServiceUnavailable(NeutronClientException):
|
||||
class ServiceUnavailable(TackerClientException):
|
||||
status_code = 503
|
||||
|
||||
|
||||
@ -110,9 +110,9 @@ HTTP_EXCEPTION_MAP = {
|
||||
}
|
||||
|
||||
|
||||
# Exceptions mapped to Neutron server exceptions
|
||||
# Exceptions mapped to Tacker server exceptions
|
||||
# These are defined if a user of client library needs specific exception.
|
||||
# Exception name should be <Neutron Exception Name> + 'Client'
|
||||
# Exception name should be <Tacker Exception Name> + 'Client'
|
||||
# e.g., NetworkNotFound -> NetworkNotFoundClient
|
||||
|
||||
class NetworkNotFoundClient(NotFound):
|
||||
@ -143,7 +143,7 @@ class OverQuotaClient(Conflict):
|
||||
pass
|
||||
|
||||
|
||||
# TODO(amotoki): It is unused in Neutron, but it is referred to
|
||||
# TODO(amotoki): It is unused in Tacker, but it is referred to
|
||||
# in Horizon code. After Horizon code is updated, remove it.
|
||||
class AlreadyAttachedClient(Conflict):
|
||||
pass
|
||||
@ -160,23 +160,23 @@ class ExternalIpAddressExhaustedClient(BadRequest):
|
||||
# Exceptions from client library
|
||||
|
||||
class NoAuthURLProvided(Unauthorized):
|
||||
message = _("auth_url was not provided to the Neutron client")
|
||||
message = _("auth_url was not provided to the Tacker client")
|
||||
|
||||
|
||||
class EndpointNotFound(NeutronClientException):
|
||||
class EndpointNotFound(TackerClientException):
|
||||
message = _("Could not find Service or Region in Service Catalog.")
|
||||
|
||||
|
||||
class EndpointTypeNotFound(NeutronClientException):
|
||||
class EndpointTypeNotFound(TackerClientException):
|
||||
message = _("Could not find endpoint type %(type_)s in Service Catalog.")
|
||||
|
||||
|
||||
class AmbiguousEndpoints(NeutronClientException):
|
||||
class AmbiguousEndpoints(TackerClientException):
|
||||
message = _("Found more than one matching endpoint in Service Catalog: "
|
||||
"%(matching_endpoints)")
|
||||
|
||||
|
||||
class RequestURITooLong(NeutronClientException):
|
||||
class RequestURITooLong(TackerClientException):
|
||||
"""Raised when a request fails with HTTP error 414."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -184,40 +184,40 @@ class RequestURITooLong(NeutronClientException):
|
||||
super(RequestURITooLong, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class ConnectionFailed(NeutronClientException):
|
||||
message = _("Connection to neutron failed: %(reason)s")
|
||||
class ConnectionFailed(TackerClientException):
|
||||
message = _("Connection to tacker failed: %(reason)s")
|
||||
|
||||
|
||||
class SslCertificateValidationError(NeutronClientException):
|
||||
class SslCertificateValidationError(TackerClientException):
|
||||
message = _("SSL certificate validation has failed: %(reason)s")
|
||||
|
||||
|
||||
class MalformedResponseBody(NeutronClientException):
|
||||
class MalformedResponseBody(TackerClientException):
|
||||
message = _("Malformed response body: %(reason)s")
|
||||
|
||||
|
||||
class InvalidContentType(NeutronClientException):
|
||||
class InvalidContentType(TackerClientException):
|
||||
message = _("Invalid content type %(content_type)s.")
|
||||
|
||||
|
||||
# Command line exceptions
|
||||
|
||||
class NeutronCLIError(NeutronException):
|
||||
class TackerCLIError(TackerException):
|
||||
"""Exception raised when command line parsing fails."""
|
||||
pass
|
||||
|
||||
|
||||
class CommandError(NeutronCLIError):
|
||||
class CommandError(TackerCLIError):
|
||||
pass
|
||||
|
||||
|
||||
class UnsupportedVersion(NeutronCLIError):
|
||||
class UnsupportedVersion(TackerCLIError):
|
||||
"""Indicates that the user is trying to use an unsupported
|
||||
version of the API
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class NeutronClientNoUniqueMatch(NeutronCLIError):
|
||||
class TackerClientNoUniqueMatch(TackerCLIError):
|
||||
message = _("Multiple %(resource)s matches found for name '%(name)s',"
|
||||
" use an ID to be more specific.")
|
@ -14,7 +14,7 @@
|
||||
# under the License.
|
||||
#
|
||||
###
|
||||
### Codes from neutron wsgi
|
||||
### Codes from tacker wsgi
|
||||
###
|
||||
|
||||
import logging
|
||||
@ -22,10 +22,10 @@ import logging
|
||||
from xml.etree import ElementTree as etree
|
||||
from xml.parsers import expat
|
||||
|
||||
from neutronclient.common import constants
|
||||
from neutronclient.common import exceptions as exception
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from neutronclient.openstack.common import jsonutils
|
||||
from tackerclient.common import constants
|
||||
from tackerclient.common import exceptions as exception
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
from tackerclient.openstack.common import jsonutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -76,7 +76,7 @@ class XMLDictSerializer(DictSerializer):
|
||||
if not xmlns:
|
||||
xmlns = self.metadata.get('xmlns')
|
||||
if not xmlns:
|
||||
xmlns = constants.XML_NS_V20
|
||||
xmlns = constants.XML_NS_V10
|
||||
self.xmlns = xmlns
|
||||
|
||||
def default(self, data):
|
||||
@ -242,7 +242,7 @@ class XMLDeserializer(TextDeserializer):
|
||||
self.metadata = metadata or {}
|
||||
xmlns = self.metadata.get('xmlns')
|
||||
if not xmlns:
|
||||
xmlns = constants.XML_NS_V20
|
||||
xmlns = constants.XML_NS_V10
|
||||
self.xmlns = xmlns
|
||||
|
||||
def _get_key(self, tag):
|
||||
@ -359,7 +359,7 @@ class XMLDeserializer(TextDeserializer):
|
||||
return self.default(datastring)
|
||||
|
||||
|
||||
# NOTE(maru): this class is duplicated from neutron.wsgi
|
||||
# NOTE(maru): this class is duplicated from tacker.wsgi
|
||||
class Serializer(object):
|
||||
"""Serializes and deserializes dictionaries to certain MIME types."""
|
||||
|
@ -23,9 +23,9 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from neutronclient.common import _
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.openstack.common import strutils
|
||||
from tackerclient.common import _
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.openstack.common import strutils
|
||||
|
||||
|
||||
def env(*vars, **kwargs):
|
@ -15,8 +15,8 @@
|
||||
|
||||
import netaddr
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
|
||||
|
||||
def validate_int_range(parsed_args, attr_name, min_value=None, max_value=None):
|
@ -19,7 +19,7 @@ gettext for openstack-common modules.
|
||||
|
||||
Usual usage in an openstack.common module:
|
||||
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
"""
|
||||
|
||||
import copy
|
||||
@ -32,8 +32,8 @@ import UserString
|
||||
from babel import localedata
|
||||
import six
|
||||
|
||||
_localedir = os.environ.get('neutronclient'.upper() + '_LOCALEDIR')
|
||||
_t = gettext.translation('neutronclient', localedir=_localedir, fallback=True)
|
||||
_localedir = os.environ.get('tackerclient'.upper() + '_LOCALEDIR')
|
||||
_t = gettext.translation('tackerclient', localedir=_localedir, fallback=True)
|
||||
|
||||
_AVAILABLE_LANGUAGES = {}
|
||||
USE_LAZY = False
|
||||
@ -53,7 +53,7 @@ def enable_lazy():
|
||||
|
||||
def _(msg):
|
||||
if USE_LAZY:
|
||||
return Message(msg, 'neutronclient')
|
||||
return Message(msg, 'tackerclient')
|
||||
else:
|
||||
return _t.ugettext(msg)
|
||||
|
@ -19,7 +19,7 @@ Import related utilities and helper functions.
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
|
||||
|
||||
def import_class(import_str):
|
@ -51,10 +51,10 @@ else:
|
||||
import six
|
||||
import six.moves.xmlrpc_client as xmlrpclib
|
||||
|
||||
from neutronclient.openstack.common import gettextutils
|
||||
from neutronclient.openstack.common import importutils
|
||||
from neutronclient.openstack.common import strutils
|
||||
from neutronclient.openstack.common import timeutils
|
||||
from tackerclient.openstack.common import gettextutils
|
||||
from tackerclient.openstack.common import importutils
|
||||
from tackerclient.openstack.common import strutils
|
||||
from tackerclient.openstack.common import timeutils
|
||||
|
||||
netaddr = importutils.try_import("netaddr")
|
||||
|
@ -23,7 +23,7 @@ import unicodedata
|
||||
|
||||
import six
|
||||
|
||||
from neutronclient.openstack.common.gettextutils import _ # noqa
|
||||
from tackerclient.openstack.common.gettextutils import _ # noqa
|
||||
|
||||
|
||||
# Used for looking up extensions of text
|
@ -14,21 +14,21 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.common import utils
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.common import utils
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
|
||||
|
||||
API_NAME = 'network'
|
||||
API_VERSIONS = {
|
||||
'2.0': 'neutronclient.v2_0.client.Client',
|
||||
'1.0': 'tackerclient.v1_0.client.Client',
|
||||
}
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
"""Returns an neutron client.
|
||||
"""Returns an tacker client.
|
||||
"""
|
||||
neutron_client = utils.get_client_class(
|
||||
tacker_client = utils.get_client_class(
|
||||
API_NAME,
|
||||
instance._api_version[API_NAME],
|
||||
API_VERSIONS,
|
||||
@ -36,17 +36,17 @@ def make_client(instance):
|
||||
instance.initialize()
|
||||
url = instance._url
|
||||
url = url.rstrip("/")
|
||||
if '2.0' == instance._api_version[API_NAME]:
|
||||
client = neutron_client(username=instance._username,
|
||||
tenant_name=instance._tenant_name,
|
||||
password=instance._password,
|
||||
region_name=instance._region_name,
|
||||
auth_url=instance._auth_url,
|
||||
endpoint_url=url,
|
||||
token=instance._token,
|
||||
auth_strategy=instance._auth_strategy,
|
||||
insecure=instance._insecure,
|
||||
ca_cert=instance._ca_cert)
|
||||
if '1.0' == instance._api_version[API_NAME]:
|
||||
client = tacker_client(username=instance._username,
|
||||
tenant_name=instance._tenant_name,
|
||||
password=instance._password,
|
||||
region_name=instance._region_name,
|
||||
auth_url=instance._auth_url,
|
||||
endpoint_url=url,
|
||||
token=instance._token,
|
||||
auth_strategy=instance._auth_strategy,
|
||||
insecure=instance._insecure,
|
||||
ca_cert=instance._ca_cert)
|
||||
return client
|
||||
else:
|
||||
raise exceptions.UnsupportedVersion(_("API version %s is not "
|
||||
@ -55,12 +55,12 @@ def make_client(instance):
|
||||
|
||||
|
||||
def Client(api_version, *args, **kwargs):
|
||||
"""Return an neutron client.
|
||||
@param api_version: only 2.0 is supported now
|
||||
"""Return an tacker client.
|
||||
@param api_version: only 1.0 is supported now
|
||||
"""
|
||||
neutron_client = utils.get_client_class(
|
||||
tacker_client = utils.get_client_class(
|
||||
API_NAME,
|
||||
api_version,
|
||||
API_VERSIONS,
|
||||
)
|
||||
return neutron_client(*args, **kwargs)
|
||||
return tacker_client(*args, **kwargs)
|
@ -26,10 +26,10 @@ from cliff import lister
|
||||
from cliff import show
|
||||
import six
|
||||
|
||||
from neutronclient.common import command
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.common import utils
|
||||
from neutronclient.openstack.common.gettextutils import _
|
||||
from tackerclient.common import command
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.common import utils
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
|
||||
HEX_ELEM = '[0-9A-Fa-f]'
|
||||
UUID_PATTERN = '-'.join([HEX_ELEM + '{8}', HEX_ELEM + '{4}',
|
||||
@ -59,7 +59,7 @@ def find_resourceid_by_id(client, resource, resource_id):
|
||||
"'%(id)s'") %
|
||||
{'resource': resource, 'id': resource_id})
|
||||
# 404 is used to simulate server side behavior
|
||||
raise exceptions.NeutronClientException(
|
||||
raise exceptions.TackerClientException(
|
||||
message=not_found_message, status_code=404)
|
||||
|
||||
|
||||
@ -70,14 +70,14 @@ def _find_resourceid_by_name(client, resource, name):
|
||||
collection = resource_plural
|
||||
info = data[collection]
|
||||
if len(info) > 1:
|
||||
raise exceptions.NeutronClientNoUniqueMatch(resource=resource,
|
||||
name=name)
|
||||
raise exceptions.TackerClientNoUniqueMatch(resource=resource,
|
||||
name=name)
|
||||
elif len(info) == 0:
|
||||
not_found_message = (_("Unable to find %(resource)s with name "
|
||||
"'%(name)s'") %
|
||||
{'resource': resource, 'name': name})
|
||||
# 404 is used to simulate server side behavior
|
||||
raise exceptions.NeutronClientException(
|
||||
raise exceptions.TackerClientException(
|
||||
message=not_found_message, status_code=404)
|
||||
else:
|
||||
return info[0]['id']
|
||||
@ -86,7 +86,7 @@ def _find_resourceid_by_name(client, resource, name):
|
||||
def find_resourceid_by_name_or_id(client, resource, name_or_id):
|
||||
try:
|
||||
return find_resourceid_by_id(client, resource, name_or_id)
|
||||
except exceptions.NeutronClientException:
|
||||
except exceptions.TackerClientException:
|
||||
return _find_resourceid_by_name(client, resource, name_or_id)
|
||||
|
||||
|
||||
@ -182,7 +182,7 @@ def parse_args_to_dict(values_specs):
|
||||
Besides known options and arguments, our commands also support user to
|
||||
put more options to the end of command line. For example,
|
||||
list_nets -- --tag x y --key1 value1, where '-- --tag x y --key1 value1'
|
||||
is extra options to our list_nets. This feature can support V2.0 API's
|
||||
is extra options to our list_nets. This feature can support V1.0 API's
|
||||
fields selection and filters. For example, to list networks which has name
|
||||
'test4', we can have list_nets -- --name=test4.
|
||||
|
||||
@ -327,7 +327,7 @@ def update_dict(obj, dict, attributes):
|
||||
class TableFormater(table.TableFormatter):
|
||||
"""This class is used to keep consistency with prettytable 0.6.
|
||||
|
||||
https://bugs.launchpad.net/python-neutronclient/+bug/1165962
|
||||
https://bugs.launchpad.net/python-tackerclient/+bug/1165962
|
||||
"""
|
||||
def emit_list(self, column_names, data, stdout, parsed_args):
|
||||
if column_names:
|
||||
@ -340,35 +340,35 @@ class TableFormater(table.TableFormatter):
|
||||
# command.OpenStackCommand is abstract class so that metaclass of
|
||||
# subclass must be subclass of metaclass of all its base.
|
||||
# otherwise metaclass conflict exception is raised.
|
||||
class NeutronCommandMeta(abc.ABCMeta):
|
||||
class TackerCommandMeta(abc.ABCMeta):
|
||||
def __new__(cls, name, bases, cls_dict):
|
||||
if 'log' not in cls_dict:
|
||||
cls_dict['log'] = logging.getLogger(
|
||||
cls_dict['__module__'] + '.' + name)
|
||||
return super(NeutronCommandMeta, cls).__new__(cls,
|
||||
name, bases, cls_dict)
|
||||
return super(TackerCommandMeta, cls).__new__(cls,
|
||||
name, bases, cls_dict)
|
||||
|
||||
|
||||
@six.add_metaclass(NeutronCommandMeta)
|
||||
class NeutronCommand(command.OpenStackCommand):
|
||||
@six.add_metaclass(TackerCommandMeta)
|
||||
class TackerCommand(command.OpenStackCommand):
|
||||
|
||||
api = 'network'
|
||||
values_specs = []
|
||||
json_indent = None
|
||||
|
||||
def __init__(self, app, app_args):
|
||||
super(NeutronCommand, self).__init__(app, app_args)
|
||||
super(TackerCommand, self).__init__(app, app_args)
|
||||
# NOTE(markmcclain): This is no longer supported in cliff version 1.5.2
|
||||
# see https://bugs.launchpad.net/python-neutronclient/+bug/1265926
|
||||
# see https://bugs.launchpad.net/python-tackerclient/+bug/1265926
|
||||
|
||||
#if hasattr(self, 'formatters'):
|
||||
#self.formatters['table'] = TableFormater()
|
||||
|
||||
def get_client(self):
|
||||
return self.app.client_manager.neutron
|
||||
return self.app.client_manager.tacker
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(NeutronCommand, self).get_parser(prog_name)
|
||||
parser = super(TackerCommand, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--request-format',
|
||||
help=_('The xml or json request format'),
|
||||
@ -403,7 +403,7 @@ class NeutronCommand(command.OpenStackCommand):
|
||||
return {}
|
||||
|
||||
|
||||
class CreateCommand(NeutronCommand, show.ShowOne):
|
||||
class CreateCommand(TackerCommand, show.ShowOne):
|
||||
"""Create a resource for a given tenant
|
||||
|
||||
"""
|
||||
@ -425,14 +425,14 @@ class CreateCommand(NeutronCommand, show.ShowOne):
|
||||
|
||||
def get_data(self, parsed_args):
|
||||
self.log.debug('get_data(%s)' % parsed_args)
|
||||
neutron_client = self.get_client()
|
||||
neutron_client.format = parsed_args.request_format
|
||||
tacker_client = self.get_client()
|
||||
tacker_client.format = parsed_args.request_format
|
||||
_extra_values = parse_args_to_dict(self.values_specs)
|
||||
_merge_args(self, parsed_args, _extra_values,
|
||||
self.values_specs)
|
||||
body = self.args2body(parsed_args)
|
||||
body[self.resource].update(_extra_values)
|
||||
obj_creator = getattr(neutron_client,
|
||||
obj_creator = getattr(tacker_client,
|
||||
"create_%s" % self.resource)
|
||||
data = obj_creator(body)
|
||||
self.format_output_data(data)
|
||||
@ -446,7 +446,7 @@ class CreateCommand(NeutronCommand, show.ShowOne):
|
||||
return zip(*sorted(info.iteritems()))
|
||||
|
||||
|
||||
class UpdateCommand(NeutronCommand):
|
||||
class UpdateCommand(TackerCommand):
|
||||
"""Update resource's information
|
||||
"""
|
||||
|
||||
@ -465,8 +465,8 @@ class UpdateCommand(NeutronCommand):
|
||||
|
||||
def run(self, parsed_args):
|
||||
self.log.debug('run(%s)', parsed_args)
|
||||
neutron_client = self.get_client()
|
||||
neutron_client.format = parsed_args.request_format
|
||||
tacker_client = self.get_client()
|
||||
tacker_client.format = parsed_args.request_format
|
||||
_extra_values = parse_args_to_dict(self.values_specs)
|
||||
_merge_args(self, parsed_args, _extra_values,
|
||||
self.values_specs)
|
||||
@ -480,11 +480,11 @@ class UpdateCommand(NeutronCommand):
|
||||
_("Must specify new values to update %s") % self.resource)
|
||||
if self.allow_names:
|
||||
_id = find_resourceid_by_name_or_id(
|
||||
neutron_client, self.resource, parsed_args.id)
|
||||
tacker_client, self.resource, parsed_args.id)
|
||||
else:
|
||||
_id = find_resourceid_by_id(
|
||||
neutron_client, self.resource, parsed_args.id)
|
||||
obj_updator = getattr(neutron_client,
|
||||
tacker_client, self.resource, parsed_args.id)
|
||||
obj_updator = getattr(tacker_client,
|
||||
"update_%s" % self.resource)
|
||||
obj_updator(_id, body)
|
||||
print((_('Updated %(resource)s: %(id)s') %
|
||||
@ -493,7 +493,7 @@ class UpdateCommand(NeutronCommand):
|
||||
return
|
||||
|
||||
|
||||
class DeleteCommand(NeutronCommand):
|
||||
class DeleteCommand(TackerCommand):
|
||||
"""Delete a given resource
|
||||
|
||||
"""
|
||||
@ -516,12 +516,12 @@ class DeleteCommand(NeutronCommand):
|
||||
|
||||
def run(self, parsed_args):
|
||||
self.log.debug('run(%s)', parsed_args)
|
||||
neutron_client = self.get_client()
|
||||
neutron_client.format = parsed_args.request_format
|
||||
obj_deleter = getattr(neutron_client,
|
||||
tacker_client = self.get_client()
|
||||
tacker_client.format = parsed_args.request_format
|
||||
obj_deleter = getattr(tacker_client,
|
||||
"delete_%s" % self.resource)
|
||||
if self.allow_names:
|
||||
_id = find_resourceid_by_name_or_id(neutron_client, self.resource,
|
||||
_id = find_resourceid_by_name_or_id(tacker_client, self.resource,
|
||||
parsed_args.id)
|
||||
else:
|
||||
_id = parsed_args.id
|
||||
@ -533,7 +533,7 @@ class DeleteCommand(NeutronCommand):
|
||||
return
|
||||
|
||||
|
||||
class ListCommand(NeutronCommand, lister.Lister):
|
||||
class ListCommand(TackerCommand, lister.Lister):
|
||||
"""List resources that belong to a given tenant
|
||||
|
||||
"""
|
||||
@ -565,16 +565,16 @@ class ListCommand(NeutronCommand, lister.Lister):
|
||||
search_opts.update({'verbose': 'True'})
|
||||
return search_opts
|
||||
|
||||
def call_server(self, neutron_client, search_opts, parsed_args):
|
||||
resource_plural = _get_resource_plural(self.resource, neutron_client)
|
||||
obj_lister = getattr(neutron_client, "list_%s" % resource_plural)
|
||||
def call_server(self, tacker_client, search_opts, parsed_args):
|
||||
resource_plural = _get_resource_plural(self.resource, tacker_client)
|
||||
obj_lister = getattr(tacker_client, "list_%s" % resource_plural)
|
||||
data = obj_lister(**search_opts)
|
||||
return data
|
||||
|
||||
def retrieve_list(self, parsed_args):
|
||||
"""Retrieve a list of resources from Neutron server"""
|
||||
neutron_client = self.get_client()
|
||||
neutron_client.format = parsed_args.request_format
|
||||
"""Retrieve a list of resources from Tacker server"""
|
||||
tacker_client = self.get_client()
|
||||
tacker_client.format = parsed_args.request_format
|
||||
_extra_values = parse_args_to_dict(self.values_specs)
|
||||
_merge_args(self, parsed_args, _extra_values,
|
||||
self.values_specs)
|
||||
@ -596,15 +596,15 @@ class ListCommand(NeutronCommand, lister.Lister):
|
||||
dirs = dirs[:len(keys)]
|
||||
if dirs:
|
||||
search_opts.update({'sort_dir': dirs})
|
||||
data = self.call_server(neutron_client, search_opts, parsed_args)
|
||||
collection = _get_resource_plural(self.resource, neutron_client)
|
||||
data = self.call_server(tacker_client, search_opts, parsed_args)
|
||||
collection = _get_resource_plural(self.resource, tacker_client)
|
||||
return data.get(collection, [])
|
||||
|
||||
def extend_list(self, data, parsed_args):
|
||||
"""Update a retrieved list.
|
||||
|
||||
This method provides a way to modify a original list returned from
|
||||
the neutron server. For example, you can add subnet cidr information
|
||||
the tacker server. For example, you can add subnet cidr information
|
||||
to a list network.
|
||||
"""
|
||||
pass
|
||||
@ -632,7 +632,7 @@ class ListCommand(NeutronCommand, lister.Lister):
|
||||
return self.setup_columns(data, parsed_args)
|
||||
|
||||
|
||||
class ShowCommand(NeutronCommand, show.ShowOne):
|
||||
class ShowCommand(TackerCommand, show.ShowOne):
|
||||
"""Show information of a given resource
|
||||
|
||||
"""
|
||||
@ -656,8 +656,8 @@ class ShowCommand(NeutronCommand, show.ShowOne):
|
||||
|
||||
def get_data(self, parsed_args):
|
||||
self.log.debug('get_data(%s)', parsed_args)
|
||||
neutron_client = self.get_client()
|
||||
neutron_client.format = parsed_args.request_format
|
||||
tacker_client = self.get_client()
|
||||
tacker_client.format = parsed_args.request_format
|
||||
|
||||
params = {}
|
||||
if parsed_args.show_details:
|
||||
@ -665,12 +665,12 @@ class ShowCommand(NeutronCommand, show.ShowOne):
|
||||
if parsed_args.fields:
|
||||
params = {'fields': parsed_args.fields}
|
||||
if self.allow_names:
|
||||
_id = find_resourceid_by_name_or_id(neutron_client, self.resource,
|
||||
_id = find_resourceid_by_name_or_id(tacker_client, self.resource,
|
||||
parsed_args.id)
|
||||
else:
|
||||
_id = parsed_args.id
|
||||
|
||||
obj_shower = getattr(neutron_client, "show_%s" % self.resource)
|
||||
obj_shower = getattr(tacker_client, "show_%s" % self.resource)
|
||||
data = obj_shower(_id, **params)
|
||||
self.format_output_data(data)
|
||||
resource = data[self.resource]
|
40
tackerclient/tacker/v1_0/extension.py
Normal file
40
tackerclient/tacker/v1_0/extension.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright 2012 OpenStack Foundation.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from tackerclient.openstack.common.gettextutils import _
|
||||
from tackerclient.tacker import v1_0 as cmd_base
|
||||
|
||||
|
||||
class ListExt(cmd_base.ListCommand):
|
||||
"""List all extensions."""
|
||||
|
||||
resource = 'extension'
|
||||
list_columns = ['alias', 'name']
|
||||
|
||||
|
||||
class ShowExt(cmd_base.ShowCommand):
|
||||
"""Show information of a given resource."""
|
||||
|
||||
resource = "extension"
|
||||
allow_names = False
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(cmd_base.ShowCommand, self).get_parser(prog_name)
|
||||
cmd_base.add_show_list_common_argument(parser)
|
||||
parser.add_argument(
|
||||
'id', metavar='EXT-ALIAS',
|
||||
help=_('The extension alias'))
|
||||
return parser
|
@ -23,9 +23,9 @@ import mox
|
||||
import requests
|
||||
import testtools
|
||||
|
||||
from neutronclient import client
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.common import utils
|
||||
from tackerclient import client
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.common import utils
|
||||
|
||||
|
||||
USERNAME = 'testuser'
|
||||
@ -53,7 +53,7 @@ KS_TOKEN_RESULT = {
|
||||
'publicURL': ENDPOINT_URL,
|
||||
'region': REGION}],
|
||||
'type': 'network',
|
||||
'name': 'Neutron Service'}
|
||||
'name': 'Tacker Service'}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -61,7 +61,7 @@ KS_TOKEN_RESULT = {
|
||||
ENDPOINTS_RESULT = {
|
||||
'endpoints': [{
|
||||
'type': 'network',
|
||||
'name': 'Neutron Service',
|
||||
'name': 'Tacker Service',
|
||||
'region': REGION,
|
||||
'adminURL': ENDPOINT_URL,
|
||||
'internalURL': ENDPOINT_URL,
|
||||
@ -170,7 +170,7 @@ class CLITestAuthKeystone(testtools.TestCase):
|
||||
res200 = get_response(200)
|
||||
res401 = get_response(401)
|
||||
|
||||
# If a token is expired, neutron server retruns 401
|
||||
# If a token is expired, tacker server retruns 401
|
||||
self.client.request(
|
||||
mox.StrContains(ENDPOINT_URL + '/resource'), 'GET',
|
||||
headers=mox.ContainsKeyValue('X-Auth-Token', TOKEN)
|
||||
@ -195,7 +195,7 @@ class CLITestAuthKeystone(testtools.TestCase):
|
||||
|
||||
res401 = get_response(401)
|
||||
|
||||
# If a token is expired, neutron server returns 401
|
||||
# If a token is expired, tacker server returns 401
|
||||
self.client.request(
|
||||
mox.StrContains(ENDPOINT_URL + '/resource'), 'GET',
|
||||
headers=mox.ContainsKeyValue('X-Auth-Token', TOKEN)
|
@ -16,104 +16,104 @@
|
||||
|
||||
import testtools
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.tacker import v1_0 as tackerV10
|
||||
|
||||
|
||||
class CLITestArgs(testtools.TestCase):
|
||||
|
||||
def test_empty(self):
|
||||
_mydict = neutronV20.parse_args_to_dict([])
|
||||
_mydict = tackerV10.parse_args_to_dict([])
|
||||
self.assertEqual({}, _mydict)
|
||||
|
||||
def test_default_bool(self):
|
||||
_specs = ['--my_bool', '--arg1', 'value1']
|
||||
_mydict = neutronV20.parse_args_to_dict(_specs)
|
||||
_mydict = tackerV10.parse_args_to_dict(_specs)
|
||||
self.assertTrue(_mydict['my_bool'])
|
||||
|
||||
def test_bool_true(self):
|
||||
_specs = ['--my-bool', 'type=bool', 'true', '--arg1', 'value1']
|
||||
_mydict = neutronV20.parse_args_to_dict(_specs)
|
||||
_mydict = tackerV10.parse_args_to_dict(_specs)
|
||||
self.assertTrue(_mydict['my_bool'])
|
||||
|
||||
def test_bool_false(self):
|
||||
_specs = ['--my_bool', 'type=bool', 'false', '--arg1', 'value1']
|
||||
_mydict = neutronV20.parse_args_to_dict(_specs)
|
||||
_mydict = tackerV10.parse_args_to_dict(_specs)
|
||||
self.assertFalse(_mydict['my_bool'])
|
||||
|
||||
def test_nargs(self):
|
||||
_specs = ['--tag', 'x', 'y', '--arg1', 'value1']
|
||||
_mydict = neutronV20.parse_args_to_dict(_specs)
|
||||
_mydict = tackerV10.parse_args_to_dict(_specs)
|
||||
self.assertIn('x', _mydict['tag'])
|
||||
self.assertIn('y', _mydict['tag'])
|
||||
|
||||
def test_badarg(self):
|
||||
_specs = ['--tag=t', 'x', 'y', '--arg1', 'value1']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
|
||||
def test_badarg_with_minus(self):
|
||||
_specs = ['--arg1', 'value1', '-D']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
|
||||
def test_goodarg_with_minus_number(self):
|
||||
_specs = ['--arg1', 'value1', '-1', '-1.0']
|
||||
_mydict = neutronV20.parse_args_to_dict(_specs)
|
||||
_mydict = tackerV10.parse_args_to_dict(_specs)
|
||||
self.assertEqual(['value1', '-1', '-1.0'],
|
||||
_mydict['arg1'])
|
||||
|
||||
def test_badarg_duplicate(self):
|
||||
_specs = ['--tag=t', '--arg1', 'value1', '--arg1', 'value1']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
|
||||
def test_badarg_early_type_specification(self):
|
||||
_specs = ['type=dict', 'key=value']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
|
||||
def test_arg(self):
|
||||
_specs = ['--tag=t', '--arg1', 'value1']
|
||||
self.assertEqual('value1',
|
||||
neutronV20.parse_args_to_dict(_specs)['arg1'])
|
||||
tackerV10.parse_args_to_dict(_specs)['arg1'])
|
||||
|
||||
def test_dict_arg(self):
|
||||
_specs = ['--tag=t', '--arg1', 'type=dict', 'key1=value1,key2=value2']
|
||||
arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
|
||||
arg1 = tackerV10.parse_args_to_dict(_specs)['arg1']
|
||||
self.assertEqual('value1', arg1['key1'])
|
||||
self.assertEqual('value2', arg1['key2'])
|
||||
|
||||
def test_dict_arg_with_attribute_named_type(self):
|
||||
_specs = ['--tag=t', '--arg1', 'type=dict', 'type=value1,key2=value2']
|
||||
arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
|
||||
arg1 = tackerV10.parse_args_to_dict(_specs)['arg1']
|
||||
self.assertEqual('value1', arg1['type'])
|
||||
self.assertEqual('value2', arg1['key2'])
|
||||
|
||||
def test_list_of_dict_arg(self):
|
||||
_specs = ['--tag=t', '--arg1', 'type=dict',
|
||||
'list=true', 'key1=value1,key2=value2']
|
||||
arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
|
||||
arg1 = tackerV10.parse_args_to_dict(_specs)['arg1']
|
||||
self.assertEqual('value1', arg1[0]['key1'])
|
||||
self.assertEqual('value2', arg1[0]['key2'])
|
||||
|
||||
def test_clear_action(self):
|
||||
_specs = ['--anyarg', 'action=clear']
|
||||
args = neutronV20.parse_args_to_dict(_specs)
|
||||
args = tackerV10.parse_args_to_dict(_specs)
|
||||
self.assertIsNone(args['anyarg'])
|
||||
|
||||
def test_bad_values_str(self):
|
||||
_specs = ['--strarg', 'type=str']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
|
||||
def test_bad_values_list(self):
|
||||
_specs = ['--listarg', 'list=true', 'type=str']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
_specs = ['--listarg', 'type=list']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
||||
_specs = ['--listarg', 'type=list', 'action=clear']
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
neutronV20.parse_args_to_dict, _specs)
|
||||
tackerV10.parse_args_to_dict, _specs)
|
@ -23,13 +23,13 @@ import mox
|
||||
import sys
|
||||
import testtools
|
||||
|
||||
from neutronclient.common import constants
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.neutron import v2_0 as neutronV2_0
|
||||
from neutronclient import shell
|
||||
from neutronclient.v2_0 import client
|
||||
from tackerclient.common import constants
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient import shell
|
||||
from tackerclient.tacker import v1_0 as tackerV1_0
|
||||
from tackerclient.v1_0 import client
|
||||
|
||||
API_VERSION = "2.0"
|
||||
API_VERSION = "1.0"
|
||||
FORMAT = 'json'
|
||||
TOKEN = 'testtoken'
|
||||
ENDURL = 'localurl'
|
||||
@ -155,7 +155,7 @@ class MyComparator(mox.Comparator):
|
||||
return str(self.lhs)
|
||||
|
||||
|
||||
class CLITestV20Base(testtools.TestCase):
|
||||
class CLITestV10Base(testtools.TestCase):
|
||||
|
||||
format = 'json'
|
||||
test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
@ -169,16 +169,16 @@ class CLITestV20Base(testtools.TestCase):
|
||||
client.Client.EXTED_PLURALS.update(constants.PLURALS)
|
||||
client.Client.EXTED_PLURALS.update({'tags': 'tag'})
|
||||
return {'plurals': client.Client.EXTED_PLURALS,
|
||||
'xmlns': constants.XML_NS_V20,
|
||||
'xmlns': constants.XML_NS_V10,
|
||||
constants.EXT_NS: {'prefix': 'http://xxxx.yy.com'}}
|
||||
|
||||
def setUp(self, plurals={}):
|
||||
"""Prepare the test environment."""
|
||||
super(CLITestV20Base, self).setUp()
|
||||
super(CLITestV10Base, self).setUp()
|
||||
client.Client.EXTED_PLURALS.update(constants.PLURALS)
|
||||
client.Client.EXTED_PLURALS.update(plurals)
|
||||
self.metadata = {'plurals': client.Client.EXTED_PLURALS,
|
||||
'xmlns': constants.XML_NS_V20,
|
||||
'xmlns': constants.XML_NS_V10,
|
||||
constants.EXT_NS: {'prefix':
|
||||
'http://xxxx.yy.com'}}
|
||||
self.mox = mox.Mox()
|
||||
@ -186,13 +186,13 @@ class CLITestV20Base(testtools.TestCase):
|
||||
self.fake_stdout = FakeStdout()
|
||||
self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.fake_stdout))
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'neutronclient.neutron.v2_0.find_resourceid_by_name_or_id',
|
||||
'tackerclient.tacker.v1_0.find_resourceid_by_name_or_id',
|
||||
self._find_resourceid))
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'neutronclient.neutron.v2_0.find_resourceid_by_id',
|
||||
'tackerclient.tacker.v1_0.find_resourceid_by_id',
|
||||
self._find_resourceid))
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'neutronclient.v2_0.client.Client.get_attr_metadata',
|
||||
'tackerclient.v1_0.client.Client.get_attr_metadata',
|
||||
self._get_attr_metadata))
|
||||
self.client = client.Client(token=TOKEN, endpoint_url=self.endurl)
|
||||
|
||||
@ -210,7 +210,9 @@ class CLITestV20Base(testtools.TestCase):
|
||||
'credential', 'network_profile',
|
||||
'policy_profile', 'ikepolicy',
|
||||
'ipsecpolicy', 'metering_label',
|
||||
'metering_label_rule', 'net_partition']
|
||||
'metering_label_rule', 'net_partition',
|
||||
'device_template', 'device',
|
||||
'service_instance']
|
||||
if (resource in non_admin_status_resources):
|
||||
body = {resource: {}, }
|
||||
else:
|
||||
@ -232,8 +234,8 @@ class CLITestV20Base(testtools.TestCase):
|
||||
self.client.format = self.format
|
||||
resstr = self.client.serialize(ress)
|
||||
# url method body
|
||||
resource_plural = neutronV2_0._get_resource_plural(resource,
|
||||
self.client)
|
||||
resource_plural = tackerV1_0._get_resource_plural(resource,
|
||||
self.client)
|
||||
path = getattr(self.client, resource_plural + "_path")
|
||||
# Work around for LP #1217791. XML deserializer called from
|
||||
# MyComparator does not decodes XML string correctly.
|
||||
@ -502,7 +504,7 @@ class CLITestV20Base(testtools.TestCase):
|
||||
self.assertIn(myid, _str)
|
||||
|
||||
|
||||
class ClientV2TestJson(CLITestV20Base):
|
||||
class ClientV1TestJson(CLITestV10Base):
|
||||
def test_do_request_unicode(self):
|
||||
self.client.format = self.format
|
||||
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
||||
@ -551,7 +553,7 @@ class ClientV2TestJson(CLITestV20Base):
|
||||
).AndReturn((MyResp(400, reason='An error'), ''))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
error = self.assertRaises(exceptions.NeutronClientException,
|
||||
error = self.assertRaises(exceptions.TackerClientException,
|
||||
self.client.do_request, 'PUT', '/test',
|
||||
body='', params=params)
|
||||
self.assertEqual("An error", str(error))
|
||||
@ -559,23 +561,23 @@ class ClientV2TestJson(CLITestV20Base):
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
|
||||
class ClientV2UnicodeTestXML(ClientV2TestJson):
|
||||
class ClientV1UnicodeTestXML(ClientV1TestJson):
|
||||
format = 'xml'
|
||||
|
||||
|
||||
class CLITestV20ExceptionHandler(CLITestV20Base):
|
||||
class CLITestV10ExceptionHandler(CLITestV10Base):
|
||||
|
||||
def _test_exception_handler_v20(
|
||||
def _test_exception_handler_v10(
|
||||
self, expected_exception, status_code, expected_msg,
|
||||
error_type=None, error_msg=None, error_detail=None,
|
||||
error_content=None):
|
||||
if error_content is None:
|
||||
error_content = {'NeutronError': {'type': error_type,
|
||||
'message': error_msg,
|
||||
'detail': error_detail}}
|
||||
error_content = {'TackerError': {'type': error_type,
|
||||
'message': error_msg,
|
||||
'detail': error_detail}}
|
||||
|
||||
e = self.assertRaises(expected_exception,
|
||||
client.exception_handler_v20,
|
||||
client.exception_handler_v10,
|
||||
status_code, error_content)
|
||||
self.assertEqual(status_code, e.status_code)
|
||||
|
||||
@ -586,14 +588,14 @@ class CLITestV20ExceptionHandler(CLITestV20Base):
|
||||
expected_msg = error_msg
|
||||
self.assertEqual(expected_msg, e.message)
|
||||
|
||||
def test_exception_handler_v20_ip_address_in_use(self):
|
||||
def test_exception_handler_v10_ip_address_in_use(self):
|
||||
err_msg = ('Unable to complete operation for network '
|
||||
'fake-network-uuid. The IP address fake-ip is in use.')
|
||||
self._test_exception_handler_v20(
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.IpAddressInUseClient, 409, err_msg,
|
||||
'IpAddressInUse', err_msg, '')
|
||||
|
||||
def test_exception_handler_v20_neutron_known_error(self):
|
||||
def test_exception_handler_v10_tacker_known_error(self):
|
||||
known_error_map = [
|
||||
('NetworkNotFound', exceptions.NetworkNotFoundClient, 404),
|
||||
('PortNotFound', exceptions.PortNotFoundClient, 404),
|
||||
@ -611,62 +613,62 @@ class CLITestV20ExceptionHandler(CLITestV20Base):
|
||||
error_msg = 'dummy exception message'
|
||||
error_detail = 'sample detail'
|
||||
for server_exc, client_exc, status_code in known_error_map:
|
||||
self._test_exception_handler_v20(
|
||||
self._test_exception_handler_v10(
|
||||
client_exc, status_code,
|
||||
error_msg + '\n' + error_detail,
|
||||
server_exc, error_msg, error_detail)
|
||||
|
||||
def test_exception_handler_v20_neutron_known_error_without_detail(self):
|
||||
def test_exception_handler_v10_tacker_known_error_without_detail(self):
|
||||
error_msg = 'Network not found'
|
||||
error_detail = ''
|
||||
self._test_exception_handler_v20(
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.NetworkNotFoundClient, 404,
|
||||
error_msg,
|
||||
'NetworkNotFound', error_msg, error_detail)
|
||||
|
||||
def test_exception_handler_v20_unknown_error_to_per_code_exception(self):
|
||||
def test_exception_handler_v10_unknown_error_to_per_code_exception(self):
|
||||
for status_code, client_exc in exceptions.HTTP_EXCEPTION_MAP.items():
|
||||
error_msg = 'Unknown error'
|
||||
error_detail = 'This is detail'
|
||||
self._test_exception_handler_v20(
|
||||
self._test_exception_handler_v10(
|
||||
client_exc, status_code,
|
||||
error_msg + '\n' + error_detail,
|
||||
'UnknownError', error_msg, error_detail)
|
||||
|
||||
def test_exception_handler_v20_neutron_unknown_status_code(self):
|
||||
def test_exception_handler_v10_tacker_unknown_status_code(self):
|
||||
error_msg = 'Unknown error'
|
||||
error_detail = 'This is detail'
|
||||
self._test_exception_handler_v20(
|
||||
exceptions.NeutronClientException, 501,
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.TackerClientException, 501,
|
||||
error_msg + '\n' + error_detail,
|
||||
'UnknownError', error_msg, error_detail)
|
||||
|
||||
def test_exception_handler_v20_bad_neutron_error(self):
|
||||
error_content = {'NeutronError': {'unknown_key': 'UNKNOWN'}}
|
||||
self._test_exception_handler_v20(
|
||||
exceptions.NeutronClientException, 500,
|
||||
def test_exception_handler_v10_bad_tacker_error(self):
|
||||
error_content = {'TackerError': {'unknown_key': 'UNKNOWN'}}
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.TackerClientException, 500,
|
||||
expected_msg={'unknown_key': 'UNKNOWN'},
|
||||
error_content=error_content)
|
||||
|
||||
def test_exception_handler_v20_error_dict_contains_message(self):
|
||||
def test_exception_handler_v10_error_dict_contains_message(self):
|
||||
error_content = {'message': 'This is an error message'}
|
||||
self._test_exception_handler_v20(
|
||||
exceptions.NeutronClientException, 500,
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.TackerClientException, 500,
|
||||
expected_msg='This is an error message',
|
||||
error_content=error_content)
|
||||
|
||||
def test_exception_handler_v20_error_dict_not_contain_message(self):
|
||||
def test_exception_handler_v10_error_dict_not_contain_message(self):
|
||||
error_content = {'error': 'This is an error message'}
|
||||
expected_msg = '%s-%s' % (500, error_content)
|
||||
self._test_exception_handler_v20(
|
||||
exceptions.NeutronClientException, 500,
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.TackerClientException, 500,
|
||||
expected_msg=expected_msg,
|
||||
error_content=error_content)
|
||||
|
||||
def test_exception_handler_v20_default_fallback(self):
|
||||
def test_exception_handler_v10_default_fallback(self):
|
||||
error_content = 'This is an error message'
|
||||
expected_msg = '%s-%s' % (500, error_content)
|
||||
self._test_exception_handler_v20(
|
||||
exceptions.NeutronClientException, 500,
|
||||
self._test_exception_handler_v10(
|
||||
exceptions.TackerClientException, 500,
|
||||
expected_msg=expected_msg,
|
||||
error_content=error_content)
|
@ -15,13 +15,13 @@
|
||||
|
||||
import sys
|
||||
|
||||
from neutronclient.neutron.v2_0.extension import ListExt
|
||||
from neutronclient.neutron.v2_0.extension import ShowExt
|
||||
from neutronclient.tests.unit.test_cli20 import CLITestV20Base
|
||||
from neutronclient.tests.unit.test_cli20 import MyApp
|
||||
from tackerclient.tacker.v1_0.extension import ListExt
|
||||
from tackerclient.tacker.v1_0.extension import ShowExt
|
||||
from tackerclient.tests.unit.test_cli10 import CLITestV10Base
|
||||
from tackerclient.tests.unit.test_cli10 import MyApp
|
||||
|
||||
|
||||
class CLITestV20Extension(CLITestV20Base):
|
||||
class CLITestV10Extension(CLITestV10Base):
|
||||
id_field = 'alias'
|
||||
|
||||
def test_list_extensions(self):
|
@ -23,20 +23,20 @@ import logging
|
||||
import testtools
|
||||
from testtools import helpers
|
||||
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
from tackerclient.tacker import v1_0 as tackerV10
|
||||
|
||||
|
||||
class TestCommandMeta(testtools.TestCase):
|
||||
def test_neutron_command_meta_defines_log(self):
|
||||
class FakeCommand(neutronV20.NeutronCommand):
|
||||
def test_tacker_command_meta_defines_log(self):
|
||||
class FakeCommand(tackerV10.TackerCommand):
|
||||
pass
|
||||
|
||||
self.assertTrue(helpers.safe_hasattr(FakeCommand, 'log'))
|
||||
self.assertIsInstance(FakeCommand.log, logging.getLoggerClass())
|
||||
self.assertEqual(FakeCommand.log.name, __name__ + ".FakeCommand")
|
||||
|
||||
def test_neutron_command_log_defined_explicitly(self):
|
||||
class FakeCommand(neutronV20.NeutronCommand):
|
||||
def test_tacker_command_log_defined_explicitly(self):
|
||||
class FakeCommand(tackerV10.TackerCommand):
|
||||
log = None
|
||||
|
||||
self.assertTrue(helpers.safe_hasattr(FakeCommand, 'log'))
|
@ -16,15 +16,15 @@
|
||||
import mox
|
||||
import testtools
|
||||
|
||||
from neutronclient.client import HTTPClient
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.tests.unit.test_cli20 import MyResp
|
||||
from tackerclient.client import HTTPClient
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.tests.unit.test_cli10 import MyResp
|
||||
|
||||
|
||||
AUTH_TOKEN = 'test_token'
|
||||
END_URL = 'test_url'
|
||||
METHOD = 'GET'
|
||||
URL = 'http://test.test:1234/v2.0/test'
|
||||
URL = 'http://test.test:1234/v1.0/test'
|
||||
|
||||
|
||||
class TestHTTPClient(testtools.TestCase):
|
@ -25,17 +25,17 @@ import mox
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
from neutronclient.common import clientmanager
|
||||
from neutronclient import shell as openstack_shell
|
||||
from tackerclient.common import clientmanager
|
||||
from tackerclient import shell as openstack_shell
|
||||
|
||||
|
||||
DEFAULT_USERNAME = 'username'
|
||||
DEFAULT_PASSWORD = 'password'
|
||||
DEFAULT_TENANT_ID = 'tenant_id'
|
||||
DEFAULT_TENANT_NAME = 'tenant_name'
|
||||
DEFAULT_AUTH_URL = 'http://127.0.0.1:5000/v2.0/'
|
||||
DEFAULT_AUTH_URL = 'http://127.0.0.1:5000/v1.0/'
|
||||
DEFAULT_TOKEN = '3bcc3d3a03f44e3d8377f9247b0ad155'
|
||||
DEFAULT_URL = 'http://quantum.example.org:9696/'
|
||||
DEFAULT_URL = 'http://tacker.example.org:8888/'
|
||||
|
||||
|
||||
class ShellTest(testtools.TestCase):
|
||||
@ -63,7 +63,7 @@ class ShellTest(testtools.TestCase):
|
||||
try:
|
||||
sys.stdout = cStringIO.StringIO()
|
||||
sys.stderr = cStringIO.StringIO()
|
||||
_shell = openstack_shell.NeutronShell('2.0')
|
||||
_shell = openstack_shell.TackerShell('1.0')
|
||||
_shell.run(argstr.split())
|
||||
except SystemExit:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
@ -93,8 +93,8 @@ class ShellTest(testtools.TestCase):
|
||||
|
||||
def test_help_on_subcommand(self):
|
||||
required = [
|
||||
'.*?^usage: .* quota-list']
|
||||
stdout, stderr = self.shell('help quota-list')
|
||||
'.*?^usage: .* device-template-list']
|
||||
stdout, stderr = self.shell('help device-template-list')
|
||||
for r in required:
|
||||
self.assertThat(
|
||||
stdout,
|
||||
@ -111,43 +111,44 @@ class ShellTest(testtools.TestCase):
|
||||
|
||||
def test_unknown_auth_strategy(self):
|
||||
self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
|
||||
stdout, stderr = self.shell('--os-auth-strategy fake quota-list')
|
||||
stdout, stderr = self.shell('--os-auth-strategy fake '
|
||||
'device-template-list')
|
||||
self.assertFalse(stdout)
|
||||
self.assertEqual('You must provide a service URL via '
|
||||
'either --os-url or env[OS_URL]', stderr.strip())
|
||||
|
||||
def test_auth(self):
|
||||
#import pdb; pdb.set_trace()
|
||||
neutron_shell = openstack_shell.NeutronShell('2.0')
|
||||
tacker_shell = openstack_shell.TackerShell('1.0')
|
||||
self.addCleanup(self.mox.UnsetStubs)
|
||||
self.mox.StubOutWithMock(clientmanager.ClientManager, '__init__')
|
||||
self.mox.StubOutWithMock(neutron_shell, 'run_subcommand')
|
||||
self.mox.StubOutWithMock(tacker_shell, 'run_subcommand')
|
||||
clientmanager.ClientManager.__init__(
|
||||
token='', url='', auth_url='http://127.0.0.1:5000/',
|
||||
tenant_name='test', tenant_id='tenant_id',
|
||||
username='test', user_id='',
|
||||
password='test', region_name='', api_version={'network': '2.0'},
|
||||
password='test', region_name='', api_version={'network': '1.0'},
|
||||
auth_strategy='keystone', service_type='network',
|
||||
endpoint_type='publicURL', insecure=False, ca_cert=None,
|
||||
log_credentials=True)
|
||||
neutron_shell.run_subcommand(['quota-list'])
|
||||
tacker_shell.run_subcommand(['device-template-list'])
|
||||
self.mox.ReplayAll()
|
||||
cmdline = ('--os-username test '
|
||||
'--os-password test '
|
||||
'--os-tenant-name test '
|
||||
'--os-auth-url http://127.0.0.1:5000/ '
|
||||
'--os-auth-strategy keystone quota-list')
|
||||
neutron_shell.run(cmdline.split())
|
||||
'--os-auth-strategy keystone device-template-list')
|
||||
tacker_shell.run(cmdline.split())
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_build_option_parser(self):
|
||||
neutron_shell = openstack_shell.NeutronShell('2.0')
|
||||
result = neutron_shell.build_option_parser('descr', '2.0')
|
||||
tacker_shell = openstack_shell.TackerShell('1.0')
|
||||
result = tacker_shell.build_option_parser('descr', '1.0')
|
||||
self.assertEqual(True, isinstance(result, argparse.ArgumentParser))
|
||||
|
||||
def test_main_with_unicode(self):
|
||||
self.mox.StubOutClassWithMocks(openstack_shell, 'NeutronShell')
|
||||
qshell_mock = openstack_shell.NeutronShell('2.0')
|
||||
self.mox.StubOutClassWithMocks(openstack_shell, 'TackerShell')
|
||||
qshell_mock = openstack_shell.TackerShell('1.0')
|
||||
unicode_text = u'\u7f51\u7edc'
|
||||
argv = ['net-list', unicode_text, unicode_text.encode('utf-8')]
|
||||
qshell_mock.run([u'net-list', unicode_text,
|
||||
@ -159,8 +160,8 @@ class ShellTest(testtools.TestCase):
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
def test_endpoint_option(self):
|
||||
shell = openstack_shell.NeutronShell('2.0')
|
||||
parser = shell.build_option_parser('descr', '2.0')
|
||||
shell = openstack_shell.TackerShell('1.0')
|
||||
parser = shell.build_option_parser('descr', '1.0')
|
||||
|
||||
# Neither $OS_ENDPOINT_TYPE nor --endpoint-type
|
||||
namespace = parser.parse_args([])
|
||||
@ -175,8 +176,8 @@ class ShellTest(testtools.TestCase):
|
||||
"public")
|
||||
self.useFixture(fixture)
|
||||
|
||||
shell = openstack_shell.NeutronShell('2.0')
|
||||
parser = shell.build_option_parser('descr', '2.0')
|
||||
shell = openstack_shell.TackerShell('1.0')
|
||||
parser = shell.build_option_parser('descr', '1.0')
|
||||
|
||||
# $OS_ENDPOINT_TYPE but not --endpoint-type
|
||||
namespace = parser.parse_args([])
|
@ -18,16 +18,16 @@ import mox
|
||||
import requests
|
||||
import testtools
|
||||
|
||||
from neutronclient.client import HTTPClient
|
||||
from neutronclient.common.clientmanager import ClientManager
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient import shell as openstack_shell
|
||||
from tackerclient.client import HTTPClient
|
||||
from tackerclient.common.clientmanager import ClientManager
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient import shell as openstack_shell
|
||||
|
||||
|
||||
AUTH_TOKEN = 'test_token'
|
||||
END_URL = 'test_url'
|
||||
METHOD = 'GET'
|
||||
URL = 'http://test.test:1234/v2.0/'
|
||||
URL = 'http://test.test:1234/v1.0/'
|
||||
CA_CERT = '/tmp/test/path'
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ class TestSSL(testtools.TestCase):
|
||||
|
||||
def test_ca_cert_passed(self):
|
||||
self.mox.StubOutWithMock(ClientManager, '__init__')
|
||||
self.mox.StubOutWithMock(openstack_shell.NeutronShell, 'interact')
|
||||
self.mox.StubOutWithMock(openstack_shell.TackerShell, 'interact')
|
||||
|
||||
ClientManager.__init__(
|
||||
ca_cert=CA_CERT,
|
||||
@ -64,17 +64,17 @@ class TestSSL(testtools.TestCase):
|
||||
user_id=mox.IgnoreArg(),
|
||||
log_credentials=mox.IgnoreArg(),
|
||||
)
|
||||
openstack_shell.NeutronShell.interact().AndReturn(0)
|
||||
openstack_shell.TackerShell.interact().AndReturn(0)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
openstack_shell.NeutronShell('2.0').run(['--os-cacert', CA_CERT])
|
||||
openstack_shell.TackerShell('1.0').run(['--os-cacert', CA_CERT])
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_ca_cert_passed_as_env_var(self):
|
||||
self.useFixture(fixtures.EnvironmentVariable('OS_CACERT', CA_CERT))
|
||||
|
||||
self.mox.StubOutWithMock(ClientManager, '__init__')
|
||||
self.mox.StubOutWithMock(openstack_shell.NeutronShell, 'interact')
|
||||
self.mox.StubOutWithMock(openstack_shell.TackerShell, 'interact')
|
||||
|
||||
ClientManager.__init__(
|
||||
ca_cert=CA_CERT,
|
||||
@ -95,10 +95,10 @@ class TestSSL(testtools.TestCase):
|
||||
user_id=mox.IgnoreArg(),
|
||||
log_credentials=mox.IgnoreArg(),
|
||||
)
|
||||
openstack_shell.NeutronShell.interact().AndReturn(0)
|
||||
openstack_shell.TackerShell.interact().AndReturn(0)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
openstack_shell.NeutronShell('2.0').run([])
|
||||
openstack_shell.TackerShell('1.0').run([])
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_client_manager_properly_creates_httpclient_instance(self):
|
||||
@ -118,11 +118,11 @@ class TestSSL(testtools.TestCase):
|
||||
)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
version = {'network': '2.0'}
|
||||
version = {'network': '1.0'}
|
||||
ClientManager(ca_cert=CA_CERT,
|
||||
api_version=version,
|
||||
url=END_URL,
|
||||
token=AUTH_TOKEN).neutron
|
||||
token=AUTH_TOKEN).tacker
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_proper_exception_is_raised_when_cert_validation_fails(self):
|
@ -18,8 +18,8 @@ import sys
|
||||
|
||||
import testtools
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.common import utils
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.common import utils
|
||||
|
||||
|
||||
class TestUtils(testtools.TestCase):
|
@ -15,8 +15,8 @@
|
||||
|
||||
import testtools
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.common import validators
|
||||
from tackerclient.common import exceptions
|
||||
from tackerclient.common import validators
|
||||
|
||||
|
||||
class FakeParsedArgs():
|
@ -19,4 +19,4 @@
|
||||
import pbr.version
|
||||
|
||||
|
||||
__version__ = pbr.version.VersionInfo('python-neutronclient').version_string()
|
||||
__version__ = pbr.version.VersionInfo('python-tackerclient').version_string()
|
Loading…
Reference in New Issue
Block a user