@cli.command(name='nsd-create', short_help='creates a new NSD/NSpkg')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in NSD')
+@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.pass_context
def nsd_create1(ctx, filename, overwrite):
"""creates a new NSD/NSpkg
@cli.command(name='nspkg-create', short_help='creates a new NSD/NSpkg')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in NSD')
+@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.pass_context
def nsd_create2(ctx, filename, overwrite):
"""creates a new NSD/NSpkg
@cli.command(name='vnfd-create', short_help='creates a new VNFD/VNFpkg')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in VNFD')
+@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.pass_context
def vnfd_create1(ctx, filename, overwrite):
"""creates a new VNFD/VNFpkg
@cli.command(name='vnfpkg-create', short_help='creates a new VNFD/VNFpkg')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in VNFD')
+@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.pass_context
def vnfd_create2(ctx, filename, overwrite):
"""creates a new VNFD/VNFpkg
@cli.command(name='nfpkg-create', short_help='creates a new NFpkg')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in NFD')
+@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.pass_context
def nfpkg_create(ctx, filename, overwrite):
"""creates a new NFpkg
@cli.command(name='nst-create', short_help='creates a new Network Slice Template (NST)')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in NST')
+@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)
@cli.command(name='netslice-template-create', short_help='creates a new Network Slice Template (NST)')
@click.argument('filename')
-@click.option('--overwrite', default=None,
- help='overwrites some fields in NST')
+@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)
table.align = 'l'
print(table)
-
if __name__ == '__main__':
try:
cli()
self._project = project
self._auth_endpoint = '/admin/v1/tokens'
self._headers = {}
+ self._token = None
if len(host.split(':')) > 1:
# backwards compatible, port provided as part of host
for (key, val) in list(self._headers.items())]
self._http_client.set_http_header(http_header)
- token = self.get_token()
- if not token:
- raise ClientException(
- 'Authentication error: not possible to get auth token')
- self._headers['Authorization'] = 'Bearer {}'.format(token)
- http_header.append('Authorization: Bearer {}'.format(token))
- self._http_client.set_http_header(http_header)
-
self.vnfd = vnfd.Vnfd(self._http_client, client=self)
self.nsd = nsd.Nsd(self._http_client, client=self)
self.nst = nst.Nst(self._http_client, client=self)
'''
def get_token(self):
- postfields_dict = {'username': self._user,
- 'password': self._password,
- 'project_id': self._project}
- http_code, resp = self._http_client.post_cmd(endpoint=self._auth_endpoint,
- postfields_dict=postfields_dict)
- if http_code not in (200, 201, 202, 204):
- raise ClientException(resp)
- token = json.loads(resp) if resp else None
- if token is not None:
- return token['_id']
- return None
+ if self._token is None:
+ postfields_dict = {'username': self._user,
+ 'password': self._password,
+ 'project_id': self._project}
+ http_code, resp = self._http_client.post_cmd(endpoint=self._auth_endpoint,
+ postfields_dict=postfields_dict)
+ if http_code not in (200, 201, 202, 204):
+ message ='Authentication error: not possible to get auth token\nresp:\n{}'.format(resp)
+ raise ClientException(message)
+
+ token = json.loads(resp) if resp else None
+ self._token = token['id']
+ if self._token is not None:
+ self._headers['Authorization'] = 'Bearer {}'.format(self._token)
+ http_header = ['{}: {}'.format(key, val)
+ for (key, val) in list(self._headers.items())]
+ self._http_client.set_http_header(http_header)
def list(self, filter=None):
"""Returns a list of NS
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns an NS based on name or id
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for ns in self.list():
if name == ns['_id']:
raise NotFound("ns {} not found".format(name))
def get_individual(self, name):
+ self._client.get_token()
ns_id = name
if not utils.validate_uuid4(name):
for ns in self.list():
def create(self, nsd_name, nsr_name, account, config=None,
ssh_keys=None, description='default description',
admin_status='ENABLED', wait=False):
-
+ self._client.get_token()
nsd = self._client.nsd.get(nsd_name)
vim_account_id = {}
def get_op(self, operationId):
"""Returns the status of an operation
"""
+ self._client.get_token()
try:
self._apiResource = '/ns_lcm_op_occs'
self._apiBase = '{}{}{}'.format(self._apiName,
def scale_vnf(self, ns_name, vnf_name, scaling_group, scale_in, scale_out, wait=False):
"""Scales a VNF by adding/removing VDUs
"""
+ self._client.get_token()
try:
op_data={}
op_data["scaleType"] = "SCALE_VNF"
raise ClientException(message)
def create_alarm(self, alarm):
+ self._client.get_token()
data = {}
data["create_alarm_request"] = {}
data["create_alarm_request"]["alarm_create_request"] = alarm
raise ClientException(message)
def delete_alarm(self, name):
+ self._client.get_token()
data = {}
data["delete_alarm_request"] = {}
data["delete_alarm_request"]["alarm_delete_request"] = {}
raise ClientException(message)
def export_metric(self, metric):
+ self._client.get_token()
data = {}
data["read_metric_data_request"] = metric
try:
#self._apiBase='/nsds'
def list(self, filter=None):
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
return list()
def get(self, name):
+ self._client.get_token()
if utils.validate_uuid4(name):
for nsd in self.list():
if name == nsd['_id']:
raise NotFound("nsd {} not found".format(name))
def get_individual(self, name):
+ # Called to get_token not required, because will be implicitly called by get.
nsd = self.get(name)
# It is redundant, since the previous one already gets the whole nsdinfo
# The only difference is that a different primitive is exercised
raise ClientException("failed to delete nsd {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
+ self._client.get_token()
mime_type = magic.from_file(filename, mime=True)
if mime_type is None:
raise ClientException(
# NSI '--wait' option
def _wait(self, id, deleteFlag=False):
+ self._client.get_token()
# Endpoint to get operation status
apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/nsi_lcm_op_occs')
# Wait for status for NSI instance creation/update/deletion
def list(self, filter=None):
"""Returns a list of NSI
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns an NSI based on name or id
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for nsi in self.list():
if name == nsi['_id']:
def get_individual(self, name):
nsi_id = name
+ self._client.get_token()
if not utils.validate_uuid4(name):
for nsi in self.list():
if name == nsi['name']:
ssh_keys=None, description='default description',
admin_status='ENABLED', wait=False):
+ self._client.get_token()
nst = self._client.nst.get(nst_name)
vim_account_id = {}
def get_op(self, operationId):
"""Returns the status of an operation
"""
+ self._client.get_token()
try:
self._apiResource = '/nsi_lcm_op_occs'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
def list(self, filter=None):
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
return list()
def get(self, name):
+ self._client.get_token()
if utils.validate_uuid4(name):
for nst in self.list():
if name == nst['_id']:
raise ClientException("failed to delete nst {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
+ self._client.get_token()
mime_type = magic.from_file(filename, mime=True)
if mime_type is None:
raise ClientException(
"""wait(block) for an upload to succeed.
The filename passed is assumed to be a descriptor tarball.
"""
+ self._client.get_token()
pkg_type = utils.get_key_val_from_pkg(filename)
if pkg_type is None:
.format(filename))
def upload(self, filename):
+ self._client.get_token()
pkg_type = utils.get_key_val_from_pkg(filename)
if pkg_type is None:
raise ClientException("Cannot determine package type")
self._apiVersion, self._apiResource)
def list(self, filter=None):
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
return list()
def get(self, name):
+ self._client.get_token()
if utils.validate_uuid4(name):
for pdud in self.list():
if name == pdud['_id']:
raise ClientException("failed to delete pdu {} - {}".format(name, msg))
def create(self, pdu, update_endpoint=None):
+ self._client.get_token()
headers= self._client._headers
headers['Content-Type'] = 'application/yaml'
http_header = ['{}: {}'.format(key,val)
def create(self, name, project):
"""Creates a new OSM project
"""
+ self._client.get_token()
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=project)
#print('HTTP CODE: {}'.format(http_code))
def update(self, project, project_changes):
"""Updates an OSM project identified by name
"""
+ self._client.get_token()
proj = self.get(project)
http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, proj['_id']),
postfields_dict=project_changes)
def delete(self, name, force=False):
"""Deletes an OSM project identified by name
"""
+ self._client.get_token()
project = self.get(name)
querystring = ''
if force:
def list(self, filter=None):
"""Returns the list of OSM projects
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns a specific OSM project based on name or id
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for proj in self.list():
if name == proj['_id']:
:raises ClientException: when receives an unexpected from the server.
:raises ClientException: when fails creating a role.
"""
+ self._client.get_token()
role = {"name": name}
if permissions:
:raises ClientException: when receives an unexpected response from the server.
:raises ClientException: when fails updating a role.
"""
+ self._client.get_token()
if new_name is None and permissions is None and add is None and remove is None:
raise ClientException('At least one option should be provided')
elif permissions and (add or remove):
:param force:
:raises ClientException: when fails to delete a role.
"""
+ self._client.get_token()
role = self.get(name)
querystring = ''
if force:
:param filter:
:returns:
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
:raises NotFound: when the role is not found.
:returns: the specified role.
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for role in self.list():
if name == role['_id']:
# SDNC '--wait' option
def _wait(self, id, deleteFlag=False):
+ self._client.get_token()
# Endpoint to get operation status
apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/sdns')
# Wait for status for SDN instance creation/update/deletion
return ''
def create(self, name, sdn_controller, wait=False):
+ self._client.get_token()
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=sdn_controller)
#print('HTTP CODE: {}'.format(http_code))
raise ClientException("failed to create SDN controller {} - {}".format(name, msg))
def update(self, name, sdn_controller, wait=False):
+ self._client.get_token()
sdnc = self.get(name)
sdnc_id_for_wait = self._get_id_for_wait(name)
http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
raise ClientException("failed to update SDN controller {} - {}".format(name, msg))
def delete(self, name, force=False, wait=False):
+ self._client.get_token()
sdn_controller = self.get(name)
sdnc_id_for_wait = self._get_id_for_wait(name)
querystring = ''
def list(self, filter=None):
"""Returns a list of SDN controllers
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns an SDN controller based on name or id
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for sdnc in self.list():
if name == sdnc['_id']:
def create(self, name, user):
"""Creates a new OSM user
"""
+ self._client.get_token()
if not user["projects"] or (len(user["projects"]) == 1 and not user["projects"][0]):
del user["projects"]
elif len(user["projects"]) == 1:
def update(self, name, user):
"""Updates an existing OSM user identified by name
"""
+ self._client.get_token()
# print(user)
myuser = self.get(name)
update_user = {
def delete(self, name, force=False):
"""Deletes an existing OSM user identified by name
"""
+ self._client.get_token()
user = self.get(name)
querystring = ''
if force:
def list(self, filter=None):
"""Returns the list of OSM users
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns an OSM user based on name or id
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for user in self.list():
if name == user['_id']:
self._apiResource = '/vim_accounts'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
+
# VIM '--wait' option
def _wait(self, id, deleteFlag=False):
+ self._client.get_token()
# Endpoint to get operation status
apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/vim_accounts')
# Wait for status for VIM instance creation/deletion
return ''
def create(self, name, vim_access, sdn_controller=None, sdn_port_mapping=None, wait=False):
+ self._client.get_token()
if 'vim-type' not in vim_access:
#'openstack' not in vim_access['vim-type']):
raise Exception("vim type not provided")
raise ClientException("failed to create vim {} - {}".format(name, msg))
def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False):
+ self._client.get_token()
vim = self.get(vim_name)
vim_id_for_wait = self._get_id_for_wait(vim_name)
vim_config = {}
raise NotFound("vim {} not found".format(name))
def delete(self, vim_name, force=False, wait=False):
+ self._client.get_token()
vim_id = vim_name
if not utils.validate_uuid4(vim_name):
vim_id = self.get_id(vim_name)
def list(self, filter=None):
"""Returns a list of VIM accounts
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns a VIM account based on name or id
"""
+ self._client.get_token()
vim_id = name
if not utils.validate_uuid4(name):
vim_id = self.get_id(name)
def list(self, ns=None, filter=None):
"""Returns a list of VNF instances
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns a VNF instance based on name or id
"""
+ self._client.get_token()
if utils.validate_uuid4(name):
for vnf in self.list():
if name == vnf['_id']:
raise NotFound("vnf {} not found".format(name))
def get_individual(self, name):
+ self._client.get_token()
vnf_id = name
if not utils.validate_uuid4(name):
for vnf in self.list():
#self._apiBase='/vnfds'
def list(self, filter=None):
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
return list()
def get(self, name):
+ self._client.get_token()
if utils.validate_uuid4(name):
for vnfd in self.list():
if name == vnfd['_id']:
self.get_thing(name, 'artifacts/{}'.format(artifact), filename)
def delete(self, name, force=False):
+ self._client.get_token()
vnfd = self.get(name)
querystring = ''
if force:
raise ClientException("failed to delete vnfd {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
+ self._client.get_token()
mime_type = magic.from_file(filename, mime=True)
if mime_type is None:
raise ClientException(
raise ClientException("failed to create/update vnfd - {}".format(msg))
def update(self, name, filename):
+ self._client.get_token()
vnfd = self.get(name)
endpoint = '{}/{}/package_content'.format(self._apiBase, vnfd['_id'])
self.create(filename=filename, update_endpoint=endpoint)
self._apiResource = '/wim_accounts'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
+
# WIM '--wait' option
def _wait(self, id, deleteFlag=False):
+ self._client.get_token()
# Endpoint to get operation status
apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/wim_accounts')
# Wait for status for WIM instance creation/deletion
return ''
def create(self, name, wim_input, wim_port_mapping=None, wait=False):
+ self._client.get_token()
if 'wim_type' not in wim_input:
raise Exception("wim type not provided")
raise ClientException("failed to create wim {} - {}".format(name, msg))
def update(self, wim_name, wim_account, wim_port_mapping=None, wait=False):
+ self._client.get_token()
wim = self.get(wim_name)
wim_id_for_wait = self._get_id_for_wait(wim_name)
wim_config = {}
raise NotFound("wim {} not found".format(name))
def delete(self, wim_name, force=False, wait=False):
+ self._client.get_token()
wim_id = wim_name
wim_id_for_wait = self._get_id_for_wait(wim_name)
if not utils.validate_uuid4(wim_name):
def list(self, filter=None):
"""Returns a list of VIM accounts
"""
+ self._client.get_token()
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
def get(self, name):
"""Returns a VIM account based on name or id
"""
+ self._client.get_token()
wim_id = name
if not utils.validate_uuid4(name):
wim_id = self.get_id(name)