Code Coverage

Cobertura Coverage Report > osmclient.cli_commands >

nfpkg.py

Trend

Classes100%
 
Lines54%
   
Conditionals100%
 

File Coverage summary

NameClassesLinesConditionals
nfpkg.py
100%
1/1
54%
116/214
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
nfpkg.py
54%
116/214
N/A

Source

osmclient/cli_commands/nfpkg.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.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 from datetime import datetime
23 1 import logging
24
25 1 logger = logging.getLogger("osmclient")
26
27
28 1 def vnfd_list(ctx, nf_type, filter, long):
29 0     logger.debug("")
30 0     if nf_type:
31 0         utils.check_client_version(ctx.obj, "--nf_type")
32 0     elif filter:
33 0         utils.check_client_version(ctx.obj, "--filter")
34 0     if filter:
35 0         filter = "&".join(filter)
36 0     if nf_type:
37 0         if nf_type == "vnf":
38 0             nf_filter = "_admin.type=vnfd"
39 0         elif nf_type == "pnf":
40 0             nf_filter = "_admin.type=pnfd"
41 0         elif nf_type == "hnf":
42 0             nf_filter = "_admin.type=hnfd"
43         else:
44 0             raise ClientException(
45                 'wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf'
46             )
47 0         if filter:
48 0             filter = "{}&{}".format(nf_filter, filter)
49         else:
50 0             filter = nf_filter
51 0     if filter:
52 0         resp = ctx.obj.vnfd.list(filter)
53     else:
54 0         resp = ctx.obj.vnfd.list()
55     # print(yaml.safe_dump(resp))
56 0     fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
57 0     if fullclassname == "osmclient.sol005.client.Client":
58 0         if long:
59 0             table = PrettyTable(
60                 [
61                     "nfpkg name",
62                     "id",
63                     "desc type",
64                     "vendor",
65                     "version",
66                     "onboarding state",
67                     "operational state",
68                     "usage state",
69                     "date",
70                     "last update",
71                 ]
72             )
73         else:
74 0             table = PrettyTable(["nfpkg name", "id", "desc type"])
75 0         for vnfd in resp:
76 0             name = vnfd.get("id", vnfd.get("name", "-"))
77 0             descriptor_type = "sol006" if "product-name" in vnfd else "rel8"
78 0             if long:
79 0                 onb_state = vnfd["_admin"].get("onboardingState", "-")
80 0                 op_state = vnfd["_admin"].get("operationalState", "-")
81 0                 vendor = vnfd.get("provider", vnfd.get("vendor"))
82 0                 version = vnfd.get("version")
83 0                 usage_state = vnfd["_admin"].get("usageState", "-")
84 0                 date = datetime.fromtimestamp(vnfd["_admin"]["created"]).strftime(
85                     "%Y-%m-%dT%H:%M:%S"
86                 )
87 0                 last_update = datetime.fromtimestamp(
88                     vnfd["_admin"]["modified"]
89                 ).strftime("%Y-%m-%dT%H:%M:%S")
90 0                 table.add_row(
91                     [
92                         name,
93                         vnfd["_id"],
94                         descriptor_type,
95                         vendor,
96                         version,
97                         onb_state,
98                         op_state,
99                         usage_state,
100                         date,
101                         last_update,
102                     ]
103                 )
104             else:
105 0                 table.add_row([name, vnfd["_id"], descriptor_type])
106     else:
107 0         table = PrettyTable(["nfpkg name", "id"])
108 0         for vnfd in resp:
109 0             table.add_row([vnfd["name"], vnfd["id"]])
110 0     table.align = "l"
111 0     print(table)
112
113
114 1 @click.command(name="vnfd-list", short_help="list all xNF packages (VNF, HNF, PNF)")
115 1 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
116 1 @click.option(
117     "--filter",
118     default=None,
119     multiple=True,
120     help="restricts the list to the NF pkg matching the filter",
121 )
122 1 @click.option("--long", is_flag=True, help="get more details")
123 1 @click.pass_context
124 1 def vnfd_list1(ctx, nf_type, filter, long):
125     """list all xNF packages (VNF, HNF, PNF)"""
126 0     logger.debug("")
127 0     vnfd_list(ctx, nf_type, filter, long)
128
129
130 1 @click.command(name="vnfpkg-list", short_help="list all xNF packages (VNF, HNF, PNF)")
131 1 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
132 1 @click.option(
133     "--filter",
134     default=None,
135     multiple=True,
136     help="restricts the list to the NFpkg matching the filter",
137 )
138 1 @click.option("--long", is_flag=True, help="get more details")
139 1 @click.pass_context
140 1 def vnfd_list2(ctx, nf_type, filter, long):
141     """list all xNF packages (VNF, HNF, PNF)"""
142 0     logger.debug("")
143 0     vnfd_list(ctx, nf_type, filter, long)
144
145
146 1 @click.command(name="nfpkg-list", short_help="list all xNF packages (VNF, HNF, PNF)")
147 1 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
148 1 @click.option(
149     "--filter",
150     default=None,
151     multiple=True,
152     help="restricts the list to the NFpkg matching the filter",
153 )
154 1 @click.option("--long", is_flag=True, help="get more details")
155 1 @click.pass_context
156 1 def nfpkg_list(ctx, nf_type, filter, long):
157     """list all xNF packages (VNF, HNF, PNF)"""
158 0     logger.debug("")
159 0     utils.check_client_version(ctx.obj, ctx.command.name)
160 0     vnfd_list(ctx, nf_type, filter, long)
161
162
163 1 def vnfd_show(ctx, name, literal):
164 0     logger.debug("")
165 0     resp = ctx.obj.vnfd.get(name)
166     # resp = ctx.obj.vnfd.get_individual(name)
167
168 0     if literal:
169 0         print(yaml.safe_dump(resp, indent=4, default_flow_style=False))
170 0         return
171
172 0     table = PrettyTable(["field", "value"])
173 0     for k, v in list(resp.items()):
174 0         table.add_row([k, utils.wrap_text(text=json.dumps(v, indent=2), width=100)])
175 0     table.align = "l"
176 0     print(table)
177
178
179 1 @click.command(name="vnfd-show", short_help="shows the details of a NF package")
180 1 @click.option("--literal", is_flag=True, help="print literally, no pretty table")
181 1 @click.argument("name")
182 1 @click.pass_context
183 1 def vnfd_show1(ctx, name, literal):
184     """shows the content of a VNFD
185
186     NAME: name or ID of the VNFD/VNFpkg
187     """
188 0     logger.debug("")
189 0     vnfd_show(ctx, name, literal)
190
191
192 1 @click.command(name="vnfpkg-show", short_help="shows the details of a NF package")
193 1 @click.option("--literal", is_flag=True, help="print literally, no pretty table")
194 1 @click.argument("name")
195 1 @click.pass_context
196 1 def vnfd_show2(ctx, name, literal):
197     """shows the content of a VNFD
198
199     NAME: name or ID of the VNFD/VNFpkg
200     """
201 0     logger.debug("")
202 0     vnfd_show(ctx, name, literal)
203
204
205 1 @click.command(name="nfpkg-show", short_help="shows the details of a NF package")
206 1 @click.option("--literal", is_flag=True, help="print literally, no pretty table")
207 1 @click.argument("name")
208 1 @click.pass_context
209 1 def nfpkg_show(ctx, name, literal):
210     """shows the content of a NF Descriptor
211
212     NAME: name or ID of the NFpkg
213     """
214 0     logger.debug("")
215 0     vnfd_show(ctx, name, literal)
216
217
218 1 def vnfd_create(
219     ctx,
220     filename,
221     overwrite,
222     skip_charm_build,
223     override_epa,
224     override_nonepa,
225     override_paravirt,
226     repo,
227     vendor,
228     version,
229 ):
230 0     logger.debug("")
231 0     utils.check_client_version(ctx.obj, ctx.command.name)
232 0     if repo:
233 0         filename = ctx.obj.osmrepo.get_pkg("vnf", filename, repo, vendor, version)
234 0     ctx.obj.vnfd.create(
235         filename,
236         overwrite=overwrite,
237         skip_charm_build=skip_charm_build,
238         override_epa=override_epa,
239         override_nonepa=override_nonepa,
240         override_paravirt=override_paravirt,
241     )
242
243
244 1 @click.command(name="vnfd-create", short_help="creates a new VNFD/VNFpkg")
245 1 @click.argument("filename")
246 1 @click.option(
247     "--overwrite", "overwrite", default=None, help="overwrite deprecated, use override"
248 )
249 1 @click.option(
250     "--override",
251     "overwrite",
252     default=None,
253     help="overrides fields in descriptor, format: "
254     '"key1.key2...=value[;key3...=value;...]"',
255 )
256 1 @click.option(
257     "--skip-charm-build",
258     default=False,
259     is_flag=True,
260     help="The charm will not be compiled, it is assumed to already exist",
261 )
262 1 @click.option(
263     "--override-epa",
264     required=False,
265     default=False,
266     is_flag=True,
267     help="adds guest-epa parameters to all VDU",
268 )
269 1 @click.option(
270     "--override-nonepa",
271     required=False,
272     default=False,
273     is_flag=True,
274     help="removes all guest-epa parameters from all VDU",
275 )
276 1 @click.option(
277     "--override-paravirt",
278     required=False,
279     default=False,
280     is_flag=True,
281     help="overrides all VDU interfaces to PARAVIRT",
282 )
283 1 @click.option("--repo", default=None, help="[repository]: Repository name")
284 1 @click.option("--vendor", default=None, help="[repository]: filter by vendor]")
285 1 @click.option(
286     "--version",
287     default="latest",
288     help="[repository]: filter by version. Default: latest",
289 )
290 1 @click.pass_context
291 1 def vnfd_create1(
292     ctx,
293     filename,
294     overwrite,
295     skip_charm_build,
296     override_epa,
297     override_nonepa,
298     override_paravirt,
299     repo,
300     vendor,
301     version,
302 ):
303     """creates a new VNFD/VNFpkg
304     \b
305     FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
306               If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
307               If FILENAME is an NF Package folder, it is built and then onboarded.
308     """
309 0     logger.debug("")
310 0     vnfd_create(
311         ctx,
312         filename,
313         overwrite=overwrite,
314         skip_charm_build=skip_charm_build,
315         override_epa=override_epa,
316         override_nonepa=override_nonepa,
317         override_paravirt=override_paravirt,
318         repo=repo,
319         vendor=vendor,
320         version=version,
321     )
322
323
324 1 @click.command(name="vnfpkg-create", short_help="creates a new VNFD/VNFpkg")
325 1 @click.argument("filename")
326 1 @click.option(
327     "--overwrite",
328     "overwrite",
329     default=None,  # hidden=True,
330     help="Deprecated. Use override",
331 )
332 1 @click.option(
333     "--override",
334     "overwrite",
335     default=None,
336     help="overrides fields in descriptor, format: "
337     '"key1.key2...=value[;key3...=value;...]"',
338 )
339 1 @click.option(
340     "--skip-charm-build",
341     default=False,
342     is_flag=True,
343     help="The charm will not be compiled, it is assumed to already exist",
344 )
345 1 @click.option(
346     "--override-epa",
347     required=False,
348     default=False,
349     is_flag=True,
350     help="adds guest-epa parameters to all VDU",
351 )
352 1 @click.option(
353     "--override-nonepa",
354     required=False,
355     default=False,
356     is_flag=True,
357     help="removes all guest-epa parameters from all VDU",
358 )
359 1 @click.option(
360     "--override-paravirt",
361     required=False,
362     default=False,
363     is_flag=True,
364     help="overrides all VDU interfaces to PARAVIRT",
365 )
366 1 @click.option("--repo", default=None, help="[repository]: Repository name")
367 1 @click.option("--vendor", default=None, help="[repository]: filter by vendor]")
368 1 @click.option(
369     "--version",
370     default="latest",
371     help="[repository]: filter by version. Default: latest",
372 )
373 1 @click.pass_context
374 1 def vnfd_create2(
375     ctx,
376     filename,
377     overwrite,
378     skip_charm_build,
379     override_epa,
380     override_nonepa,
381     override_paravirt,
382     repo,
383     vendor,
384     version,
385 ):
386     """creates a new VNFD/VNFpkg
387     \b
388     FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
389               If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
390               If FILENAME is an NF Package folder, it is built and then onboarded.
391     """
392 0     logger.debug("")
393 0     vnfd_create(
394         ctx,
395         filename,
396         overwrite=overwrite,
397         skip_charm_build=skip_charm_build,
398         override_epa=override_epa,
399         override_nonepa=override_nonepa,
400         override_paravirt=override_paravirt,
401         repo=repo,
402         vendor=vendor,
403         version=version,
404     )
405
406
407 1 @click.command(name="nfpkg-create", short_help="creates a new NFpkg")
408 1 @click.argument("filename")
409 1 @click.option(
410     "--overwrite",
411     "overwrite",
412     default=None,  # hidden=True,
413     help="Deprecated. Use override",
414 )
415 1 @click.option(
416     "--override",
417     "overwrite",
418     default=None,
419     help="overrides fields in descriptor, format: "
420     '"key1.key2...=value[;key3...=value;...]"',
421 )
422 1 @click.option(
423     "--skip-charm-build",
424     default=False,
425     is_flag=True,
426     help="The charm will not be compiled, it is assumed to already exist",
427 )
428 1 @click.option(
429     "--override-epa",
430     required=False,
431     default=False,
432     is_flag=True,
433     help="adds guest-epa parameters to all VDU",
434 )
435 1 @click.option(
436     "--override-nonepa",
437     required=False,
438     default=False,
439     is_flag=True,
440     help="removes all guest-epa parameters from all VDU",
441 )
442 1 @click.option(
443     "--override-paravirt",
444     required=False,
445     default=False,
446     is_flag=True,
447     help="overrides all VDU interfaces to PARAVIRT",
448 )
449 1 @click.option("--repo", default=None, help="[repository]: Repository name")
450 1 @click.option("--vendor", default=None, help="[repository]: filter by vendor]")
451 1 @click.option(
452     "--version",
453     default="latest",
454     help="[repository]: filter by version. Default: latest",
455 )
456 1 @click.pass_context
457 1 def nfpkg_create(
458     ctx,
459     filename,
460     overwrite,
461     skip_charm_build,
462     override_epa,
463     override_nonepa,
464     override_paravirt,
465     repo,
466     vendor,
467     version,
468 ):
469     """creates a new NFpkg
470
471     \b
472     FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
473               If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
474               If FILENAME is an NF Package folder, it is built and then onboarded.
475     """
476 0     logger.debug("")
477 0     vnfd_create(
478         ctx,
479         filename,
480         overwrite=overwrite,
481         skip_charm_build=skip_charm_build,
482         override_epa=override_epa,
483         override_nonepa=override_nonepa,
484         override_paravirt=override_paravirt,
485         repo=repo,
486         vendor=vendor,
487         version=version,
488     )
489
490
491 1 def vnfd_update(ctx, name, content):
492 0     logger.debug("")
493 0     utils.check_client_version(ctx.obj, ctx.command.name)
494 0     ctx.obj.vnfd.update(name, content)
495
496
497 1 @click.command(name="vnfd-update", short_help="updates a new VNFD/VNFpkg")
498 1 @click.argument("name")
499 1 @click.option(
500     "--content",
501     default=None,
502     help="filename with the VNFD/VNFpkg replacing the current one",
503 )
504 1 @click.pass_context
505 1 def vnfd_update1(ctx, name, content):
506     """updates a VNFD/VNFpkg
507
508     NAME: name or ID of the VNFD/VNFpkg
509     """
510 0     logger.debug("")
511 0     vnfd_update(ctx, name, content)
512
513
514 1 @click.command(name="vnfpkg-update", short_help="updates a VNFD/VNFpkg")
515 1 @click.argument("name")
516 1 @click.option(
517     "--content",
518     default=None,
519     help="filename with the VNFD/VNFpkg replacing the current one",
520 )
521 1 @click.pass_context
522 1 def vnfd_update2(ctx, name, content):
523     """updates a VNFD/VNFpkg
524
525     NAME: VNFD yaml file or VNFpkg tar.gz file
526     """
527 0     logger.debug("")
528 0     vnfd_update(ctx, name, content)
529
530
531 1 @click.command(name="nfpkg-update", short_help="updates a NFpkg")
532 1 @click.argument("name")
533 1 @click.option(
534     "--content", default=None, help="filename with the NFpkg replacing the current one"
535 )
536 1 @click.pass_context
537 1 def nfpkg_update(ctx, name, content):
538     """updates a NFpkg
539
540     NAME: NF Descriptor yaml file or NFpkg tar.gz file
541     """
542 0     logger.debug("")
543 0     vnfd_update(ctx, name, content)
544
545
546 1 def vnfd_delete(ctx, name, force):
547 0     logger.debug("")
548 0     if not force:
549 0         ctx.obj.vnfd.delete(name)
550     else:
551 0         utils.check_client_version(ctx.obj, "--force")
552 0         ctx.obj.vnfd.delete(name, force)
553
554
555 1 @click.command(name="vnfd-delete", short_help="deletes a VNFD/VNFpkg")
556 1 @click.argument("name")
557 1 @click.option(
558     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
559 )
560 1 @click.pass_context
561 1 def vnfd_delete1(ctx, name, force):
562     """deletes a VNFD/VNFpkg
563
564     NAME: name or ID of the VNFD/VNFpkg to be deleted
565     """
566 0     logger.debug("")
567 0     vnfd_delete(ctx, name, force)
568
569
570 1 @click.command(name="vnfpkg-delete", short_help="deletes a VNFD/VNFpkg")
571 1 @click.argument("name")
572 1 @click.option(
573     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
574 )
575 1 @click.pass_context
576 1 def vnfd_delete2(ctx, name, force):
577     """deletes a VNFD/VNFpkg
578
579     NAME: name or ID of the VNFD/VNFpkg to be deleted
580     """
581 0     logger.debug("")
582 0     vnfd_delete(ctx, name, force)
583
584
585 1 @click.command(name="nfpkg-delete", short_help="deletes a NFpkg")
586 1 @click.argument("name")
587 1 @click.option(
588     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
589 )
590 1 @click.pass_context
591 1 def nfpkg_delete(ctx, name, force):
592     """deletes a NFpkg
593
594     NAME: name or ID of the NFpkg to be deleted
595     """
596 0     logger.debug("")
597 0     vnfd_delete(ctx, name, force)