From: tierno Date: Fri, 27 Apr 2018 12:35:45 +0000 (+0200) Subject: Allow ns-creation params: vim-network, multisite deployement X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F6048%2F1;p=osm%2Fosmclient.git Allow ns-creation params: vim-network, multisite deployement Change-Id: Id9468e2ec761cac7a4aec70999f681580e9be716 Signed-off-by: tierno --- diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 9c3e154..16ac7d7 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -533,7 +533,8 @@ def vnfd_create2(ctx, filename, overwrite): help='comma separated list of keys to inject to vnfs') @click.option('--config', default=None, - help='ns specific yaml configuration') + help='ns specific yaml configuration:\nvnf: [member-vnf-index: TEXT, vim_account: TEXT]\n' + 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]') @click.pass_context def ns_create(ctx, nsd_name, @@ -544,8 +545,8 @@ def ns_create(ctx, config): '''creates a new NS instance''' try: - if config: - check_client_version(ctx.obj, '--config', 'v1') + # if config: + # check_client_version(ctx.obj, '--config', 'v1') ctx.obj.ns.create( nsd_name, ns_name, diff --git a/osmclient/sol005/http.py b/osmclient/sol005/http.py index 11ddca6..c89e91b 100644 --- a/osmclient/sol005/http.py +++ b/osmclient/sol005/http.py @@ -48,16 +48,15 @@ class Http(http.Http): http_code = curl_cmd.getinfo(pycurl.HTTP_CODE) #print 'HTTP_CODE: {}'.format(http_code) curl_cmd.close() - if http_code == 204: - return None - elif http_code == 404: - if data.getvalue(): - return json.loads(data.getvalue().decode()) - else: - return "NOT FOUND" + # TODO 202 accepted should be returned somehow if data.getvalue(): return json.loads(data.getvalue().decode()) - return "Failed" + elif http_code == 404: + return "NOT FOUND" + elif http_code >= 300: + return "Failed" + else: + return def send_cmd(self, endpoint='', postfields_dict=None, formfile=None, filename=None, diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index b1678cf..4b55cc2 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -76,7 +76,7 @@ class Ns(object): def delete(self, name): ns = self.get(name) resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,ns['_id'])) - #print 'RESP: '.format(resp) + # print 'RESP: {}'.format(resp) if resp is None: print 'Deleted' else: @@ -87,27 +87,55 @@ class Ns(object): admin_status='ENABLED'): nsd = self._client.nsd.get(nsd_name) - - datacenter = self._client.vim.get(account) - if datacenter is None: - raise NotFound("cannot find datacenter account {}".format(account)) + + vim_account_id = {} + + def get_vim_account_id(vim_account): + if vim_account_id.get(vim_account): + return vim_account_id[vim_account] + + vim = self._client.vim.get(vim_account) + if vim is None: + raise NotFound("cannot find vim account '{}'".format(vim_account)) + vim_account_id[vim_account] = vim['_id'] + return vim['_id'] ns = {} ns['nsdId'] = nsd['_id'] ns['nsName'] = nsr_name ns['nsDescription'] = description - ns['vimAccountId'] = datacenter['_id'] + ns['vimAccountId'] = get_vim_account_id(account) #ns['userdata'] = {} #ns['userdata']['key1']='value1' #ns['userdata']['key2']='value2' if ssh_keys is not None: # ssh_keys is comma separate list - ssh_keys_format = [] - for key in ssh_keys.split(','): - ssh_keys_format.append({'key-pair-ref': key}) + # ssh_keys_format = [] + # for key in ssh_keys.split(','): + # ssh_keys_format.append({'key-pair-ref': key}) + # + # ns['ssh-authorized-key'] = ssh_keys_format + ns['ssh-authorized-key'] = ssh_keys.split(',') + if config: + ns_config = yaml.load(config) + if "vim-network-name" in ns_config: + ns_config["vld"] = ns_config.pop("vim-network-name") + if "vld" in ns_config: + for vld in ns_config["vld"]: + if vld.get("vim-network-name"): + if isinstance(vld["vim-network-name"], dict): + vim_network_name_dict = {} + for vim_account, vim_net in vld["vim-network-name"].items(): + vim_network_name_dict[get_vim_account_id(vim_account)] = vim_net + vld["vim-network-name"] = vim_network_name_dict + ns["vld"] = ns_config["vld"] + if "vnf" in ns_config: + for vnf in ns_config["vnf"]: + if vnf.get("vim_account"): + vnf["vimAccountId"] = get_vim_account_id(vnf.pop("vim_account")) - ns['ssh-authorized-key'] = ssh_keys_format + ns["vnf"] = ns_config["vnf"] #print yaml.safe_dump(ns) try: