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
23 logger
= logging
.getLogger("osmclient")
26 def nst_list(ctx
, filter):
28 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
30 filter = "&".join(filter)
31 resp
= ctx
.obj
.nst
.list(filter)
32 table
= PrettyTable(["nst name", "id"])
34 name
= nst
["name"] if "name" in nst
else "-"
35 table
.add_row([name
, nst
["_id"]])
40 @click.command(name
="nst-list", short_help
="list all Network Slice Templates (NST)")
45 help="restricts the list to the NST matching the filter",
48 def nst_list1(ctx
, filter):
49 """list all Network Slice Templates (NST) in the system"""
55 name
="netslice-template-list", short_help
="list all Network Slice Templates (NST)"
61 help="restricts the list to the NST matching the filter",
64 def nst_list2(ctx
, filter):
65 """list all Network Slice Templates (NST) in the system"""
70 def nst_show(ctx
, name
, literal
):
72 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
73 resp
= ctx
.obj
.nst
.get(name
)
74 # resp = ctx.obj.nst.get_individual(name)
77 print(yaml
.safe_dump(resp
, indent
=4, default_flow_style
=False))
80 table
= PrettyTable(["field", "value"])
81 for k
, v
in list(resp
.items()):
82 table
.add_row([k
, utils
.wrap_text(json
.dumps(v
, indent
=2), 100)])
88 name
="nst-show", short_help
="shows the content of a Network Slice Template (NST)"
90 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
91 @click.argument("name")
93 def nst_show1(ctx
, name
, literal
):
94 """shows the content of a Network Slice Template (NST)
96 NAME: name or ID of the NST
99 nst_show(ctx
, name
, literal
)
103 name
="netslice-template-show",
104 short_help
="shows the content of a Network Slice Template (NST)",
106 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
107 @click.argument("name")
109 def nst_show2(ctx
, name
, literal
):
110 """shows the content of a Network Slice Template (NST)
112 NAME: name or ID of the NST
115 nst_show(ctx
, name
, literal
)
118 def nst_create(ctx
, filename
, overwrite
):
120 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
121 ctx
.obj
.nst
.create(filename
, overwrite
)
125 name
="nst-create", short_help
="creates a new Network Slice Template (NST)"
127 @click.argument("filename")
131 default
=None, # hidden=True,
132 help="Deprecated. Use override",
138 help="overrides fields in descriptor, format: "
139 '"key1.key2...=value[;key3...=value;...]"',
142 def nst_create1(ctx
, filename
, overwrite
):
143 """creates a new Network Slice Template (NST)
145 FILENAME: NST package folder, NST yaml file or NSTpkg tar.gz file
148 nst_create(ctx
, filename
, overwrite
)
152 name
="netslice-template-create",
153 short_help
="creates a new Network Slice Template (NST)",
155 @click.argument("filename")
159 default
=None, # hidden=True,
160 help="Deprecated. Use override",
166 help="overrides fields in descriptor, format: "
167 '"key1.key2...=value[;key3...=value;...]"',
170 def nst_create2(ctx
, filename
, overwrite
):
171 """creates a new Network Slice Template (NST)
173 FILENAME: NST yaml file or NSTpkg tar.gz file
176 nst_create(ctx
, filename
, overwrite
)
179 def nst_update(ctx
, name
, content
):
181 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
182 ctx
.obj
.nst
.update(name
, content
)
185 @click.command(name
="nst-update", short_help
="updates a Network Slice Template (NST)")
186 @click.argument("name")
190 help="filename with the NST/NSTpkg replacing the current one",
193 def nst_update1(ctx
, name
, content
):
194 """updates a Network Slice Template (NST)
196 NAME: name or ID of the NSD/NSpkg
199 nst_update(ctx
, name
, content
)
203 name
="netslice-template-update", short_help
="updates a Network Slice Template (NST)"
205 @click.argument("name")
209 help="filename with the NST/NSTpkg replacing the current one",
212 def nst_update2(ctx
, name
, content
):
213 """updates a Network Slice Template (NST)
215 NAME: name or ID of the NSD/NSpkg
218 nst_update(ctx
, name
, content
)
221 def nst_delete(ctx
, name
, force
):
223 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
224 ctx
.obj
.nst
.delete(name
, force
)
227 @click.command(name
="nst-delete", short_help
="deletes a Network Slice Template (NST)")
228 @click.argument("name")
230 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
233 def nst_delete1(ctx
, name
, force
):
234 """deletes a Network Slice Template (NST)
236 NAME: name or ID of the NST/NSTpkg to be deleted
239 nst_delete(ctx
, name
, force
)
243 name
="netslice-template-delete", short_help
="deletes a Network Slice Template (NST)"
245 @click.argument("name")
247 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
250 def nst_delete2(ctx
, name
, force
):
251 """deletes a Network Slice Template (NST)
253 NAME: name or ID of the NST/NSTpkg to be deleted
256 nst_delete(ctx
, name
, force
)