From d86773c981d4eb7e92365515066a83da75671886 Mon Sep 17 00:00:00 2001 From: tierno Date: Wed, 4 Mar 2020 20:07:02 +0000 Subject: [PATCH] allow disassociate sdn_controller from a VIM Change-Id: I92462a119b4c1821a9fa4cbb5550fc3517111fa2 Signed-off-by: tierno --- osmclient/scripts/osm.py | 25 ++++++++++++++----------- osmclient/sol005/vim.py | 16 ++++++++++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 2c0cf12..1461760 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -2177,7 +2177,8 @@ def vim_create(ctx, @click.option('--config', help='VIM specific config parameters') @click.option('--account_type', help='VIM type') @click.option('--description', help='human readable description') -@click.option('--sdn_controller', default=None, help='Name or id of the SDN controller associated to this VIM account') +@click.option('--sdn_controller', default=None, help='Name or id of the SDN controller to be associated with this VIM' + 'account. Use empty string to disassociate') @click.option('--sdn_port_mapping', default=None, help="File describing the port mapping between compute nodes' ports and switch ports") @click.option('--wait', required=False, @@ -2505,9 +2506,10 @@ def wim_show(ctx, name): @click.option('--port', # hidden=True, help='Deprecated. Use --url') @click.option('--switch_dpid', # hidden=True, - help='Deprecated. Use --config {dpid: DPID}') + help='Deprecated. Use --config {switch_id: DPID}') @click.option('--config', - help='Extra information for SDN in yaml format, as {dpid: (Openflow Datapath ID), version: version}') + help='Extra information for SDN in yaml format, as {switch_id: identity used for the plugin (e.g. DPID: ' + 'Openflow Datapath ID), version: version}') @click.option('--user', help='SDN controller username') @click.option('--password', @@ -2527,16 +2529,16 @@ def sdnc_create(ctx, **kwargs): 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") + 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") + 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") + print("option '--switch_dpid' is deprecated, use '--config={switch_id: id|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}'" + print("option '--sdn_controller_version' is deprecated, use '--config={version: SDN_CONTROLLER_VERSION}'" " instead") # try: check_client_version(ctx.obj, ctx.command.name) @@ -2552,7 +2554,8 @@ def sdnc_create(ctx, **kwargs): @click.option('--type', help='SDN controller type') @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}') + '{switch_id: identity used for the plugin (e.g. DPID: ' + 'Openflow Datapath ID), version: version}') @click.option('--user', help='SDN controller username') @click.option('--password', help='SDN controller password') @click.option('--ip_address', help='Deprecated. Use --url') # hidden=True @@ -2573,13 +2576,13 @@ def sdnc_update(ctx, **kwargs): if kwargs.get("newname"): sdncontroller["name"] = kwargs["newname"] if kwargs.get("port"): - print("option '--port' is deprecated, use '-url' instead") + 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") + 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") + print("option '--switch_dpid' is deprecated, use '--config={switch_id: id|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}'" diff --git a/osmclient/sol005/vim.py b/osmclient/sol005/vim.py index 9cd882c..16c3615 100644 --- a/osmclient/sol005/vim.py +++ b/osmclient/sol005/vim.py @@ -126,12 +126,16 @@ class Vim(object): vim_config = None else: vim_config = yaml.safe_load(vim_account['config']) - if sdn_controller: - sdnc = self._client.sdnc.get(sdn_controller) - vim_config['sdn-controller'] = sdnc['_id'] - if sdn_port_mapping: - with open(sdn_port_mapping, 'r') as f: - vim_config['sdn-port-mapping'] = yaml.safe_load(f.read()) + if sdn_controller == "": + vim_config['sdn-controller'] = None + vim_config['sdn-port-mapping'] = None + else: + if sdn_controller: + sdnc = self._client.sdnc.get(sdn_controller) + vim_config['sdn-controller'] = sdnc['_id'] + if sdn_port_mapping: + with open(sdn_port_mapping, 'r') as f: + vim_config['sdn-port-mapping'] = yaml.safe_load(f.read()) vim_account['config'] = vim_config #vim_account['config'] = json.dumps(vim_config) http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']), -- 2.25.1