+ \b
+ FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
+ If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
+ If FILENAME is an NF Package folder, it is built and then onboarded.
+ """
+ logger.debug("")
+ nsd_create(
+ ctx,
+ filename,
+ overwrite=overwrite,
+ skip_charm_build=skip_charm_build,
+ repo=repo,
+ vendor=vendor,
+ version=version,
+ )
+
+
+@cli_osm.command(name="nspkg-create", short_help="creates a new NSD/NSpkg")
+@click.argument("filename")
+@click.option(
+ "--overwrite",
+ "overwrite",
+ default=None, # hidden=True,
+ help="Deprecated. Use override",
+)
+@click.option(
+ "--override",
+ "overwrite",
+ default=None,
+ help="overrides fields in descriptor, format: "
+ '"key1.key2...=value[;key3...=value;...]"',
+)
+@click.option(
+ "--skip-charm-build",
+ default=False,
+ is_flag=True,
+ help="The charm will not be compiled, it is assumed to already exist",
+)
+@click.option("--repo", default=None, help="[repository]: Repository name")
+@click.option("--vendor", default=None, help="[repository]: filter by vendor]")
+@click.option(
+ "--version",
+ default="latest",
+ help="[repository]: filter by version. Default: latest",
+)
+@click.pass_context
+def nsd_pkg_create(ctx, filename, overwrite, skip_charm_build, repo, vendor, version):
+ """onboards a new NSpkg
+ \b
+ FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
+ If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
+ If FILENAME is an NF Package folder, it is built and then onboarded.
+ """
+ logger.debug("")
+ nsd_create(
+ ctx,
+ filename,
+ overwrite=overwrite,
+ skip_charm_build=skip_charm_build,
+ repo=repo,
+ vendor=vendor,
+ version=version,
+ )
+
+
+def vnfd_create(
+ ctx,
+ filename,
+ overwrite,
+ skip_charm_build,
+ override_epa,
+ override_nonepa,
+ override_paravirt,
+ repo,
+ vendor,
+ version,
+):
+ logger.debug("")
+ # try:
+ check_client_version(ctx.obj, ctx.command.name)
+ if repo:
+ filename = ctx.obj.osmrepo.get_pkg("vnf", filename, repo, vendor, version)
+ ctx.obj.vnfd.create(
+ filename,
+ overwrite=overwrite,
+ skip_charm_build=skip_charm_build,
+ override_epa=override_epa,
+ override_nonepa=override_nonepa,
+ override_paravirt=override_paravirt,
+ )
+ # except ClientException as e:
+ # print(str(e))
+ # exit(1)
+
+
+@cli_osm.command(name="vnfd-create", short_help="creates a new VNFD/VNFpkg")
+@click.argument("filename")
+@click.option(
+ "--overwrite", "overwrite", default=None, help="overwrite deprecated, use override"
+)
+@click.option(
+ "--override",
+ "overwrite",
+ default=None,
+ help="overrides fields in descriptor, format: "
+ '"key1.key2...=value[;key3...=value;...]"',
+)
+@click.option(
+ "--skip-charm-build",
+ default=False,
+ is_flag=True,
+ help="The charm will not be compiled, it is assumed to already exist",
+)
+@click.option(
+ "--override-epa",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="adds guest-epa parameters to all VDU",
+)
+@click.option(
+ "--override-nonepa",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="removes all guest-epa parameters from all VDU",
+)
+@click.option(
+ "--override-paravirt",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="overrides all VDU interfaces to PARAVIRT",
+)
+@click.option("--repo", default=None, help="[repository]: Repository name")
+@click.option("--vendor", default=None, help="[repository]: filter by vendor]")
+@click.option(
+ "--version",
+ default="latest",
+ help="[repository]: filter by version. Default: latest",
+)
+@click.pass_context
+def vnfd_create1(
+ ctx,
+ filename,
+ overwrite,
+ skip_charm_build,
+ override_epa,
+ override_nonepa,
+ override_paravirt,
+ repo,
+ vendor,
+ version,
+):
+ """creates a new VNFD/VNFpkg
+ \b
+ FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
+ If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
+ If FILENAME is an NF Package folder, it is built and then onboarded.
+ """
+ logger.debug("")
+ vnfd_create(
+ ctx,
+ filename,
+ overwrite=overwrite,
+ skip_charm_build=skip_charm_build,
+ override_epa=override_epa,
+ override_nonepa=override_nonepa,
+ override_paravirt=override_paravirt,
+ repo=repo,
+ vendor=vendor,
+ version=version,
+ )
+
+
+@cli_osm.command(name="vnfpkg-create", short_help="creates a new VNFD/VNFpkg")
+@click.argument("filename")
+@click.option(
+ "--overwrite",
+ "overwrite",
+ default=None, # hidden=True,
+ help="Deprecated. Use override",
+)
+@click.option(
+ "--override",
+ "overwrite",
+ default=None,
+ help="overrides fields in descriptor, format: "
+ '"key1.key2...=value[;key3...=value;...]"',
+)
+@click.option(
+ "--skip-charm-build",
+ default=False,
+ is_flag=True,
+ help="The charm will not be compiled, it is assumed to already exist",
+)
+@click.option(
+ "--override-epa",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="adds guest-epa parameters to all VDU",
+)
+@click.option(
+ "--override-nonepa",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="removes all guest-epa parameters from all VDU",
+)
+@click.option(
+ "--override-paravirt",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="overrides all VDU interfaces to PARAVIRT",
+)
+@click.option("--repo", default=None, help="[repository]: Repository name")
+@click.option("--vendor", default=None, help="[repository]: filter by vendor]")
+@click.option(
+ "--version",
+ default="latest",
+ help="[repository]: filter by version. Default: latest",
+)
+@click.pass_context
+def vnfd_create2(
+ ctx,
+ filename,
+ overwrite,
+ skip_charm_build,
+ override_epa,
+ override_nonepa,
+ override_paravirt,
+ repo,
+ vendor,
+ version,
+):
+ """creates a new VNFD/VNFpkg
+ \b
+ FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
+ If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
+ If FILENAME is an NF Package folder, it is built and then onboarded.
+ """
+ logger.debug("")
+ vnfd_create(
+ ctx,
+ filename,
+ overwrite=overwrite,
+ skip_charm_build=skip_charm_build,
+ override_epa=override_epa,
+ override_nonepa=override_nonepa,
+ override_paravirt=override_paravirt,
+ repo=repo,
+ vendor=vendor,
+ version=version,
+ )
+
+
+@cli_osm.command(name="nfpkg-create", short_help="creates a new NFpkg")
+@click.argument("filename")
+@click.option(
+ "--overwrite",
+ "overwrite",
+ default=None, # hidden=True,
+ help="Deprecated. Use override",
+)
+@click.option(
+ "--override",
+ "overwrite",
+ default=None,
+ help="overrides fields in descriptor, format: "
+ '"key1.key2...=value[;key3...=value;...]"',
+)
+@click.option(
+ "--skip-charm-build",
+ default=False,
+ is_flag=True,
+ help="The charm will not be compiled, it is assumed to already exist",
+)
+@click.option(
+ "--override-epa",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="adds guest-epa parameters to all VDU",
+)
+@click.option(
+ "--override-nonepa",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="removes all guest-epa parameters from all VDU",
+)
+@click.option(
+ "--override-paravirt",
+ required=False,
+ default=False,
+ is_flag=True,
+ help="overrides all VDU interfaces to PARAVIRT",
+)
+@click.option("--repo", default=None, help="[repository]: Repository name")
+@click.option("--vendor", default=None, help="[repository]: filter by vendor]")
+@click.option(
+ "--version",
+ default="latest",
+ help="[repository]: filter by version. Default: latest",
+)
+@click.pass_context
+def nfpkg_create(
+ ctx,
+ filename,
+ overwrite,
+ skip_charm_build,
+ override_epa,
+ override_nonepa,
+ override_paravirt,
+ repo,
+ vendor,
+ version,
+):
+ """creates a new NFpkg
+
+ \b
+ FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
+ If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
+ If FILENAME is an NF Package folder, it is built and then onboarded.
+ """
+ logger.debug("")
+ vnfd_create(
+ ctx,
+ filename,
+ overwrite=overwrite,
+ skip_charm_build=skip_charm_build,
+ override_epa=override_epa,
+ override_nonepa=override_nonepa,
+ override_paravirt=override_paravirt,
+ repo=repo,
+ vendor=vendor,
+ version=version,
+ )
+
+
+@cli_osm.command(name="ns-create", short_help="creates a new Network Service instance")
+@click.option("--ns_name", prompt=True, help="name of the NS instance")
+@click.option("--nsd_name", prompt=True, help="name of the NS descriptor")
+@click.option(
+ "--vim_account",
+ prompt=True,
+ help="default VIM account id or name for the deployment",
+)
+@click.option("--admin_status", default="ENABLED", help="administration status")
+@click.option(
+ "--ssh_keys",
+ default=None,
+ help="comma separated list of public key files to inject to vnfs",
+)
+@click.option("--config", default=None, help="ns specific yaml configuration")
+@click.option("--config_file", default=None, help="ns 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.option("--timeout", default=None, help="ns deployment timeout")
+@click.pass_context
+def ns_create(
+ ctx,
+ nsd_name,
+ ns_name,
+ vim_account,
+ admin_status,
+ ssh_keys,
+ config,
+ config_file,
+ wait,
+ timeout
+):
+ """creates a new NS instance"""
+ logger.debug("")
+ # try:
+ if config_file:
+ check_client_version(ctx.obj, "--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.ns.create(
+ nsd_name,
+ ns_name,
+ config=config,
+ ssh_keys=ssh_keys,
+ account=vim_account,
+ wait=wait,
+ timeout=timeout,
+ )
+ # except ClientException as e:
+ # print(str(e))
+ # exit(1)
+
+
+def nst_create(ctx, filename, overwrite):
+ logger.debug("")
+ # try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.nst.create(filename, overwrite)
+ # except ClientException as e:
+ # print(str(e))
+ # exit(1)
+
+
+@cli_osm.command(
+ name="nst-create", short_help="creates a new Network Slice Template (NST)"
+)
+@click.argument("filename")
+@click.option(
+ "--overwrite",
+ "overwrite",
+ default=None, # hidden=True,
+ help="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 package folder, NST yaml file or NSTpkg tar.gz file
+ """
+ logger.debug("")
+ nst_create(ctx, filename, overwrite)
+
+
+@cli_osm.command(
+ name="netslice-template-create",
+ short_help="creates a new Network Slice Template (NST)",
+)
+@click.argument("filename")
+@click.option(
+ "--overwrite",
+ "overwrite",
+ default=None, # hidden=True,
+ help="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
+ """
+ logger.debug("")
+ 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)"""
+ logger.debug("")
+ # 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 e:
+ # print(str(e))
+ # exit(1)
+
+
+@cli_osm.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)"""
+ logger.debug("")
+ nsi_create(
+ ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait=wait
+ )
+
+
+@cli_osm.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)"""
+ logger.debug("")
+ nsi_create(
+ ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait=wait
+ )
+
+
+@cli_osm.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\n"
+ + "The format for multiple VIMs is --vim_account <vim_account_id_1> "
+ + "--vim_account <vim_account_id_2> ... --vim_account <vim_account_id_N>",
+ 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)"""
+ logger.debug("")
+
+ check_client_version(ctx.obj, ctx.command.name)
+
+ pdu = create_pdu_dictionary(
+ name, pdu_type, interface, description, vim_account, descriptor_file
+ )
+ ctx.obj.pdu.create(pdu)
+
+
+########################
+# UPDATE PDU operation #
+########################
+
+
+@cli_osm.command(
+ name="pdu-update", short_help="updates a Physical Deployment Unit to the catalog"
+)
+@click.argument("name")
+@click.option("--newname", help="New name for 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\n"
+ + "The format for multiple VIMs is --vim_account <vim_account_id_1> "
+ + "--vim_account <vim_account_id_2> ... --vim_account <vim_account_id_N>",
+ 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_update(
+ ctx, name, newname, pdu_type, interface, description, vim_account, descriptor_file
+):
+ """Updates a new Physical Deployment Unit (PDU)"""
+ logger.debug("")
+
+ check_client_version(ctx.obj, ctx.command.name)
+
+ update = True
+
+ if not newname:
+ newname = name
+
+ pdu = create_pdu_dictionary(
+ newname, pdu_type, interface, description, vim_account, descriptor_file, update
+ )
+ ctx.obj.pdu.update(name, pdu)
+
+
+def create_pdu_dictionary(
+ name, pdu_type, interface, description, vim_account, descriptor_file, update=False
+):
+
+ logger.debug("")
+ pdu = {}
+
+ if not descriptor_file:
+ if not update:
+ 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
+ return pdu