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
.cli_commands
import utils
18 from prettytable
import PrettyTable
21 from datetime
import datetime
24 logger
= logging
.getLogger("osmclient")
27 def nsd_list(ctx
, filter, long):
30 utils
.check_client_version(ctx
.obj
, "--filter")
31 filter = "&".join(filter)
32 resp
= ctx
.obj
.nsd
.list(filter)
34 resp
= ctx
.obj
.nsd
.list()
35 # print(yaml.safe_dump(resp))
49 table
= PrettyTable(["nsd name", "id"])
51 name
= nsd
.get("id", "-")
53 onb_state
= nsd
["_admin"].get("onboardingState", "-")
54 op_state
= nsd
["_admin"].get("operationalState", "-")
55 usage_state
= nsd
["_admin"].get("usageState", "-")
56 date
= datetime
.fromtimestamp(nsd
["_admin"]["created"]).strftime(
59 last_update
= datetime
.fromtimestamp(nsd
["_admin"]["modified"]).strftime(
74 table
.add_row([name
, nsd
["_id"]])
79 @click.command(name
="nsd-list", short_help
="list all NS packages")
84 help="restricts the list to the NSD/NSpkg matching the filter",
86 @click.option("--long", is_flag
=True, help="get more details")
88 def nsd_list1(ctx
, filter, long):
89 """list all NSD/NS pkg in the system"""
91 nsd_list(ctx
, filter, long)
94 @click.command(name
="nspkg-list", short_help
="list all NS packages")
99 help="restricts the list to the NSD/NSpkg matching the filter",
101 @click.option("--long", is_flag
=True, help="get more details")
103 def nsd_list2(ctx
, filter, long):
104 """list all NS packages"""
106 nsd_list(ctx
, filter, long)
109 def nsd_show(ctx
, name
, literal
):
111 resp
= ctx
.obj
.nsd
.get(name
)
112 # resp = ctx.obj.nsd.get_individual(name)
115 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
118 table
= PrettyTable(["field", "value"])
119 for k
, v
in list(resp
.items()):
120 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])
125 @click.command(name
="nsd-show", short_help
="shows the details of a NS package")
126 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
127 @click.argument("name")
129 def nsd_show1(ctx
, name
, literal
):
130 """shows the content of a NSD
132 NAME: name or ID of the NSD/NSpkg
135 nsd_show(ctx
, name
, literal
)
138 @click.command(name
="nspkg-show", short_help
="shows the details of a NS package")
139 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
140 @click.argument("name")
142 def nsd_show2(ctx
, name
, literal
):
143 """shows the content of a NSD
145 NAME: name or ID of the NSD/NSpkg
148 nsd_show(ctx
, name
, literal
)
151 def nsd_create(ctx
, filename
, overwrite
, skip_charm_build
, repo
, vendor
, version
):
153 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
155 filename
= ctx
.obj
.osmrepo
.get_pkg("ns", filename
, repo
, vendor
, version
)
156 ctx
.obj
.nsd
.create(filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
)
159 @click.command(name
="nsd-create", short_help
="creates a new NSD/NSpkg")
160 @click.argument("filename")
164 default
=None, # hidden=True,
165 help="Deprecated. Use override",
171 help="overrides fields in descriptor, format: "
172 '"key1.key2...=value[;key3...=value;...]"',
175 "--skip-charm-build",
178 help="The charm will not be compiled, it is assumed to already exist",
180 @click.option("--repo", default
=None, help="[repository]: Repository name")
181 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
185 help="[repository]: filter by version. Default: latest",
188 def nsd_create1(ctx
, filename
, overwrite
, skip_charm_build
, repo
, vendor
, version
):
189 """onboards a new NSpkg (alias of nspkg-create) (TO BE DEPRECATED)
192 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
193 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
194 If FILENAME is an NF Package folder, it is built and then onboarded.
201 skip_charm_build
=skip_charm_build
,
208 @click.command(name
="nspkg-create", short_help
="creates a new NSD/NSpkg")
209 @click.argument("filename")
213 default
=None, # hidden=True,
214 help="Deprecated. Use override",
220 help="overrides fields in descriptor, format: "
221 '"key1.key2...=value[;key3...=value;...]"',
224 "--skip-charm-build",
227 help="The charm will not be compiled, it is assumed to already exist",
229 @click.option("--repo", default
=None, help="[repository]: Repository name")
230 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
234 help="[repository]: filter by version. Default: latest",
237 def nsd_create2(ctx
, filename
, overwrite
, skip_charm_build
, repo
, vendor
, version
):
238 """onboards a new NSpkg
240 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
241 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
242 If FILENAME is an NF Package folder, it is built and then onboarded.
249 skip_charm_build
=skip_charm_build
,
256 def nsd_update(ctx
, name
, content
):
258 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
259 ctx
.obj
.nsd
.update(name
, content
)
262 @click.command(name
="nsd-update", short_help
="updates a NSD/NSpkg")
263 @click.argument("name")
267 help="filename with the NSD/NSpkg replacing the current one",
270 def nsd_update1(ctx
, name
, content
):
271 """updates a NSD/NSpkg
273 NAME: name or ID of the NSD/NSpkg
276 nsd_update(ctx
, name
, content
)
279 @click.command(name
="nspkg-update", short_help
="updates a NSD/NSpkg")
280 @click.argument("name")
284 help="filename with the NSD/NSpkg replacing the current one",
287 def nsd_update2(ctx
, name
, content
):
288 """updates a NSD/NSpkg
290 NAME: name or ID of the NSD/NSpkg
293 nsd_update(ctx
, name
, content
)
296 def nsd_delete(ctx
, name
, force
):
299 ctx
.obj
.nsd
.delete(name
)
301 utils
.check_client_version(ctx
.obj
, "--force")
302 ctx
.obj
.nsd
.delete(name
, force
)
305 @click.command(name
="nsd-delete", short_help
="deletes a NSD/NSpkg")
306 @click.argument("name")
308 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
311 def nsd_delete1(ctx
, name
, force
):
312 """deletes a NSD/NSpkg
314 NAME: name or ID of the NSD/NSpkg to be deleted
317 nsd_delete(ctx
, name
, force
)
320 @click.command(name
="nspkg-delete", short_help
="deletes a NSD/NSpkg")
321 @click.argument("name")
323 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
326 def nsd_delete2(ctx
, name
, force
):
327 """deletes a NSD/NSpkg
329 NAME: name or ID of the NSD/NSpkg to be deleted
332 nsd_delete(ctx
, name
, force
)