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,
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,
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,
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:
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: