Code Coverage

Cobertura Coverage Report > osmclient.cli_commands >

sdnc.py

Trend

File Coverage summary

NameClassesLinesConditionals
sdnc.py
100%
1/1
49%
51/104
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
sdnc.py
49%
51/104
N/A

Source

osmclient/cli_commands/sdnc.py
1 # Copyright ETSI Contributors and Others.
2 # All Rights Reserved.
3 #
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
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
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
14 #    under the License.
15
16 1 import click
17 1 from osmclient.cli_commands import utils
18 1 from prettytable import PrettyTable
19 1 import json
20 1 import logging
21
22 1 logger = logging.getLogger("osmclient")
23
24
25 1 @click.command(name="sdnc-create", short_help="creates a new SDN controller")
26 1 @click.option("--name", prompt=True, help="Name to create sdn controller")
27 1 @click.option("--type", prompt=True, help="SDN controller type")
28 1 @click.option(
29     "--sdn_controller_version",  # hidden=True,
30     help="Deprecated. Use --config {version: sdn_controller_version}",
31 )
32 1 @click.option("--url", help="URL in format http[s]://HOST:IP/")
33 1 @click.option("--ip_address", help="Deprecated. Use --url")  # hidden=True,
34 1 @click.option("--port", help="Deprecated. Use --url")  # hidden=True,
35 1 @click.option(
36     "--switch_dpid", help="Deprecated. Use --config {switch_id: DPID}"  # hidden=True,
37 )
38 1 @click.option(
39     "--config",
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}",
42 )
43 1 @click.option("--user", help="SDN controller username")
44 1 @click.option(
45     "--password",
46     hide_input=True,
47     confirmation_prompt=True,
48     help="SDN controller password",
49 )
50 1 @click.option("--description", default=None, help="human readable description")
51 1 @click.option(
52     "--wait",
53     required=False,
54     default=False,
55     is_flag=True,
56     help="do not return the control immediately, but keep it until the operation is completed, or timeout",
57 )
58 1 @click.pass_context
59 1 def sdnc_create(ctx, **kwargs):
60     """creates a new SDN controller"""
61 0     logger.debug("")
62 0     sdncontroller = {
63         x: kwargs[x]
64         for x in kwargs
65         if kwargs[x] and x not in ("wait", "ip_address", "port", "switch_dpid")
66     }
67 0     if kwargs.get("port"):
68 0         print("option '--port' is deprecated, use '--url' instead")
69 0         sdncontroller["port"] = int(kwargs["port"])
70 0     if kwargs.get("ip_address"):
71 0         print("option '--ip_address' is deprecated, use '--url' instead")
72 0         sdncontroller["ip"] = kwargs["ip_address"]
73 0     if kwargs.get("switch_dpid"):
74 0         print(
75             "option '--switch_dpid' is deprecated, use '--config={switch_id: id|DPID}' instead"
76         )
77 0         sdncontroller["dpid"] = kwargs["switch_dpid"]
78 0     if kwargs.get("sdn_controller_version"):
79 0         print(
80             "option '--sdn_controller_version' is deprecated, use '--config={version: SDN_CONTROLLER_VERSION}'"
81             " instead"
82         )
83 0     utils.check_client_version(ctx.obj, ctx.command.name)
84 0     ctx.obj.sdnc.create(kwargs["name"], sdncontroller, wait=kwargs["wait"])
85
86
87 1 @click.command(name="sdnc-update", short_help="updates an SDN controller")
88 1 @click.argument("name")
89 1 @click.option("--newname", help="New name for the SDN controller")
90 1 @click.option("--description", default=None, help="human readable description")
91 1 @click.option("--type", help="SDN controller type")
92 1 @click.option("--url", help="URL in format http[s]://HOST:IP/")
93 1 @click.option(
94     "--config",
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}",
98 )
99 1 @click.option("--user", help="SDN controller username")
100 1 @click.option("--password", help="SDN controller password")
101 1 @click.option("--ip_address", help="Deprecated. Use --url")  # hidden=True
102 1 @click.option("--port", help="Deprecated. Use --url")  # hidden=True
103 1 @click.option(
104     "--switch_dpid", help="Deprecated. Use --config {switch_dpid: DPID}"
105 )  # hidden=True
106 1 @click.option(
107     "--sdn_controller_version", help="Deprecated. Use --config {version: VERSION}"
108 )  # hidden=True
109 1 @click.option(
110     "--wait",
111     required=False,
112     default=False,
113     is_flag=True,
114     help="do not return the control immediately, but keep it until the operation is completed, or timeout",
115 )
116 1 @click.pass_context
117 1 def sdnc_update(ctx, **kwargs):
118     """updates an SDN controller
119
120     NAME: name or ID of the SDN controller
121     """
122 0     logger.debug("")
123 0     sdncontroller = {
124         x: kwargs[x]
125         for x in kwargs
126         if kwargs[x]
127         and x not in ("wait", "ip_address", "port", "switch_dpid", "new_name")
128     }
129 0     if kwargs.get("newname"):
130 0         sdncontroller["name"] = kwargs["newname"]
131 0     if kwargs.get("port"):
132 0         print("option '--port' is deprecated, use '--url' instead")
133 0         sdncontroller["port"] = int(kwargs["port"])
134 0     if kwargs.get("ip_address"):
135 0         print("option '--ip_address' is deprecated, use '--url' instead")
136 0         sdncontroller["ip"] = kwargs["ip_address"]
137 0     if kwargs.get("switch_dpid"):
138 0         print(
139             "option '--switch_dpid' is deprecated, use '--config={switch_id: id|DPID}' instead"
140         )
141 0         sdncontroller["dpid"] = kwargs["switch_dpid"]
142 0     if kwargs.get("sdn_controller_version"):
143 0         print(
144             "option '--sdn_controller_version' is deprecated, use '---config={version: SDN_CONTROLLER_VERSION}'"
145             " instead"
146         )
147
148 0     utils.check_client_version(ctx.obj, ctx.command.name)
149 0     ctx.obj.sdnc.update(kwargs["name"], sdncontroller, wait=kwargs["wait"])
150
151
152 1 @click.command(name="sdnc-delete", short_help="deletes an SDN controller")
153 1 @click.argument("name")
154 1 @click.option(
155     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
156 )
157 1 @click.option(
158     "--wait",
159     required=False,
160     default=False,
161     is_flag=True,
162     help="do not return the control immediately, but keep it until the operation is completed, or timeout",
163 )
164 1 @click.pass_context
165 1 def sdnc_delete(ctx, name, force, wait):
166     """deletes an SDN controller
167
168     NAME: name or ID of the SDN controller to be deleted
169     """
170 0     logger.debug("")
171 0     utils.check_client_version(ctx.obj, ctx.command.name)
172 0     ctx.obj.sdnc.delete(name, force, wait=wait)
173
174
175 1 @click.command(name="sdnc-list", short_help="list all SDN controllers")
176 1 @click.option(
177     "--filter",
178     default=None,
179     multiple=True,
180     help="restricts the list to the SDN controllers matching the filter with format: 'k[.k..]=v[&k[.k]=v2]'",
181 )
182 1 @click.pass_context
183 1 def sdnc_list(ctx, filter):
184     """list all SDN controllers"""
185 0     logger.debug("")
186 0     utils.check_client_version(ctx.obj, ctx.command.name)
187 0     if filter:
188 0         filter = "&".join(filter)
189 0     resp = ctx.obj.sdnc.list(filter)
190 0     table = PrettyTable(["sdnc name", "id"])
191 0     for sdnc in resp:
192 0         table.add_row([sdnc["name"], sdnc["_id"]])
193 0     table.align = "l"
194 0     print(table)
195
196
197 1 @click.command(name="sdnc-show", short_help="shows the details of an SDN controller")
198 1 @click.argument("name")
199 1 @click.pass_context
200 1 def sdnc_show(ctx, name):
201     """shows the details of an SDN controller
202
203     NAME: name or ID of the SDN controller
204     """
205 0     logger.debug("")
206 0     utils.check_client_version(ctx.obj, ctx.command.name)
207 0     resp = ctx.obj.sdnc.get(name)
208
209 0     table = PrettyTable(["key", "attribute"])
210 0     for k, v in list(resp.items()):
211 0         table.add_row([k, json.dumps(v, indent=2)])
212 0     table.align = "l"
213 0     print(table)