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
.common
.exceptions
import ClientException
18 from osmclient
.cli_commands
import utils
19 from prettytable
import PrettyTable
22 from datetime
import datetime
25 logger
= logging
.getLogger("osmclient")
28 def vnfd_list(ctx
, nf_type
, filter, long):
31 utils
.check_client_version(ctx
.obj
, "--nf_type")
33 utils
.check_client_version(ctx
.obj
, "--filter")
35 filter = "&".join(filter)
38 nf_filter
= "_admin.type=vnfd"
39 elif nf_type
== "pnf":
40 nf_filter
= "_admin.type=pnfd"
41 elif nf_type
== "hnf":
42 nf_filter
= "_admin.type=hnfd"
44 raise ClientException(
45 'wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf'
48 filter = "{}&{}".format(nf_filter
, filter)
52 resp
= ctx
.obj
.vnfd
.list(filter)
54 resp
= ctx
.obj
.vnfd
.list()
55 # print(yaml.safe_dump(resp))
72 table
= PrettyTable(["nfpkg name", "id", "desc type"])
74 name
= vnfd
.get("id", vnfd
.get("name", "-"))
75 descriptor_type
= "sol006" if "product-name" in vnfd
else "rel8"
77 onb_state
= vnfd
["_admin"].get("onboardingState", "-")
78 op_state
= vnfd
["_admin"].get("operationalState", "-")
79 vendor
= vnfd
.get("provider", vnfd
.get("vendor"))
80 version
= vnfd
.get("version")
81 usage_state
= vnfd
["_admin"].get("usageState", "-")
82 date
= datetime
.fromtimestamp(vnfd
["_admin"]["created"]).strftime(
85 last_update
= datetime
.fromtimestamp(vnfd
["_admin"]["modified"]).strftime(
103 table
.add_row([name
, vnfd
["_id"], descriptor_type
])
108 @click.command(name
="vnfd-list", short_help
="list all xNF packages (VNF, HNF, PNF)")
109 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
114 help="restricts the list to the NF pkg matching the filter",
116 @click.option("--long", is_flag
=True, help="get more details")
118 def vnfd_list1(ctx
, nf_type
, filter, long):
119 """list all xNF packages (VNF, HNF, PNF)"""
121 vnfd_list(ctx
, nf_type
, filter, long)
124 @click.command(name
="vnfpkg-list", short_help
="list all xNF packages (VNF, HNF, PNF)")
125 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
130 help="restricts the list to the NFpkg matching the filter",
132 @click.option("--long", is_flag
=True, help="get more details")
134 def vnfd_list2(ctx
, nf_type
, filter, long):
135 """list all xNF packages (VNF, HNF, PNF)"""
137 vnfd_list(ctx
, nf_type
, filter, long)
140 @click.command(name
="nfpkg-list", short_help
="list all xNF packages (VNF, HNF, PNF)")
141 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
146 help="restricts the list to the NFpkg matching the filter",
148 @click.option("--long", is_flag
=True, help="get more details")
150 def nfpkg_list(ctx
, nf_type
, filter, long):
151 """list all xNF packages (VNF, HNF, PNF)"""
153 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
154 vnfd_list(ctx
, nf_type
, filter, long)
157 def vnfd_show(ctx
, name
, literal
):
159 resp
= ctx
.obj
.vnfd
.get(name
)
160 # resp = ctx.obj.vnfd.get_individual(name)
163 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
166 table
= PrettyTable(["field", "value"])
167 for k
, v
in list(resp
.items()):
168 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])
173 @click.command(name
="vnfd-show", short_help
="shows the details of a NF package")
174 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
175 @click.argument("name")
177 def vnfd_show1(ctx
, name
, literal
):
178 """shows the content of a VNFD
180 NAME: name or ID of the VNFD/VNFpkg
183 vnfd_show(ctx
, name
, literal
)
186 @click.command(name
="vnfpkg-show", short_help
="shows the details of a NF package")
187 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
188 @click.argument("name")
190 def vnfd_show2(ctx
, name
, literal
):
191 """shows the content of a VNFD
193 NAME: name or ID of the VNFD/VNFpkg
196 vnfd_show(ctx
, name
, literal
)
199 @click.command(name
="nfpkg-show", short_help
="shows the details of a NF package")
200 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
201 @click.argument("name")
203 def nfpkg_show(ctx
, name
, literal
):
204 """shows the content of a NF Descriptor
206 NAME: name or ID of the NFpkg
209 vnfd_show(ctx
, name
, literal
)
225 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
227 filename
= ctx
.obj
.osmrepo
.get_pkg("vnf", filename
, repo
, vendor
, version
)
231 skip_charm_build
=skip_charm_build
,
232 override_epa
=override_epa
,
233 override_nonepa
=override_nonepa
,
234 override_paravirt
=override_paravirt
,
238 @click.command(name
="vnfd-create", short_help
="creates a new VNFD/VNFpkg")
239 @click.argument("filename")
241 "--overwrite", "overwrite", default
=None, help="overwrite deprecated, use override"
247 help="overrides fields in descriptor, format: "
248 '"key1.key2...=value[;key3...=value;...]"',
251 "--skip-charm-build",
254 help="The charm will not be compiled, it is assumed to already exist",
261 help="adds guest-epa parameters to all VDU",
268 help="removes all guest-epa parameters from all VDU",
271 "--override-paravirt",
275 help="overrides all VDU interfaces to PARAVIRT",
277 @click.option("--repo", default
=None, help="[repository]: Repository name")
278 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
282 help="[repository]: filter by version. Default: latest",
297 """creates a new VNFD/VNFpkg
299 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
300 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
301 If FILENAME is an NF Package folder, it is built and then onboarded.
308 skip_charm_build
=skip_charm_build
,
309 override_epa
=override_epa
,
310 override_nonepa
=override_nonepa
,
311 override_paravirt
=override_paravirt
,
318 @click.command(name
="vnfpkg-create", short_help
="creates a new VNFD/VNFpkg")
319 @click.argument("filename")
323 default
=None, # hidden=True,
324 help="Deprecated. Use override",
330 help="overrides fields in descriptor, format: "
331 '"key1.key2...=value[;key3...=value;...]"',
334 "--skip-charm-build",
337 help="The charm will not be compiled, it is assumed to already exist",
344 help="adds guest-epa parameters to all VDU",
351 help="removes all guest-epa parameters from all VDU",
354 "--override-paravirt",
358 help="overrides all VDU interfaces to PARAVIRT",
360 @click.option("--repo", default
=None, help="[repository]: Repository name")
361 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
365 help="[repository]: filter by version. Default: latest",
380 """creates a new VNFD/VNFpkg
382 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
383 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
384 If FILENAME is an NF Package folder, it is built and then onboarded.
391 skip_charm_build
=skip_charm_build
,
392 override_epa
=override_epa
,
393 override_nonepa
=override_nonepa
,
394 override_paravirt
=override_paravirt
,
401 @click.command(name
="nfpkg-create", short_help
="creates a new NFpkg")
402 @click.argument("filename")
406 default
=None, # hidden=True,
407 help="Deprecated. Use override",
413 help="overrides fields in descriptor, format: "
414 '"key1.key2...=value[;key3...=value;...]"',
417 "--skip-charm-build",
420 help="The charm will not be compiled, it is assumed to already exist",
427 help="adds guest-epa parameters to all VDU",
434 help="removes all guest-epa parameters from all VDU",
437 "--override-paravirt",
441 help="overrides all VDU interfaces to PARAVIRT",
443 @click.option("--repo", default
=None, help="[repository]: Repository name")
444 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
448 help="[repository]: filter by version. Default: latest",
463 """creates a new NFpkg
466 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
467 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
468 If FILENAME is an NF Package folder, it is built and then onboarded.
475 skip_charm_build
=skip_charm_build
,
476 override_epa
=override_epa
,
477 override_nonepa
=override_nonepa
,
478 override_paravirt
=override_paravirt
,
485 def vnfd_update(ctx
, name
, content
):
487 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
488 ctx
.obj
.vnfd
.update(name
, content
)
491 @click.command(name
="vnfd-update", short_help
="updates a new VNFD/VNFpkg")
492 @click.argument("name")
496 help="filename with the VNFD/VNFpkg replacing the current one",
499 def vnfd_update1(ctx
, name
, content
):
500 """updates a VNFD/VNFpkg
502 NAME: name or ID of the VNFD/VNFpkg
505 vnfd_update(ctx
, name
, content
)
508 @click.command(name
="vnfpkg-update", short_help
="updates a VNFD/VNFpkg")
509 @click.argument("name")
513 help="filename with the VNFD/VNFpkg replacing the current one",
516 def vnfd_update2(ctx
, name
, content
):
517 """updates a VNFD/VNFpkg
519 NAME: VNFD yaml file or VNFpkg tar.gz file
522 vnfd_update(ctx
, name
, content
)
525 @click.command(name
="nfpkg-update", short_help
="updates a NFpkg")
526 @click.argument("name")
528 "--content", default
=None, help="filename with the NFpkg replacing the current one"
531 def nfpkg_update(ctx
, name
, content
):
534 NAME: NF Descriptor yaml file or NFpkg tar.gz file
537 vnfd_update(ctx
, name
, content
)
540 def vnfd_delete(ctx
, name
, force
):
543 ctx
.obj
.vnfd
.delete(name
)
545 utils
.check_client_version(ctx
.obj
, "--force")
546 ctx
.obj
.vnfd
.delete(name
, force
)
549 @click.command(name
="vnfd-delete", short_help
="deletes a VNFD/VNFpkg")
550 @click.argument("name")
552 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
555 def vnfd_delete1(ctx
, name
, force
):
556 """deletes a VNFD/VNFpkg
558 NAME: name or ID of the VNFD/VNFpkg to be deleted
561 vnfd_delete(ctx
, name
, force
)
564 @click.command(name
="vnfpkg-delete", short_help
="deletes a VNFD/VNFpkg")
565 @click.argument("name")
567 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
570 def vnfd_delete2(ctx
, name
, force
):
571 """deletes a VNFD/VNFpkg
573 NAME: name or ID of the VNFD/VNFpkg to be deleted
576 vnfd_delete(ctx
, name
, force
)
579 @click.command(name
="nfpkg-delete", short_help
="deletes a NFpkg")
580 @click.argument("name")
582 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
585 def nfpkg_delete(ctx
, name
, force
):
588 NAME: name or ID of the NFpkg to be deleted
591 vnfd_delete(ctx
, name
, force
)