import shutil
import yaml
import logging
-import pathlib
class PackageTool(object):
def charms_search(self, descriptor_file, desc_type):
self._logger.debug("")
-
- descriptor_dict = {}
- charm_list = []
- bundle_list = []
-
with open("{}".format(descriptor_file)) as yaml_desc:
descriptor_dict = yaml.safe_load(yaml_desc)
- for _, v1 in descriptor_dict.items():
- for _, v2 in v1.items():
- for entry in v2:
- if "{}-configuration".format(desc_type) in entry:
- name = entry["{}-configuration".format(desc_type)]
- for _, v3 in name.items():
- if "charm" in v3:
- charm_list.append((v3["charm"]))
- if "vdu" in entry:
- name = entry["vdu"]
- for vdu in name:
- if "vdu-configuration" in vdu:
- for _, v4 in vdu["vdu-configuration"].items():
- if "charm" in v4:
- charm_list.append((v4["charm"]))
- if "kdu" in entry:
- name = entry["kdu"]
- for kdu in name:
- if "juju-bundle" in kdu:
- bundle_list.append(kdu["juju-bundle"])
-
- path = pathlib.Path(descriptor_file).parent
- for bundle in bundle_list:
- descriptor_dict = {}
- with open("{}/juju-bundles/{}".format(path, bundle)) as yaml_desc:
- descriptor_dict = yaml.safe_load(yaml_desc)
- if "applications" in descriptor_dict:
- for _, v in descriptor_dict["applications"].items():
- charm_list.append(pathlib.Path(v["charm"]).name)
-
- return charm_list
+ if "catalog" in descriptor_dict: # Match OSM-IM vnfd-catalog and nsd-catalog
+ charms_list = self._charms_search_on_osm_im_dict(descriptor_dict, desc_type)
+ else:
+ charms_list = self._charms_search_on_sol006_dict(descriptor_dict, desc_type)
+
+ return charms_list
+
+ def _charms_search_on_osm_im_dict(self, osm_im_dict, desc_type):
+ charms_list = []
+ for k1, v1 in osm_im_dict.items():
+ for k2, v2 in v1.items():
+ for entry in v2:
+ if '{}-configuration'.format(desc_type) in entry:
+ vnf_config = entry['{}-configuration'.format(desc_type)]
+ for k3, v3 in vnf_config.items():
+ if 'charm' in v3:
+ charms_list.append((v3['charm']))
+ if 'vdu' in entry:
+ vdus = entry['vdu']
+ for vdu in vdus:
+ if 'vdu-configuration' in vdu:
+ for k4, v4 in vdu['vdu-configuration'].items():
+ if 'charm' in v4:
+ charms_list.append((v4['charm']))
+ return charms_list
+
+ def _charms_search_on_sol006_dict(self, sol006_dict, desc_type):
+ charms_list = []
+ for k1, v1 in sol006_dict.items():
+ for k2, v2 in v1.items():
+ if '{}-configuration'.format(desc_type) in k2:
+ for vnf_config in v2:
+ for k3, v3 in vnf_config.items():
+ if 'charm' in v3:
+ charms_list.append((v3['charm']))
+ if 'vdu-configuration' in k2:
+ for vdu_config in v2:
+ for k3, v3 in vdu_config.items():
+ if 'charm' in v3:
+ charms_list.append((v3['charm']))
+ return charms_list
project = project_name
vim_id = nsr.get('datacenter')
vim_name = get_vim_name(vim_list, vim_id)
+
#vim = '{} ({})'.format(vim_name, vim_id)
vim = vim_name
if 'currentOperation' in nsr:
else:
table = PrettyTable(['nsd name', 'id'])
for nsd in resp:
- name = nsd.get('name','-')
+ name = nsd.get('id', '-')
if long:
onb_state = nsd['_admin'].get('onboardingState','-')
op_state = nsd['_admin'].get('operationalState','-')
nsd_list(ctx, filter, long)
+def pkg_repo_list(ctx, pkgtype, filter, repo, long):
+ resp = ctx.obj.osmrepo.pkg_list(pkgtype, filter, repo)
+ if long:
+ table = PrettyTable(['nfpkg name', 'vendor', 'version', 'latest', 'description', 'repository'])
+ else:
+ table = PrettyTable(['nfpkg name', 'repository'])
+ for vnfd in resp:
+ name = vnfd.get('id', vnfd.get('name','-'))
+ repository = vnfd.get('repository')
+ if long:
+ vendor = vnfd.get('provider', vnfd.get('vendor'))
+ version = vnfd.get('version')
+ description = vnfd.get('description')
+ latest = vnfd.get('latest')
+ table.add_row([name, vendor, version, latest, description, repository])
+ else:
+ table.add_row([name, repository])
+ table.align = 'l'
+ print(table)
+
def vnfd_list(ctx, nf_type, filter, long):
logger.debug("")
if nf_type:
fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
if fullclassname == 'osmclient.sol005.client.Client':
if long:
- table = PrettyTable(['nfpkg name', 'id', 'vendor', 'version', 'onboarding state', 'operational state',
+ table = PrettyTable(['nfpkg name', 'id', 'desc type', 'vendor', 'version', 'onboarding state', 'operational state',
'usage state', 'date', 'last update'])
else:
- table = PrettyTable(['nfpkg name', 'id'])
+ table = PrettyTable(['nfpkg name', 'id', 'desc type'])
for vnfd in resp:
- name = vnfd['name'] if 'name' in vnfd else '-'
+ name = vnfd.get('id', vnfd.get('name','-'))
+ descriptor_type = 'sol005' if 'product-name' in vnfd else 'rel8'
if long:
onb_state = vnfd['_admin'].get('onboardingState','-')
op_state = vnfd['_admin'].get('operationalState','-')
- vendor = vnfd.get('vendor')
+ vendor = vnfd.get('provider', vnfd.get('vendor'))
version = vnfd.get('version')
usage_state = vnfd['_admin'].get('usageState','-')
date = datetime.fromtimestamp(vnfd['_admin']['created']).strftime("%Y-%m-%dT%H:%M:%S")
last_update = datetime.fromtimestamp(vnfd['_admin']['modified']).strftime("%Y-%m-%dT%H:%M:%S")
- table.add_row([name, vnfd['_id'], vendor, version, onb_state, op_state, usage_state, date, last_update])
+ table.add_row([name, vnfd['_id'], descriptor_type, vendor, version, onb_state, op_state, usage_state, date, last_update])
else:
- table.add_row([name, vnfd['_id']])
+ table.add_row([name, vnfd['_id'], descriptor_type])
else:
table = PrettyTable(['nfpkg name', 'id'])
for vnfd in resp:
# exit(1)
-def pkg_repo_list(ctx, pkgtype, filter, repo, long):
- if filter:
- filter='&'.join(filter)
- resp = ctx.obj.osmrepo.pkg_list(pkgtype, filter, repo)
- if long:
- table = PrettyTable(['nfpkg name', 'vendor', 'version', 'latest', 'description', 'repository'])
- else:
- table = PrettyTable(['nfpkg name', 'repository'])
- for vnfd in resp:
- name = vnfd.get('name', '-')
- repository = vnfd.get('repository')
- if long:
- vendor = vnfd.get('vendor')
- version = vnfd.get('version')
- description = vnfd.get('description')
- latest = vnfd.get('latest')
- table.add_row([name, vendor, version, latest, description, repository])
- else:
- table.add_row([name, repository])
- table.align = 'l'
- print(table)
-
-
@cli_osm.command(name='vnfpkg-repo-list', short_help='list all xNF from OSM repositories')
-@click.option('--filter', default=None, multiple=True,
+@click.option('--filter', default=None,
help='restricts the list to the NFpkg matching the filter')
@click.option('--repo', default=None,
help='restricts the list to a particular OSM repository')
pkgtype = 'vnf'
pkg_repo_list(ctx, pkgtype, filter, repo, long)
-
@cli_osm.command(name='nfpkg-repo-list', short_help='list all xNF from OSM repositories')
-@click.option('--filter', default=None, multiple=True,
+@click.option('--filter', default=None,
help='restricts the list to the NFpkg matching the filter')
@click.option('--repo', default=None,
help='restricts the list to a particular OSM repository')
pkg_repo_list(ctx, pkgtype, filter, repo, long)
-@cli_osm.command(name='nsd-repo-list', short_help='list all NS from OSM repositories')
-@click.option('--filter', default=None, multiple=True,
- help='restricts the list to the NS matching the filter')
-@click.option('--repo', default=None,
- help='restricts the list to a particular OSM repository')
-@click.option('--long', is_flag=True, help='get more details')
-@click.pass_context
-def nspkg_repo_list(ctx, filter, repo, long):
- """list xNF packages from OSM repositories"""
- pkgtype = 'ns'
- pkg_repo_list(ctx, pkgtype, filter, repo, long)
-
-
-@cli_osm.command(name='nspkg-repo-list', short_help='list all NS from OSM repositories')
-@click.option('--filter', default=None, multiple=True,
- help='restricts the list to the NS matching the filter')
-@click.option('--repo', default=None,
- help='restricts the list to a particular OSM repository')
-@click.option('--long', is_flag=True, help='get more details')
-@click.pass_context
-def nspkg_repo_list2(ctx, filter, repo, long):
- """list xNF packages from OSM repositories"""
- pkgtype = 'ns'
- pkg_repo_list(ctx, pkgtype, filter, repo, long)
-
-
def vnf_list(ctx, ns, filter, long):
# try:
if ns or filter:
logger.debug("")
vnf_list(ctx, ns, filter, long)
+@cli_osm.command(name='nsd-repo-list', short_help='list all NS from OSM repositories')
+@click.option('--filter', default=None, multiple=True,
+ help='restricts the list to the NS matching the filter')
+@click.option('--repo', default=None,
+ help='restricts the list to a particular OSM repository')
+@click.option('--long', is_flag=True, help='get more details')
+@click.pass_context
+def nspkg_repo_list(ctx, filter, repo, long):
+ """list xNF packages from OSM repositories"""
+ pkgtype = 'ns'
+ pkg_repo_list(ctx, pkgtype, filter, repo, long)
+
+@cli_osm.command(name='nspkg-repo-list', short_help='list all NS from OSM repositories')
+@click.option('--filter', default=None, multiple=True,
+ help='restricts the list to the NS matching the filter')
+@click.option('--repo', default=None,
+ help='restricts the list to a particular OSM repository')
+@click.option('--long', is_flag=True, help='get more details')
+@click.pass_context
+def nspkg_repo_list2(ctx, filter, repo, long):
+ """list xNF packages from OSM repositories"""
+ pkgtype = 'ns'
+ pkg_repo_list(ctx, pkgtype, filter, repo, long)
@cli_osm.command(name='nf-list', short_help='list all NF instances')
@click.option('--ns', default=None, help='NS instance id or name to restrict the NF list')
logger.debug("")
vnfd_show(ctx, name, literal)
-
@cli_osm.command(name='vnfpkg-repo-show', short_help='shows the details of a NF package in an OSM repository')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
pkgtype = 'ns'
pkg_repo_show(ctx, pkgtype, name, repo, version, filter, literal)
-
@cli_osm.command(name='nspkg-repo-show', short_help='shows the details of a NS package in an OSM repository')
@click.option('--literal', is_flag=True,
help='print literally, no pretty table')
return
table = PrettyTable(['field', 'value'])
-
for k, v in list(resp.items()):
if not filter or k in filter:
table.add_row([k, wrap_text(text=json.dumps(v,indent=2),width=100)])
if filter:
filter_string = '?{}'.format(filter)
_, resp = self._http.get2_cmd('{}{}'.format(self._apiBase, filter_string))
+
if resp:
return json.loads(resp)
return list()
return vnfd
else:
for vnfd in self.list():
- if 'name' in vnfd and name == vnfd['name']:
+ if 'product-name' in vnfd and name == vnfd['product-name']:
+ return vnfd
+ elif 'name' in vnfd and name == vnfd['name']:
return vnfd
raise NotFound("vnfd {} not found".format(name))
filename = filename.rstrip('/')
filename = self._client.package_tool.build(filename, skip_validation=False,
skip_charm_build=skip_charm_build)
+
print('Uploading package {}'.format(filename))
self.create(filename, overwrite=overwrite, update_endpoint=update_endpoint,
override_epa=override_epa, override_nonepa=override_nonepa,
"Unexpected MIME type for file {}: MIME type {}".format(
filename, mime_type)
)
- special_ow_string = ''
+
+ special_override_string = ''
if override_epa or override_nonepa or override_paravirt:
- # If override for EPA, non-EPA or paravirt is required, get the descriptor data
+ # If override for EPA, non-EPA or paravirt is required, get the descriptor data
descriptor_data = None
if mime_type in ['application/yaml', 'text/plain', 'application/json']:
with open(filename) as df:
raise ClientException('Descriptor could not be read')
desc_type, vnfd = validation_im().yaml_validation(descriptor_data)
validation_im().pyangbind_validation(desc_type, vnfd)
+
vnfd = yaml.safe_load(descriptor_data)
+ vcd_list = []
vdu_list = []
for k in vnfd:
# Get only the first descriptor in case there are many in the yaml file
- # k can be vnfd:vnfd-catalog or vnfd-catalog. This check is skipped
- first_vnfd = vnfd[k]['vnfd'][0]
+ # k can be vnfd or etsi-nfv-vnfd:vnfd. This check is skipped
+ first_vnfd = vnfd.get(k, {})
+ vcd_list = first_vnfd.get('virtual-compute-desc', [])
vdu_list = first_vnfd.get('vdu', [])
break
- for vdu_number, vdu in enumerate(vdu_list):
+
+ for vcd_number, vcd in enumerate(vcd_list):
if override_epa:
- guest_epa = {}
- guest_epa["mempage-size"] = "LARGE"
- guest_epa["cpu-pinning-policy"] = "DEDICATED"
- guest_epa["cpu-thread-pinning-policy"] = "PREFER"
- guest_epa["numa-node-policy"] = {}
- guest_epa["numa-node-policy"]["node-cnt"] = 1
- guest_epa["numa-node-policy"]["mem-policy"] = "STRICT"
- special_ow_string = "{}vdu.{}.guest-epa={};".format(special_ow_string, vdu_number,
- quote(yaml.safe_dump(guest_epa)))
- headers['Query-String-Format'] = 'yaml'
+ virtual_memory = vcd["virtual-memory"]
+ virtual_memory["mempage-size"] = "LARGE"
+ virtual_memory["numa-enabled"] = True
+ virtual_memory["numa-node-policy"] = {
+ "node-cnt": 1,
+ "mem-policy": "STRICT"
+ }
+ virtual_cpu = vcd["virtual-cpu"]
+ virtual_cpu["pinning"] = {
+ "policy": "static",
+ "thread-policy": "PREFER"
+ }
+
+ cpu_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\
+ .format(vcd_number, quote(yaml.safe_dump(virtual_cpu)))
+ memory_override_string = "virtual-compute-desc.{}.virtual-memory={};"\
+ .format(vcd_number, quote(yaml.safe_dump(virtual_memory)))
+ special_override_string = "{}{}{}".format(special_override_string,
+ cpu_override_string, memory_override_string)
+
+ headers['Query-String-Format'] = 'yaml'
if override_nonepa:
- special_ow_string = "{}vdu.{}.guest-epa=;".format(special_ow_string, vdu_number)
- if override_paravirt:
- for iface_number in range(len(vdu['interface'])):
- special_ow_string = "{}vdu.{}.interface.{}.virtual-interface.type=PARAVIRT;".format(
- special_ow_string, vdu_number, iface_number)
- special_ow_string = special_ow_string.rstrip(";")
+ virtual_memory = vcd["virtual-memory"]
+ virtual_memory["mempage-size"] = ""
+ virtual_memory["numa-enabled"] = ""
+ virtual_memory["numa-node-policy"] = {}
+ virtual_cpu = vcd["virtual-cpu"]
+ virtual_cpu["pinning"] = {}
+
+ cpu_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\
+ .format(vcd_number, quote(yaml.safe_dump(virtual_cpu)))
+ memory_override_string = "virtual-compute-desc.{}.virtual-memory={};"\
+ .format(vcd_number, quote(yaml.safe_dump(virtual_memory)))
+ special_override_string = "{}{}{}".format(special_override_string,
+ cpu_override_string, memory_override_string)
+
+ if override_paravirt:
+ for vdu_number, vdu in enumerate(vdu_list):
+ for cpd_number, cpd in enumerate(vdu["int-cpd"]):
+ for vnir_number, vnir in enumerate(cpd['virtual-network-interface-requirement']):
+ special_override_string = "{}vdu.{}.int-cpd.{}.virtual-network-interface-" \
+ "requirement.{}.virtual-interface.type=PARAVIRT;"\
+ .format(special_override_string, vdu_number, cpd_number, vnir_number)
+
+ special_override_string = special_override_string.rstrip(";")
headers["Content-File-MD5"] = utils.md5(filename)
http_header = ['{}: {}'.format(key, val)
for (key, val) in list(headers.items())]
+
self._http.set_http_header(http_header)
if update_endpoint:
http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
else:
ow_string = ''
- if special_ow_string:
+ if special_override_string:
if overwrite:
- overwrite = "{};{}".format(overwrite, special_ow_string)
+ overwrite = "{};{}".format(overwrite, special_override_string)
else:
- overwrite = special_ow_string
+ overwrite = special_override_string
+
if overwrite:
ow_string = '?{}'.format(overwrite)
self._apiResource = '/vnf_packages_content'