1 # Copyright ETSI Contributors and Others.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
17 from osmclient
.cli_commands
import utils
18 from prettytable
import PrettyTable
22 logger
= logging
.getLogger("osmclient")
25 @click.command(name
="sdnc-create", short_help
="creates a new SDN controller")
26 @click.option("--name", prompt
=True, help="Name to create sdn controller")
27 @click.option("--type", prompt
=True, help="SDN controller type")
29 "--sdn_controller_version", # hidden=True,
30 help="Deprecated. Use --config {version: sdn_controller_version}",
32 @click.option("--url", help="URL in format http[s]://HOST:IP/")
33 @click.option("--ip_address", help="Deprecated. Use --url") # hidden=True,
34 @click.option("--port", help="Deprecated. Use --url") # hidden=True,
36 "--switch_dpid", help="Deprecated. Use --config {switch_id: DPID}" # hidden=True,
40 help="Extra information for SDN in yaml format, as {switch_id: identity used for the plugin (e.g. DPID: "
41 "Openflow Datapath ID), version: version}",
43 @click.option("--user", help="SDN controller username")
47 confirmation_prompt
=True,
48 help="SDN controller password",
50 @click.option("--description", default
=None, help="human readable description")
56 help="do not return the control immediately, but keep it until the operation is completed, or timeout",
59 def sdnc_create(ctx
, **kwargs
):
60 """creates a new SDN controller"""
65 if kwargs
[x
] and x
not in ("wait", "ip_address", "port", "switch_dpid")
67 if kwargs
.get("port"):
68 print("option '--port' is deprecated, use '--url' instead")
69 sdncontroller
["port"] = int(kwargs
["port"])
70 if kwargs
.get("ip_address"):
71 print("option '--ip_address' is deprecated, use '--url' instead")
72 sdncontroller
["ip"] = kwargs
["ip_address"]
73 if kwargs
.get("switch_dpid"):
75 "option '--switch_dpid' is deprecated, use '--config={switch_id: id|DPID}' instead"
77 sdncontroller
["dpid"] = kwargs
["switch_dpid"]
78 if kwargs
.get("sdn_controller_version"):
80 "option '--sdn_controller_version' is deprecated, use '--config={version: SDN_CONTROLLER_VERSION}'"
83 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
84 ctx
.obj
.sdnc
.create(kwargs
["name"], sdncontroller
, wait
=kwargs
["wait"])
87 @click.command(name
="sdnc-update", short_help
="updates an SDN controller")
88 @click.argument("name")
89 @click.option("--newname", help="New name for the SDN controller")
90 @click.option("--description", default
=None, help="human readable description")
91 @click.option("--type", help="SDN controller type")
92 @click.option("--url", help="URL in format http[s]://HOST:IP/")
95 help="Extra information for SDN in yaml format, as "
96 "{switch_id: identity used for the plugin (e.g. DPID: "
97 "Openflow Datapath ID), version: version}",
99 @click.option("--user", help="SDN controller username")
100 @click.option("--password", help="SDN controller password")
101 @click.option("--ip_address", help="Deprecated. Use --url") # hidden=True
102 @click.option("--port", help="Deprecated. Use --url") # hidden=True
104 "--switch_dpid", help="Deprecated. Use --config {switch_dpid: DPID}"
107 "--sdn_controller_version", help="Deprecated. Use --config {version: VERSION}"
114 help="do not return the control immediately, but keep it until the operation is completed, or timeout",
117 def sdnc_update(ctx
, **kwargs
):
118 """updates an SDN controller
120 NAME: name or ID of the SDN controller
127 and x
not in ("wait", "ip_address", "port", "switch_dpid", "new_name")
129 if kwargs
.get("newname"):
130 sdncontroller
["name"] = kwargs
["newname"]
131 if kwargs
.get("port"):
132 print("option '--port' is deprecated, use '--url' instead")
133 sdncontroller
["port"] = int(kwargs
["port"])
134 if kwargs
.get("ip_address"):
135 print("option '--ip_address' is deprecated, use '--url' instead")
136 sdncontroller
["ip"] = kwargs
["ip_address"]
137 if kwargs
.get("switch_dpid"):
139 "option '--switch_dpid' is deprecated, use '--config={switch_id: id|DPID}' instead"
141 sdncontroller
["dpid"] = kwargs
["switch_dpid"]
142 if kwargs
.get("sdn_controller_version"):
144 "option '--sdn_controller_version' is deprecated, use '---config={version: SDN_CONTROLLER_VERSION}'"
148 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
149 ctx
.obj
.sdnc
.update(kwargs
["name"], sdncontroller
, wait
=kwargs
["wait"])
152 @click.command(name
="sdnc-delete", short_help
="deletes an SDN controller")
153 @click.argument("name")
155 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
162 help="do not return the control immediately, but keep it until the operation is completed, or timeout",
165 def sdnc_delete(ctx
, name
, force
, wait
):
166 """deletes an SDN controller
168 NAME: name or ID of the SDN controller to be deleted
171 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
172 ctx
.obj
.sdnc
.delete(name
, force
, wait
=wait
)
175 @click.command(name
="sdnc-list", short_help
="list all SDN controllers")
180 help="restricts the list to the SDN controllers matching the filter with format: 'k[.k..]=v[&k[.k]=v2]'",
183 def sdnc_list(ctx
, filter):
184 """list all SDN controllers"""
186 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
188 filter = "&".join(filter)
189 resp
= ctx
.obj
.sdnc
.list(filter)
190 table
= PrettyTable(["sdnc name", "id"])
192 table
.add_row([sdnc
["name"], sdnc
["_id"]])
197 @click.command(name
="sdnc-show", short_help
="shows the details of an SDN controller")
198 @click.argument("name")
200 def sdnc_show(ctx
, name
):
201 """shows the details of an SDN controller
203 NAME: name or ID of the SDN controller
206 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
207 resp
= ctx
.obj
.sdnc
.get(name
)
209 table
= PrettyTable(["key", "attribute"])
210 for k
, v
in list(resp
.items()):
211 table
.add_row([k
, json
.dumps(v
, indent
=2)])