+@cli.command(name='nst-create', short_help='creates a new Network Slice Template (NST)')
+@click.argument('filename')
+@click.option('--overwrite', 'overwrite', default=None,
+ help='overwrites deprecated use override')
+@click.option('--override', 'overwrite' ,default=None,
+ help='overrides fields in descriptor, format: '
+ '"key1.key2...=value[;key3...=value;...]"')
+@click.pass_context
+def nst_create1(ctx, filename, overwrite):
+ """creates a new Network Slice Template (NST)
+
+ FILENAME: NST yaml file or NSTpkg tar.gz file
+ """
+ nst_create(ctx, filename, overwrite)
+
+
+@cli.command(name='netslice-template-create', short_help='creates a new Network Slice Template (NST)')
+@click.argument('filename')
+@click.option('--overwrite', 'overwrite', default=None,
+ help='overwrites deprecated use override')
+@click.option('--override', 'overwrite', default=None,
+ help='overrides fields in descriptor, format: '
+ '"key1.key2...=value[;key3...=value;...]"')
+@click.pass_context
+def nst_create2(ctx, filename, overwrite):
+ """creates a new Network Slice Template (NST)
+
+ FILENAME: NST yaml file or NSTpkg tar.gz file
+ """
+ nst_create(ctx, filename, overwrite)
+
+
+def nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait):
+ """creates a new Network Slice Instance (NSI)"""
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ if config_file:
+ if config:
+ raise ClientException('"--config" option is incompatible with "--config_file" option')
+ with open(config_file, 'r') as cf:
+ config=cf.read()
+ ctx.obj.nsi.create(nst_name, nsi_name, config=config, ssh_keys=ssh_keys,
+ account=vim_account, wait=wait)
+ except ClientException as inst:
+ print(inst.message)
+ exit(1)
+
+
+@cli.command(name='nsi-create', short_help='creates a new Network Slice Instance')
+@click.option('--nsi_name', prompt=True, help='name of the Network Slice Instance')
+@click.option('--nst_name', prompt=True, help='name of the Network Slice Template')
+@click.option('--vim_account', prompt=True, help='default VIM account id or name for the deployment')
+@click.option('--ssh_keys', default=None,
+ help='comma separated list of keys to inject to vnfs')
+@click.option('--config', default=None,
+ help='Netslice specific yaml configuration:\n'
+ 'netslice_subnet: [\n'
+ 'id: TEXT, vim_account: TEXT,\n'
+ 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
+ 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
+ 'additionalParamsForNsi: {param: value, ...}\n'
+ 'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
+ '],\n'
+ 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
+ )
+@click.option('--config_file',
+ default=None,
+ help='nsi specific yaml configuration file')
+@click.option('--wait',
+ required=False,
+ default=False,
+ is_flag=True,
+ help='do not return the control immediately, but keep it \
+ until the operation is completed, or timeout')
+@click.pass_context
+def nsi_create1(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait):
+ """creates a new Network Slice Instance (NSI)"""
+ nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait=wait)
+
+
+@cli.command(name='netslice-instance-create', short_help='creates a new Network Slice Instance')
+@click.option('--nsi_name', prompt=True, help='name of the Network Slice Instance')
+@click.option('--nst_name', prompt=True, help='name of the Network Slice Template')
+@click.option('--vim_account', prompt=True, help='default VIM account id or name for the deployment')
+@click.option('--ssh_keys', default=None,
+ help='comma separated list of keys to inject to vnfs')
+@click.option('--config', default=None,
+ help='Netslice specific yaml configuration:\n'
+ 'netslice_subnet: [\n'
+ 'id: TEXT, vim_account: TEXT,\n'
+ 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
+ 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
+ '],\n'
+ 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
+ )
+@click.option('--config_file',
+ default=None,
+ help='nsi specific yaml configuration file')
+@click.option('--wait',
+ required=False,
+ default=False,
+ is_flag=True,
+ help='do not return the control immediately, but keep it \
+ until the operation is completed, or timeout')
+@click.pass_context
+def nsi_create2(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait):
+ """creates a new Network Slice Instance (NSI)"""
+ nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait=wait)
+
+
+@cli.command(name='pdu-create', short_help='adds a new Physical Deployment Unit to the catalog')
+@click.option('--name', help='name of the Physical Deployment Unit')
+@click.option('--pdu_type', help='type of PDU (e.g. router, firewall, FW001)')
+@click.option('--interface',
+ help='interface(s) of the PDU: name=<NAME>,mgmt=<true|false>,ip-address=<IP_ADDRESS>'+
+ '[,type=<overlay|underlay>][,mac-address=<MAC_ADDRESS>][,vim-network-name=<VIM_NET_NAME>]',
+ multiple=True)
+@click.option('--description', help='human readable description')
+@click.option('--vim_account', help='list of VIM accounts (in the same VIM) that can reach this PDU', multiple=True)
+@click.option('--descriptor_file', default=None, help='PDU descriptor file (as an alternative to using the other arguments')
+@click.pass_context
+def pdu_create(ctx, name, pdu_type, interface, description, vim_account, descriptor_file):
+ """creates a new Physical Deployment Unit (PDU)"""
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ pdu = {}
+ if not descriptor_file:
+ if not name:
+ raise ClientException('in absence of descriptor file, option "--name" is mandatory')
+ if not pdu_type:
+ raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
+ if not interface:
+ raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
+ if not vim_account:
+ raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
+ else:
+ with open(descriptor_file, 'r') as df:
+ pdu = yaml.safe_load(df.read())
+ if name: pdu["name"] = name
+ if pdu_type: pdu["type"] = pdu_type
+ if description: pdu["description"] = description
+ if vim_account: pdu["vim_accounts"] = vim_account
+ if interface:
+ ifaces_list = []
+ for iface in interface:
+ new_iface={k:v for k,v in [i.split('=') for i in iface.split(',')]}
+ new_iface["mgmt"] = (new_iface.get("mgmt","false").lower() == "true")
+ ifaces_list.append(new_iface)
+ pdu["interfaces"] = ifaces_list
+ ctx.obj.pdu.create(pdu)
+ except ClientException as inst:
+ print((inst.message))
+ exit(1)
+