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))
56 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
57 if fullclassname
== "osmclient.sol005.client.Client":
74 table
= PrettyTable(["nfpkg name", "id", "desc type"])
76 name
= vnfd
.get("id", vnfd
.get("name", "-"))
77 descriptor_type
= "sol006" if "product-name" in vnfd
else "rel8"
79 onb_state
= vnfd
["_admin"].get("onboardingState", "-")
80 op_state
= vnfd
["_admin"].get("operationalState", "-")
81 vendor
= vnfd
.get("provider", vnfd
.get("vendor"))
82 version
= vnfd
.get("version")
83 usage_state
= vnfd
["_admin"].get("usageState", "-")
84 date
= datetime
.fromtimestamp(vnfd
["_admin"]["created"]).strftime(
87 last_update
= datetime
.fromtimestamp(
88 vnfd
["_admin"]["modified"]
89 ).strftime("%Y-%m-%dT%H:%M:%S")
105 table
.add_row([name
, vnfd
["_id"], descriptor_type
])
107 table
= PrettyTable(["nfpkg name", "id"])
109 table
.add_row([vnfd
["name"], vnfd
["id"]])
114 @click.command(name
="vnfd-list", short_help
="list all xNF packages (VNF, HNF, PNF)")
115 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
120 help="restricts the list to the NF pkg matching the filter",
122 @click.option("--long", is_flag
=True, help="get more details")
124 def vnfd_list1(ctx
, nf_type
, filter, long):
125 """list all xNF packages (VNF, HNF, PNF)"""
127 vnfd_list(ctx
, nf_type
, filter, long)
130 @click.command(name
="vnfpkg-list", short_help
="list all xNF packages (VNF, HNF, PNF)")
131 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
136 help="restricts the list to the NFpkg matching the filter",
138 @click.option("--long", is_flag
=True, help="get more details")
140 def vnfd_list2(ctx
, nf_type
, filter, long):
141 """list all xNF packages (VNF, HNF, PNF)"""
143 vnfd_list(ctx
, nf_type
, filter, long)
146 @click.command(name
="nfpkg-list", short_help
="list all xNF packages (VNF, HNF, PNF)")
147 @click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
152 help="restricts the list to the NFpkg matching the filter",
154 @click.option("--long", is_flag
=True, help="get more details")
156 def nfpkg_list(ctx
, nf_type
, filter, long):
157 """list all xNF packages (VNF, HNF, PNF)"""
159 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
160 vnfd_list(ctx
, nf_type
, filter, long)
163 def vnfd_show(ctx
, name
, literal
):
165 resp
= ctx
.obj
.vnfd
.get(name
)
166 # resp = ctx.obj.vnfd.get_individual(name)
169 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
172 table
= PrettyTable(["field", "value"])
173 for k
, v
in list(resp
.items()):
174 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])
179 @click.command(name
="vnfd-show", short_help
="shows the details of a NF package")
180 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
181 @click.argument("name")
183 def vnfd_show1(ctx
, name
, literal
):
184 """shows the content of a VNFD
186 NAME: name or ID of the VNFD/VNFpkg
189 vnfd_show(ctx
, name
, literal
)
192 @click.command(name
="vnfpkg-show", short_help
="shows the details of a NF package")
193 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
194 @click.argument("name")
196 def vnfd_show2(ctx
, name
, literal
):
197 """shows the content of a VNFD
199 NAME: name or ID of the VNFD/VNFpkg
202 vnfd_show(ctx
, name
, literal
)
205 @click.command(name
="nfpkg-show", short_help
="shows the details of a NF package")
206 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
207 @click.argument("name")
209 def nfpkg_show(ctx
, name
, literal
):
210 """shows the content of a NF Descriptor
212 NAME: name or ID of the NFpkg
215 vnfd_show(ctx
, name
, literal
)
231 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
233 filename
= ctx
.obj
.osmrepo
.get_pkg("vnf", filename
, repo
, vendor
, version
)
237 skip_charm_build
=skip_charm_build
,
238 override_epa
=override_epa
,
239 override_nonepa
=override_nonepa
,
240 override_paravirt
=override_paravirt
,
244 @click.command(name
="vnfd-create", short_help
="creates a new VNFD/VNFpkg")
245 @click.argument("filename")
247 "--overwrite", "overwrite", default
=None, help="overwrite deprecated, use override"
253 help="overrides fields in descriptor, format: "
254 '"key1.key2...=value[;key3...=value;...]"',
257 "--skip-charm-build",
260 help="The charm will not be compiled, it is assumed to already exist",
267 help="adds guest-epa parameters to all VDU",
274 help="removes all guest-epa parameters from all VDU",
277 "--override-paravirt",
281 help="overrides all VDU interfaces to PARAVIRT",
283 @click.option("--repo", default
=None, help="[repository]: Repository name")
284 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
288 help="[repository]: filter by version. Default: latest",
303 """creates a new VNFD/VNFpkg
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.
314 skip_charm_build
=skip_charm_build
,
315 override_epa
=override_epa
,
316 override_nonepa
=override_nonepa
,
317 override_paravirt
=override_paravirt
,
324 @click.command(name
="vnfpkg-create", short_help
="creates a new VNFD/VNFpkg")
325 @click.argument("filename")
329 default
=None, # hidden=True,
330 help="Deprecated. Use override",
336 help="overrides fields in descriptor, format: "
337 '"key1.key2...=value[;key3...=value;...]"',
340 "--skip-charm-build",
343 help="The charm will not be compiled, it is assumed to already exist",
350 help="adds guest-epa parameters to all VDU",
357 help="removes all guest-epa parameters from all VDU",
360 "--override-paravirt",
364 help="overrides all VDU interfaces to PARAVIRT",
366 @click.option("--repo", default
=None, help="[repository]: Repository name")
367 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
371 help="[repository]: filter by version. Default: latest",
386 """creates a new VNFD/VNFpkg
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.
397 skip_charm_build
=skip_charm_build
,
398 override_epa
=override_epa
,
399 override_nonepa
=override_nonepa
,
400 override_paravirt
=override_paravirt
,
407 @click.command(name
="nfpkg-create", short_help
="creates a new NFpkg")
408 @click.argument("filename")
412 default
=None, # hidden=True,
413 help="Deprecated. Use override",
419 help="overrides fields in descriptor, format: "
420 '"key1.key2...=value[;key3...=value;...]"',
423 "--skip-charm-build",
426 help="The charm will not be compiled, it is assumed to already exist",
433 help="adds guest-epa parameters to all VDU",
440 help="removes all guest-epa parameters from all VDU",
443 "--override-paravirt",
447 help="overrides all VDU interfaces to PARAVIRT",
449 @click.option("--repo", default
=None, help="[repository]: Repository name")
450 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
454 help="[repository]: filter by version. Default: latest",
469 """creates a new NFpkg
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.
481 skip_charm_build
=skip_charm_build
,
482 override_epa
=override_epa
,
483 override_nonepa
=override_nonepa
,
484 override_paravirt
=override_paravirt
,
491 def vnfd_update(ctx
, name
, content
):
493 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
494 ctx
.obj
.vnfd
.update(name
, content
)
497 @click.command(name
="vnfd-update", short_help
="updates a new VNFD/VNFpkg")
498 @click.argument("name")
502 help="filename with the VNFD/VNFpkg replacing the current one",
505 def vnfd_update1(ctx
, name
, content
):
506 """updates a VNFD/VNFpkg
508 NAME: name or ID of the VNFD/VNFpkg
511 vnfd_update(ctx
, name
, content
)
514 @click.command(name
="vnfpkg-update", short_help
="updates a VNFD/VNFpkg")
515 @click.argument("name")
519 help="filename with the VNFD/VNFpkg replacing the current one",
522 def vnfd_update2(ctx
, name
, content
):
523 """updates a VNFD/VNFpkg
525 NAME: VNFD yaml file or VNFpkg tar.gz file
528 vnfd_update(ctx
, name
, content
)
531 @click.command(name
="nfpkg-update", short_help
="updates a NFpkg")
532 @click.argument("name")
534 "--content", default
=None, help="filename with the NFpkg replacing the current one"
537 def nfpkg_update(ctx
, name
, content
):
540 NAME: NF Descriptor yaml file or NFpkg tar.gz file
543 vnfd_update(ctx
, name
, content
)
546 def vnfd_delete(ctx
, name
, force
):
549 ctx
.obj
.vnfd
.delete(name
)
551 utils
.check_client_version(ctx
.obj
, "--force")
552 ctx
.obj
.vnfd
.delete(name
, force
)
555 @click.command(name
="vnfd-delete", short_help
="deletes a VNFD/VNFpkg")
556 @click.argument("name")
558 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
561 def vnfd_delete1(ctx
, name
, force
):
562 """deletes a VNFD/VNFpkg
564 NAME: name or ID of the VNFD/VNFpkg to be deleted
567 vnfd_delete(ctx
, name
, force
)
570 @click.command(name
="vnfpkg-delete", short_help
="deletes a VNFD/VNFpkg")
571 @click.argument("name")
573 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
576 def vnfd_delete2(ctx
, name
, force
):
577 """deletes a VNFD/VNFpkg
579 NAME: name or ID of the VNFD/VNFpkg to be deleted
582 vnfd_delete(ctx
, name
, force
)
585 @click.command(name
="nfpkg-delete", short_help
="deletes a NFpkg")
586 @click.argument("name")
588 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
591 def nfpkg_delete(ctx
, name
, force
):
594 NAME: name or ID of the NFpkg to be deleted
597 vnfd_delete(ctx
, name
, force
)