From 94ccf2ded83b5923f5637e3368355429883256c9 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Mon, 4 Jul 2016 20:40:59 +0530 Subject: [PATCH] VNF scaling: CLI and python client vnf-scale --vnf-name --vnf-id --scaling-policy-name --scaling-type implements: blueprint #vnf-scaling depends-on: Ib8cdd1295460e617806eec173e4d4ed8f35e6642 Change-Id: If88273efad41eaff466895ad7dbba6a8de31d119 --- tackerclient/shell.py | 1 + tackerclient/tacker/v1_0/vm/vnf.py | 55 ++++++++++++++++++++++++++++++ tackerclient/v1_0/client.py | 5 +++ 3 files changed, 61 insertions(+) diff --git a/tackerclient/shell.py b/tackerclient/shell.py index ddfecebd..7ca7468e 100644 --- a/tackerclient/shell.py +++ b/tackerclient/shell.py @@ -115,6 +115,7 @@ COMMAND_V1 = { 'vnf-delete': vnf.DeleteVNF, 'vnf-list': vnf.ListVNF, 'vnf-show': vnf.ShowVNF, + 'vnf-scale': vnf.ScaleVNF, # 'vnf-config-create' # 'vnf-config-push' diff --git a/tackerclient/tacker/v1_0/vm/vnf.py b/tackerclient/tacker/v1_0/vm/vnf.py index 97f7b496..2ce3845c 100644 --- a/tackerclient/tacker/v1_0/vm/vnf.py +++ b/tackerclient/tacker/v1_0/vm/vnf.py @@ -143,3 +143,58 @@ class DeleteVNF(tackerV10.DeleteCommand): """Delete a given VNF.""" resource = _VNF + + +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 diff --git a/tackerclient/v1_0/client.py b/tackerclient/v1_0/client.py index 8304ad97..6a8432be 100644 --- a/tackerclient/v1_0/client.py +++ b/tackerclient/v1_0/client.py @@ -338,6 +338,7 @@ class Client(ClientBase): vnfd_path = '/vnfds/%s' vnfs_path = '/vnfs' vnf_path = '/vnfs/%s' + vnf_scale_path = '/vnfs/%s/actions' vims_path = '/vims' vim_path = '/vims/%s' @@ -417,6 +418,10 @@ class Client(ClientBase): def update_vnf(self, vnf, body=None): return self.put(self.vnf_path % vnf, body=body) + @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)