Code Coverage

Cobertura Coverage Report > osmclient.cli_commands >

wim.py

Trend

Classes100%
 
Lines45%
   
Conditionals100%
 

File Coverage summary

NameClassesLinesConditionals
wim.py
100%
1/1
45%
45/101
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
wim.py
45%
45/101
N/A

Source

osmclient/cli_commands/wim.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="wim-create", short_help="creates a new WIM account")
26 1 @click.option("--name", prompt=True, help="Name for the WIM account")
27 1 @click.option("--user", help="WIM username")
28 1 @click.option("--password", help="WIM password")
29 1 @click.option("--url", prompt=True, help="WIM url")
30 1 @click.option("--config", default=None, help="WIM specific config parameters")
31 1 @click.option("--wim_type", help="WIM type")
32 1 @click.option("--description", default=None, help="human readable description")
33 1 @click.option(
34     "--wim_port_mapping",
35     default=None,
36     help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge "
37     "(WAN service endpoint id and info)",
38 )
39 1 @click.option(
40     "--wait",
41     required=False,
42     default=False,
43     is_flag=True,
44     help="do not return the control immediately, but keep it "
45     "until the operation is completed, or timeout",
46 )
47 1 @click.pass_context
48 1 def wim_create(
49     ctx,
50     name,
51     user,
52     password,
53     url,
54     config,
55     wim_type,
56     description,
57     wim_port_mapping,
58     wait,
59 ):
60     """creates a new WIM account"""
61 0     logger.debug("")
62 0     utils.check_client_version(ctx.obj, ctx.command.name)
63 0     wim = {}
64 0     if user:
65 0         wim["user"] = user
66 0     if password:
67 0         wim["password"] = password
68 0     if url:
69 0         wim["wim_url"] = url
70 0     wim["wim_type"] = wim_type
71 0     if description:
72 0         wim["description"] = description
73 0     if config:
74 0         wim["config"] = config
75 0     ctx.obj.wim.create(name, wim, wim_port_mapping, wait=wait)
76
77
78 1 @click.command(name="wim-update", short_help="updates a WIM account")
79 1 @click.argument("name")
80 1 @click.option("--newname", help="New name for the WIM account")
81 1 @click.option("--user", help="WIM username")
82 1 @click.option("--password", help="WIM password")
83 1 @click.option("--url", help="WIM url")
84 1 @click.option("--config", help="WIM specific config parameters")
85 1 @click.option("--wim_type", help="WIM type")
86 1 @click.option("--description", help="human readable description")
87 1 @click.option(
88     "--wim_port_mapping",
89     default=None,
90     help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge "
91     "(WAN service endpoint id and info)",
92 )
93 1 @click.option(
94     "--wait",
95     required=False,
96     default=False,
97     is_flag=True,
98     help="do not return the control immediately, but keep it until the operation is completed, or timeout",
99 )
100 1 @click.pass_context
101 1 def wim_update(
102     ctx,
103     name,
104     newname,
105     user,
106     password,
107     url,
108     config,
109     wim_type,
110     description,
111     wim_port_mapping,
112     wait,
113 ):
114     """updates a WIM account
115
116     NAME: name or ID of the WIM account
117     """
118 0     logger.debug("")
119 0     utils.check_client_version(ctx.obj, ctx.command.name)
120 0     wim = {}
121 0     if newname:
122 0         wim["name"] = newname
123 0     if user:
124 0         wim["user"] = user
125 0     if password:
126 0         wim["password"] = password
127 0     if url:
128 0         wim["url"] = url
129 0     if wim_type:
130 0         wim["wim_type"] = wim_type
131 0     if description:
132 0         wim["description"] = description
133 0     if config:
134 0         wim["config"] = config
135 0     ctx.obj.wim.update(name, wim, wim_port_mapping, wait=wait)
136
137
138 1 @click.command(name="wim-delete", short_help="deletes a WIM account")
139 1 @click.argument("name")
140 1 @click.option(
141     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
142 )
143 1 @click.option(
144     "--wait",
145     required=False,
146     default=False,
147     is_flag=True,
148     help="do not return the control immediately, but keep it until the operation is completed, or timeout",
149 )
150 1 @click.pass_context
151 1 def wim_delete(ctx, name, force, wait):
152     """deletes a WIM account
153
154     NAME: name or ID of the WIM account to be deleted
155     """
156 0     logger.debug("")
157 0     utils.check_client_version(ctx.obj, ctx.command.name)
158 0     ctx.obj.wim.delete(name, force, wait=wait)
159
160
161 1 @click.command(name="wim-list", short_help="list all WIM accounts")
162 1 @click.option(
163     "--filter",
164     default=None,
165     multiple=True,
166     help="restricts the list to the WIM accounts matching the filter",
167 )
168 1 @click.pass_context
169 1 def wim_list(ctx, filter):
170     """list all WIM accounts"""
171 0     logger.debug("")
172 0     utils.check_client_version(ctx.obj, ctx.command.name)
173 0     if filter:
174 0         filter = "&".join(filter)
175 0     resp = ctx.obj.wim.list(filter)
176 0     table = PrettyTable(["wim name", "uuid"])
177 0     for wim in resp:
178 0         table.add_row([wim["name"], wim["uuid"]])
179 0     table.align = "l"
180 0     print(table)
181
182
183 1 @click.command(name="wim-show", short_help="shows the details of a WIM account")
184 1 @click.argument("name")
185 1 @click.pass_context
186 1 def wim_show(ctx, name):
187     """shows the details of a WIM account
188
189     NAME: name or ID of the WIM account
190     """
191 0     logger.debug("")
192 0     utils.check_client_version(ctx.obj, ctx.command.name)
193 0     resp = ctx.obj.wim.get(name)
194 0     if "password" in resp:
195 0         resp["password"] = "********"
196
197 0     table = PrettyTable(["key", "attribute"])
198 0     for k, v in list(resp.items()):
199 0         table.add_row([k, json.dumps(v, indent=2)])
200 0     table.align = "l"
201 0     print(table)