cli: modify vnfd, param & config attr. to dict obj

vnfd templates, parameter and config files are sent as yaml
strings in requests body to tacker server.

Change the attributes to dictionary objects. New behavior
is applicable to tosca templates only. Also, this change may mangle
the order of nodes in tosca templates. In order to address this
concern and preserve the network interfaces order in these nodes,
there will be follow on patch (on server) to addres this.

Change-Id: I05a1d60dc643dca864aff559f37491914b1fcfc3
Partial-Bug: #1591361
This commit is contained in:
Sripriya 2016-08-25 14:55:24 -07:00
parent 144408331e
commit ed102cac10
5 changed files with 48 additions and 10 deletions

View File

@ -12,5 +12,6 @@ six>=1.9.0 # MIT
Babel>=2.3.4 # BSD
oslo.i18n>=2.1.0 # Apache-2.0
oslo.log>=1.14.0 # Apache-2.0
oslo.utils>=3.16.0 # Apache-2.0
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0

View File

@ -21,6 +21,7 @@ import argparse
import logging
import os
from oslo_log import versionutils
from oslo_utils import encodeutils
from oslo_utils import importutils
import six
@ -185,3 +186,9 @@ def get_file_path(filename):
file_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'../%s' % filename))
return file_path
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)

View File

@ -65,7 +65,7 @@ class CreateVIM(tackerV10.CreateCommand):
if parsed_args.config_file:
with open(parsed_args.config_file) as f:
vim_config = f.read()
config_param = yaml.load(vim_config)
config_param = yaml.load(vim_config, Loader=yaml.SafeLoader)
vim_obj = body[self.resource]
try:
auth_url = config_param.pop('auth_url')

View File

@ -15,6 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import yaml
from tackerclient.common import utils
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
@ -82,14 +85,22 @@ class CreateVNF(tackerV10.CreateCommand):
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()
args['attributes']['config'] = config_yaml
config = yaml.load(
config_yaml, Loader=yaml.SafeLoader)
if parsed_args.config:
parsed_args.config = parsed_args.config.decode('unicode_escape')
args['attributes']['config'] = parsed_args.config
config = parsed_args.config
if isinstance(config, str):
config_str = parsed_args.config.decode('unicode_escape')
config = yaml.load(config_str, Loader=yaml.SafeLoader)
utils.deprecate_warning(what='yaml as string', as_of='N',
in_favor_of='yaml as dictionary')
if config:
args['attributes']['config'] = config
if parsed_args.vim_region_name:
args.setdefault('placement_attr', {})['region_name'] = \
parsed_args.vim_region_name
@ -111,7 +122,8 @@ class CreateVNF(tackerV10.CreateCommand):
if parsed_args.param_file:
with open(parsed_args.param_file) as f:
param_yaml = f.read()
args['attributes']['param_values'] = param_yaml
args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader)
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description',
'vnfd_id', 'vim_id'])
@ -134,13 +146,20 @@ class UpdateVNF(tackerV10.UpdateCommand):
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()
body[self.resource]['attributes'] = {'config': config_yaml}
config = yaml.load(config_yaml, Loader=yaml.SafeLoader)
if parsed_args.config:
parsed_args.config = parsed_args.config.decode('unicode_escape')
body[self.resource]['attributes'] = {'config': parsed_args.config}
config = parsed_args.config
if isinstance(parsed_args.config, str):
config_str = parsed_args.config.decode('unicode_escape')
config = yaml.load(config_str, Loader=yaml.SafeLoader)
utils.deprecate_warning(what='yaml as string', as_of='N',
in_favor_of='yaml as dictionary')
if config:
body[self.resource]['attributes'] = {'config': config}
tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id'])
return body

View File

@ -16,7 +16,9 @@
# under the License.
from oslo_serialization import jsonutils
import yaml
from tackerclient.common import utils
from tackerclient.i18n import _
from tackerclient.tacker import v1_0 as tackerV10
@ -56,12 +58,21 @@ class CreateVNFD(tackerV10.CreateCommand):
def args2body(self, parsed_args):
body = {self.resource: {}}
vnfd = None
if parsed_args.vnfd_file:
with open(parsed_args.vnfd_file) as f:
vnfd = f.read()
body[self.resource]['attributes'] = {'vnfd': vnfd}
if "tosca_definitions_version" in vnfd:
vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader)
if parsed_args.vnfd:
body[self.resource]['attributes'] = {'vnfd': parsed_args.vnfd}
vnfd = parsed_args.vnfd
if isinstance(vnfd, str):
vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader)
utils.deprecate_warning(what='yaml as string',
as_of='N',
in_favor_of='yaml as dictionary')
if vnfd:
body[self.resource]['attributes'] = {'vnfd': vnfd}
tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description'])