Obsolete Legacy APIs excluding VIM feature

This patch obsoletes CLI for Legacy APIs excluding VIM feature.

Implements: blueprint deprecate-legacy-apis
Change-Id: I9be376a660c6f7c34c0abe7e327dec7a91d49ee2
This commit is contained in:
Ayumu Ueha 2023-11-15 05:16:35 +00:00
parent 1c608378b1
commit e1cd39fa41
49 changed files with 23 additions and 5908 deletions

View File

@ -0,0 +1,4 @@
---
upgrade:
- |
Legacy APIs excluding VIM feature are obsoleted.

View File

@ -40,45 +40,6 @@ openstack.tackerclient.v1 =
vim_set = tackerclient.osc.v1.nfvo.vim:UpdateVIM
vim_delete = tackerclient.osc.v1.nfvo.vim:DeleteVIM
vim_show = tackerclient.osc.v1.nfvo.vim:ShowVIM
vnf_descriptor_create = tackerclient.osc.v1.vnfm.vnfd:CreateVNFD
vnf_descriptor_delete = tackerclient.osc.v1.vnfm.vnfd:DeleteVNFD
vnf_descriptor_list = tackerclient.osc.v1.vnfm.vnfd:ListVNFD
vnf_descriptor_show = tackerclient.osc.v1.vnfm.vnfd:ShowVNFD
vnf_descriptor_template_show = tackerclient.osc.v1.vnfm.vnfd:ShowTemplateVNFD
vnf_create = tackerclient.osc.v1.vnfm.vnf:CreateVNF
vnf_delete = tackerclient.osc.v1.vnfm.vnf:DeleteVNF
vnf_list = tackerclient.osc.v1.vnfm.vnf:ListVNF
vnf_show = tackerclient.osc.v1.vnfm.vnf:ShowVNF
vnf_resource_list = tackerclient.osc.v1.vnfm.vnf:ListVNFResources
vnf_set = tackerclient.osc.v1.vnfm.vnf:UpdateVNF
vnf_scale = tackerclient.osc.v1.vnfm.vnf:ScaleVNF
vnf_graph_descriptor_create = tackerclient.osc.v1.nfvo.vnffgd:CreateVNFFGD
vnf_graph_descriptor_delete = tackerclient.osc.v1.nfvo.vnffgd:DeleteVNFFGD
vnf_graph_descriptor_list = tackerclient.osc.v1.nfvo.vnffgd:ListVNFFGD
vnf_graph_descriptor_show = tackerclient.osc.v1.nfvo.vnffgd:ShowVNFFGD
vnf_graph_descriptor_template_show = tackerclient.osc.v1.nfvo.vnffgd:ShowTemplateVNFFGD
ns_descriptor_create = tackerclient.osc.v1.nfvo.nsd:CreateNSD
ns_descriptor_delete = tackerclient.osc.v1.nfvo.nsd:DeleteNSD
ns_descriptor_list = tackerclient.osc.v1.nfvo.nsd:ListNSD
ns_descriptor_show = tackerclient.osc.v1.nfvo.nsd:ShowNSD
ns_descriptor_template_show = tackerclient.osc.v1.nfvo.nsd:ShowTemplateNSD
nfv_event_show = tackerclient.osc.v1.events.events:ShowEvent
nfv_event_list = tackerclient.osc.v1.events.events:ListEvent
ns_create = tackerclient.osc.v1.nfvo.ns:CreateNS
ns_delete = tackerclient.osc.v1.nfvo.ns:DeleteNS
ns_list = tackerclient.osc.v1.nfvo.ns:ListNS
ns_show = tackerclient.osc.v1.nfvo.ns:ShowNS
vnf_graph_create = tackerclient.osc.v1.nfvo.vnffg:CreateVNFFG
vnf_graph_delete = tackerclient.osc.v1.nfvo.vnffg:DeleteVNFFG
vnf_graph_set = tackerclient.osc.v1.nfvo.vnffg:UpdateVNFFG
vnf_graph_list = tackerclient.osc.v1.nfvo.vnffg:ListVNFFG
vnf_graph_show = tackerclient.osc.v1.nfvo.vnffg:ShowVNFFG
vnf_network_forwarding_path_list = tackerclient.osc.v1.nfvo.vnffg:ListNFP
vnf_network_forwarding_path_show = tackerclient.osc.v1.nfvo.vnffg:ShowNFP
vnf_classifier_list = tackerclient.osc.v1.nfvo.vnffg:ListFC
vnf_classifier_show = tackerclient.osc.v1.nfvo.vnffg:ShowFC
vnf_chain_list = tackerclient.osc.v1.nfvo.vnffg:ListSFC
vnf_chain_show = tackerclient.osc.v1.nfvo.vnffg:ShowSFC
vnf_package_create = tackerclient.osc.v1.vnfpkgm.vnf_package:CreateVnfPackage
vnf_package_list = tackerclient.osc.v1.vnfpkgm.vnf_package:ListVnfPackage
vnf_package_show = tackerclient.osc.v1.vnfpkgm.vnf_package:ShowVnfPackage

View File

@ -1,20 +0,0 @@
#!/bin/bash
set -x
function die() {
local exitcode=$?
set +o xtrace
echo $@
exit $exitcode
}
noauth_tenant_id=me
if [ $1 == 'noauth' ]; then
NOAUTH="--tenant_id $noauth_tenant_id"
else
NOAUTH=
fi
FORMAT=" --request-format xml"
# test the CRUD of xxx
# TODO(yamahata)

View File

@ -14,24 +14,8 @@
# limitations under the License.
EXT_NS = '_extension_ns'
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:tacker"
TYPE_ATTR = "tacker:type"
VIRTUAL_ROOT_KEY = "_v_root"
ATOM_NAMESPACE = "http://www.w3.org/2005/Atom"
ATOM_XMLNS = "xmlns:atom"
ATOM_LINK_NOTATION = "{%s}link" % ATOM_NAMESPACE
TYPE_BOOL = "bool"
TYPE_INT = "int"
TYPE_FLOAT = "float"
TYPE_LIST = "list"
TYPE_DICT = "dict"
PLURALS = {'templates': 'template',
'devices': 'device'}

View File

@ -111,55 +111,6 @@ HTTP_EXCEPTION_MAP = {
}
# Exceptions mapped to Tacker server exceptions
# These are defined if a user of client library needs specific exception.
# Exception name should be <Tacker Exception Name> + 'Client'
# e.g., NetworkNotFound -> NetworkNotFoundClient
class NetworkNotFoundClient(NotFound):
pass
class PortNotFoundClient(NotFound):
pass
class StateInvalidClient(BadRequest):
pass
class NetworkInUseClient(Conflict):
pass
class PortInUseClient(Conflict):
pass
class IpAddressInUseClient(Conflict):
pass
class InvalidIpForNetworkClient(BadRequest):
pass
class OverQuotaClient(Conflict):
pass
class IpAddressGenerationFailureClient(Conflict):
pass
class MacAddressInUseClient(Conflict):
pass
class ExternalIpAddressExhaustedClient(BadRequest):
pass
# Exceptions from client library
class NoAuthURLProvided(Unauthorized):
@ -174,11 +125,6 @@ class EndpointTypeNotFound(TackerClientException):
message = _("Could not find endpoint type %(type_)s in Service Catalog.")
class AmbiguousEndpoints(TackerClientException):
message = _("Found more than one matching endpoint in Service Catalog: "
"%(matching_endpoints)")
class RequestURITooLong(TackerClientException):
"""Raised when a request fails with HTTP error 414."""

View File

@ -14,12 +14,9 @@
# under the License.
import logging
from xml.etree import ElementTree as etree
from xml.parsers import expat
from oslo_serialization import jsonutils
from tackerclient.common import constants
from tackerclient.common import exceptions as exception
from tackerclient.i18n import _
@ -58,144 +55,6 @@ class JSONDictSerializer(DictSerializer):
return jsonutils.dumps(data, default=sanitizer)
class XMLDictSerializer(DictSerializer):
def __init__(self, metadata=None, xmlns=None):
"""XMLDictSerializer constructor.
:param metadata: information needed to deserialize XML into
a dictionary.
:param xmlns: XML namespace to include with serialized XML
"""
super(XMLDictSerializer, self).__init__()
self.metadata = metadata or {}
if not xmlns:
xmlns = self.metadata.get('xmlns')
if not xmlns:
xmlns = constants.XML_NS_V10
self.xmlns = xmlns
def default(self, data):
"""Default serializer of XMLDictSerializer.
:param data: expect data to contain a single key as XML root, or
contain another '*_links' key as atom links. Other
case will use 'VIRTUAL_ROOT_KEY' as XML root.
"""
try:
links = None
has_atom = False
if data is None:
root_key = constants.VIRTUAL_ROOT_KEY
root_value = None
else:
link_keys = [k for k in data.keys() or []
if k.endswith('_links')]
if link_keys:
links = data.pop(link_keys[0], None)
has_atom = True
root_key = (len(data) == 1 and
list(data.keys())[0] or constants.VIRTUAL_ROOT_KEY)
root_value = data.get(root_key, data)
doc = etree.Element("_temp_root")
used_prefixes = []
self._to_xml_node(doc, self.metadata, root_key,
root_value, used_prefixes)
if links:
self._create_link_nodes(list(doc)[0], links)
return self.to_xml_string(list(doc)[0], used_prefixes, has_atom)
except AttributeError as e:
LOG.exception(str(e))
return ''
def __call__(self, data):
# Provides a migration path to a cleaner WSGI layer, this
# "default" stuff and extreme extensibility isn't being used
# like originally intended
return self.default(data)
def to_xml_string(self, node, used_prefixes, has_atom=False):
self._add_xmlns(node, used_prefixes, has_atom)
return etree.tostring(node, encoding='UTF-8')
# NOTE(ameade): the has_atom should be removed after all of the
# XML serializers and view builders have been updated to the current
# spec that required all responses include the xmlns:atom, the has_atom
# flag is to prevent current tests from breaking
def _add_xmlns(self, node, used_prefixes, has_atom=False):
node.set('xmlns', self.xmlns)
node.set(constants.TYPE_XMLNS, self.xmlns)
if has_atom:
node.set(constants.ATOM_XMLNS, constants.ATOM_NAMESPACE)
node.set(constants.XSI_NIL_ATTR, constants.XSI_NAMESPACE)
ext_ns = self.metadata.get(constants.EXT_NS, {})
for prefix in used_prefixes:
if prefix in ext_ns:
node.set('xmlns:' + prefix, ext_ns[prefix])
def _to_xml_node(self, parent, metadata, nodename, data, used_prefixes):
"""Recursive method to convert data members to XML nodes."""
result = etree.SubElement(parent, nodename)
if ":" in nodename:
used_prefixes.append(nodename.split(":", 1)[0])
# TODO(bcwaldon): accomplish this without a type-check
if isinstance(data, list):
if not data:
result.set(
constants.TYPE_ATTR,
constants.TYPE_LIST)
return result
singular = metadata.get('plurals', {}).get(nodename, None)
if singular is None:
if nodename.endswith('s'):
singular = nodename[:-1]
else:
singular = 'item'
for item in data:
self._to_xml_node(result, metadata, singular, item,
used_prefixes)
# TODO(bcwaldon): accomplish this without a type-check
elif isinstance(data, dict):
if not data:
result.set(
constants.TYPE_ATTR,
constants.TYPE_DICT)
return result
attrs = metadata.get('attributes', {}).get(nodename, {})
for k, v in sorted(data.items()):
if k in attrs:
result.set(k, str(v))
else:
self._to_xml_node(result, metadata, k, v,
used_prefixes)
elif data is None:
result.set(constants.XSI_ATTR, 'true')
else:
if isinstance(data, bool):
result.set(
constants.TYPE_ATTR,
constants.TYPE_BOOL)
elif isinstance(data, int):
result.set(
constants.TYPE_ATTR,
constants.TYPE_INT)
elif isinstance(data, float):
result.set(
constants.TYPE_ATTR,
constants.TYPE_FLOAT)
LOG.debug("Data %(data)s type is %(type)s",
{'data': data,
'type': type(data)})
result.text = str(data)
return result
def _create_link_nodes(self, xml_doc, links):
for link in links:
link_node = etree.SubElement(xml_doc, 'atom:link')
link_node.set('rel', link['rel'])
link_node.set('href', link['href'])
class TextDeserializer(ActionDispatcher):
"""Default request body deserialization."""
@ -219,138 +78,11 @@ class JSONDeserializer(TextDeserializer):
return {'body': self._from_json(datastring)}
class XMLDeserializer(TextDeserializer):
def __init__(self, metadata=None):
"""XMLDeserializer constructor.
:param metadata: information needed to deserialize XML into
a dictionary.
"""
super(XMLDeserializer, self).__init__()
self.metadata = metadata or {}
xmlns = self.metadata.get('xmlns')
if not xmlns:
xmlns = constants.XML_NS_V10
self.xmlns = xmlns
def _get_key(self, tag):
tags = tag.split("}", 1)
if len(tags) == 2:
ns = tags[0][1:]
bare_tag = tags[1]
ext_ns = self.metadata.get(constants.EXT_NS, {})
if ns == self.xmlns:
return bare_tag
for prefix, _ns in ext_ns.items():
if ns == _ns:
return prefix + ":" + bare_tag
else:
return tag
def _get_links(self, root_tag, node):
link_nodes = node.findall(constants.ATOM_LINK_NOTATION)
root_tag = self._get_key(node.tag)
link_key = "%s_links" % root_tag
link_list = []
for link in link_nodes:
link_list.append({'rel': link.get('rel'),
'href': link.get('href')})
# Remove link node in order to avoid link node being
# processed as an item in _from_xml_node
node.remove(link)
return link_list and {link_key: link_list} or {}
def _from_xml(self, datastring):
if datastring is None:
return None
plurals = set(self.metadata.get('plurals', {}))
try:
node = etree.fromstring(datastring)
root_tag = self._get_key(node.tag)
links = self._get_links(root_tag, node)
result = self._from_xml_node(node, plurals)
# There is no case where root_tag = constants.VIRTUAL_ROOT_KEY
# and links is not None because of the way data are serialized
if root_tag == constants.VIRTUAL_ROOT_KEY:
return result
return dict({root_tag: result}, **links)
except Exception as e:
parseError = False
# Python2.7
if (hasattr(etree, 'ParseError') and
isinstance(e, getattr(etree, 'ParseError'))):
parseError = True
# Python2.6
elif isinstance(e, expat.ExpatError):
parseError = True
if parseError:
msg = _("Cannot understand XML")
raise exception.MalformedResponseBody(reason=msg)
else:
raise
def _from_xml_node(self, node, listnames):
"""Convert a minidom node to a simple Python type.
:param node: minidom node name
:param listnames: list of XML node names whose subnodes should
be considered list items.
"""
attrNil = node.get(str(etree.QName(constants.XSI_NAMESPACE, "nil")))
attrType = node.get(str(etree.QName(
self.metadata.get('xmlns'), "type")))
if (attrNil and attrNil.lower() == 'true'):
return None
elif not len(node) and not node.text:
if (attrType and attrType == constants.TYPE_DICT):
return {}
elif (attrType and attrType == constants.TYPE_LIST):
return []
else:
return ''
elif (len(node) == 0 and node.text):
converters = {constants.TYPE_BOOL:
lambda x: x.lower() == 'true',
constants.TYPE_INT:
lambda x: int(x),
constants.TYPE_FLOAT:
lambda x: float(x)}
if attrType and attrType in converters:
return converters[attrType](node.text)
else:
return node.text
elif self._get_key(node.tag) in listnames:
return [self._from_xml_node(n, listnames) for n in node]
else:
result = dict()
for attr in node.keys():
if (attr == 'xmlns' or
attr.startswith('xmlns:') or
attr == constants.XSI_ATTR or
attr == constants.TYPE_ATTR):
continue
result[self._get_key(attr)] = node.get(attr)
children = list(node)
for child in children:
result[self._get_key(child.tag)] = self._from_xml_node(
child, listnames)
return result
def default(self, datastring):
return {'body': self._from_xml(datastring)}
def __call__(self, datastring):
# Adding a migration path to allow us to remove unncessary classes
return self.default(datastring)
# NOTE(maru): this class is duplicated from tacker.wsgi
class Serializer(object):
"""Serializes and deserializes dictionaries to certain MIME types."""
def __init__(self, metadata=None, default_xmlns=None):
def __init__(self, metadata=None):
"""Create a serializer based on the given WSGI environment.
'metadata' is an optional dict mapping MIME types to information
@ -358,12 +90,10 @@ class Serializer(object):
"""
self.metadata = metadata or {}
self.default_xmlns = default_xmlns
def _get_serialize_handler(self, content_type):
handlers = {
'application/json': JSONDictSerializer(),
'application/xml': XMLDictSerializer(self.metadata),
'application/json': JSONDictSerializer()
}
try:
@ -385,8 +115,7 @@ class Serializer(object):
def get_deserialize_handler(self, content_type):
handlers = {
'application/json': JSONDeserializer(),
'application/xml': XMLDeserializer(self.metadata),
'application/json': JSONDeserializer()
}
try:

View File

@ -20,7 +20,6 @@
import argparse
import logging
import os
import sys
from oslo_log import versionutils
from oslo_utils import encodeutils
@ -184,15 +183,3 @@ def deprecate_warning(what, as_of, in_favor_of=None, remove_in=1):
versionutils.deprecation_warning(as_of=as_of, what=what,
in_favor_of=in_favor_of,
remove_in=remove_in)
# TODO(ueha): Remove this along with the deprecated commands in the first major
# python-tackerclient release after the Tacker server version 9.0.0 (2023.1
# Antelope release).
def deprecate_legacy_warning():
# NOTE(ueha): versionutils has not support Antelope version yet.
msg = _(
'The Legacy API interface has been deprecated. This command will be '
'removed in the first major release after the Tacker server version '
'9.0.0 (2023.1 Antelope release).')
print(msg, file=sys.stderr)

View File

@ -1,119 +0,0 @@
# Copyright 2018 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 osc_lib.command import command
from osc_lib import utils
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_attr_map = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('resource_type', 'Resource Type', tacker_osc_utils.LIST_BOTH),
('resource_id', 'Resource ID', tacker_osc_utils.LIST_BOTH),
('resource_state', 'Resource State', tacker_osc_utils.LIST_BOTH),
('event_type', 'Event Type', tacker_osc_utils.LIST_BOTH),
('timestamp', 'Timestamp', tacker_osc_utils.LIST_BOTH),
('event_details', 'Event Details', tacker_osc_utils.LIST_LONG_ONLY),
)
_EVENT = "event"
events_path = '/events'
def _get_columns(item):
column_map = {}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
class ShowEvent(command.ShowOne):
_description = _("Show event given the event id.")
def get_parser(self, prog_name):
parser = super(ShowEvent, self).get_parser(prog_name)
parser.add_argument(
_EVENT,
metavar="ID",
help=_("ID of event to display")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _EVENT, parsed_args.event)
obj = client.show_event(obj_id)
display_columns, columns = _get_columns(obj[_EVENT])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_EVENT]),
columns,)
return (display_columns, data)
class ListEvent(command.Lister):
_description = _("List events of resources.")
def get_parser(self, prog_name):
parser = super(ListEvent, self).get_parser(prog_name)
parser.add_argument(
'--id',
help=_("id of the event to look up."))
parser.add_argument(
'--resource-type',
help=_("resource type of the events to look up."))
parser.add_argument(
'--resource-id',
help=_("resource id of the events to look up."))
parser.add_argument(
'--resource-state',
help=_("resource state of the events to look up."))
parser.add_argument(
'--event-type',
help=_("event type of the events to look up."))
parser.add_argument(
'--long',
action='store_true',
help=_("List additional fields in output"))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
_params = {}
if parsed_args.id:
_params['id'] = parsed_args.id
if parsed_args.resource_id:
_params['resource_id'] = parsed_args.resource_id
if parsed_args.resource_state:
_params['resource_state'] = parsed_args.resource_id
if parsed_args.event_type:
_params['event_type'] = parsed_args.event_type
if parsed_args.resource_type:
_params['resource_type'] = parsed_args.resource_type
events = client.list('events', events_path, True, **_params)
data = {}
data['events'] = events['events']
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map, long_listing=parsed_args.long)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_EVENT + 's']))

View File

@ -1,261 +0,0 @@
# Copyright 2018 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.
#
import yaml
from osc_lib.command import command
from osc_lib import utils
from tackerclient.common import exceptions
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_attr_map = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('nsd_id', 'NSD ID', tacker_osc_utils.LIST_BOTH),
('vnf_ids', 'VNF IDs', tacker_osc_utils.LIST_BOTH),
('vnffg_ids', 'VNFFG IDs', tacker_osc_utils.LIST_BOTH),
('mgmt_ip_addresses', 'Mgmt Ip Addresses', tacker_osc_utils.LIST_BOTH),
('status', 'Status', tacker_osc_utils.LIST_BOTH),
)
_NS = 'ns'
_RESOURCE = 'resource'
def _get_columns(item):
column_map = {
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
class CreateNS(command.ShowOne):
_description = _("Create a new NS")
def get_parser(self, prog_name):
parser = super(CreateNS, self).get_parser(prog_name)
parser.add_argument(
'name', metavar='NAME',
help=_('Name for NS'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID'))
parser.add_argument(
'--description',
help=_('Set description for the NS'))
nsd_group = parser.add_mutually_exclusive_group(required=True)
nsd_group.add_argument(
'--nsd-id',
help=_('NSD ID to use as template to create NS'))
nsd_group.add_argument(
'--nsd-template',
help=_('NSD file to create NS'))
nsd_group.add_argument(
'--nsd-name',
help=_('NSD name to use as template to create NS'))
vim_group = parser.add_mutually_exclusive_group()
vim_group.add_argument(
'--vim-id',
help=_('VIM ID to use to create NS on the specified VIM'))
vim_group.add_argument(
'--vim-name',
help=_('VIM name to use to create NS on the specified VIM'))
parser.add_argument(
'--vim-region-name',
help=_('VIM Region to use to create NS on the specified VIM'))
parser.add_argument(
'--param-file',
help=_('Specify parameter YAML file'))
return parser
def args2body(self, parsed_args):
body = {_NS: {}}
body[_NS]['attributes'] = {}
if parsed_args.vim_region_name:
body[_NS].setdefault('placement_attr', {})['region_name'] = \
parsed_args.vim_region_name
client = self.app.client_manager.tackerclient
if parsed_args.vim_name:
_id = tackerV10.find_resourceid_by_name_or_id(client, 'vim',
parsed_args.vim_name)
parsed_args.vim_id = _id
if parsed_args.nsd_name:
_id = tackerV10.find_resourceid_by_name_or_id(client, 'nsd',
parsed_args.nsd_name)
parsed_args.nsd_id = _id
elif parsed_args.nsd_template:
with open(parsed_args.nsd_template) as f:
template = f.read()
try:
template = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not template:
raise exceptions.InvalidInput(
reason='The nsd file is empty')
body[_NS]['nsd_template'] = template
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not param_yaml:
raise exceptions.InvalidInput(
reason='The parameter file is empty')
body[_NS]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_NS],
['tenant_id', 'name', 'description',
'nsd_id', 'vim_id'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
ns = client.create_ns(self.args2body(parsed_args))
display_columns, columns = _get_columns(ns[_NS])
data = utils.get_item_properties(
sdk_utils.DictModel(ns[_NS]),
columns)
lstdata = list(data)
for index, value in enumerate(lstdata):
if value is None:
lstdata[index] = ''
data = tuple(lstdata)
return (display_columns, data)
class DeleteNS(command.Command):
_description = _("Delete NS(s).")
def get_parser(self, prog_name):
parser = super(DeleteNS, self).get_parser(prog_name)
parser.add_argument(
_NS,
metavar="<NS>",
nargs="+",
help=_("NS(s) to delete (name or ID)")
)
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete Network Service')
)
return parser
def args2body(self, parsed_args):
if parsed_args.force:
body = {_NS: {'attributes': {'force': True}}}
else:
body = dict()
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
body = self.args2body(parsed_args)
for resource_id in parsed_args.ns:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _NS, resource_id)
client.delete_ns(obj, body)
deleted_ids.append(resource_id)
except Exception as e:
failure = True
failed_items[resource_id] = e
if failure:
msg = ''
if deleted_ids:
msg = (_('Successfully deleted %(resource)s(s):'
' %(deleted_list)s') % {'deleted_list':
', '.join(deleted_ids),
'resource': _NS})
err_msg = _("\n\nUnable to delete the below"
" %s(s):") % _NS
for failed_id, error in failed_items.items():
err_msg += (_('\n Cannot delete %(failed_id)s: %(error)s')
% {'failed_id': failed_id,
'error': error})
msg += err_msg
raise exceptions.CommandError(message=msg)
else:
print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _NS}))
return
class ListNS(command.Lister):
_description = ("List (NS)s that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListNS, self).get_parser(prog_name)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
data = client.list_nss()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_NS + 's']))
class ShowNS(command.ShowOne):
_description = _("Display NS details")
def get_parser(self, prog_name):
parser = super(ShowNS, self).get_parser(prog_name)
parser.add_argument(
_NS,
metavar="<NS>",
help=_("NS to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _NS, parsed_args.ns)
obj = client.show_ns(obj_id)
display_columns, columns = _get_columns(obj[_NS])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_NS]),
columns)
lstdata = list(data)
for index, value in enumerate(lstdata):
if value is None:
lstdata[index] = ''
data = tuple(lstdata)
return (display_columns, data)

View File

@ -1,229 +0,0 @@
# Copyright 2018 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.
#
import yaml
from osc_lib.command import command
from osc_lib import utils
from tackerclient.common import exceptions
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_attr_map = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('template_source', 'Template_Source',
tacker_osc_utils.LIST_BOTH),
('description', 'Description', tacker_osc_utils.LIST_BOTH),
)
_NSD = 'nsd'
_formatters = {
'attributes': tacker_osc_utils.format_dict_with_indention,
}
def _get_columns(item):
column_map = {
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
class CreateNSD(command.ShowOne):
_description = _("Create a new NSD.")
def get_parser(self, prog_name):
parser = super(CreateNSD, self).get_parser(prog_name)
parser.add_argument(
'name', metavar='NAME',
help=_('Name for NSD'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
parser.add_argument(
'--nsd-file',
required=True,
help=_('YAML file with NSD parameters'))
parser.add_argument(
'--description',
help=_('Set a description for the NSD'))
return parser
def args2body(self, parsed_args):
body = {_NSD: {}}
nsd = None
if not parsed_args.nsd_file:
raise exceptions.InvalidInput(reason="Invalid input for nsd file")
with open(parsed_args.nsd_file) as f:
nsd = f.read()
try:
nsd = yaml.load(nsd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not nsd:
raise exceptions.InvalidInput(reason="nsd file is empty")
body[_NSD]['attributes'] = {'nsd': nsd}
tackerV10.update_dict(parsed_args, body[_NSD],
['tenant_id', 'name', 'description'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
nsd = client.create_nsd(self.args2body(parsed_args))
display_columns, columns = _get_columns(nsd[_NSD])
nsd[_NSD]['attributes']['nsd'] = yaml.load(
nsd[_NSD]['attributes']['nsd'])
data = utils.get_item_properties(
sdk_utils.DictModel(nsd[_NSD]),
columns, formatters=_formatters)
return (display_columns, data)
class DeleteNSD(command.Command):
_description = _("Delete NSD(s).")
def get_parser(self, prog_name):
parser = super(DeleteNSD, self).get_parser(prog_name)
parser.add_argument(
_NSD,
metavar="<NSD>",
nargs="+",
help=_("NSD(s) to delete (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
for resource_id in parsed_args.nsd:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _NSD, resource_id)
client.delete_nsd(obj)
deleted_ids.append(resource_id)
except Exception as e:
failure = True
failed_items[resource_id] = e
if failure:
msg = ''
if deleted_ids:
msg = (_('Successfully deleted %(resource)s(s):'
' %(deleted_list)s') % {'deleted_list':
', '.join(deleted_ids),
'resource': _NSD})
err_msg = _("\n\nUnable to delete the below"
" %s(s):") % _NSD
for failed_id, error in failed_items.items():
err_msg += (_('\n Cannot delete %(failed_id)s: %(error)s')
% {'failed_id': failed_id,
'error': error})
msg += err_msg
raise exceptions.CommandError(message=msg)
else:
print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _NSD}))
return
class ListNSD(command.Lister):
_description = ("List (NSD)s that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListNSD, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List NSD with specified template source. Available \
options are 'onboared' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
data = client.list_nsds()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_NSD + 's']))
class ShowNSD(command.ShowOne):
_description = _("Display NSD details")
def get_parser(self, prog_name):
parser = super(ShowNSD, self).get_parser(prog_name)
parser.add_argument(
_NSD,
metavar="<NSD>",
help=_("NSD to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _NSD, parsed_args.nsd)
obj = client.show_nsd(obj_id)
obj[_NSD]['attributes']['nsd'] = yaml.load(
obj[_NSD]['attributes']['nsd'])
display_columns, columns = _get_columns(obj[_NSD])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_NSD]),
columns,
formatters=_formatters)
return (display_columns, data)
class ShowTemplateNSD(command.ShowOne):
_description = _("Display NSD Template details")
def get_parser(self, prog_name):
parser = super(ShowTemplateNSD, self).get_parser(prog_name)
parser.add_argument(
_NSD,
metavar="<NSD>",
help=_("NSD to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _NSD, parsed_args.nsd)
obj = client.show_nsd(obj_id)
obj[_NSD]['attributes']['nsd'] = yaml.load(
obj[_NSD]['attributes']['nsd'])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_NSD]),
('attributes',),
formatters=_formatters)
data = (data or _('Unable to display NSD template!'))
return (('attributes',), data)

View File

@ -1,574 +0,0 @@
# Copyright 2018 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.
#
import yaml
from osc_lib.command import command
from osc_lib import utils
from tackerclient.common import exceptions
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_VNFFG = 'vnffg' # VNF Forwarding Graph
_NFP = 'nfp' # Network Forwarding Path
_SFC = 'sfc' # Service Function Chain
_FC = 'classifier' # Flow Classifier
nfps_path = '/nfps'
fcs_path = '/classifiers'
sfcs_path = '/sfcs'
DEFAULT_ERROR_REASON_LENGTH = 100
_attr_map_vnffg = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('ns_id', 'NS ID', tacker_osc_utils.LIST_BOTH),
('vnffgd_id', 'VNFFGD ID', tacker_osc_utils.LIST_BOTH),
('status', 'Status', tacker_osc_utils.LIST_BOTH),
('description', 'Description', tacker_osc_utils.LIST_LONG_ONLY),
)
_attr_map_nfp = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('status', 'Status', tacker_osc_utils.LIST_BOTH),
('vnffg_id', 'VNFFG ID', tacker_osc_utils.LIST_BOTH),
('path_id', 'Path ID', tacker_osc_utils.LIST_BOTH),
)
_attr_map_sfc = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('status', 'Status', tacker_osc_utils.LIST_BOTH),
('nfp_id', 'NFP ID', tacker_osc_utils.LIST_BOTH),
)
_attr_map_fc = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('status', 'Status', tacker_osc_utils.LIST_BOTH),
('nfp_id', 'NFP ID', tacker_osc_utils.LIST_BOTH),
('chain_id', 'Chain ID', tacker_osc_utils.LIST_BOTH),
)
_formatters = {
'attributes': tacker_osc_utils.format_dict_with_indention,
'match': tacker_osc_utils.format_dict_with_indention,
'chain': tacker_osc_utils.format_dict_with_indention,
}
def _get_columns(item):
column_map = {
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
class CreateVNFFG(command.ShowOne):
_description = _("Create a new VNFFG.")
def get_parser(self, prog_name):
parser = super(CreateVNFFG, self).get_parser(prog_name)
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the VNFFG'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID'))
vnffgd_group = parser.add_mutually_exclusive_group(required=True)
vnffgd_group.add_argument(
'--vnffgd-id',
help=_('VNFFGD ID to use as template to create VNFFG'))
vnffgd_group.add_argument(
'--vnffgd-name',
help=_('VNFFGD Name to use as template to create VNFFG'))
vnffgd_group.add_argument(
'--vnffgd-template',
help=_('VNFFGD file to create VNFFG'))
parser.add_argument(
'--vnf-mapping',
help=_('List of logical VNFD name to VNF instance name mapping. '
'Example: VNF1:my_vnf1,VNF2:my_vnf2'))
parser.add_argument(
'--symmetrical',
action='store_true',
default=False,
help=_('Should a reverse path be created for the NFP '
'(True or False)'))
parser.add_argument(
'--param-file',
help=_('YAML file with specific VNFFG parameters'))
parser.add_argument(
'--description',
help=_('Set a description for the VNFFG'))
return parser
def args2body(self, parsed_args):
body = {_VNFFG: {}}
body[_VNFFG]['attributes'] = {}
client = self.app.client_manager.tackerclient
if parsed_args.vnf_mapping:
_vnf_mapping = dict()
_vnf_mappings = parsed_args.vnf_mapping.split(",")
for mapping in _vnf_mappings:
vnfd_name, vnf = mapping.split(":", 1)
_vnf_mapping[vnfd_name] = \
tackerV10.find_resourceid_by_name_or_id(
client, 'vnf', vnf)
parsed_args.vnf_mapping = _vnf_mapping
if parsed_args.vnffgd_name:
_id = tackerV10.find_resourceid_by_name_or_id(
client, 'vnffgd', parsed_args.vnffgd_name)
parsed_args.vnffgd_id = _id
elif parsed_args.vnffgd_template:
with open(parsed_args.vnffgd_template) as f:
template = f.read()
try:
template = yaml.load(template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not template:
raise exceptions.InvalidInput(
reason='The vnffgd file is empty')
body[_VNFFG]['vnffgd_template'] = template
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not param_yaml:
raise exceptions.InvalidInput(
reason='The parameter file is empty')
body[_VNFFG]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_VNFFG],
['tenant_id', 'name', 'vnffgd_id',
'symmetrical', 'vnf_mapping', 'description'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
vnffg = client.create_vnffg(self.args2body(parsed_args))
display_columns, columns = _get_columns(vnffg[_VNFFG])
data = utils.get_item_properties(
sdk_utils.DictModel(vnffg[_VNFFG]),
columns,
formatters=_formatters)
return (display_columns, data)
class DeleteVNFFG(command.Command):
_description = _("Delete VNFFG(s).")
def get_parser(self, prog_name):
parser = super(DeleteVNFFG, self).get_parser(prog_name)
parser.add_argument(
_VNFFG,
metavar="<VNFFG>",
nargs="+",
help=_("VNFFG(s) to delete (name or ID)")
)
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete VNFFG'))
return parser
def args2body(self, parsed_args):
body = dict()
if parsed_args.force:
body[_VNFFG] = dict()
body[_VNFFG]['attributes'] = dict()
body[_VNFFG]['attributes']['force'] = True
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
body = self.args2body(parsed_args)
for resource_id in parsed_args.vnffg:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _VNFFG, resource_id)
client.delete_vnffg(obj, body)
deleted_ids.append(resource_id)
except Exception as e:
failure = True
failed_items[resource_id] = e
if failure:
msg = ''
if deleted_ids:
msg = (_('Successfully deleted %(resource)s(s):'
' %(deleted_list)s') % {'deleted_list':
', '.join(deleted_ids),
'resource': _VNFFG})
err_msg = _("\n\nUnable to delete the below"
" %s(s):") % _VNFFG
for failed_id, error in failed_items.items():
err_msg += (_('\n Cannot delete %(failed_id)s: %(error)s')
% {'failed_id': failed_id,
'error': error})
msg += err_msg
raise exceptions.CommandError(message=msg)
else:
print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNFFG}))
return
class UpdateVNFFG(command.ShowOne):
_description = _("Update VNFFG.")
def get_parser(self, prog_name):
parser = super(UpdateVNFFG, self).get_parser(prog_name)
parser.add_argument(
_VNFFG,
metavar="<VNFFG>",
help=_('VNFFG to update (name or ID)'))
parser.add_argument(
'--vnffgd-template',
help=_('VNFFGD file to update VNFFG'))
parser.add_argument(
'--vnf-mapping',
help=_('List of logical VNFD name to VNF instance name mapping. '
'Example: VNF1:my_vnf1,VNF2:my_vnf2'))
parser.add_argument(
'--symmetrical',
action='store_true',
default=False,
help=_('Should a reverse path be created for the NFP'))
parser.add_argument(
'--description',
help=_('Set a description for the VNFFG'))
parser.add_argument(
'--param-file',
help=_('YAML file with specific VNFFG parameters'))
return parser
def args2body(self, parsed_args):
body = {_VNFFG: {}}
body[_VNFFG]['attributes'] = {}
client = self.app.client_manager.tackerclient
if parsed_args.vnf_mapping:
_vnf_mapping = dict()
_vnf_mappings = parsed_args.vnf_mapping.split(",")
for mapping in _vnf_mappings:
vnfd_name, vnf = mapping.split(":", 1)
_vnf_mapping[vnfd_name] = \
tackerV10.find_resourceid_by_name_or_id(
client, 'vnf', vnf)
parsed_args.vnf_mapping = _vnf_mapping
if parsed_args.vnffgd_template:
with open(parsed_args.vnffgd_template) as f:
template = f.read()
try:
template = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not template:
raise exceptions.InvalidInput(
reason='The vnffgd file is empty')
body[_VNFFG]['vnffgd_template'] = template
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not param_yaml:
raise exceptions.InvalidInput(
reason='The parameter file is empty')
body[_VNFFG]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_VNFFG],
['vnf_mapping', 'symmetrical', 'description'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNFFG, parsed_args.vnffg)
vnffg = client.update_vnffg(obj_id, self.args2body(parsed_args))
display_columns, columns = _get_columns(vnffg[_VNFFG])
data = utils.get_item_properties(
sdk_utils.DictModel(vnffg[_VNFFG]),
columns,
formatters=_formatters)
return (display_columns, data)
class ListVNFFG(command.Lister):
_description = ("List VNFFG(s) that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListVNFFG, self).get_parser(prog_name)
parser.add_argument(
'--long',
action='store_true',
help=_('List additional fields in output')
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
data = client.list_vnffgs()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map_vnffg, long_listing=parsed_args.long)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_VNFFG + 's']))
class ShowVNFFG(command.ShowOne):
_description = _("Display VNFFG details")
def get_parser(self, prog_name):
parser = super(ShowVNFFG, self).get_parser(prog_name)
parser.add_argument(
_VNFFG,
metavar="<VNFFG>",
help=_('VNFFG to display (name or ID)')
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNFFG, parsed_args.vnffg)
obj = client.show_vnffg(obj_id)
display_columns, columns = _get_columns(obj[_VNFFG])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_VNFFG]),
columns,
formatters=_formatters)
return (display_columns, data)
class ListNFP(command.Lister):
_description = ("List NFP(s) that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListNFP, self).get_parser(prog_name)
parser.add_argument(
'--vnffg-id',
help=_('List NFP(s) with specific VNFFG ID'))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
_params = {}
if parsed_args.vnffg_id:
_params['vnffg_id'] = parsed_args.vnffg_id
nfps = client.list('nfps', nfps_path, True, **_params)
for nfp in nfps['nfps']:
error_reason = nfp.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
nfp['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
nfp['error_reason'] += '...'
data = {}
data['nfps'] = nfps['nfps']
data = client.list_nfps()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map_nfp, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_NFP + 's']))
class ShowNFP(command.ShowOne):
_description = _("Display NFP details")
def get_parser(self, prog_name):
parser = super(ShowNFP, self).get_parser(prog_name)
parser.add_argument(
_NFP,
metavar="<NFP>",
help=_('NFP to display (name or ID)')
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _NFP, parsed_args.nfp)
obj = client.show_nfp(obj_id)
display_columns, columns = _get_columns(obj[_NFP])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_NFP]),
columns)
return (display_columns, data)
class ListFC(command.Lister):
_description = ("List flow classifier(s) that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListFC, self).get_parser(prog_name)
parser.add_argument(
'--nfp-id',
help=_('List flow classifier(s) with specific nfp id'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
_params = {}
if parsed_args.nfp_id:
_params['nfp_id'] = parsed_args.nfp_id
if parsed_args.tenant_id:
_params['tenant_id'] = parsed_args.tenant_id
classifiers = client.list('classifiers', fcs_path, True,
**_params)
for classifier in classifiers['classifiers']:
error_reason = classifier.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
classifier['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
classifier['error_reason'] += '...'
data = {}
data['classifiers'] = classifiers['classifiers']
data = client.list_classifiers()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map_fc, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_FC + 's']))
class ShowFC(command.ShowOne):
_description = _("Display flow classifier details")
def get_parser(self, prog_name):
parser = super(ShowFC, self).get_parser(prog_name)
parser.add_argument(
_FC,
metavar="<Classifier ID>",
help=_('Flow Classifier to display (name or ID)')
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _FC, parsed_args.classifier)
obj = client.show_classifier(obj_id)
display_columns, columns = _get_columns(obj[_FC])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_FC]),
columns,
formatters=_formatters)
return (display_columns, data)
class ListSFC(command.Lister):
_description = ("List SFC(s) that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListSFC, self).get_parser(prog_name)
parser.add_argument(
'--nfp-id',
help=_('List SFC(s) with specific nfp id'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
_params = {}
if parsed_args.nfp_id:
_params['nfp_id'] = parsed_args.nfp_id
if parsed_args.tenant_id:
_params['tenant_id'] = parsed_args.tenant_id
sfcs = client.list('sfcs', sfcs_path, True, **_params)
for chain in sfcs['sfcs']:
error_reason = chain.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
chain['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
chain['error_reason'] += '...'
data = {}
data['sfcs'] = sfcs['sfcs']
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map_sfc, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_SFC + 's']))
class ShowSFC(command.ShowOne):
_description = _("Display SFC details")
def get_parser(self, prog_name):
parser = super(ShowSFC, self).get_parser(prog_name)
parser.add_argument(
_SFC,
metavar="<SFC>",
help=_('SFC to display (name or ID)')
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _SFC, parsed_args.sfc)
obj = client.show_sfc(obj_id)
display_columns, columns = _get_columns(obj[_SFC])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_SFC]),
columns,
formatters=_formatters)
return (display_columns, data)

View File

@ -1,223 +0,0 @@
# Copyright 2018 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.
#
import yaml
from osc_lib.command import command
from osc_lib import utils
from tackerclient.common import exceptions
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_attr_map = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('template_source', 'Template_Source',
tacker_osc_utils.LIST_BOTH),
('description', 'Description', tacker_osc_utils.LIST_BOTH),
)
_VNFFGD = "vnffgd"
_formatters = {
'template': tacker_osc_utils.format_dict_with_indention,
}
def _get_columns(item):
column_map = {
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
class CreateVNFFGD(command.ShowOne):
_description = _("Create a new VNFFGD")
def get_parser(self, prog_name):
parser = super(CreateVNFFGD, self).get_parser(prog_name)
parser.add_argument(
'name', metavar='NAME',
help=_('Name for VNFFGD'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
parser.add_argument(
'--vnffgd-file',
required=True,
help=_('YAML file with VNFFGD parameters'))
parser.add_argument(
'--description',
help=_('Set a description for the VNFFGD'))
return parser
def args2body(self, parsed_args):
body = {_VNFFGD: {}}
vnffgd = None
if not parsed_args.vnffgd_file:
raise exceptions.InvalidInput(
reason="Invalid input for vnffgd file")
with open(parsed_args.vnffgd_file) as f:
vnffgd = f.read()
try:
vnffgd = yaml.load(vnffgd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not vnffgd:
raise exceptions.InvalidInput(reason="vnffgd file is empty")
body[_VNFFGD]['template'] = {'vnffgd': vnffgd}
tackerV10.update_dict(parsed_args, body[_VNFFGD],
['tenant_id', 'name', 'description'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
vnffgd = client.create_vnffgd(self.args2body(parsed_args))
display_columns, columns = _get_columns(vnffgd[_VNFFGD])
data = utils.get_item_properties(
sdk_utils.DictModel(vnffgd[_VNFFGD]),
columns, formatters=_formatters)
return (display_columns, data)
class DeleteVNFFGD(command.Command):
_description = _("Delete VNFFGD(s).")
def get_parser(self, prog_name):
parser = super(DeleteVNFFGD, self).get_parser(prog_name)
parser.add_argument(
_VNFFGD,
metavar="<VNFFGD>",
nargs="+",
help=_("VNFFGD(s) to delete (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
for resource_id in parsed_args.vnffgd:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _VNFFGD, resource_id)
client.delete_vnffgd(obj)
deleted_ids.append(resource_id)
except Exception as e:
failure = True
failed_items[resource_id] = e
if failure:
msg = ''
if deleted_ids:
msg = (_('Successfully deleted %(resource)s(s):'
' %(deleted_list)s') % {'deleted_list':
', '.join(deleted_ids),
'resource': _VNFFGD})
err_msg = _("\n\nUnable to delete the below"
" %s(s):") % _VNFFGD
for failed_id, error in failed_items.items():
err_msg += (_('\n Cannot delete %(failed_id)s: %(error)s')
% {'failed_id': failed_id,
'error': error})
msg += err_msg
raise exceptions.CommandError(message=msg)
else:
print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNFFGD}))
return
class ListVNFFGD(command.Lister):
_description = ("List (VNFFGD)s that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListVNFFGD, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List VNFFGD with specified template source. Available \
options are 'onboarded' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
data = client.list_vnffgds()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_VNFFGD + 's']))
class ShowVNFFGD(command.ShowOne):
_description = _("Display VNFFGD details")
def get_parser(self, prog_name):
parser = super(ShowVNFFGD, self).get_parser(prog_name)
parser.add_argument(
_VNFFGD,
metavar="<VNFFGD>",
help=_("VNFFGD to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNFFGD, parsed_args.vnffgd)
obj = client.show_vnffgd(obj_id)
display_columns, columns = _get_columns(obj[_VNFFGD])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_VNFFGD]),
columns, formatters=_formatters)
return (display_columns, data)
class ShowTemplateVNFFGD(command.ShowOne):
_description = _("Display VNFFGD Template details")
def get_parser(self, prog_name):
parser = super(ShowTemplateVNFFGD, self).get_parser(prog_name)
parser.add_argument(
_VNFFGD,
metavar="<VNFFGD>",
help=_("VNFFGD to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNFFGD, parsed_args.vnffgd)
obj = client.show_vnffgd(obj_id)
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_VNFFGD]),
('template',),
formatters=_formatters)
data = (data or _('Unable to display VNFFGD template!'))
return (('template',), data)

View File

@ -1,472 +0,0 @@
# Copyright 2018 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.
#
import yaml
from osc_lib.command import command
from osc_lib import utils
from oslo_utils import encodeutils
from tackerclient.common import exceptions
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_attr_map = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('mgmt_ip_address', 'Mgmt Ip Address',
tacker_osc_utils.LIST_BOTH),
('status', 'Status', tacker_osc_utils.LIST_BOTH),
('vim_id', 'VIM ID', tacker_osc_utils.LIST_BOTH),
('vnfd_id', 'VNFD ID', tacker_osc_utils.LIST_BOTH),
('tenant_id', 'Project ID', tacker_osc_utils.LIST_LONG_ONLY),
)
_attr_map_rsc = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('type', 'Type', tacker_osc_utils.LIST_BOTH),
)
_VNF = "vnf"
def _get_columns(item):
column_map = {
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
def _break_string(vnf_monitoring_policy):
count_space = 0
monitoring_policy = "\n"
for i in range(0, len(vnf_monitoring_policy)):
monitoring_policy += vnf_monitoring_policy[i]
if vnf_monitoring_policy[i] == ' ':
count_space += 1
if count_space == 9:
monitoring_policy += "\n"
count_space = 0
return monitoring_policy
class CreateVNF(command.ShowOne):
_description = _("Create a new VNF")
def get_parser(self, prog_name):
parser = super(CreateVNF, self).get_parser(prog_name)
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the VNF'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
vnfd_group = parser.add_mutually_exclusive_group(required=True)
vnfd_group.add_argument(
'--vnfd-id',
help=_('VNFD ID to use as template to create VNF'))
vnfd_group.add_argument(
'--vnfd-name',
help=_('VNFD Name to use as template to create VNF'))
vnfd_group.add_argument(
'--vnfd-template',
help=_("VNFD file to create VNF"))
vim_group = parser.add_mutually_exclusive_group()
vim_group.add_argument(
'--vim-id',
help=_('VIM ID to deploy VNF on specified VIM'))
vim_group.add_argument(
'--vim-name',
help=_('VIM name to deploy VNF on specified VIM'))
parser.add_argument(
'--vim-region-name',
help=_('VIM Region to deploy VNF on specified VIM'))
parser.add_argument(
'--config-file',
help=_('YAML file with VNF configuration'))
parser.add_argument(
'--param-file',
help=_('Specify parameter yaml file'))
parser.add_argument(
'--description',
help=_('Set description for the VNF'))
return parser
def args2body(self, parsed_args):
body = {_VNF: {}}
body[_VNF]['attributes'] = {}
config = None
if parsed_args.config_file:
with open(parsed_args.config_file) as f:
config_yaml = f.read()
try:
config = yaml.load(
config_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if config:
body[_VNF]['attributes'] = {'config': config}
if parsed_args.vim_region_name:
body[_VNF].setdefault('placement_attr', {})['region_name'] = \
parsed_args.vim_region_name
client = self.app.client_manager.tackerclient
if parsed_args.vim_name:
_id = tackerV10.find_resourceid_by_name_or_id(client, 'vim',
parsed_args.vim_name)
parsed_args.vim_id = _id
if parsed_args.vnfd_name:
_id = tackerV10.find_resourceid_by_name_or_id(
client, 'vnfd',
parsed_args.vnfd_name
)
parsed_args.vnfd_id = _id
elif parsed_args.vnfd_template:
with open(parsed_args.vnfd_template) as f:
template = f.read()
try:
template = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not template:
raise exceptions.InvalidInput(
reason='The vnfd file is empty')
body[_VNF]['vnfd_template'] = template
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not param_yaml:
raise exceptions.InvalidInput(
reason='The parameter file is empty')
body[_VNF]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_VNF],
['tenant_id', 'name', 'description',
'vnfd_id', 'vim_id'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
vnf = client.create_vnf(self.args2body(parsed_args))
display_columns, columns = _get_columns(vnf[_VNF])
if vnf[_VNF]['attributes'].get('monitoring_policy'):
vnf[_VNF]['attributes']['monitoring_policy'] =\
_break_string(vnf[_VNF]['attributes']['monitoring_policy'])
data = utils.get_item_properties(
sdk_utils.DictModel(vnf[_VNF]),
columns)
return (display_columns, data)
class DeleteVNF(command.Command):
_description = _("Delete VNF(s).")
def get_parser(self, prog_name):
parser = super(DeleteVNF, self).get_parser(prog_name)
parser.add_argument(
_VNF,
metavar="<VNF>",
nargs="+",
help=_("VNF(s) to delete (name or ID)"))
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete VNF instance'))
return parser
def args2body(self, parsed_args):
body = dict()
if parsed_args.force:
body[_VNF] = dict()
body[_VNF]['attributes'] = dict()
body[_VNF]['attributes']['force'] = True
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
body = self.args2body(parsed_args)
for resource_id in parsed_args.vnf:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _VNF, resource_id)
client.delete_vnf(obj, body)
deleted_ids.append(resource_id)
except Exception as e:
failure = True
failed_items[resource_id] = e
if failure:
msg = ''
if deleted_ids:
msg = (_('Successfully deleted %(resource)s(s):'
' %(deleted_list)s') % {'deleted_list':
', '.join(deleted_ids),
'resource': _VNF})
err_msg = _("\n\nUnable to delete the below"
" %s(s):") % _VNF
for failed_id, error in failed_items.items():
err_msg += (_('\n Cannot delete %(failed_id)s: %(error)s')
% {'failed_id': failed_id,
'error': error})
msg += err_msg
raise exceptions.CommandError(message=msg)
else:
print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNF}))
return
class ListVNF(command.Lister):
_description = _("List VNF(s) that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListVNF, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List VNF with specified template source. Available \
options are 'onboarded' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
vim_group = parser.add_mutually_exclusive_group()
vim_group.add_argument(
'--vim-id',
help=_('List VNF(s) that belong to a given VIM ID'))
vim_group.add_argument(
'--vim-name',
help=_('List VNF(s) that belong to a given VIM Name'))
vnfd_group = parser.add_mutually_exclusive_group()
vnfd_group.add_argument(
'--vnfd-id',
help=_('List VNF(s) that belong to a given VNFD ID'))
vnfd_group.add_argument(
'--vnfd-name',
help=_('List VNF(s) that belong to a given VNFD Name'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
parser.add_argument(
'--long',
action='store_true',
help=_('List additional fields in output'))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
_params = {}
if parsed_args.vim_id:
_params['vim_id'] = parsed_args.vim_id
if parsed_args.vim_name:
vim_id = tackerV10.find_resourceid_by_name_or_id(
client, 'vim', parsed_args.vim_name
)
_params['vim_id'] = vim_id
if parsed_args.vnfd_id:
_params['vnfd_id'] = parsed_args.vnfd_id
if parsed_args.vnfd_name:
vim_id = tackerV10.find_resourceid_by_name_or_id(
client, 'vnfd', parsed_args.vnfd_name
)
_params['vnfd_id'] = vim_id
if parsed_args.tenant_id:
_params['tenant_id'] = parsed_args.tenant_id
data = client.list_vnfs(**_params)
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map, long_listing=parsed_args.long)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_VNF + 's']))
class ShowVNF(command.ShowOne):
_description = _("Display VNF details")
def get_parser(self, prog_name):
parser = super(ShowVNF, self).get_parser(prog_name)
parser.add_argument(
_VNF,
metavar="<VNF>",
help=_("VNF to display (name or ID)"))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNF, parsed_args.vnf)
obj = client.show_vnf(obj_id)
if obj[_VNF]['attributes'].get('monitoring_policy'):
obj[_VNF]['attributes']['monitoring_policy'] =\
_break_string(obj[_VNF]['attributes']['monitoring_policy'])
display_columns, columns = _get_columns(obj[_VNF])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_VNF]),
columns)
return (display_columns, data)
class ListVNFResources(command.Lister):
_description = _("List resources of a VNF like VDU, CP, etc.")
def get_parser(self, prog_name):
parser = super(ListVNFResources, self).get_parser(prog_name)
parser.add_argument(
_VNF,
metavar="<VNF>",
help=_("VNF to display (name or ID)"))
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNF, parsed_args.vnf)
data = client.list_vnf_resources(obj_id)
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map_rsc, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data['resources']))
class UpdateVNF(command.ShowOne):
_description = _("Update a given VNF.")
def get_parser(self, prog_name):
parser = super(UpdateVNF, self).get_parser(prog_name)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'--config-file',
help=_('YAML file with VNF configuration'))
group.add_argument(
'--config',
help=_('YAML data with VNF configuration'))
group.add_argument(
'--param-file',
help=_('YAML file with VNF parameter'))
parser.add_argument(
_VNF,
metavar="<VNF>",
help=_("VNF to update (name or ID)"))
return parser
def args2body(self, parsed_args):
body = {_VNF: {}}
body[_VNF]['attributes'] = {}
config = None
if parsed_args.config_file:
with open(parsed_args.config_file) as f:
config_yaml = f.read()
try:
config = yaml.load(config_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not config:
raise exceptions.InvalidInput(
reason='The config file is empty')
if parsed_args.config:
decoded_config = encodeutils.safe_decode(parsed_args.config)
try:
config = yaml.load(decoded_config, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not config:
raise exceptions.InvalidInput(
reason='The parameter is empty')
if config:
body[_VNF]['attributes'] = {'config': config}
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
param = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not param:
raise exceptions.InvalidInput(
reason='The parameter file is empty')
body[_VNF]['attributes'] = {'param_values': param}
tackerV10.update_dict(parsed_args, body[_VNF], ['tenant_id'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNF, parsed_args.vnf)
vnf = client.update_vnf(obj_id, self.args2body(parsed_args))
if vnf[_VNF]['attributes'].get('monitoring_policy'):
vnf[_VNF]['attributes']['monitoring_policy'] =\
_break_string(vnf[_VNF]['attributes']['monitoring_policy'])
display_columns, columns = _get_columns(vnf[_VNF])
data = utils.get_item_properties(
sdk_utils.DictModel(vnf[_VNF]),
columns)
return (display_columns, data)
class ScaleVNF(command.Command):
_description = _("Scale a VNF.")
def get_parser(self, prog_name):
parser = super(ScaleVNF, self).get_parser(prog_name)
parser.add_argument(
'--scaling-policy-name',
help=_('VNF policy name used to scale'))
parser.add_argument(
'--scaling-type',
help=_('VNF scaling type, it could be either "out" or "in"'))
parser.add_argument(
_VNF,
metavar="<VNF>",
help=_("VNF to scale (name or ID)"))
return parser
def args2body(self, parsed_args):
args = {}
body = {"scale": args}
args['type'] = parsed_args.scaling_type
args['policy'] = parsed_args.scaling_policy_name
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNF, parsed_args.vnf)
client.scale_vnf(obj_id, self.args2body(parsed_args))
return

View File

@ -1,230 +0,0 @@
# Copyright 2016 NEC Corporation.
# 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.
#
import yaml
from osc_lib.command import command
from osc_lib import utils
from tackerclient.common import exceptions
from tackerclient.common import utils as tacker_common_utils
from tackerclient.i18n import _
from tackerclient.osc import sdk_utils
from tackerclient.osc import utils as tacker_osc_utils
from tackerclient.tacker import v1_0 as tackerV10
_attr_map = (
('id', 'ID', tacker_osc_utils.LIST_BOTH),
('name', 'Name', tacker_osc_utils.LIST_BOTH),
('template_source', 'Template_Source',
tacker_osc_utils.LIST_BOTH),
('description', 'Description', tacker_osc_utils.LIST_BOTH),
)
_VNFD = "vnfd"
_formatters = {
'attributes': tacker_osc_utils.format_dict_with_indention,
}
def _get_columns(item):
column_map = {
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
class CreateVNFD(command.ShowOne):
_description = _("Create a new VNFD")
def get_parser(self, prog_name):
parser = super(CreateVNFD, self).get_parser(prog_name)
parser.add_argument(
'name', metavar='NAME',
help=_('Name for VNFD'))
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('The owner tenant ID or project ID'))
parser.add_argument(
'--vnfd-file',
required=True,
help=_('YAML file with VNFD parameters'))
parser.add_argument(
'--description',
help=_('Set a description for the VNFD'))
return parser
def args2body(self, parsed_args):
body = {_VNFD: {}}
vnfd = None
if not parsed_args.vnfd_file:
raise exceptions.InvalidInput(reason="Invalid input for vnfd file")
with open(parsed_args.vnfd_file) as f:
vnfd = f.read()
try:
vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
msg = _("yaml failed to load vnfd file. %s") % e
raise exceptions.InvalidInput(reason=msg)
if not vnfd:
raise exceptions.InvalidInput(reason="vnfd file is empty")
body[_VNFD]['attributes'] = {'vnfd': vnfd}
tackerV10.update_dict(parsed_args, body[_VNFD],
['tenant_id', 'name', 'description'])
return body
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
vnfd = client.create_vnfd(self.args2body(parsed_args))
display_columns, columns = _get_columns(vnfd[_VNFD])
vnfd[_VNFD]['attributes']['vnfd'] = yaml.load(
vnfd[_VNFD]['attributes']['vnfd'])
data = utils.get_item_properties(
sdk_utils.DictModel(vnfd[_VNFD]),
columns, formatters=_formatters)
return (display_columns, data)
class DeleteVNFD(command.Command):
_description = _("Delete VNFD(s).")
def get_parser(self, prog_name):
parser = super(DeleteVNFD, self).get_parser(prog_name)
parser.add_argument(
_VNFD,
metavar="<VNFD>",
nargs="+",
help=_("VNFD(s) to delete (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
failure = False
deleted_ids = []
failed_items = {}
for resource_id in parsed_args.vnfd:
try:
obj = tackerV10.find_resourceid_by_name_or_id(
client, _VNFD, resource_id)
client.delete_vnfd(obj)
deleted_ids.append(resource_id)
except Exception as e:
failure = True
failed_items[resource_id] = e
if failure:
msg = ''
if deleted_ids:
msg = (_('Successfully deleted %(resource)s(s):'
' %(deleted_list)s') % {'deleted_list':
', '.join(deleted_ids),
'resource': _VNFD})
err_msg = _("\n\nUnable to delete the below"
" %s(s):") % _VNFD
for failed_id, error in failed_items.items():
err_msg += (_('\n Cannot delete %(failed_id)s: %(error)s')
% {'failed_id': failed_id,
'error': error})
msg += err_msg
raise exceptions.CommandError(message=msg)
else:
print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNFD}))
return
class ListVNFD(command.Lister):
_description = ("List (VNFD)s that belong to a given tenant.")
def get_parser(self, prog_name):
parser = super(ListVNFD, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List VNFD with specified template source. Available \
options are 'onboarded' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
data = client.list_vnfds()
headers, columns = tacker_osc_utils.get_column_definitions(
_attr_map, long_listing=None)
return (headers,
(utils.get_dict_properties(
s, columns,
) for s in data[_VNFD + 's']))
class ShowVNFD(command.ShowOne):
_description = _("Display VNFD details")
def get_parser(self, prog_name):
parser = super(ShowVNFD, self).get_parser(prog_name)
parser.add_argument(
_VNFD,
metavar="<VNFD>",
help=_("VNFD to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNFD, parsed_args.vnfd)
obj = client.show_vnfd(obj_id)
obj[_VNFD]['attributes']['vnfd'] = yaml.load(
obj[_VNFD]['attributes']['vnfd'])
display_columns, columns = _get_columns(obj[_VNFD])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_VNFD]),
columns,
formatters=_formatters)
return (display_columns, data)
class ShowTemplateVNFD(command.ShowOne):
_description = _("Display VNFD Template details")
def get_parser(self, prog_name):
parser = super(ShowTemplateVNFD, self).get_parser(prog_name)
parser.add_argument(
_VNFD,
metavar="<VNFD>",
help=_("VNFD to display (name or ID)")
)
return parser
def take_action(self, parsed_args):
tacker_common_utils.deprecate_legacy_warning()
client = self.app.client_manager.tackerclient
obj_id = tackerV10.find_resourceid_by_name_or_id(
client, _VNFD, parsed_args.vnfd)
obj = client.show_vnfd(obj_id)
obj[_VNFD]['attributes']['vnfd'] = yaml.load(
obj[_VNFD]['attributes']['vnfd'])
data = utils.get_item_properties(
sdk_utils.DictModel(obj[_VNFD]),
('attributes',),
formatters=_formatters)
data = (data or _('Unable to display VNFD template!'))
return (('attributes',), data)

View File

@ -43,16 +43,7 @@ from tackerclient.common import exceptions as exc
from tackerclient.common import extension as client_extension
from tackerclient.common import utils
from tackerclient.i18n import _
from tackerclient.tacker.v1_0.events import events
from tackerclient.tacker.v1_0 import extension
from tackerclient.tacker.v1_0.nfvo import ns
from tackerclient.tacker.v1_0.nfvo import nsd
from tackerclient.tacker.v1_0.nfvo import vim
from tackerclient.tacker.v1_0.nfvo import vnfcluster
from tackerclient.tacker.v1_0.nfvo import vnffg
from tackerclient.tacker.v1_0.nfvo import vnffgd
from tackerclient.tacker.v1_0.vnfm import vnf
from tackerclient.tacker.v1_0.vnfm import vnfd
from tackerclient.version import __version__
@ -105,79 +96,13 @@ class BashCompletionCommand(openstack_command.OpenStackCommand):
COMMAND_V1 = {
'bash-completion': BashCompletionCommand,
'ext-list': extension.ListExt,
'ext-show': extension.ShowExt,
# MANO lingo
'vnfd-create': vnfd.CreateVNFD,
'vnfd-delete': vnfd.DeleteVNFD,
'vnfd-list': vnfd.ListVNFD,
'vnfd-show': vnfd.ShowVNFD,
'vnfd-template-show': vnfd.ShowTemplateVNFD,
'vnf-create': vnf.CreateVNF,
'vnf-update': vnf.UpdateVNF,
'vnf-delete': vnf.DeleteVNF,
'vnf-list': vnf.ListVNF,
'vnf-show': vnf.ShowVNF,
'vnf-scale': vnf.ScaleVNF,
'vnf-resource-list': vnf.ListVNFResources,
# 'vnf-config-create'
# 'vnf-config-push'
'vim-register': vim.CreateVIM,
'vim-update': vim.UpdateVIM,
'vim-delete': vim.DeleteVIM,
'vim-list': vim.ListVIM,
'vim-show': vim.ShowVIM,
'events-list': events.ListResourceEvents,
'event-show': events.ShowEvent,
'vnf-events-list': events.ListVNFEvents,
'vim-events-list': events.ListVIMEvents,
'vnfd-events-list': events.ListVNFDEvents,
'vnffgd-create': vnffgd.CreateVNFFGD,
'vnffgd-delete': vnffgd.DeleteVNFFGD,
'vnffgd-list': vnffgd.ListVNFFGD,
'vnffgd-show': vnffgd.ShowVNFFGD,
'vnffgd-template-show': vnffgd.ShowTemplateVNFFGD,
'vnffg-create': vnffg.CreateVNFFG,
'vnffg-delete': vnffg.DeleteVNFFG,
'vnffg-list': vnffg.ListVNFFG,
'vnffg-show': vnffg.ShowVNFFG,
'vnffg-update': vnffg.UpdateVNFFG,
'nfp-list': vnffg.ListNFP,
'nfp-show': vnffg.ShowNFP,
'chain-list': vnffg.ListSFC,
'chain-show': vnffg.ShowSFC,
'classifier-list': vnffg.ListFC,
'classifier-show': vnffg.ShowFC,
'nsd-create': nsd.CreateNSD,
'nsd-list': nsd.ListNSD,
'nsd-delete': nsd.DeleteNSD,
'nsd-show': nsd.ShowNSD,
'nsd-template-show': nsd.ShowTemplateNSD,
'ns-create': ns.CreateNS,
'ns-list': ns.ListNS,
'ns-delete': ns.DeleteNS,
'ns-show': ns.ShowNS,
'cluster-create': vnfcluster.CreateCluster,
'cluster-delete': vnfcluster.DeleteCluster,
'cluster-list': vnfcluster.ListCluster,
'cluster-show': vnfcluster.ShowCluster,
'cluster-member-add': vnfcluster.AddClusterMember,
'cluster-member-show': vnfcluster.ShowClusterMember,
'cluster-member-list': vnfcluster.ListClusterMember,
'cluster-member-delete': vnfcluster.DeleteClusterMember,
'vim-show': vim.ShowVIM
}
COMMANDS = {'1.0': COMMAND_V1}

View File

@ -374,12 +374,12 @@ class TackerCommand(command.OpenStackCommand, metaclass=TackerCommandMeta):
parser = super(TackerCommand, self).get_parser(prog_name)
parser.add_argument(
'--request-format',
help=_('The xml or json request format'),
help=_('The json request format'),
default='json',
choices=['json', 'xml', ], )
choices=['json', ], )
parser.add_argument(
'--request_format',
choices=['json', 'xml', ],
choices=['json', ],
help=argparse.SUPPRESS)
return parser

View File

@ -1,95 +0,0 @@
# Copyright 2016 Brocade Communications Systems Inc
# 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.tacker import v1_0 as tackerV10
_EVENT = "event"
class ListEventsBase(tackerV10.ListCommand):
"""Base class for list command."""
list_columns = ['id', 'resource_type', 'resource_id',
'resource_state', 'event_type',
'timestamp', 'event_details']
def get_parser(self, prog_name):
parser = super(ListEventsBase, self).get_parser(prog_name)
parser.add_argument('--id',
help='id of the event to look up.')
parser.add_argument('--resource-id',
help='resource id of the events to look up.')
parser.add_argument('--resource-state',
help='resource state of the events to look up.')
parser.add_argument('--event-type',
help='event type of the events to look up.')
return parser
def args2search_opts(self, parsed_args):
search_opts = super(ListEventsBase, self).args2search_opts(
parsed_args)
if parsed_args.id:
search_opts.update({'id': parsed_args.id})
if parsed_args.resource_id:
search_opts.update({'resource_id': parsed_args.resource_id})
if parsed_args.resource_state:
search_opts.update({'resource_state': parsed_args.resource_state})
if parsed_args.event_type:
search_opts.update({'event_type': parsed_args.event_type})
return search_opts
class ListResourceEvents(ListEventsBase):
"""List events of resources."""
resource = _EVENT
def get_parser(self, prog_name):
parser = super(ListResourceEvents, self).get_parser(prog_name)
parser.add_argument('--resource-type',
help='resource type of the events to look up.')
return parser
def args2search_opts(self, parsed_args):
search_opts = super(ListResourceEvents, self).args2search_opts(
parsed_args)
if parsed_args.resource_type:
search_opts.update({'resource_type': parsed_args.resource_type})
return search_opts
class ListVNFEvents(ListEventsBase):
"""List events of VNFs."""
resource = "vnf_event"
class ListVNFDEvents(ListEventsBase):
"""List events of VNFDs."""
resource = "vnfd_event"
class ListVIMEvents(ListEventsBase):
"""List events of VIMs."""
resource = "vim_event"
class ShowEvent(tackerV10.ShowCommand):
"""Show event given the event id."""
resource = _EVENT

View File

@ -1,34 +0,0 @@
# 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.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_id(self):
return 'EXT-ALIAS'

View File

@ -1,139 +0,0 @@
# 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.
import yaml
from tackerclient.common import exceptions
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
_NS = 'ns'
_RESOURCE = 'resource'
class ListNS(tackerV10.ListCommand):
"""List NS that belong to a given tenant."""
resource = _NS
list_columns = ['id', 'name', 'nsd_id', 'vnf_ids', 'vnffg_ids',
'mgmt_ip_addresses', 'status']
class ShowNS(tackerV10.ShowCommand):
"""Show information of a given NS."""
resource = _NS
class CreateNS(tackerV10.CreateCommand):
"""Create a NS."""
resource = _NS
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the NS'))
parser.add_argument(
'--description',
help=_('Set description for the NS'))
nsd_group = parser.add_mutually_exclusive_group(required=True)
nsd_group.add_argument(
'--nsd-id',
help=_('NSD ID to use as template to create NS'))
nsd_group.add_argument(
'--nsd-template',
help=_('NSD file to create NS'))
nsd_group.add_argument(
'--nsd-name',
help=_('NSD name to use as template to create NS'))
vim_group = parser.add_mutually_exclusive_group()
vim_group.add_argument(
'--vim-id',
help=_('VIM ID to use to create NS on the specified VIM'))
vim_group.add_argument(
'--vim-name',
help=_('VIM name to use to create NS on the specified VIM'))
parser.add_argument(
'--vim-region-name',
help=_('VIM Region to use to create NS on the specified VIM'))
parser.add_argument(
'--param-file',
help=_('Specify parameter yaml file'))
def args2body(self, parsed_args):
args = {'attributes': {}}
body = {self.resource: args}
if parsed_args.vim_region_name:
args.setdefault('placement_attr', {})['region_name'] = \
parsed_args.vim_region_name
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.vim_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vim',
parsed_args.
vim_name)
parsed_args.vim_id = _id
if parsed_args.nsd_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'nsd',
parsed_args.
nsd_name)
parsed_args.nsd_id = _id
elif parsed_args.nsd_template:
with open(parsed_args.nsd_template) as f:
template = f.read()
try:
args['nsd_template'] = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not args['nsd_template']:
raise exceptions.InvalidInput(reason='The nsd file is empty')
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description',
'nsd_id', 'vim_id'])
return body
class DeleteNS(tackerV10.DeleteCommand):
"""Delete given NS(s)."""
resource = _NS
deleted_msg = {'ns': 'delete initiated'}
def add_known_arguments(self, parser):
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete Network Service'))
def args2body(self, parsed_args):
if parsed_args.force:
body = {self.resource: {'attributes': {'force': True}}}
else:
body = dict()
return body

View File

@ -1,100 +0,0 @@
# 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.
import yaml
from oslo_serialization import jsonutils
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
_NSD = "nsd"
class ListNSD(tackerV10.ListCommand):
"""List NSDs that belong to a given tenant."""
resource = _NSD
list_columns = ['id', 'name', 'template_source', 'description']
def get_parser(self, prog_name):
parser = super(ListNSD, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List NSD with specified template source. Available \
options are 'onboared' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
return parser
def args2search_opts(self, parsed_args):
search_opts = super(ListNSD, self).args2search_opts(parsed_args)
template_source = parsed_args.template_source
if parsed_args.template_source:
search_opts.update({'template_source': template_source})
return search_opts
class ShowNSD(tackerV10.ShowCommand):
"""Show information of a given NSD."""
resource = _NSD
class CreateNSD(tackerV10.CreateCommand):
"""Create a NSD."""
resource = _NSD
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument('--nsd-file', help='Specify NSD file',
required=True)
parser.add_argument(
'name', metavar='NAME',
help='Set a name for the NSD')
parser.add_argument(
'--description',
help='Set a description for the NSD')
def args2body(self, parsed_args):
body = {self.resource: {}}
nsd = None
with open(parsed_args.nsd_file) as f:
nsd = yaml.safe_load(f.read())
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description'])
if nsd:
body[self.resource]['attributes'] = {'nsd': nsd}
return body
class DeleteNSD(tackerV10.DeleteCommand):
"""Delete a given NSD."""
resource = _NSD
class ShowTemplateNSD(tackerV10.ShowCommand):
"""Show template of a given NSD."""
resource = _NSD
def run(self, parsed_args):
self.log.debug('run(%s)', parsed_args)
template = None
data = self.get_data(parsed_args)
try:
attributes_index = data[0].index('attributes')
attributes_json = data[1][attributes_index]
template = jsonutils.loads(attributes_json).get('nsd', None)
except (IndexError, TypeError, ValueError) as e:
self.log.debug('Data handling error: %s', str(e))
print(template or _('Unable to display NSD template!'))

View File

@ -1,191 +0,0 @@
# 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.tacker import v1_0 as tackerV10
import yaml
_CLUSTER = 'cluster'
_CLUSTER_MEMBER = 'clustermember'
class ListCluster(tackerV10.ListCommand):
"""List Clusters that belong to a given tenant."""
resource = _CLUSTER
list_columns = ['id', 'name', 'vnfd_id', 'status', 'vip_endpoint']
class ShowCluster(tackerV10.ShowCommand):
"""Show information of a given Cluster."""
resource = _CLUSTER
class DeleteCluster(tackerV10.DeleteCommand):
"""Delete a given Cluster."""
resource = _CLUSTER
class CreateCluster(tackerV10.CreateCommand):
"""Create a Cluster."""
resource = _CLUSTER
def add_known_arguments(self, parser):
parser.add_argument(
'name', metavar='NAME',
help='Set a name for the VNF cluster')
vnfd_group = parser.add_mutually_exclusive_group(required=True)
vnfd_group.add_argument(
'--vnfd-id',
help='VNFD ID to use as template to create member VNF')
vnfd_group.add_argument(
'--vnfd-name',
help='VNFD name to use as template to create member VNF')
parser.add_argument('--policy-file',
help='Specify policy file for cluster',
required=True)
parser.add_argument(
'--description',
help='Set a description for the created VNF cluster')
def args2body(self, parsed_args):
body = {self.resource: {}}
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.vnfd_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vnfd',
parsed_args.
vnfd_name)
parsed_args.vnfd_id = _id
policy_info = None
with open(parsed_args.policy_file) as f:
policy_info = yaml.safe_load(f.read())
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'vnfd_id', 'description'])
if policy_info:
body[self.resource]['policy_info'] = policy_info
return body
class AddClusterMember(tackerV10.CreateCommand):
"""Add a new Cluster Member to given Cluster."""
resource = _CLUSTER_MEMBER
def add_known_arguments(self, parser):
parser.add_argument(
'name', metavar='NAME',
help='Set a name for the VNF cluster member')
cluster_group = parser.add_mutually_exclusive_group()
cluster_group.add_argument(
'--cluster-id',
help='VNFD ID to use as template to create member VNF')
cluster_group.add_argument(
'--cluster-name',
help='VNFD name to use as template to create member VNF')
vnfd_group = parser.add_mutually_exclusive_group()
vnfd_group.add_argument(
'--vnfd-id',
help='Set a id for the VNFD')
vnfd_group.add_argument(
'--vnfd-name',
help='Set a name for the VNFD')
parser.add_argument(
'--role',
help='Set a [Active/Standby] role to cluster member',
required=True)
vim_group = parser.add_mutually_exclusive_group()
vim_group.add_argument(
'--vim-id',
help='Set a VIM ID to deploy cluster member')
vim_group.add_argument(
'--vim-name',
help='Set a VIM name to deploy cluster member')
def args2body(self, parsed_args):
body = {self.resource: {}}
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.cluster_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'cluster',
parsed_args.
cluster_name)
parsed_args.cluster_id = _id
if parsed_args.vnfd_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vnfd',
parsed_args.
vnfd_name)
parsed_args.vnfd_id = _id
parsed_args.role = parsed_args.role.upper()
if parsed_args.vim_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vim',
parsed_args.
vim_name)
parsed_args.vim_id = _id
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'cluster_id', 'vnfd_id',
'role', 'vim_id'])
return body
class ListClusterMember(tackerV10.ListCommand):
"""List Cluster Members that belong to a given tenant."""
resource = _CLUSTER_MEMBER
def add_known_arguments(self, parser):
cluster_group = parser.add_mutually_exclusive_group(required=True)
cluster_group.add_argument(
'--cluster-id',
help='Set a ID for the queried cluster')
cluster_group.add_argument(
'--cluster-name',
help='Set a name for the queried cluster')
def args2body(self, parsed_args):
body = {self.resource: {}}
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.cluster_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'cluster',
parsed_args.
cluster_name)
parsed_args.cluster_id = _id
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'cluster_id'])
return body
list_columns = ['id', 'name', 'cluster_id', 'role', 'vnf_id',
'vim_id', 'mgmt_ip_address', 'lb_member_id']
class DeleteClusterMember(tackerV10.DeleteCommand):
"""Delete a given Cluster Member."""
resource = _CLUSTER_MEMBER
class ShowClusterMember(tackerV10.ShowCommand):
"""Show information of a given Cluster Member."""
resource = _CLUSTER_MEMBER

View File

@ -1,249 +0,0 @@
# 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.
import yaml
from tackerclient.common import exceptions
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
_VNFFG = 'vnffg'
_NFP = 'nfp'
_SFC = 'sfc'
_FC = 'classifier'
class ListFC(tackerV10.ListCommand):
"""List FCs that belong to a given tenant."""
resource = _FC
list_columns = ['id', 'status', 'nfp_id', 'chain_id']
def extend_list(self, data, parsed_args):
"""Update the list_columns list.
This method update the list_columns list by adding the
'name' column in case the retrieved FC list from the tacker
server side contains the names of the FCs.
"""
for item in data:
if 'name' in item:
self.list_columns.insert(1, 'name')
break
class ShowFC(tackerV10.ShowCommand):
"""Show information of a given FC."""
resource = _FC
class ListSFC(tackerV10.ListCommand):
"""List SFCs that belong to a given tenant."""
resource = _SFC
list_columns = ['id', 'status', 'nfp_id']
class ShowSFC(tackerV10.ShowCommand):
"""Show information of a given SFC."""
resource = _SFC
class ListNFP(tackerV10.ListCommand):
"""List NFPs that belong to a given tenant."""
resource = _NFP
list_columns = ['id', 'name', 'status', 'vnffg_id', 'path_id']
class ShowNFP(tackerV10.ShowCommand):
"""Show information of a given NFP."""
resource = _NFP
class ListVNFFG(tackerV10.ListCommand):
"""List VNFFGs that belong to a given tenant."""
resource = _VNFFG
list_columns = ['id', 'name', 'ns_id',
'description', 'status', 'vnffgd_id']
class ShowVNFFG(tackerV10.ShowCommand):
"""Show information of a given VNFFG."""
resource = _VNFFG
class CreateVNFFG(tackerV10.CreateCommand):
"""Create a VNFFG."""
resource = _VNFFG
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the VNFFG'))
vnffgd_group = parser.add_mutually_exclusive_group(required=True)
vnffgd_group.add_argument(
'--vnffgd-id',
help=_('VNFFGD ID to use as template to create VNFFG'))
vnffgd_group.add_argument(
'--vnffgd-name',
help=_('VNFFGD Name to use as template to create VNFFG'))
vnffgd_group.add_argument(
'--vnffgd-template',
help=_('VNFFGD file to create VNFFG'))
parser.add_argument(
'--vnf-mapping',
help=_('List of logical VNFD name to VNF instance name mapping. '
'Example: VNF1:my_vnf1,VNF2:my_vnf2'))
parser.add_argument(
'--symmetrical',
action='store_true',
default=False,
help=_('Should a reverse path be created for the NFP'))
parser.add_argument(
'--param-file',
help='Specify parameter yaml file'
)
def args2body(self, parsed_args):
args = {'attributes': {}}
body = {self.resource: args}
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.vnf_mapping:
_vnf_mapping = dict()
_vnf_mappings = parsed_args.vnf_mapping.split(",")
for mapping in _vnf_mappings:
vnfd_name, vnf = mapping.split(":", 1)
_vnf_mapping[vnfd_name] = \
tackerV10.find_resourceid_by_name_or_id(
tacker_client, 'vnf', vnf)
parsed_args.vnf_mapping = _vnf_mapping
if parsed_args.vnffgd_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vnffgd',
parsed_args.
vnffgd_name)
parsed_args.vnffgd_id = _id
elif parsed_args.vnffgd_template:
with open(parsed_args.vnffgd_template) as f:
template = f.read()
try:
args['vnffgd_template'] = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not args['vnffgd_template']:
raise exceptions.InvalidInput(
reason='The vnffgd file is empty')
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'vnffgd_id',
'symmetrical', 'vnf_mapping'])
return body
class UpdateVNFFG(tackerV10.UpdateCommand):
"""Update a given VNFFG."""
resource = _VNFFG
def add_known_arguments(self, parser):
parser.add_argument(
'--vnffgd-template',
help=_('VNFFGD file to update VNFFG')
)
parser.add_argument(
'--vnf-mapping',
help=_('List of logical VNFD name to VNF instance name mapping. '
'Example: VNF1:my_vnf1,VNF2:my_vnf2'))
parser.add_argument(
'--symmetrical',
action='store_true',
default=False,
help=_('Should a reverse path be created for the NFP'))
def args2body(self, parsed_args):
args = {}
body = {self.resource: args}
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.vnf_mapping:
_vnf_mapping = dict()
_vnf_mappings = parsed_args.vnf_mapping.split(",")
for mapping in _vnf_mappings:
vnfd_name, vnf = mapping.split(":", 1)
_vnf_mapping[vnfd_name] = \
tackerV10.find_resourceid_by_name_or_id(
tacker_client, 'vnf', vnf)
parsed_args.vnf_mapping = _vnf_mapping
if parsed_args.vnffgd_template:
with open(parsed_args.vnffgd_template) as f:
template = f.read()
try:
args['vnffgd_template'] = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not args['vnffgd_template']:
raise exceptions.InvalidInput(
reason='The vnffgd template is empty')
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'vnf_mapping', 'symmetrical'])
return body
class DeleteVNFFG(tackerV10.DeleteCommand):
"""Delete a given VNFFG."""
resource = _VNFFG
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete VNFFG'))
def args2body(self, parsed_args):
body = dict()
if parsed_args.force:
body[self.resource] = dict()
body[self.resource]['attributes'] = {'force': True}
return body

View File

@ -1,97 +0,0 @@
# 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.
import yaml
from oslo_serialization import jsonutils
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
_VNFFGD = "vnffgd"
class ListVNFFGD(tackerV10.ListCommand):
"""List VNFFGDs that belong to a given tenant."""
resource = _VNFFGD
list_columns = ['id', 'name', 'template_source', 'description']
def get_parser(self, prog_name):
parser = super(ListVNFFGD, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List VNFFGD with specified template source. Available \
options are 'onboarded' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
return parser
def args2search_opts(self, parsed_args):
search_opts = super(ListVNFFGD, self).args2search_opts(parsed_args)
template_source = parsed_args.template_source
if parsed_args.template_source:
search_opts.update({'template_source': template_source})
return search_opts
class ShowVNFFGD(tackerV10.ShowCommand):
"""Show information of a given VNFFGD."""
resource = _VNFFGD
class CreateVNFFGD(tackerV10.CreateCommand):
"""Create a VNFFGD."""
resource = _VNFFGD
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument('--vnffgd-file', help=_('Specify VNFFGD file'))
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the VNFFGD'))
parser.add_argument(
'--description',
help=_('Set a description for the VNFFGD'))
def args2body(self, parsed_args):
body = {self.resource: {}}
if parsed_args.vnffgd_file:
with open(parsed_args.vnffgd_file) as f:
vnffgd = yaml.safe_load(f.read())
body[self.resource]['template'] = {'vnffgd': vnffgd}
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description'])
return body
class DeleteVNFFGD(tackerV10.DeleteCommand):
"""Delete a given VNFFGD."""
resource = _VNFFGD
class ShowTemplateVNFFGD(tackerV10.ShowCommand):
"""Show template of a given VNFFGD."""
resource = _VNFFGD
def run(self, parsed_args):
self.log.debug('run(%s)', parsed_args)
template = None
data = self.get_data(parsed_args)
try:
attributes_index = data[0].index('template')
attributes_json = data[1][attributes_index]
template = jsonutils.loads(attributes_json).get('vnffgd', None)
except (IndexError, TypeError, ValueError) as e:
self.log.debug('Data handling error: %s', str(e))
print(template or _('Unable to display VNFFGD template!'))

View File

@ -1,341 +0,0 @@
#
# Copyright 2013 Intel Corporation
# 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.
import yaml
from oslo_utils import encodeutils
from tackerclient.common import exceptions
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
_VNF = 'vnf'
_RESOURCE = 'resource'
class ListVNF(tackerV10.ListCommand):
"""List VNF that belong to a given tenant."""
resource = _VNF
list_columns = ['id', 'name', 'mgmt_ip_address', 'status',
'vim_id', 'vnfd_id']
class ShowVNF(tackerV10.ShowCommand):
"""Show information of a given VNF."""
resource = _VNF
class CreateVNF(tackerV10.CreateCommand):
"""Create a VNF."""
resource = _VNF
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the VNF'))
parser.add_argument(
'--description',
help=_('Set description for the VNF'))
vnfd_group = parser.add_mutually_exclusive_group(required=True)
vnfd_group.add_argument(
'--vnfd-id',
help=_('VNFD ID to use as template to create VNF'))
vnfd_group.add_argument(
'--vnfd-name',
help=_('VNFD Name to use as template to create VNF'))
vnfd_group.add_argument(
'--vnfd-template',
help=_("VNFD file to create VNF"))
vim_group = parser.add_mutually_exclusive_group()
vim_group.add_argument(
'--vim-id',
help=_('VIM ID to use to create VNF on the specified VIM'))
vim_group.add_argument(
'--vim-name',
help=_('VIM name to use to create VNF on the specified VIM'))
parser.add_argument(
'--vim-region-name',
help=_('VIM Region to use to create VNF on the specified VIM'))
parser.add_argument(
'--config-file',
help=_('YAML file with VNF configuration'))
parser.add_argument(
'--param-file',
help=_('Specify parameter yaml file'))
def args2body(self, parsed_args):
args = {'attributes': {}}
body = {self.resource: args}
# config arg passed as data overrides config yaml when both args passed
config = None
if parsed_args.config_file:
with open(parsed_args.config_file) as f:
config_yaml = f.read()
try:
config = yaml.load(
config_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if config:
args['attributes']['config'] = config
if parsed_args.vim_region_name:
args.setdefault('placement_attr', {})['region_name'] = \
parsed_args.vim_region_name
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if parsed_args.vim_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vim',
parsed_args.
vim_name)
parsed_args.vim_id = _id
if parsed_args.vnfd_name:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vnfd',
parsed_args.
vnfd_name)
parsed_args.vnfd_id = _id
elif parsed_args.vnfd_template:
with open(parsed_args.vnfd_template) as f:
template = f.read()
try:
args['vnfd_template'] = yaml.load(
template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description',
'vnfd_id', 'vim_id'])
return body
class UpdateVNF(tackerV10.UpdateCommand):
"""Update a given VNF."""
resource = _VNF
def add_known_arguments(self, parser):
group = parser.add_mutually_exclusive_group()
group.add_argument(
'--config-file',
help=_('YAML file with VNF configuration'))
group.add_argument(
'--config',
help=_('YAML data with VNF configuration'))
group.add_argument(
'--param-file',
help=_('YAML file with VNF parameter'))
def args2body(self, parsed_args):
body = {self.resource: {}}
# config arg passed as data overrides config yaml when both args passed
config = None
if parsed_args.config_file:
with open(parsed_args.config_file) as f:
config_yaml = f.read()
try:
config = yaml.load(config_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not config:
raise exceptions.InvalidInput(
reason='The config file is empty')
if parsed_args.config:
config_param = encodeutils.safe_decode(parsed_args.config)
try:
config = yaml.load(config_param, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not config:
raise exceptions.InvalidInput(
reason='The parameter is empty')
if config:
body[self.resource]['attributes'] = {'config': config}
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
try:
param = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not param:
raise exceptions.InvalidInput(
reason='The parameter file is empty')
body[self.resource]['attributes'] = {'param_values': param}
tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id'])
return body
class DeleteVNF(tackerV10.DeleteCommand):
"""Delete given VNF(s)."""
resource = _VNF
remove_output_fields = ["attributes"]
deleted_msg = {'vnf': 'delete initiated'}
def add_known_arguments(self, parser):
parser.add_argument(
'--force',
default=False,
action='store_true',
help=_('Force delete VNF instance'))
def args2body(self, parsed_args):
body = dict()
if parsed_args.force:
body[self.resource] = dict()
body[self.resource]['attributes'] = {'force': True}
return body
class ListVNFResources(tackerV10.ListCommand):
"""List resources of a VNF like VDU, CP, etc."""
list_columns = ['name', 'id', 'type']
allow_names = True
resource = _VNF
def get_id(self):
if self.resource:
return self.resource.upper()
def get_parser(self, prog_name):
parser = super(ListVNFResources, self).get_parser(prog_name)
if self.allow_names:
help_str = _('ID or name of %s to look up')
else:
help_str = _('ID of %s to look up')
parser.add_argument(
'id', metavar=self.get_id(),
help=help_str % self.resource)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)', parsed_args)
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
if self.allow_names:
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
self.resource,
parsed_args.id)
else:
_id = parsed_args.id
data = self.retrieve_list_by_id(_id, parsed_args)
self.extend_list(data, parsed_args)
return self.setup_columns(data, parsed_args)
def retrieve_list_by_id(self, id, parsed_args):
"""Retrieve a list of sub resources from Tacker server"""
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
_extra_values = tackerV10.parse_args_to_dict(self.values_specs)
tackerV10._merge_args(self, parsed_args, _extra_values,
self.values_specs)
search_opts = self.args2search_opts(parsed_args)
search_opts.update(_extra_values)
if self.pagination_support:
page_size = parsed_args.page_size
if page_size:
search_opts.update({'limit': page_size})
if self.sorting_support:
keys = parsed_args.sort_key
if keys:
search_opts.update({'sort_key': keys})
dirs = parsed_args.sort_dir
len_diff = len(keys) - len(dirs)
if len_diff > 0:
dirs += ['asc'] * len_diff
elif len_diff < 0:
dirs = dirs[:len(keys)]
if dirs:
search_opts.update({'sort_dir': dirs})
obj_lister = getattr(tacker_client, "list_vnf_resources")
data = obj_lister(id, **search_opts)
return data.get('resources', [])
class ScaleVNF(tackerV10.TackerCommand):
"""Scale a VNF."""
api = 'nfv-orchestration'
resource = None
log = None
def get_parser(self, prog_name):
parser = super(ScaleVNF, self).get_parser(prog_name)
self.add_known_arguments(parser)
return parser
def run(self, parsed_args):
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
body = self.args2body(parsed_args)
obj_creator = getattr(tacker_client,
"scale_vnf")
obj_creator(body["scale"].pop('vnf_id'), body)
def add_known_arguments(self, parser):
vnf_group = parser.add_mutually_exclusive_group(required=True)
vnf_group.add_argument(
'--vnf-id',
help=_('VNF ID'))
vnf_group.add_argument(
'--vnf-name',
help=_('VNF name'))
parser.add_argument(
'--scaling-policy-name',
help=_('VNF policy name used to scale'))
parser.add_argument(
'--scaling-type',
help=_('VNF scaling type, it could be either "out" or "in"'))
def args2body(self, parsed_args):
args = {}
body = {"scale": args}
if parsed_args.vnf_name:
tacker_client = self.get_client()
tacker_client.format = parsed_args.request_format
_id = tackerV10.find_resourceid_by_name_or_id(tacker_client,
'vnf',
parsed_args.
vnf_name)
parsed_args.vnf_id = _id
args['vnf_id'] = parsed_args.vnf_id
args['type'] = parsed_args.scaling_type
args['policy'] = parsed_args.scaling_policy_name
return body

View File

@ -1,113 +0,0 @@
#
# Copyright 2013 Intel Corporation
# 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 oslo_serialization import jsonutils
import yaml
from tackerclient.common import exceptions
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
_VNFD = "vnfd"
class ListVNFD(tackerV10.ListCommand):
"""List VNFD that belong to a given tenant."""
resource = _VNFD
list_columns = ['id', 'name', 'template_source', 'description']
def get_parser(self, prog_name):
parser = super(ListVNFD, self).get_parser(prog_name)
parser.add_argument(
'--template-source',
help=_("List VNFD with specified template source. Available \
options are 'onboarded' (default), 'inline' or 'all'"),
action='store',
default='onboarded')
return parser
def args2search_opts(self, parsed_args):
search_opts = super(ListVNFD, self).args2search_opts(parsed_args)
template_source = parsed_args.template_source
if parsed_args.template_source:
search_opts.update({'template_source': template_source})
return search_opts
class ShowVNFD(tackerV10.ShowCommand):
"""Show information of a given VNFD."""
resource = _VNFD
class CreateVNFD(tackerV10.CreateCommand):
"""Create a VNFD."""
resource = _VNFD
remove_output_fields = ["attributes"]
def add_known_arguments(self, parser):
parser.add_argument('--vnfd-file', help=_('Specify VNFD file'))
parser.add_argument(
'name', metavar='NAME',
help=_('Set a name for the VNFD'))
parser.add_argument(
'--description',
help=_('Set a description for the VNFD'))
def args2body(self, parsed_args):
body = {self.resource: {}}
vnfd = None
if not parsed_args.vnfd_file:
raise exceptions.InvalidInput(reason="Invalid input for vnfd file")
with open(parsed_args.vnfd_file) as f:
vnfd = f.read()
try:
vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e:
raise exceptions.InvalidInput(reason=e)
if not vnfd:
raise exceptions.InvalidInput(reason="vnfd file is empty")
body[self.resource]['attributes'] = {'vnfd': vnfd}
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description'])
return body
class DeleteVNFD(tackerV10.DeleteCommand):
"""Delete given VNFD(s)."""
resource = _VNFD
class ShowTemplateVNFD(tackerV10.ShowCommand):
"""Show template of a given VNFD."""
resource = _VNFD
def run(self, parsed_args):
self.log.debug('run(%s)', parsed_args)
template = None
data = self.get_data(parsed_args)
try:
attributes_index = data[0].index('attributes')
attributes_json = data[1][attributes_index]
template = jsonutils.loads(attributes_json).get('vnfd', None)
except (IndexError, TypeError, ValueError) as e:
self.log.debug('Data handling error: %s', str(e))
print(template or _('Unable to display VNFD template!'))

View File

@ -1,7 +0,0 @@
auth_url: 'http://1.2.3.4:5000'
username: 'xyz'
password: '12345'
project_name: 'abc'
project_domain_name: 'prj_domain_name'
user_domain_name: 'user_domain_name'
type: 'openstack'

View File

@ -1,7 +0,0 @@
auth_url: ][
username: 'xyz'
password: '12345'
project_name: 'abc'
project_domain_name: 'prj_domain_name'
user_domain_name: 'user_domain_name'
type: 'openstack'

View File

@ -1 +0,0 @@
key: new-value

View File

@ -1,313 +0,0 @@
# Copyright 2014 Intel Corporation
# 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.
import ast
from unittest import mock
import fixtures
import yaml
from tackerclient.common import exceptions
from tackerclient.common import utils
from tackerclient.osc.v1.vnfm import vnf
from tackerclient.tests.unit.osc import base
from tackerclient.tests.unit.osc.v1.fixture_data import client
def _get_columns_vnf_parameter():
columns = ['attributes', 'project_id']
return columns
class TestVnfParameter(base.FixturedTestCase):
client_fixture_class = client.ClientFixture
def setUp(self):
super(TestVnfParameter, self).setUp()
self.url = client.TACKER_URL
self.header = {'content-type': 'application/json'}
self.app = mock.Mock()
self.app_args = mock.Mock()
self.client_manager = self.cs
self.app.client_manager.tackerclient = self.client_manager
class TestUpdateVNF(TestVnfParameter):
def setUp(self):
super(TestUpdateVNF, self).setUp()
self.useFixture(fixtures.MonkeyPatch(
'tackerclient.tacker.v1_0.find_resourceid_by_name_or_id',
self._find_resourceid))
self.set_vnf = vnf.UpdateVNF(
self.app, self.app_args, cmd_name='vnf set')
def _find_resourceid(self, client, resource, name_or_id):
return name_or_id
def _cmd_parser(self, cmd_parser, sub_argv):
_argv = sub_argv
index = -1
if '--' in sub_argv:
index = sub_argv.index('--')
_argv = sub_argv[:index]
known_args, _values_specs = cmd_parser.parse_known_args(_argv)
return known_args
def _get_vnf_data(self, vnf_parameter):
return tuple([vnf_parameter[key]
for key in sorted(vnf_parameter.keys())])
def _take_action(self, args, extra_fields, get_client_called_count=1):
cmd_par = self.set_vnf.get_parser("update_vnf")
parsed_args = self._cmd_parser(cmd_par, args)
body = {"vnf": extra_fields}
body = str(body)
project_id = {"tenant_id": "test-vnf-tenant_id"}
extra_fields.update(project_id)
json = {"vnf": extra_fields}
self.requests_mock.register_uri(
'PUT', self.url + '/v1.0/vnfs/my-id.json',
json=json, headers=self.header)
columns, data = (self.set_vnf.take_action(parsed_args))
self.assertCountEqual(_get_columns_vnf_parameter(),
columns)
self.assertEqual(get_client_called_count,
self.requests_mock.call_count)
self.assertCountEqual(
ast.literal_eval(self.requests_mock.last_request.body),
ast.literal_eval(body))
self.assertCountEqual(self._get_vnf_data(json['vnf']), data)
def test_vnf_update_param_file(self):
my_id = 'my-id'
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
args = [my_id, '--param-file', str(param_file)]
extra_fields = {'attributes': {'param_values': {'key': 'new-value'}}}
self._take_action(args, extra_fields)
def test_vnf_update_config_file(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
p_auth_url = 'http://1.2.3.4:5000'
p_project_name = 'abc'
p_username = 'xyz'
p_project_domain_name = 'prj_domain_name'
p_type = 'openstack'
p_user_domain_name = 'user_domain_name'
p_password = '12345'
args = [my_id, '--config-file', str(config_file)]
config = {'auth_url': p_auth_url, 'project_name': p_project_name,
'username': p_username,
'project_domain_name': p_project_domain_name,
'type': p_type, 'user_domain_name': p_user_domain_name,
'password': p_password}
extra_fields = {'attributes': {'config': config}}
self._take_action(args, extra_fields)
def test_vnf_update_config(self):
my_id = 'my-id'
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
config = yaml.dump(config)
args = [my_id, '--config', str(config)]
extra_fields = {'attributes': {'config': config}}
self._take_action(args, extra_fields)
def test_vnf_update_invalid_format_param_file(self):
my_id = 'my-id'
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_invalid_format_param.yaml')
args = [my_id, '--param-file', str(param_file)]
extra_fields = {'attributes': {'param_values': None}}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_empty_param_file(self):
my_id = 'my-id'
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_empty_param.yaml')
args = [my_id, '--param-file', str(param_file)]
extra_fields = {'attributes': {'param_values': None}}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_invalid_format_config_file(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_invalid_format_config.yaml')
args = [my_id, '--config-file', str(config_file)]
extra_fields = {'attributes': {'config': None}}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_empty_config_file(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_empty_config.yaml')
args = [my_id, '--config-file', str(config_file)]
extra_fields = {'attributes': {'config': None}}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_invalid_format_config(self):
my_id = 'my_id'
config = 'test: : ]['
args = [my_id, '--config', config]
extra_fields = {'attributes': {'config': None}}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_empty_config(self):
my_id = 'my-id'
config = ' '
args = [my_id, '--config', config]
extra_fields = {'attributes': {'config': None}}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_multi_args_config_configfile_paramfile(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
config = yaml.dump(config)
args = [my_id, '--config-file', str(config_file),
'--config', str(config), '--param-file', str(param_file)]
extra_fields = {'attributes': None}
self.assertRaises(BaseException,
self._take_action,
args, extra_fields)
def test_vnf_update_multi_args_configfile_paramfile(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
args = [my_id, '--param-file', str(param_file),
'--config-file', str(config_file)]
extra_fields = {'attributes': None}
self.assertRaises(BaseException,
self._take_action,
args, extra_fields)
def test_vnf_update_multi_args_config_configfile(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
config = yaml.dump(config)
args = [my_id, '--config-file', str(config_file),
'--config', str(config)]
extra_fields = {'attributes': None}
self.assertRaises(BaseException,
self._take_action,
args, extra_fields)
def test_vnf_update_multi_args_config_paramfile(self):
my_id = 'my-id'
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
config = yaml.dump(config)
args = [my_id, '--param-file', str(param_file),
'--config', str(config)]
extra_fields = {'attributes': None}
self.assertRaises(BaseException,
self._take_action,
args, extra_fields)
def test_vnf_update_param_file_with_empty_dict(self):
my_id = 'my-id'
param_file = utils.get_file_path(
'tests/unit/osc/samples/'
'vnf_update_param_file_with_empty_dict.yaml')
args = [my_id, '--param-file', str(param_file)]
extra_fields = {'attributes': None}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)
def test_vnf_update_config_file_with_empty_dict(self):
my_id = 'my-id'
config_file = utils.get_file_path(
'tests/unit/osc/samples/'
'vnf_update_config_file_with_empty_dict.yaml')
args = [my_id, '--config-file', str(config_file)]
extra_fields = {'attributes': None}
self.assertRaises(exceptions.InvalidInput,
self._take_action,
args, extra_fields)

View File

@ -23,7 +23,6 @@ from unittest import mock
import urllib
from urllib import parse as urlparse
from tackerclient.common import constants
from tackerclient.common import exceptions
from tackerclient import shell
from tackerclient.tacker import v1_0 as tackerV1_0
@ -191,12 +190,6 @@ class CLITestV10Base(testtools.TestCase):
def setUp(self, plurals={}):
"""Prepare the test environment."""
super(CLITestV10Base, self).setUp()
client.LegacyClient.EXTED_PLURALS.update(constants.PLURALS)
client.LegacyClient.EXTED_PLURALS.update(plurals)
self.metadata = {'plurals': client.LegacyClient.EXTED_PLURALS,
'xmlns': constants.XML_NS_V10,
constants.EXT_NS: {'prefix':
'http://xxxx.yy.com'}}
self.endurl = ENDURL
self.fake_stdout = FakeStdout()
self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.fake_stdout))
@ -217,7 +210,7 @@ class CLITestV10Base(testtools.TestCase):
tags=None, admin_state_up=True, extra_body=None,
**kwargs):
mock_get.return_value = self.client
non_admin_status_resources = ['vnfd', 'vnf', 'vim', 'vnffgd', 'vnffg']
non_admin_status_resources = ['vim']
if (resource in non_admin_status_resources):
body = {resource: {}, }
else:
@ -714,44 +707,6 @@ class CLITestV10ExceptionHandler(CLITestV10Base):
expected_msg = error_msg
self.assertEqual(expected_msg, e.message)
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_v10(
exceptions.IpAddressInUseClient, 409, err_msg,
'IpAddressInUse', err_msg, '')
def test_exception_handler_v10_tacker_known_error(self):
known_error_map = [
('NetworkNotFound', exceptions.NetworkNotFoundClient, 404),
('PortNotFound', exceptions.PortNotFoundClient, 404),
('NetworkInUse', exceptions.NetworkInUseClient, 409),
('PortInUse', exceptions.PortInUseClient, 409),
('StateInvalid', exceptions.StateInvalidClient, 400),
('IpAddressInUse', exceptions.IpAddressInUseClient, 409),
('IpAddressGenerationFailure',
exceptions.IpAddressGenerationFailureClient, 409),
('ExternalIpAddressExhausted',
exceptions.ExternalIpAddressExhaustedClient, 400),
('OverQuota', exceptions.OverQuotaClient, 409),
]
error_msg = 'dummy exception message'
error_detail = 'sample detail'
for server_exc, client_exc, status_code in known_error_map:
self._test_exception_handler_v10(
client_exc, status_code,
error_msg + '\n' + error_detail,
server_exc, error_msg, error_detail)
def test_exception_handler_v10_tacker_known_error_without_detail(self):
error_msg = 'Network not found'
error_detail = ''
self._test_exception_handler_v10(
exceptions.NetworkNotFoundClient, 404,
error_msg,
'NetworkNotFound', error_msg, error_detail)
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'

View File

@ -1,47 +0,0 @@
# Copyright 2013 NEC Corporation
# 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.
import sys
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 CLITestV10Extension(CLITestV10Base):
id_field = 'alias'
def test_list_extensions(self):
resources = 'extensions'
cmd = ListExt(MyApp(sys.stdout), None)
contents = [{'alias': 'ext1', 'name': 'name1', 'other': 'other1'},
{'alias': 'ext2', 'name': 'name2', 'other': 'other2'}]
ret = self._test_list_resources(resources, cmd,
response_contents=contents)
ret_words = set(ret.split())
# Check only the default columns are shown.
self.assertIn('name', ret_words)
self.assertIn('alias', ret_words)
self.assertNotIn('other', ret_words)
def test_show_extension(self):
# -F option does not work for ext-show at the moment, so -F option
# is not passed in the commandline args as other tests do.
resource = 'extension'
cmd = ShowExt(MyApp(sys.stdout), None)
args = [self.test_id]
ext_alias = self.test_id
self._test_show_resource(resource, cmd, ext_alias, args, fields=[])

View File

@ -94,8 +94,8 @@ class ShellTest(testtools.TestCase):
def test_help_on_subcommand(self):
required = [
'.*?^usage: .* vnfd-list']
stdout, stderr = self.shell('help vnfd-list')
'.*?^usage: .* vim-list']
stdout, stderr = self.shell('help vim-list')
for r in required:
self.assertThat(
stdout,
@ -104,7 +104,7 @@ class ShellTest(testtools.TestCase):
def test_help_command(self):
required = 'usage:'
help_text, stderr = self.shell('help vnfd-create')
help_text, stderr = self.shell('help vim-create')
self.assertThat(
help_text,
matchers.MatchesRegex(required))
@ -113,7 +113,7 @@ 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 '
'vnfd-list')
'vim-list')
self.assertFalse(stdout)
def test_auth(self):
@ -130,7 +130,7 @@ class ShellTest(testtools.TestCase):
'--os-password test '
'--os-tenant-name test '
'--os-auth-url http://127.0.0.1:5000/ '
'--os-auth-strategy keystone vnfd-list')
'--os-auth-strategy keystone vim-list')
shell.authenticate_user()
shell.run(cmdline.split())

View File

@ -1,69 +0,0 @@
# Copyright 2014 Intel Corporation
# 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.
import sys
from tackerclient.tacker.v1_0.events import events
from tackerclient.tests.unit import test_cli10
API_VERSION = "1.0"
FORMAT = 'json'
TOKEN = 'testtoken'
ENDURL = 'localurl'
class CLITestV10EventJSON(test_cli10.CLITestV10Base):
_EVT_RESOURCE = 'event'
_EVT_RESOURCES = _EVT_RESOURCE + 's'
_VNF_EVT_RESOURCE = "vnf_event"
_VNF_EVT_RESOURCES = _VNF_EVT_RESOURCE + 's'
_VNFD_EVT_RESOURCE = "vnfd_event"
_VNFD_EVT_RESOURCES = _VNFD_EVT_RESOURCE + 's'
_VIM_EVT_RESOURCE = "vim_event"
_VIM_EVT_RESOURCES = _VIM_EVT_RESOURCE + 's'
def setUp(self):
plurals = {'events': 'event', 'vnf_events': 'vnf_event',
'vnfd_events': 'vnfd_event', 'vim_events': 'vim_event'}
super(CLITestV10EventJSON, self).setUp(plurals=plurals)
def test_list_events(self):
cmd = events.ListResourceEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._EVT_RESOURCES, cmd, True)
def test_show_event_id(self):
cmd = events.ShowEvent(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(self._EVT_RESOURCE, cmd, self.test_id, args,
['id'])
def notest_list_vnf_events(self):
# TODO(vishwanathj): Need to enhance _test_list_resources()
# for supporting filters to get this test working
cmd = events.ListVNFEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._VNF_EVT_RESOURCES, cmd, True)
def notest_list_vnfd_events(self):
# TODO(vishwanathj): Need to enhance _test_list_resources()
# for supporting filters to get this test working
cmd = events.ListVNFDEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._VNFD_EVT_RESOURCES, cmd, True)
def notest_list_vim_events(self):
# TODO(vishwanathj): Need to enhance _test_list_resources()
# for supporting filters to get this test working
cmd = events.ListVIMEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._VIM_EVT_RESOURCES, cmd, True)

View File

@ -1,526 +0,0 @@
# Copyright 2014 Intel Corporation
# 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.
import sys
from unittest import mock
from tackerclient.common import exceptions
from tackerclient.common import utils
from tackerclient import shell
from tackerclient.tacker import v1_0 as tackerV1_0
from tackerclient.tacker.v1_0 import TackerCommand
from tackerclient.tacker.v1_0.vnfm import vnf
from tackerclient.tests.unit import test_cli10
from tackerclient.tests.unit import test_utils
API_VERSION = "1.0"
FORMAT = 'json'
TOKEN = 'testtoken'
ENDURL = 'localurl'
class CLITestV10VmVNFJSON(test_cli10.CLITestV10Base):
_RESOURCE = 'vnf'
_RESOURCES = 'vnfs'
_VNF_RESOURCES = 'vnf_resources'
def setUp(self):
plurals = {'vnfs': 'vnf',
'resources': 'resource'}
super(CLITestV10VmVNFJSON, self).setUp(plurals=plurals)
@mock.patch.object(TackerCommand, 'get_client')
def _test_create_resource(self, resource, cmd, name, myid, args,
position_names, position_values, mock_get,
tenant_id=None, tags=None, admin_state_up=True,
extra_body=None, **kwargs):
mock_get.return_value = self.client
non_admin_status_resources = ['vnfd', 'vnf']
if (resource in non_admin_status_resources):
body = {resource: {}, }
else:
body = {resource: {'admin_state_up': admin_state_up, }, }
if tenant_id:
body[resource].update({'tenant_id': tenant_id})
if tags:
body[resource].update({'tags': tags})
if extra_body:
body[resource].update(extra_body)
body[resource].update(kwargs)
for i in range(len(position_names)):
body[resource].update({position_names[i]: position_values[i]})
ress = {resource:
{self.id_field: myid}, }
if name:
ress[resource].update({'name': name})
self.client.format = self.format
resstr = self.client.serialize(ress)
# url method body
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.
if self.format == 'json':
_body = test_cli10.MyComparator(body, self.client)
else:
_body = self.client.serialize(body)
with mock.patch.object(self.client.httpclient, 'request') as mock_req:
mock_req.return_value = (test_cli10.MyResp(200), resstr)
args.extend(['--request-format', self.format])
args.extend(['--vnfd-id', 'vnfd'])
cmd_parser = cmd.get_parser('create_' + resource)
shell.run_command(cmd, cmd_parser, args)
mock_req.assert_called_once_with(
test_cli10.end_url(path, format=self.format), 'POST',
body=_body,
headers=test_utils.ContainsKeyValue('X-Auth-Token', TOKEN))
mock_get.assert_any_call()
def test_create_vnf_all_params(self):
cmd = vnf.CreateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
vnfd_id = 'vnfd'
vim_id = 'vim_id'
description = 'my-description'
region_name = 'region'
key = 'key'
value = 'value'
args = [
name,
'--vnfd-id', vnfd_id,
'--vim-id', vim_id,
'--description', description,
'--vim-region-name', region_name,
'--%s' % key, value]
position_names = [
'name',
'vnfd_id',
'vim_id',
'description',
'attributes',
]
position_values = [
name,
vnfd_id,
vim_id,
description,
{},
]
extra_body = {key: value, 'placement_attr': {'region_name':
region_name}}
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values,
extra_body=extra_body)
def test_create_vnf_with_vnfd_id(self):
cmd = vnf.CreateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
vnfd_id = 'vnfd'
args = [
name,
'--vnfd-id', vnfd_id,
]
position_names = ['name', 'vnfd_id', 'attributes']
position_values = [name, vnfd_id, {}]
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values)
def test_create_vnf_with_description_param(self):
cmd = vnf.CreateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
vnfd_id = 'vnfd'
description = 'my-description'
args = [
name,
'--vnfd-id', vnfd_id,
'--description', description,
]
position_names = ['name', 'vnfd_id', 'description',
'attributes']
position_values = [name, vnfd_id, description, {}]
self._test_create_resource(self._RESOURCE, cmd, None, my_id,
args, position_names, position_values)
def test_list_vnfs(self):
cmd = vnf.ListVNF(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True)
def test_list_vnfs_pagenation(self):
cmd = vnf.ListVNF(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True)
def test_show_vnf_id(self):
cmd = vnf.ShowVNF(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id, args,
['id'])
def test_show_vnf_id_name(self):
cmd = vnf.ShowVNF(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id,
args, ['id', 'name'])
def test_update_vnf(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
key = 'new_key'
value = 'new-value'
self._test_update_resource(self._RESOURCE, cmd, my_id,
[my_id, '--%s' % key, value],
{key: value})
def test_vnf_update_param_file(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
key = 'key'
value = 'new-value'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
args = [my_id, '--param-file', str(config_file)]
extra_fields = {'attributes': {'param_values': {key: value}}}
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
extra_fields)
def test_vnf_update_config_file(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my-name'
description = 'Vim Description'
vim_config = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
args = [
name,
'--config-file', vim_config,
'--description', description]
p_auth_url = 'http://1.2.3.4:5000'
p_type = 'openstack'
p_project_name = 'abc'
p_username = 'xyz'
p_project_domain_name = 'prj_domain_name'
p_user_domain_name = 'user_domain_name'
p_password = '12345'
config = {'auth_url': p_auth_url, 'project_name': p_project_name,
'username': p_username,
'project_domain_name': p_project_domain_name,
'type': p_type, 'user_domain_name': p_user_domain_name,
'password': p_password}
extra_body = {'description': description,
'attributes': {'config': config}}
self._test_update_resource(self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_config(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my-name'
description = 'Vim Description'
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
args = [
name,
'--description', description,
'--config', str(config)]
extra_body = {'description': description,
'attributes': {'config': config}}
self._test_update_resource(self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_invalid_format_param_file(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'my-name'
key = 'key'
value = 'new-value'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_invalid_format_param.yaml')
args = [my_id, '--param-file', str(config_file)]
extra_fields = {'attributes': {'param_values': {key: value}}}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_fields)
def test_vnf_update_empty_param_file(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'my-name'
key = 'key'
value = 'new-value'
config_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_empty_param.yaml')
args = [my_id, '--param-file', str(config_file)]
extra_fields = {'attributes': {'param_values': {key: value}}}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_fields)
def test_vnf_update_invalid_format_config_file(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my-name'
description = 'Vim Description'
vim_config = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_invalid_format_config.yaml')
args = [
name,
'--config-file', vim_config,
'--description', description]
p_auth_url = 'http://1.2.3.4:5000'
p_type = 'openstack'
p_project_name = 'abc'
p_username = 'xyz'
p_project_domain_name = 'prj_domain_name'
p_user_domain_name = 'user_domain_name'
p_password = '12345'
config = {'auth_url': p_auth_url, 'project_name': p_project_name,
'username': p_username,
'project_domain_name': p_project_domain_name, 'type': p_type,
'user_domain_name': p_user_domain_name,
'password': p_password}
extra_body = {'description': description,
'attributes': {'config': config}}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_empty_config_file(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my-name'
description = 'Vim Description'
vim_config = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_empty_config.yaml')
args = [
name,
'--config-file', vim_config,
'--description', description]
extra_body = {'description': description}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_invalid_format_config(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'vnfs/my-id'
key = 'key'
value = 'new-value'
description = 'Vim Description'
extra_fields = {'attributes': {'param_values': {key: value}}}
config = 'test: : ]['
args = [my_id,
'--config', config,
'--description', description]
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_fields)
def test_vnf_update_empty_config(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my-name'
description = 'Vim Description'
config = {}
args = [name,
'--config', str(config),
'--description', description]
extra_body = {'description': description}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_multi_args_config_configfile_paramfile(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
key = 'key'
name = 'my-name'
value = 'new-value'
description = 'Vim Description'
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
vim_config = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
args = [my_id,
'--config-file', str(vim_config),
'--param-file', str(param_file),
'--config', str(config),
'--description', description]
extra_fields = {'attributes': {'param_values': {key: value}}}
self.assertRaises(BaseException,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_fields)
def test_vnf_update_multi_args_configfile_paramfile(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
description = 'Vim Description'
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
vim_config = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
args = [
my_id,
'--param-file', str(param_file),
'--config-file', vim_config,
'--description', description]
extra_body = {'description': description}
self.assertRaises(BaseException,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_multi_args_config_configfile(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
description = 'Vim Description'
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
vim_config = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_config.yaml')
args = [
my_id,
'--config-file', str(vim_config),
'--config', str(config),
'--description', description]
extra_body = {'description': description}
self.assertRaises(BaseException,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_multi_args_config_paramfile(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
description = 'Vim Description'
p_auth_url = 'https://1.2.3.4:6443'
p_type = 'kubernetes'
p_password = '12345'
p_project_name = 'default'
p_username = 'xyz'
p_ssl_ca_cert = 'abcxyz'
config = {'password': p_password, 'project_name': p_project_name,
'username': p_username, 'type': p_type,
'ssl_ca_cert': p_ssl_ca_cert, 'auth_url': p_auth_url}
param_file = utils.get_file_path(
'tests/unit/osc/samples/vnf_update_param.yaml')
args = [
my_id,
'--param-file', str(param_file),
'--config', str(config),
'--description', description]
extra_body = {'description': description}
self.assertRaises(BaseException,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_vnf_update_param_file_with_empty_dict(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'my-name'
key = 'key'
value = 'new-value'
config_file = utils.get_file_path(
'tests/unit/osc/samples/'
'vnf_update_param_file_with_empty_dict.yaml')
args = [my_id, '--param-file', str(config_file)]
extra_fields = {'attributes': {'param_values': {key: value}}}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_fields)
def test_vnf_update_config_file_with_empty_dict(self):
cmd = vnf.UpdateVNF(test_cli10.MyApp(sys.stdout), None)
name = 'my-name'
description = 'Vim Description'
vim_config = utils.get_file_path(
'tests/unit/osc/samples/'
'vnf_update_config_file_with_empty_dict.yaml')
args = [
name,
'--config-file', vim_config,
'--description', description]
extra_body = {'description': description}
self.assertRaises(exceptions.InvalidInput,
self._test_update_resource,
self._RESOURCE, cmd, name, args, extra_body)
def test_delete_vnf(self):
cmd = vnf.DeleteVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
def test_delete_vnf_with_force(self):
cmd = vnf.DeleteVNF(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id, '--force']
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
def test_list_vnf_resources(self):
cmd = vnf.ListVNFResources(test_cli10.MyApp(sys.stdout), None)
base_args = [self.test_id]
response = [{'name': 'CP11', 'id': 'id1', 'type': 'NeutronPort'},
{'name': 'CP12', 'id': 'id2', 'type': 'NeutronPort'}]
val = self._test_list_sub_resources(self._VNF_RESOURCES, 'resources',
cmd, self.test_id,
response_contents=response,
detail=True, base_args=base_args)
self.assertIn('id1', val)
self.assertIn('NeutronPort', val)
self.assertIn('CP11', val)
def test_multi_delete_vnf(self):
cmd = vnf.DeleteVNF(test_cli10.MyApp(sys.stdout), None)
vnf_ids = 'vnf1 vnf2 vnf3'
args = [vnf_ids]
self._test_delete_resource(self._RESOURCE, cmd, vnf_ids, args)

View File

@ -1,146 +0,0 @@
# Copyright 2014 Intel Corporation
# 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.
import sys
from tackerclient.common.exceptions import InvalidInput
from tackerclient.tacker.v1_0.vnfm import vnfd
from tackerclient.tests.unit import test_cli10
from unittest.mock import mock_open
from unittest.mock import patch
class CLITestV10VmVNFDJSON(test_cli10.CLITestV10Base):
_RESOURCE = 'vnfd'
_RESOURCES = 'vnfds'
def setUp(self):
plurals = {'vnfds': 'vnfd'}
super(CLITestV10VmVNFDJSON, self).setUp(plurals=plurals)
@patch("tackerclient.tacker.v1_0.vnfm.vnfd.open",
side_effect=mock_open(read_data="vnfd"),
create=True)
def test_create_vnfd_all_params(self, mo):
cmd = vnfd.CreateVNFD(
test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'my-name'
attr_key = 'vnfd'
attr_val = 'vnfd'
args = [
name,
'--vnfd-file', 'vnfd-file'
]
position_names = ['name']
position_values = [name]
extra_body = {
'service_types': [{'service_type': 'vnfd'}],
'attributes': {attr_key: attr_val},
}
self._test_create_resource(self._RESOURCE, cmd, None, my_id,
args, position_names, position_values,
extra_body=extra_body)
@patch("tackerclient.tacker.v1_0.vnfm.vnfd.open",
side_effect=mock_open(read_data="vnfd"),
create=True)
def test_create_vnfd_with_mandatory_params(self, mo):
cmd = vnfd.CreateVNFD(
test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
args = [name, '--vnfd-file', 'vnfd-file', ]
position_names = ['name']
position_values = [name]
extra_body = {
'service_types': [{'service_type': 'vnfd'}],
'attributes': {'vnfd': 'vnfd'}
}
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values,
extra_body=extra_body)
@patch("tackerclient.tacker.v1_0.vnfm.vnfd.open",
side_effect=mock_open(read_data=""),
create=True)
def test_create_vnfd_with_empty_file(self, mo):
cmd = vnfd.CreateVNFD(
test_cli10.MyApp(sys.stdout), None)
name = 'my_name'
my_id = 'my-id'
args = [name, '--vnfd-file', 'vnfd-file', ]
position_names = ['name']
position_values = [name]
extra_body = {
'service_types': [{'service_type': 'vnfd'}],
'attributes': {'vnfd': 'vnfd'}
}
err = None
try:
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values,
extra_body=extra_body)
except InvalidInput:
err = True
self.assertEqual(True, err)
def test_list_vnfds(self):
cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='onboarded')
def test_list_inline_vnfds(self):
cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='inline')
def test_list_all_vnfds(self):
cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='all')
def test_list_vnfds_pagenation(self):
cmd = vnfd.ListVNFD(test_cli10.MyApp(sys.stdout), None)
print(cmd)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='onboarded')
def test_show_vnfd_id(self):
cmd = vnfd.ShowVNFD(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id, args,
['id'])
def test_show_vnfd_id_name(self):
cmd = vnfd.ShowVNFD(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id,
args, ['id', 'name'])
def test_delete_vnfd(self):
cmd = vnfd.DeleteVNFD(
test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
def test_multi_delete_vnfd(self):
cmd = vnfd.DeleteVNFD(
test_cli10.MyApp(sys.stdout), None)
vnfd_ids = 'my-id1 my-id2 my-id3'
args = [vnfd_ids]
self._test_delete_resource(self._RESOURCE, cmd, vnfd_ids, args)

View File

@ -1,126 +0,0 @@
# Copyright 2014 Intel Corporation
# 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.
import sys
from tackerclient.common import utils
from tackerclient.tacker.v1_0.nfvo import vnffg
from tackerclient.tests.unit import test_cli10
API_VERSION = "1.0"
FORMAT = 'json'
TOKEN = 'testtoken'
ENDURL = 'localurl'
class CLITestV10VmVNFFGJSON(test_cli10.CLITestV10Base):
_RESOURCE = 'vnffg'
_RESOURCES = 'vnffgs'
def setUp(self):
plurals = {'vnffgs': 'vnffg'}
super(CLITestV10VmVNFFGJSON, self).setUp(plurals=plurals)
def test_create_vnffg_all_params(self):
cmd = vnffg.CreateVNFFG(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
vnffgd_id = 'vnffgd'
vnffg_name = 'fake-vnffg'
vnf_mapping = 'VNFD1:VNF1'
args = [
vnffg_name,
'--vnffgd-id', vnffgd_id,
'--vnf-mapping', vnf_mapping,
'--symmetrical']
position_names = ['vnffgd_id', 'vnf_mapping', 'symmetrical']
position_values = [vnffgd_id, {"VNFD1": "VNF1"}, True]
extra_body = {'name': vnffg_name, 'attributes': {}}
self._test_create_resource(self._RESOURCE, cmd, None, my_id,
args, position_names, position_values,
extra_body=extra_body,
get_client_called_count=2)
def test_create_vnffg_with_mandatory_params(self):
cmd = vnffg.CreateVNFFG(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
vnffg_name = 'fake-vnffg'
vnffgd_id = 'vnffgd'
args = [
vnffg_name,
'--vnffgd-id', vnffgd_id,
]
position_names = ['vnffgd_id']
position_values = [vnffgd_id]
extra_body = {'symmetrical': False, 'name': vnffg_name,
'attributes': {}}
self._test_create_resource(self._RESOURCE, cmd, vnffg_name, my_id,
args, position_names, position_values,
extra_body=extra_body,
get_client_called_count=2)
def test_list_vnffgs(self):
cmd = vnffg.ListVNFFG(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True)
def test_list_vnffgs_pagenation(self):
cmd = vnffg.ListVNFFG(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True)
def test_show_vnffg_id(self):
cmd = vnffg.ShowVNFFG(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id, args,
['id'])
def test_show_vnffg_id_name(self):
cmd = vnffg.ShowVNFFG(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id,
args, ['id', 'name'])
def test_update_vnffg(self):
cmd = vnffg.UpdateVNFFG(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
update_vnffg = utils.get_file_path(
'tests/unit/vm/samples/vnffg_update_file.yaml')
vnf_mapping = 'VNFD1:VNF1'
args = [
my_id,
'--vnf-mapping', vnf_mapping,
'--vnffgd-template', str(update_vnffg),
'--symmetrical'
]
extra_fields = {
"vnf_mapping": {"VNFD1": "VNF1"},
"vnffgd_template": "abcxyz",
"symmetrical": True
}
self._test_update_resource(self._RESOURCE, cmd, my_id,
args, extra_fields,
get_client_called_count=2)
def test_delete_vnffg_without_force(self):
cmd = vnffg.DeleteVNFFG(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
def test_delete_vnffg_with_force(self):
cmd = vnffg.DeleteVNFFG(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id, '--force']
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)

View File

@ -1,113 +0,0 @@
# 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.
import sys
from tackerclient.tacker.v1_0.nfvo import vnffgd
from tackerclient.tests.unit import test_cli10
from unittest.mock import mock_open
from unittest.mock import patch
class CLITestV10VmVNFFGDJSON(test_cli10.CLITestV10Base):
_RESOURCE = 'vnffgd'
_RESOURCES = 'vnffgds'
def setUp(self):
plurals = {'vnffgds': 'vnffgd'}
super(CLITestV10VmVNFFGDJSON, self).setUp(plurals=plurals)
@patch("tackerclient.tacker.v1_0.nfvo.vnffgd.open",
side_effect=mock_open(read_data="vnffgd"),
create=True)
def test_create_vnffgd_all_params(self, mo):
cmd = vnffgd.CreateVNFFGD(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'my-name'
attr_key = 'vnffgd'
attr_val = 'vnffgd'
description = 'vnffgd description'
args = [
name,
'--vnffgd-file', 'vnffgd_file',
'--description', description,
]
position_names = ['name', 'description']
position_values = [name, description]
extra_body = {
'template': {attr_key: attr_val},
}
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values,
extra_body=extra_body)
@patch("tackerclient.tacker.v1_0.nfvo.vnffgd.open",
side_effect=mock_open(read_data="vnffgd"),
create=True)
def test_create_vnffgd_with_mandatory_params(self, mo):
cmd = vnffgd.CreateVNFFGD(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
name = 'my-name'
attr_key = 'vnffgd'
attr_val = 'vnffgd'
args = [
name,
'--vnffgd-file', 'vnffgd_file',
]
position_names = ['name']
position_values = [name]
extra_body = {
'template': {attr_key: attr_val},
}
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values,
extra_body=extra_body)
def test_list_vnffgds(self):
cmd = vnffgd.ListVNFFGD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='onboarded')
def test_list_inline_vnffgds(self):
cmd = vnffgd.ListVNFFGD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='inline')
def test_list_all_vnffgds(self):
cmd = vnffgd.ListVNFFGD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='all')
def test_list_vnffgds_pagenation(self):
cmd = vnffgd.ListVNFFGD(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._RESOURCES, cmd, True,
template_source='onboarded')
def test_show_vnffgd_id(self):
cmd = vnffgd.ShowVNFFGD(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id, args,
['id'])
def test_show_vnffgd_id_name(self):
cmd = vnffgd.ShowVNFFGD(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', '--fields', 'name', self.test_id]
self._test_show_resource(self._RESOURCE, cmd, self.test_id,
args, ['id', 'name'])
def test_delete_vnffgd(self):
cmd = vnffgd.DeleteVNFFGD(test_cli10.MyApp(sys.stdout), None)
my_id = 'my-id'
args = [my_id]
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)

View File

@ -23,7 +23,6 @@ import requests
from urllib import parse as urlparse
from tackerclient import client
from tackerclient.common import constants
from tackerclient.common import exceptions
from tackerclient.common import serializer
from tackerclient.common import utils
@ -277,7 +276,7 @@ class ClientBase(object):
return self.httpclient.get_auth_info()
def serialize(self, data):
"""Serializes a dictionary into either XML or JSON.
"""Serializes a dictionary JSON.
A dictionary with a single key can be passed and it can contain any
structure.
@ -287,34 +286,20 @@ class ClientBase(object):
elif self.format in ('zip', 'text'):
return data
elif type(data) is dict:
return serializer.Serializer(
self.get_attr_metadata()).serialize(data, self.content_type())
return serializer.Serializer().serialize(data, 'application/json')
else:
raise Exception(_("Unable to serialize object of type = '%s'") %
type(data))
def deserialize(self, data, status_code):
"""Deserializes an XML or JSON string into a dictionary."""
"""Deserializes an JSON string into a dictionary."""
if status_code in (204, 202) or self.format in ('zip', 'text', 'any'):
return data
return serializer.Serializer(self.get_attr_metadata()).deserialize(
data, self.content_type())['body']
def get_attr_metadata(self):
if self.format == 'json':
return {}
old_request_format = self.format
self.format = 'json'
exts = self.list_extensions()['extensions']
self.format = old_request_format
ns = dict([(ext['alias'], ext['namespace']) for ext in exts])
self.EXTED_PLURALS.update(constants.PLURALS)
return {'plurals': self.EXTED_PLURALS,
'xmlns': constants.XML_NS_V10,
constants.EXT_NS: ns}
return serializer.Serializer().deserialize(
data, 'application/json')['body']
def content_type(self, _format=None):
"""Returns the mime-type for either 'xml', 'json, 'text', or 'zip'.
"""Returns the mime-type for either 'json, 'text', or 'zip'.
Defaults to the currently set format.
"""
@ -418,129 +403,12 @@ class ClientBase(object):
class LegacyClient(ClientBase):
extensions_path = "/extensions"
extension_path = "/extensions/%s"
vnfds_path = '/vnfds'
vnfd_path = '/vnfds/%s'
vnfs_path = '/vnfs'
vnf_path = '/vnfs/%s'
vnf_scale_path = '/vnfs/%s/actions'
vnf_resources_path = '/vnfs/%s/resources'
vims_path = '/vims'
vim_path = '/vims/%s'
events_path = '/events'
event_path = '/events/%s'
vnffgds_path = '/vnffgds'
vnffgd_path = '/vnffgds/%s'
vnffgs_path = '/vnffgs'
vnffg_path = '/vnffgs/%s'
nfps_path = '/nfps'
nfp_path = '/nfps/%s'
sfcs_path = '/sfcs'
sfc_path = '/sfcs/%s'
fcs_path = '/classifiers'
fc_path = '/classifiers/%s'
nsds_path = '/nsds'
nsd_path = '/nsds/%s'
nss_path = '/nss'
ns_path = '/nss/%s'
clusters_path = '/clusters'
cluster_path = '/clusters/%s'
cluster_members_path = '/clustermembers'
cluster_member_path = '/clustermembers/%s'
# API has no way to report plurals, so we have to hard code them
# EXTED_PLURALS = {}
@APIParamsCall
def list_extensions(self, **_params):
"""Fetch a list of all exts on server side."""
return self.get(self.extensions_path, params=_params)
@APIParamsCall
def show_extension(self, ext_alias, **_params):
"""Fetch a list of all exts on server side."""
return self.get(self.extension_path % ext_alias, params=_params)
_VNFD = "vnfd"
_NSD = "nsd"
@APIParamsCall
def list_vnfds(self, retrieve_all=True, **_params):
vnfds_dict = self.list(self._VNFD + 's',
self.vnfds_path,
retrieve_all,
**_params)
for vnfd in vnfds_dict['vnfds']:
if vnfd.get('description'):
if len(vnfd['description']) > DEFAULT_DESC_LENGTH:
vnfd['description'] = \
vnfd['description'][:DEFAULT_DESC_LENGTH]
vnfd['description'] += '...'
return vnfds_dict
@APIParamsCall
def show_vnfd(self, vnfd, **_params):
return self.get(self.vnfd_path % vnfd,
params=_params)
@APIParamsCall
def create_vnfd(self, body):
body[self._VNFD]['service_types'] = [{'service_type': 'vnfd'}]
return self.post(self.vnfds_path, body)
@APIParamsCall
def delete_vnfd(self, vnfd):
return self.delete(self.vnfd_path % vnfd)
@APIParamsCall
def list_vnfs(self, retrieve_all=True, **_params):
vnfs = self.list('vnfs', self.vnfs_path, retrieve_all, **_params)
for vnf in vnfs['vnfs']:
error_reason = vnf.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
vnf['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
vnf['error_reason'] += '...'
return vnfs
@APIParamsCall
def show_vnf(self, vnf, **_params):
return self.get(self.vnf_path % vnf, params=_params)
@APIParamsCall
def create_vnf(self, body):
return self.post(self.vnfs_path, body=body)
@APIParamsCall
def delete_vnf(self, vnf, body=None):
return self.delete(self.vnf_path % vnf, body=body)
@APIParamsCall
def update_vnf(self, vnf, body):
return self.put(self.vnf_path % vnf, body=body)
@APIParamsCall
def list_vnf_resources(self, vnf, retrieve_all=True, **_params):
return self.list('resources', self.vnf_resources_path % vnf,
retrieve_all, **_params)
@APIParamsCall
def scale_vnf(self, vnf, body=None):
return self.post(self.vnf_scale_path % vnf, body=body)
@APIParamsCall
def show_vim(self, vim, **_params):
return self.get(self.vim_path % vim, params=_params)
@ -563,239 +431,6 @@ class LegacyClient(ClientBase):
def list_vims(self, retrieve_all=True, **_params):
return self.list('vims', self.vims_path, retrieve_all, **_params)
@APIParamsCall
def list_events(self, retrieve_all=True, **_params):
events = self.list('events', self.events_path, retrieve_all,
**_params)
return events
@APIParamsCall
def list_vnf_events(self, retrieve_all=True, **_params):
_params['resource_type'] = 'vnf'
events = self.list('events', self.events_path, retrieve_all,
**_params)
vnf_events = {}
vnf_events['vnf_events'] = events['events']
return vnf_events
@APIParamsCall
def list_vnfd_events(self, retrieve_all=True, **_params):
_params['resource_type'] = 'vnfd'
events = self.list('events', self.events_path, retrieve_all,
**_params)
vnfd_events = {}
vnfd_events['vnfd_events'] = events['events']
return vnfd_events
@APIParamsCall
def list_vim_events(self, retrieve_all=True, **_params):
_params['resource_type'] = 'vim'
events = self.list('events', self.events_path, retrieve_all,
**_params)
vim_events = {}
vim_events['vim_events'] = events['events']
return vim_events
@APIParamsCall
def show_event(self, event_id, **_params):
return self.get(self.event_path % event_id, params=_params)
_VNFFGD = "vnffgd"
@APIParamsCall
def create_vnffgd(self, body):
return self.post(self.vnffgds_path, body)
@APIParamsCall
def list_vnffgds(self, retrieve_all=True, **_params):
vnffgds_dict = self.list(self._VNFFGD + 's',
self.vnffgds_path,
retrieve_all,
**_params)
for vnffgd in vnffgds_dict['vnffgds']:
if 'description' in vnffgd.keys() and \
len(vnffgd['description']) > DEFAULT_DESC_LENGTH:
vnffgd['description'] = vnffgd['description'][
:DEFAULT_DESC_LENGTH]
vnffgd['description'] += '...'
return vnffgds_dict
@APIParamsCall
def show_vnffgd(self, vnffgd, **_params):
return self.get(self.vnffgd_path % vnffgd, params=_params)
@APIParamsCall
def delete_vnffgd(self, vnffgd):
return self.delete(self.vnffgd_path % vnffgd)
@APIParamsCall
def list_vnffgs(self, retrieve_all=True, **_params):
vnffgs = self.list('vnffgs', self.vnffgs_path, retrieve_all, **_params)
for vnffg in vnffgs['vnffgs']:
error_reason = vnffg.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
vnffg['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
vnffg['error_reason'] += '...'
return vnffgs
@APIParamsCall
def show_vnffg(self, vnffg, **_params):
return self.get(self.vnffg_path % vnffg, params=_params)
@APIParamsCall
def create_vnffg(self, body):
return self.post(self.vnffgs_path, body=body)
@APIParamsCall
def delete_vnffg(self, vnffg, body=None):
return self.delete(self.vnffg_path % vnffg, body=body)
@APIParamsCall
def update_vnffg(self, vnffg, body):
return self.put(self.vnffg_path % vnffg, body=body)
@APIParamsCall
def list_sfcs(self, retrieve_all=True, **_params):
sfcs = self.list('sfcs', self.sfcs_path, retrieve_all, **_params)
for chain in sfcs['sfcs']:
error_reason = chain.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
chain['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
chain['error_reason'] += '...'
return sfcs
@APIParamsCall
def show_sfc(self, chain, **_params):
return self.get(self.sfc_path % chain, params=_params)
@APIParamsCall
def list_nfps(self, retrieve_all=True, **_params):
nfps = self.list('nfps', self.nfps_path, retrieve_all, **_params)
for nfp in nfps['nfps']:
error_reason = nfp.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
nfp['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
nfp['error_reason'] += '...'
return nfps
@APIParamsCall
def show_nfp(self, nfp, **_params):
return self.get(self.nfp_path % nfp, params=_params)
@APIParamsCall
def list_classifiers(self, retrieve_all=True, **_params):
classifiers = self.list('classifiers', self.fcs_path, retrieve_all,
**_params)
for classifier in classifiers['classifiers']:
error_reason = classifier.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
classifier['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
classifier['error_reason'] += '...'
return classifiers
@APIParamsCall
def show_classifier(self, classifier, **_params):
return self.get(self.fc_path % classifier, params=_params)
@APIParamsCall
def list_nsds(self, retrieve_all=True, **_params):
nsds_dict = self.list(self._NSD + 's',
self.nsds_path,
retrieve_all,
**_params)
for nsd in nsds_dict['nsds']:
if 'description' in nsd.keys() and \
len(nsd['description']) > DEFAULT_DESC_LENGTH:
nsd['description'] = nsd['description'][:DEFAULT_DESC_LENGTH]
nsd['description'] += '...'
return nsds_dict
@APIParamsCall
def show_nsd(self, nsd, **_params):
return self.get(self.nsd_path % nsd,
params=_params)
@APIParamsCall
def create_nsd(self, body):
return self.post(self.nsds_path, body)
@APIParamsCall
def delete_nsd(self, nsd):
return self.delete(self.nsd_path % nsd)
@APIParamsCall
def list_nss(self, retrieve_all=True, **_params):
nss = self.list('nss', self.nss_path, retrieve_all, **_params)
for ns in nss['nss']:
error_reason = ns.get('error_reason', None)
if error_reason and \
len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
ns['error_reason'] = error_reason[
:DEFAULT_ERROR_REASON_LENGTH]
ns['error_reason'] += '...'
return nss
@APIParamsCall
def show_ns(self, ns, **_params):
return self.get(self.ns_path % ns, params=_params)
@APIParamsCall
def create_ns(self, body):
return self.post(self.nss_path, body=body)
@APIParamsCall
def delete_ns(self, ns, body=None):
return self.delete(self.ns_path % ns, body=body)
@APIParamsCall
def create_cluster(self, body=None):
return self.post(self.clusters_path, body)
@APIParamsCall
def list_clusters(self, retrieve_all=True, **_params):
clusters = self.list('clusters', self.clusters_path,
retrieve_all, **_params)
return clusters
@APIParamsCall
def show_cluster(self, cluster, **_params):
member = self.get(self.cluster_path % cluster,
params=_params)
return member
@APIParamsCall
def delete_cluster(self, cluster):
return self.delete(self.cluster_path % cluster)
@APIParamsCall
def create_clustermember(self, body=None):
return self.post(self.cluster_members_path, body)
@APIParamsCall
def list_clustermembers(self, retrieve_all=True, **_params):
cluster_members = self.list('clustermembers',
self.cluster_members_path,
retrieve_all, **_params)
return cluster_members
@APIParamsCall
def show_clustermember(self, clustermember, **_params):
member = self.get(self.cluster_member_path % clustermember,
params=_params)
return member
@APIParamsCall
def delete_clustermember(self, clustermember):
return self.delete(self.cluster_member_path % clustermember)
class VnfPackageClient(ClientBase):
"""Client for vnfpackage APIs.
@ -1224,49 +859,6 @@ class Client(object):
return self.legacy_client.list(collection, path,
retrieve_all=retrieve_all, **params)
def list_extensions(self, **_params):
return self.legacy_client.list_extensions(**_params)
def show_extension(self, ext_alias, **_params):
"""Fetch a list of all exts on server side."""
return self.legacy_client.show_extension(ext_alias, **_params)
def list_vnfds(self, retrieve_all=True, **_params):
return self.legacy_client.list_vnfds(retrieve_all=retrieve_all,
**_params)
def show_vnfd(self, vnfd, **_params):
return self.legacy_client.show_vnfd(vnfd, **_params)
def create_vnfd(self, body):
return self.legacy_client.create_vnfd(body)
def delete_vnfd(self, vnfd):
return self.legacy_client.delete_vnfd(vnfd)
def list_vnfs(self, retrieve_all=True, **_params):
return self.legacy_client.list_vnfs(retrieve_all=retrieve_all,
**_params)
def show_vnf(self, vnf, **_params):
return self.legacy_client.show_vnf(vnf, **_params)
def create_vnf(self, body):
return self.legacy_client.create_vnf(body)
def delete_vnf(self, vnf, body=None):
return self.legacy_client.delete_vnf(vnf, body=body)
def update_vnf(self, vnf, body):
return self.legacy_client.update_vnf(vnf, body)
def list_vnf_resources(self, vnf, retrieve_all=True, **_params):
return self.legacy_client.list_vnf_resources(
vnf, retrieve_all=retrieve_all, **_params)
def scale_vnf(self, vnf, body=None):
return self.legacy_client.scale_vnf(vnf, body=body)
def show_vim(self, vim, **_params):
return self.legacy_client.show_vim(vim, **_params)
@ -1283,128 +875,6 @@ class Client(object):
return self.legacy_client.list_vims(retrieve_all=retrieve_all,
**_params)
def list_events(self, retrieve_all=True, **_params):
return self.legacy_client.list_events(retrieve_all=retrieve_all,
**_params)
def list_vnf_events(self, retrieve_all=True, **_params):
return self.legacy_client.list_vnf_events(
retrieve_all=retrieve_all, **_params)
def list_vnfd_events(self, retrieve_all=True, **_params):
return self.legacy_client.list_vnfd_events(
retrieve_all=retrieve_all, **_params)
def list_vim_events(self, retrieve_all=True, **_params):
return self.legacy_client.list_vim_events(
retrieve_all=retrieve_all, **_params)
def show_event(self, event_id, **_params):
return self.legacy_client.show_event(event_id, **_params)
def create_vnffgd(self, body):
return self.legacy_client.create_vnffgd(body)
def list_vnffgds(self, retrieve_all=True, **_params):
return self.legacy_client.list_vnffgds(retrieve_all=retrieve_all,
**_params)
def show_vnffgd(self, vnffgd, **_params):
return self.legacy_client.show_vnffgd(vnffgd, **_params)
def delete_vnffgd(self, vnffgd):
return self.legacy_client.delete_vnffgd(vnffgd)
def list_vnffgs(self, retrieve_all=True, **_params):
return self.legacy_client.list_vnffgs(retrieve_all=retrieve_all,
**_params)
def show_vnffg(self, vnffg, **_params):
return self.legacy_client.show_vnffg(vnffg, **_params)
def create_vnffg(self, body):
return self.legacy_client.create_vnffg(body)
def delete_vnffg(self, vnffg):
return self.legacy_client.delete_vnffg(vnffg)
def update_vnffg(self, vnffg, body):
return self.legacy_client.update_vnffg(vnffg, body)
def list_sfcs(self, retrieve_all=True, **_params):
return self.legacy_client.list_sfcs(retrieve_all=retrieve_all,
**_params)
def show_sfc(self, chain, **_params):
return self.legacy_client.show_sfc(chain, **_params)
def list_nfps(self, retrieve_all=True, **_params):
return self.legacy_client.list_nfps(retrieve_all=retrieve_all,
**_params)
def show_nfp(self, nfp, **_params):
return self.legacy_client.show_nfp(nfp, **_params)
def list_classifiers(self, retrieve_all=True, **_params):
return self.legacy_client.list_classifiers(
retrieve_all=retrieve_all, **_params)
def show_classifier(self, classifier, **_params):
return self.legacy_client.show_classifier(classifier, **_params)
def list_nsds(self, retrieve_all=True, **_params):
return self.legacy_client.list_nsds(retrieve_all=retrieve_all,
**_params)
def show_nsd(self, nsd, **_params):
return self.legacy_client.show_nsd(nsd, **_params)
def create_nsd(self, body):
return self.legacy_client.create_nsd(body)
def delete_nsd(self, nsd):
return self.legacy_client.delete_nsd(nsd)
def list_nss(self, retrieve_all=True, **_params):
return self.legacy_client.list_nss(retrieve_all=retrieve_all,
**_params)
def show_ns(self, ns, **_params):
return self.legacy_client.show_ns(ns, **_params)
def create_ns(self, body):
return self.legacy_client.create_ns(body)
def delete_ns(self, ns, body=None):
return self.legacy_client.delete_ns(ns, body=body)
def create_cluster(self, body=None):
return self.legacy_client.create_cluster(body=body)
def list_clusters(self, retrieve_all=True, **_params):
return self.legacy_client.list_clusters(retrieve_all=retrieve_all,
**_params)
def show_cluster(self, cluster, **_params):
return self.legacy_client.show_cluster(cluster, **_params)
def delete_cluster(self, cluster):
return self.legacy_client.delete_cluster(cluster)
def create_clustermember(self, body=None):
return self.legacy_client.create_clustermember(body=body)
def list_clustermembers(self, retrieve_all=True, **_params):
return self.legacy_client.list_clustermembers(
retrieve_all=retrieve_all, **_params)
def show_clustermember(self, clustermember, **_params):
return self.legacy_client.show_clustermember(clustermember,
**_params)
def delete_clustermember(self, clustermember):
return self.legacy_client.delete_clustermember(clustermember)
# VnfPackageClient methods
def create_vnf_package(self, body):