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.common.exceptions import ClientException |
18 |
1 |
from osmclient.cli_commands import utils |
19 |
1 |
from prettytable import PrettyTable |
20 |
1 |
import yaml |
21 |
1 |
import json |
22 |
1 |
import logging |
23 |
|
|
24 |
1 |
logger = logging.getLogger("osmclient") |
25 |
|
|
26 |
|
|
27 |
1 |
def nsi_list(ctx, filter): |
28 |
|
"""list all Network Slice Instances""" |
29 |
0 |
logger.debug("") |
30 |
0 |
utils.check_client_version(ctx.obj, ctx.command.name) |
31 |
0 |
if filter: |
32 |
0 |
filter = "&".join(filter) |
33 |
0 |
resp = ctx.obj.nsi.list(filter) |
34 |
0 |
table = PrettyTable( |
35 |
|
[ |
36 |
|
"netslice instance name", |
37 |
|
"id", |
38 |
|
"operational status", |
39 |
|
"config status", |
40 |
|
"detailed status", |
41 |
|
] |
42 |
|
) |
43 |
0 |
for nsi in resp: |
44 |
0 |
nsi_name = nsi["name"] |
45 |
0 |
nsi_id = nsi["_id"] |
46 |
0 |
opstatus = ( |
47 |
|
nsi["operational-status"] if "operational-status" in nsi else "Not found" |
48 |
|
) |
49 |
0 |
configstatus = nsi["config-status"] if "config-status" in nsi else "Not found" |
50 |
0 |
detailed_status = ( |
51 |
|
nsi["detailed-status"] if "detailed-status" in nsi else "Not found" |
52 |
|
) |
53 |
0 |
if configstatus == "config_not_needed": |
54 |
0 |
configstatus = "configured (no charms)" |
55 |
0 |
table.add_row([nsi_name, nsi_id, opstatus, configstatus, detailed_status]) |
56 |
0 |
table.align = "l" |
57 |
0 |
print(table) |
58 |
|
|
59 |
|
|
60 |
1 |
@click.command(name="nsi-list", short_help="list all Network Slice Instances (NSI)") |
61 |
1 |
@click.option( |
62 |
|
"--filter", |
63 |
|
default=None, |
64 |
|
multiple=True, |
65 |
|
help="restricts the list to the Network Slice Instances matching the filter", |
66 |
|
) |
67 |
1 |
@click.pass_context |
68 |
1 |
def nsi_list1(ctx, filter): |
69 |
|
"""list all Network Slice Instances (NSI)""" |
70 |
0 |
logger.debug("") |
71 |
0 |
nsi_list(ctx, filter) |
72 |
|
|
73 |
|
|
74 |
1 |
@click.command( |
75 |
|
name="netslice-instance-list", short_help="list all Network Slice Instances (NSI)" |
76 |
|
) |
77 |
1 |
@click.option( |
78 |
|
"--filter", |
79 |
|
default=None, |
80 |
|
multiple=True, |
81 |
|
help="restricts the list to the Network Slice Instances matching the filter", |
82 |
|
) |
83 |
1 |
@click.pass_context |
84 |
1 |
def nsi_list2(ctx, filter): |
85 |
|
"""list all Network Slice Instances (NSI)""" |
86 |
0 |
logger.debug("") |
87 |
0 |
nsi_list(ctx, filter) |
88 |
|
|
89 |
|
|
90 |
1 |
def nsi_show(ctx, name, literal, filter): |
91 |
0 |
logger.debug("") |
92 |
0 |
utils.check_client_version(ctx.obj, ctx.command.name) |
93 |
0 |
nsi = ctx.obj.nsi.get(name) |
94 |
|
|
95 |
0 |
if literal: |
96 |
0 |
print(yaml.safe_dump(nsi, indent=4, default_flow_style=False)) |
97 |
0 |
return |
98 |
|
|
99 |
0 |
table = PrettyTable(["field", "value"]) |
100 |
|
|
101 |
0 |
for k, v in list(nsi.items()): |
102 |
0 |
if not filter or k in filter: |
103 |
0 |
table.add_row([k, json.dumps(v, indent=2)]) |
104 |
|
|
105 |
0 |
table.align = "l" |
106 |
0 |
print(table) |
107 |
|
|
108 |
|
|
109 |
1 |
@click.command( |
110 |
|
name="nsi-show", short_help="shows the content of a Network Slice Instance (NSI)" |
111 |
|
) |
112 |
1 |
@click.argument("name") |
113 |
1 |
@click.option("--literal", is_flag=True, help="print literally, no pretty table") |
114 |
1 |
@click.option( |
115 |
|
"--filter", |
116 |
|
multiple=True, |
117 |
|
help="restricts the information to the fields in the filter", |
118 |
|
) |
119 |
1 |
@click.pass_context |
120 |
1 |
def nsi_show1(ctx, name, literal, filter): |
121 |
|
"""shows the content of a Network Slice Instance (NSI) |
122 |
|
|
123 |
|
NAME: name or ID of the Network Slice Instance |
124 |
|
""" |
125 |
0 |
logger.debug("") |
126 |
0 |
nsi_show(ctx, name, literal, filter) |
127 |
|
|
128 |
|
|
129 |
1 |
@click.command( |
130 |
|
name="netslice-instance-show", |
131 |
|
short_help="shows the content of a Network Slice Instance (NSI)", |
132 |
|
) |
133 |
1 |
@click.argument("name") |
134 |
1 |
@click.option("--literal", is_flag=True, help="print literally, no pretty table") |
135 |
1 |
@click.option( |
136 |
|
"--filter", |
137 |
|
multiple=True, |
138 |
|
help="restricts the information to the fields in the filter", |
139 |
|
) |
140 |
1 |
@click.pass_context |
141 |
1 |
def nsi_show2(ctx, name, literal, filter): |
142 |
|
"""shows the content of a Network Slice Instance (NSI) |
143 |
|
|
144 |
|
NAME: name or ID of the Network Slice Instance |
145 |
|
""" |
146 |
0 |
logger.debug("") |
147 |
0 |
nsi_show(ctx, name, literal, filter) |
148 |
|
|
149 |
|
|
150 |
1 |
def nsi_create( |
151 |
|
ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait |
152 |
|
): |
153 |
|
"""creates a new Network Slice Instance (NSI)""" |
154 |
0 |
logger.debug("") |
155 |
0 |
utils.check_client_version(ctx.obj, ctx.command.name) |
156 |
0 |
if config_file: |
157 |
0 |
if config: |
158 |
0 |
raise ClientException( |
159 |
|
'"--config" option is incompatible with "--config_file" option' |
160 |
|
) |
161 |
0 |
with open(config_file, "r") as cf: |
162 |
0 |
config = cf.read() |
163 |
0 |
ctx.obj.nsi.create( |
164 |
|
nst_name, |
165 |
|
nsi_name, |
166 |
|
config=config, |
167 |
|
ssh_keys=ssh_keys, |
168 |
|
account=vim_account, |
169 |
|
wait=wait, |
170 |
|
) |
171 |
|
|
172 |
|
|
173 |
1 |
@click.command(name="nsi-create", short_help="creates a new Network Slice Instance") |
174 |
1 |
@click.option("--nsi_name", prompt=True, help="name of the Network Slice Instance") |
175 |
1 |
@click.option("--nst_name", prompt=True, help="name of the Network Slice Template") |
176 |
1 |
@click.option( |
177 |
|
"--vim_account", |
178 |
|
prompt=True, |
179 |
|
help="default VIM account id or name for the deployment", |
180 |
|
) |
181 |
1 |
@click.option( |
182 |
|
"--ssh_keys", default=None, help="comma separated list of keys to inject to vnfs" |
183 |
|
) |
184 |
1 |
@click.option( |
185 |
|
"--config", |
186 |
|
default=None, |
187 |
|
help="Netslice specific yaml configuration:\n" |
188 |
|
"netslice_subnet: [\n" |
189 |
|
"id: TEXT, vim_account: TEXT,\n" |
190 |
|
"vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n" |
191 |
|
"vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n" |
192 |
|
"additionalParamsForNsi: {param: value, ...}\n" |
193 |
|
"additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n" |
194 |
|
"],\n" |
195 |
|
"netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]", |
196 |
|
) |
197 |
1 |
@click.option( |
198 |
|
"--config_file", default=None, help="nsi specific yaml configuration file" |
199 |
|
) |
200 |
1 |
@click.option( |
201 |
|
"--wait", |
202 |
|
required=False, |
203 |
|
default=False, |
204 |
|
is_flag=True, |
205 |
|
help="do not return the control immediately, but keep it " |
206 |
|
"until the operation is completed, or timeout", |
207 |
|
) |
208 |
1 |
@click.pass_context |
209 |
1 |
def nsi_create1( |
210 |
|
ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait |
211 |
|
): |
212 |
|
"""creates a new Network Slice Instance (NSI)""" |
213 |
0 |
logger.debug("") |
214 |
0 |
nsi_create( |
215 |
|
ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait=wait |
216 |
|
) |
217 |
|
|
218 |
|
|
219 |
1 |
@click.command( |
220 |
|
name="netslice-instance-create", short_help="creates a new Network Slice Instance" |
221 |
|
) |
222 |
1 |
@click.option("--nsi_name", prompt=True, help="name of the Network Slice Instance") |
223 |
1 |
@click.option("--nst_name", prompt=True, help="name of the Network Slice Template") |
224 |
1 |
@click.option( |
225 |
|
"--vim_account", |
226 |
|
prompt=True, |
227 |
|
help="default VIM account id or name for the deployment", |
228 |
|
) |
229 |
1 |
@click.option( |
230 |
|
"--ssh_keys", default=None, help="comma separated list of keys to inject to vnfs" |
231 |
|
) |
232 |
1 |
@click.option( |
233 |
|
"--config", |
234 |
|
default=None, |
235 |
|
help="Netslice specific yaml configuration:\n" |
236 |
|
"netslice_subnet: [\n" |
237 |
|
"id: TEXT, vim_account: TEXT,\n" |
238 |
|
"vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n" |
239 |
|
"vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]" |
240 |
|
"],\n" |
241 |
|
"netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]", |
242 |
|
) |
243 |
1 |
@click.option( |
244 |
|
"--config_file", default=None, help="nsi specific yaml configuration file" |
245 |
|
) |
246 |
1 |
@click.option( |
247 |
|
"--wait", |
248 |
|
required=False, |
249 |
|
default=False, |
250 |
|
is_flag=True, |
251 |
|
help="do not return the control immediately, but keep it " |
252 |
|
"until the operation is completed, or timeout", |
253 |
|
) |
254 |
1 |
@click.pass_context |
255 |
1 |
def nsi_create2( |
256 |
|
ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait |
257 |
|
): |
258 |
|
"""creates a new Network Slice Instance (NSI)""" |
259 |
0 |
logger.debug("") |
260 |
0 |
nsi_create( |
261 |
|
ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_file, wait=wait |
262 |
|
) |
263 |
|
|
264 |
|
|
265 |
1 |
def nsi_delete(ctx, name, force, wait): |
266 |
0 |
logger.debug("") |
267 |
0 |
utils.check_client_version(ctx.obj, ctx.command.name) |
268 |
0 |
ctx.obj.nsi.delete(name, force, wait=wait) |
269 |
|
|
270 |
|
|
271 |
1 |
@click.command(name="nsi-delete", short_help="deletes a Network Slice Instance (NSI)") |
272 |
1 |
@click.argument("name") |
273 |
1 |
@click.option( |
274 |
|
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions" |
275 |
|
) |
276 |
1 |
@click.option( |
277 |
|
"--wait", |
278 |
|
required=False, |
279 |
|
default=False, |
280 |
|
is_flag=True, |
281 |
|
help="do not return the control immediately, but keep it " |
282 |
|
"until the operation is completed, or timeout", |
283 |
|
) |
284 |
1 |
@click.pass_context |
285 |
1 |
def nsi_delete1(ctx, name, force, wait): |
286 |
|
"""deletes a Network Slice Instance (NSI) |
287 |
|
|
288 |
|
NAME: name or ID of the Network Slice instance to be deleted |
289 |
|
""" |
290 |
0 |
logger.debug("") |
291 |
0 |
nsi_delete(ctx, name, force, wait=wait) |
292 |
|
|
293 |
|
|
294 |
1 |
@click.command( |
295 |
|
name="netslice-instance-delete", short_help="deletes a Network Slice Instance (NSI)" |
296 |
|
) |
297 |
1 |
@click.argument("name") |
298 |
1 |
@click.option( |
299 |
|
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions" |
300 |
|
) |
301 |
1 |
@click.pass_context |
302 |
1 |
def nsi_delete2(ctx, name, force, wait): |
303 |
|
"""deletes a Network Slice Instance (NSI) |
304 |
|
|
305 |
|
NAME: name or ID of the Network Slice instance to be deleted |
306 |
|
""" |
307 |
0 |
logger.debug("") |
308 |
0 |
nsi_delete(ctx, name, force, wait=wait) |