X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fscripts%2Fosm.py;h=664ac629b576990559ab3c8aed517e5b7997fdb2;hb=d8cf387ce15e74c4c13d966ecc146499e2c37684;hp=7178d26026608aa03cdbeccd1777d9f5ec2809ee;hpb=a2999a460707408e636d81fe8e735a7625def0d4;p=osm%2Fosmclient.git diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 7178d26..664ac62 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -28,6 +28,7 @@ import time import pycurl import os import textwrap +import pkg_resources def wrap_text(text, width): @@ -1101,8 +1102,8 @@ def nsd_create(ctx, filename, overwrite): @cli.command(name='nsd-create', short_help='creates a new NSD/NSpkg') @click.argument('filename') -@click.option('--overwrite', 'overwrite', default=None, - help='overwrite deprecated, use override') +@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;...]"') @@ -1117,8 +1118,8 @@ def nsd_create1(ctx, filename, overwrite): @cli.command(name='nspkg-create', short_help='creates a new NSD/NSpkg') @click.argument('filename') -@click.option('--overwrite', 'overwrite', default=None, - help='overwrite deprecated, use override') +@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;...]"') @@ -1158,8 +1159,8 @@ def vnfd_create1(ctx, filename, overwrite): @cli.command(name='vnfpkg-create', short_help='creates a new VNFD/VNFpkg') @click.argument('filename') -@click.option('--overwrite', 'overwrite', default=None, - help='overwrite deprecated, use override') +@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;...]"') @@ -1174,8 +1175,8 @@ def vnfd_create2(ctx, filename, overwrite): @cli.command(name='nfpkg-create', short_help='creates a new NFpkg') @click.argument('filename') -@click.option('--overwrite', 'overwrite', default=None, - help='overwrite deprecated, use override') +@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;...]"') @@ -1211,8 +1212,8 @@ def nfpkg_create(ctx, filename, overwrite): required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def ns_create(ctx, nsd_name, @@ -1254,9 +1255,9 @@ def nst_create(ctx, filename, overwrite): @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, +@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 @@ -1270,8 +1271,8 @@ def nst_create1(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('--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;...]"') @@ -1324,8 +1325,8 @@ def nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_fi required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + 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)""" @@ -1354,8 +1355,8 @@ def nsi_create1(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_f required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + 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)""" @@ -1371,7 +1372,8 @@ def nsi_create2(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_f 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.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)""" @@ -1623,8 +1625,8 @@ def nfpkg_delete(ctx, name, force): required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def ns_delete(ctx, name, force, wait): """deletes a NS instance @@ -1691,8 +1693,8 @@ def nsi_delete(ctx, name, force, 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') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def nsi_delete1(ctx, name, force, wait): """deletes a Network Slice Instance (NSI) @@ -1768,8 +1770,8 @@ def pdu_delete(ctx, name, force): required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def vim_create(ctx, name, @@ -1822,8 +1824,8 @@ def vim_create(ctx, required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def vim_update(ctx, name, @@ -1866,8 +1868,8 @@ def vim_update(ctx, required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def vim_delete(ctx, name, force, wait): """deletes a VIM account @@ -1958,13 +1960,15 @@ def vim_show(ctx, name): @click.option('--description', default='no description', help='human readable description') -@click.option('--wim_port_mapping', default=None, help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge (WAN service endpoint id and info)") +@click.option('--wim_port_mapping', default=None, + help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge " + "(WAN service endpoint id and info)") @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') + help='do not return the control immediately, but keep it ' + 'until the operation is completed, or timeout') @click.pass_context def wim_create(ctx, name, @@ -2007,13 +2011,14 @@ def wim_create(ctx, @click.option('--config', help='WIM specific config parameters') @click.option('--wim_type', help='WIM type') @click.option('--description', help='human readable description') -@click.option('--wim_port_mapping', default=None, help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge (WAN service endpoint id and info)") +@click.option('--wim_port_mapping', default=None, + help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge " + "(WAN service endpoint id and info)") @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') + help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def wim_update(ctx, name, @@ -2054,8 +2059,7 @@ def wim_update(ctx, required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def wim_delete(ctx, name, force, wait): """deletes a WIM account @@ -2124,60 +2128,50 @@ def wim_show(ctx, name): @click.option('--type', prompt=True, help='SDN controller type') -@click.option('--sdn_controller_version', - help='SDN controller version') -@click.option('--ip_address', - prompt=True, - help='SDN controller IP address') -@click.option('--port', - prompt=True, - help='SDN controller port') -@click.option('--switch_dpid', - prompt=True, - help='Switch DPID (Openflow Datapath ID)') +@click.option('--sdn_controller_version', hidden=True, + help='Deprecated. Use --config {version: sdn_controller_version}') +@click.option('--url', + help='URL in format http[s]://HOST:IP/') +@click.option('--ip_address', hidden=True, + help='Deprecated. Use --url') +@click.option('--port', hidden=True, + help='Deprecated. Use --url') +@click.option('--switch_dpid', hidden=True, + help='Deprecated. Use --config {dpid: DPID}') +@click.option('--config', + help='Extra information for SDN in yaml format, as {dpid: (Openflow Datapath ID), version: version}') @click.option('--user', help='SDN controller username') @click.option('--password', hide_input=True, confirmation_prompt=True, help='SDN controller password') -#@click.option('--description', -# default='no description', -# help='human readable description') +@click.option('--description', default=None, help='human readable description') @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 sdnc_create(ctx, - name, - type, - sdn_controller_version, - ip_address, - port, - switch_dpid, - user, - password, - wait): + help="do not return the control immediately, but keep it until the operation is completed, or timeout") +@click.pass_context +def sdnc_create(ctx, **kwargs): """creates a new SDN controller""" - sdncontroller = {} - sdncontroller['name'] = name - sdncontroller['type'] = type - sdncontroller['ip'] = ip_address - sdncontroller['port'] = int(port) - sdncontroller['dpid'] = switch_dpid - if sdn_controller_version: - sdncontroller['version'] = sdn_controller_version - if user: - sdncontroller['user'] = user - if password: - sdncontroller['password'] = password -# sdncontroller['description'] = description + sdncontroller = {x: kwargs[x] for x in kwargs if kwargs[x] and + x not in ("wait", "ip_address", "port", "switch_dpid")} + if kwargs.get("port"): + print("option '--port' is deprecated, use '-url' instead") + sdncontroller["port"] = int(kwargs["port"]) + if kwargs.get("ip_address"): + print("option '--ip_address' is deprecated, use '-url' instead") + sdncontroller["ip"] = kwargs["ip_address"] + if kwargs.get("switch_dpid"): + print("option '--switch_dpid' is deprecated, use '---config={dpid: DPID}' instead") + sdncontroller["dpid"] = kwargs["switch_dpid"] + if kwargs.get("sdn_controller_version"): + print("option '--sdn_controller_version' is deprecated, use '---config={version: SDN_CONTROLLER_VERSION}'" + " instead") try: check_client_version(ctx.obj, ctx.command.name) - ctx.obj.sdnc.create(name, sdncontroller, wait=wait) + ctx.obj.sdnc.create(kwargs["name"], sdncontroller, wait=kwargs["wait"]) except ClientException as e: print(str(e)) exit(1) @@ -2185,61 +2179,45 @@ def sdnc_create(ctx, @cli.command(name='sdnc-update', short_help='updates an SDN controller') @click.argument('name') @click.option('--newname', help='New name for the SDN controller') +@click.option('--description', default=None, help='human readable description') @click.option('--type', help='SDN controller type') -@click.option('--sdn_controller_version', help='SDN controller username') -@click.option('--ip_address', help='SDN controller IP address') -@click.option('--port', help='SDN controller port') -@click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)') +@click.option('--url', help='URL in format http[s]://HOST:IP/') +@click.option('--config', help='Extra information for SDN in yaml format, as ' + '{dpid: (Openflow Datapath ID), version: version}') @click.option('--user', help='SDN controller username') @click.option('--password', help='SDN controller password') -#@click.option('--description', default=None, help='human readable description') -@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 sdnc_update(ctx, - name, - newname, - type, - sdn_controller_version, - ip_address, - port, - switch_dpid, - user, - password, - wait): +@click.option('--ip_address', hidden=True, help='Deprecated. Use --url') +@click.option('--port', hidden=True, help='Deprecated. Use --url') +@click.option('--switch_dpid', hidden=True, help='Deprecated. Use --config {switch_dpid: DPID}') +@click.option('--sdn_controller_version', hidden=True, help='Deprecated. Use --config {version: VERSION}') +@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 sdnc_update(ctx, **kwargs): """updates an SDN controller NAME: name or ID of the SDN controller """ - sdncontroller = {} - if newname: sdncontroller['name'] = newname - if type: sdncontroller['type'] = type - if ip_address: sdncontroller['ip'] = ip_address - if port: sdncontroller['port'] = int(port) - if switch_dpid: sdncontroller['dpid'] = switch_dpid -# sdncontroller['description'] = description - if sdn_controller_version is not None: - if sdn_controller_version=="": - sdncontroller['version'] = None - else: - sdncontroller['version'] = sdn_controller_version - if user is not None: - if user=="": - sdncontroller['user'] = None - else: - sdncontroller['user'] = user - if password is not None: - if password=="": - sdncontroller['password'] = None - else: - sdncontroller['password'] = user + sdncontroller = {x: kwargs[x] for x in kwargs if kwargs[x] and + x not in ("wait", "ip_address", "port", "switch_dpid", "new_name")} + if kwargs.get("newname"): + sdncontroller["name"] = kwargs["newname"] + if kwargs.get("port"): + print("option '--port' is deprecated, use '-url' instead") + sdncontroller["port"] = int(kwargs["port"]) + if kwargs.get("ip_address"): + print("option '--ip_address' is deprecated, use '-url' instead") + sdncontroller["ip"] = kwargs["ip_address"] + if kwargs.get("switch_dpid"): + print("option '--switch_dpid' is deprecated, use '---config={dpid: DPID}' instead") + sdncontroller["dpid"] = kwargs["switch_dpid"] + if kwargs.get("sdn_controller_version"): + print("option '--sdn_controller_version' is deprecated, use '---config={version: SDN_CONTROLLER_VERSION}'" + " instead") + try: check_client_version(ctx.obj, ctx.command.name) - ctx.obj.sdnc.update(name, sdncontroller, wait=wait) + ctx.obj.sdnc.update(kwargs["name"], sdncontroller, wait=kwargs["wait"]) except ClientException as e: print(str(e)) exit(1) @@ -2248,12 +2226,8 @@ def sdnc_update(ctx, @cli.command(name='sdnc-delete', short_help='deletes an SDN controller') @click.argument('name') @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions') -@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('--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 sdnc_delete(ctx, name, force, wait): """deletes an SDN controller @@ -2270,7 +2244,7 @@ def sdnc_delete(ctx, name, force, wait): @cli.command(name='sdnc-list', short_help='list all SDN controllers') @click.option('--filter', default=None, - help='restricts the list to the SDN controllers matching the filter') + help="restricts the list to the SDN controllers matching the filter with format: 'k[.k..]=v[&k[.k]=v2]'") @click.pass_context def sdnc_list(ctx, filter): """list all SDN controllers""" @@ -2341,8 +2315,7 @@ def sdnc_show(ctx, name): # help='If set, K8s cluster is assumed to be ready for its use with OSM') #@click.option('--wait', # is_flag=True, -# help='do not return the control immediately, but keep it \ -# until the operation is completed, or timeout') +# help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def k8scluster_add(ctx, name, @@ -2424,8 +2397,7 @@ def k8scluster_update(ctx, @click.option('--force', is_flag=True, help='forces the deletion from the DB (not recommended)') #@click.option('--wait', # is_flag=True, -# help='do not return the control immediately, but keep it \ -# until the operation is completed, or timeout') +# help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def k8scluster_delete(ctx, name, force): """deletes a K8s cluster @@ -2454,11 +2426,11 @@ def k8scluster_list(ctx, filter, literal): if literal: print(yaml.safe_dump(resp)) return - table = PrettyTable(['Name', 'Id', 'Version', 'VIM', 'K8s-nets', 'Description']) + table = PrettyTable(['Name', 'Id', 'Version', 'VIM', 'K8s-nets', 'Operational State', 'Description']) for cluster in resp: table.add_row([cluster['name'], cluster['_id'], cluster['k8s_version'], cluster['vim_account'], - json.dumps(cluster['nets']), trunc_text(cluster.get('description',''),40) - ]) + json.dumps(cluster['nets']), cluster["_admin"]["operationalState"], + trunc_text(cluster.get('description',''),40)]) table.align = 'l' print(table) except ClientException as e: @@ -2500,16 +2472,15 @@ def k8scluster_show(ctx, name, literal): @click.argument('name') @click.argument('uri') @click.option('--type', - type=click.Choice(['chart', 'bundle']), + type=click.Choice(['helm-chart', 'juju-bundle']), prompt=True, - help='type of repo (chart for helm-charts, bundle for juju-bundles)') + help='type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles)') @click.option('--description', default='', help='human readable description') #@click.option('--wait', # is_flag=True, -# help='do not return the control immediately, but keep it \ -# until the operation is completed, or timeout') +# help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def repo_add(ctx, name, @@ -2538,13 +2509,12 @@ def repo_add(ctx, @click.argument('name') @click.option('--newname', help='New name for the repo') @click.option('--uri', help='URI of the repo') -@click.option('--type', type=click.Choice(['chart', 'bundle']), - help='type of repo (chart for helm-charts, bundle for juju-bundles)') +@click.option('--type', type=click.Choice(['helm-chart', 'juju-bundle']), + help='type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles)') @click.option('--description', help='human readable description') #@click.option('--wait', # is_flag=True, -# help='do not return the control immediately, but keep it \ -# until the operation is completed, or timeout') +# help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def repo_update(ctx, name, @@ -2574,8 +2544,7 @@ def repo_update(ctx, @click.option('--force', is_flag=True, help='forces the deletion from the DB (not recommended)') #@click.option('--wait', # is_flag=True, -# help='do not return the control immediately, but keep it \ -# until the operation is completed, or timeout') +# help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def repo_delete(ctx, name, force): """deletes a repo @@ -3023,7 +2992,8 @@ def ns_metric_export(ctx, ns, vnf, vdu, metric, interval): def get_version(ctx): try: check_client_version(ctx.obj, "version") - print (ctx.obj.get_version()) + print ("Server version: {}".format(ctx.obj.get_version())) + print ("Client version: {}".format(pkg_resources.get_distribution("osmclient").version)) except ClientException as e: print(str(e)) exit(1) @@ -3209,8 +3179,7 @@ def upload_package(ctx, filename): required=False, default=False, is_flag=True, - help='do not return the control immediately, but keep it \ - until the operation is completed, or timeout') + help='do not return the control immediately, but keep it until the operation is completed, or timeout') @click.pass_context def ns_action(ctx, ns_name,