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))
36 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
37 if fullclassname
== "osmclient.sol005.client.Client":
51 table
= PrettyTable(["nsd name", "id"])
53 name
= nsd
.get("id", "-")
55 onb_state
= nsd
["_admin"].get("onboardingState", "-")
56 op_state
= nsd
["_admin"].get("operationalState", "-")
57 usage_state
= nsd
["_admin"].get("usageState", "-")
58 date
= datetime
.fromtimestamp(nsd
["_admin"]["created"]).strftime(
61 last_update
= datetime
.fromtimestamp(
62 nsd
["_admin"]["modified"]
63 ).strftime("%Y-%m-%dT%H:%M:%S")
76 table
.add_row([name
, nsd
["_id"]])
78 table
= PrettyTable(["nsd name", "id"])
80 table
.add_row([nsd
["name"], nsd
["id"]])
85 @click.command(name
="nsd-list", short_help
="list all NS packages")
90 help="restricts the list to the NSD/NSpkg matching the filter",
92 @click.option("--long", is_flag
=True, help="get more details")
94 def nsd_list1(ctx
, filter, long):
95 """list all NSD/NS pkg in the system"""
97 nsd_list(ctx
, filter, long)
100 @click.command(name
="nspkg-list", short_help
="list all NS packages")
105 help="restricts the list to the NSD/NSpkg matching the filter",
107 @click.option("--long", is_flag
=True, help="get more details")
109 def nsd_list2(ctx
, filter, long):
110 """list all NS packages"""
112 nsd_list(ctx
, filter, long)
115 def nsd_show(ctx
, name
, literal
):
117 resp
= ctx
.obj
.nsd
.get(name
)
118 # resp = ctx.obj.nsd.get_individual(name)
121 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
124 table
= PrettyTable(["field", "value"])
125 for k
, v
in list(resp
.items()):
126 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])
131 @click.command(name
="nsd-show", short_help
="shows the details of a NS package")
132 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
133 @click.argument("name")
135 def nsd_show1(ctx
, name
, literal
):
136 """shows the content of a NSD
138 NAME: name or ID of the NSD/NSpkg
141 nsd_show(ctx
, name
, literal
)
144 @click.command(name
="nspkg-show", short_help
="shows the details of a NS package")
145 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
146 @click.argument("name")
148 def nsd_show2(ctx
, name
, literal
):
149 """shows the content of a NSD
151 NAME: name or ID of the NSD/NSpkg
154 nsd_show(ctx
, name
, literal
)
157 def nsd_create(ctx
, filename
, overwrite
, skip_charm_build
, repo
, vendor
, version
):
159 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
161 filename
= ctx
.obj
.osmrepo
.get_pkg("ns", filename
, repo
, vendor
, version
)
162 ctx
.obj
.nsd
.create(filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
)
165 @click.command(name
="nsd-create", short_help
="creates a new NSD/NSpkg")
166 @click.argument("filename")
170 default
=None, # hidden=True,
171 help="Deprecated. Use override",
177 help="overrides fields in descriptor, format: "
178 '"key1.key2...=value[;key3...=value;...]"',
181 "--skip-charm-build",
184 help="The charm will not be compiled, it is assumed to already exist",
186 @click.option("--repo", default
=None, help="[repository]: Repository name")
187 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
191 help="[repository]: filter by version. Default: latest",
194 def nsd_create1(ctx
, filename
, overwrite
, skip_charm_build
, repo
, vendor
, version
):
195 """onboards a new NSpkg (alias of nspkg-create) (TO BE DEPRECATED)
198 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
199 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
200 If FILENAME is an NF Package folder, it is built and then onboarded.
207 skip_charm_build
=skip_charm_build
,
214 @click.command(name
="nspkg-create", short_help
="creates a new NSD/NSpkg")
215 @click.argument("filename")
219 default
=None, # hidden=True,
220 help="Deprecated. Use override",
226 help="overrides fields in descriptor, format: "
227 '"key1.key2...=value[;key3...=value;...]"',
230 "--skip-charm-build",
233 help="The charm will not be compiled, it is assumed to already exist",
235 @click.option("--repo", default
=None, help="[repository]: Repository name")
236 @click.option("--vendor", default
=None, help="[repository]: filter by vendor]")
240 help="[repository]: filter by version. Default: latest",
243 def nsd_create2(ctx
, filename
, overwrite
, skip_charm_build
, repo
, vendor
, version
):
244 """onboards a new NSpkg
246 FILENAME: NF Package tar.gz file, NF Descriptor YAML file or NF Package folder
247 If FILENAME is a file (NF Package tar.gz or NF Descriptor YAML), it is onboarded.
248 If FILENAME is an NF Package folder, it is built and then onboarded.
255 skip_charm_build
=skip_charm_build
,
262 def nsd_update(ctx
, name
, content
):
264 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
265 ctx
.obj
.nsd
.update(name
, content
)
268 @click.command(name
="nsd-update", short_help
="updates a NSD/NSpkg")
269 @click.argument("name")
273 help="filename with the NSD/NSpkg replacing the current one",
276 def nsd_update1(ctx
, name
, content
):
277 """updates a NSD/NSpkg
279 NAME: name or ID of the NSD/NSpkg
282 nsd_update(ctx
, name
, content
)
285 @click.command(name
="nspkg-update", short_help
="updates a NSD/NSpkg")
286 @click.argument("name")
290 help="filename with the NSD/NSpkg replacing the current one",
293 def nsd_update2(ctx
, name
, content
):
294 """updates a NSD/NSpkg
296 NAME: name or ID of the NSD/NSpkg
299 nsd_update(ctx
, name
, content
)
302 def nsd_delete(ctx
, name
, force
):
305 ctx
.obj
.nsd
.delete(name
)
307 utils
.check_client_version(ctx
.obj
, "--force")
308 ctx
.obj
.nsd
.delete(name
, force
)
311 @click.command(name
="nsd-delete", short_help
="deletes a NSD/NSpkg")
312 @click.argument("name")
314 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
317 def nsd_delete1(ctx
, name
, force
):
318 """deletes a NSD/NSpkg
320 NAME: name or ID of the NSD/NSpkg to be deleted
323 nsd_delete(ctx
, name
, force
)
326 @click.command(name
="nspkg-delete", short_help
="deletes a NSD/NSpkg")
327 @click.argument("name")
329 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
332 def nsd_delete2(ctx
, name
, force
):
333 """deletes a NSD/NSpkg
335 NAME: name or ID of the NSD/NSpkg to be deleted
338 nsd_delete(ctx
, name
, force
)