Coverage for osmclient/cli_commands/netslice_template.py: 55%
113 statements
« prev ^ index » next coverage.py v7.3.1, created at 2024-06-30 09:54 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2024-06-30 09:54 +0000
1# Copyright ETSI Contributors and Others.
2# All Rights Reserved.
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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
14# under the License.
16import click
17from osmclient.cli_commands import utils
18from prettytable import PrettyTable
19import yaml
20import json
21import logging
23logger = logging.getLogger("osmclient")
26def nst_list(ctx, filter):
27 logger.debug("")
28 utils.check_client_version(ctx.obj, ctx.command.name)
29 if filter:
30 filter = "&".join(filter)
31 resp = ctx.obj.nst.list(filter)
32 table = PrettyTable(["nst name", "id"])
33 for nst in resp:
34 name = nst["name"] if "name" in nst else "-"
35 table.add_row([name, nst["_id"]])
36 table.align = "l"
37 print(table)
40@click.command(name="nst-list", short_help="list all Network Slice Templates (NST)")
41@click.option(
42 "--filter",
43 default=None,
44 multiple=True,
45 help="restricts the list to the NST matching the filter",
46)
47@click.pass_context
48def nst_list1(ctx, filter):
49 """list all Network Slice Templates (NST) in the system"""
50 logger.debug("")
51 nst_list(ctx, filter)
54@click.command(
55 name="netslice-template-list", short_help="list all Network Slice Templates (NST)"
56)
57@click.option(
58 "--filter",
59 default=None,
60 multiple=True,
61 help="restricts the list to the NST matching the filter",
62)
63@click.pass_context
64def nst_list2(ctx, filter):
65 """list all Network Slice Templates (NST) in the system"""
66 logger.debug("")
67 nst_list(ctx, filter)
70def nst_show(ctx, name, literal):
71 logger.debug("")
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)
76 if literal:
77 print(yaml.safe_dump(resp, indent=4, default_flow_style=False))
78 return
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)])
83 table.align = "l"
84 print(table)
87@click.command(
88 name="nst-show", short_help="shows the content of a Network Slice Template (NST)"
89)
90@click.option("--literal", is_flag=True, help="print literally, no pretty table")
91@click.argument("name")
92@click.pass_context
93def nst_show1(ctx, name, literal):
94 """shows the content of a Network Slice Template (NST)
96 NAME: name or ID of the NST
97 """
98 logger.debug("")
99 nst_show(ctx, name, literal)
102@click.command(
103 name="netslice-template-show",
104 short_help="shows the content of a Network Slice Template (NST)",
105)
106@click.option("--literal", is_flag=True, help="print literally, no pretty table")
107@click.argument("name")
108@click.pass_context
109def nst_show2(ctx, name, literal):
110 """shows the content of a Network Slice Template (NST)
112 NAME: name or ID of the NST
113 """
114 logger.debug("")
115 nst_show(ctx, name, literal)
118def nst_create(ctx, filename, overwrite):
119 logger.debug("")
120 utils.check_client_version(ctx.obj, ctx.command.name)
121 ctx.obj.nst.create(filename, overwrite)
124@click.command(
125 name="nst-create", short_help="creates a new Network Slice Template (NST)"
126)
127@click.argument("filename")
128@click.option(
129 "--overwrite",
130 "overwrite",
131 default=None, # hidden=True,
132 help="Deprecated. Use override",
133)
134@click.option(
135 "--override",
136 "overwrite",
137 default=None,
138 help="overrides fields in descriptor, format: "
139 '"key1.key2...=value[;key3...=value;...]"',
140)
141@click.pass_context
142def 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
146 """
147 logger.debug("")
148 nst_create(ctx, filename, overwrite)
151@click.command(
152 name="netslice-template-create",
153 short_help="creates a new Network Slice Template (NST)",
154)
155@click.argument("filename")
156@click.option(
157 "--overwrite",
158 "overwrite",
159 default=None, # hidden=True,
160 help="Deprecated. Use override",
161)
162@click.option(
163 "--override",
164 "overwrite",
165 default=None,
166 help="overrides fields in descriptor, format: "
167 '"key1.key2...=value[;key3...=value;...]"',
168)
169@click.pass_context
170def nst_create2(ctx, filename, overwrite):
171 """creates a new Network Slice Template (NST)
173 FILENAME: NST yaml file or NSTpkg tar.gz file
174 """
175 logger.debug("")
176 nst_create(ctx, filename, overwrite)
179def nst_update(ctx, name, content):
180 logger.debug("")
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")
187@click.option(
188 "--content",
189 default=None,
190 help="filename with the NST/NSTpkg replacing the current one",
191)
192@click.pass_context
193def nst_update1(ctx, name, content):
194 """updates a Network Slice Template (NST)
196 NAME: name or ID of the NSD/NSpkg
197 """
198 logger.debug("")
199 nst_update(ctx, name, content)
202@click.command(
203 name="netslice-template-update", short_help="updates a Network Slice Template (NST)"
204)
205@click.argument("name")
206@click.option(
207 "--content",
208 default=None,
209 help="filename with the NST/NSTpkg replacing the current one",
210)
211@click.pass_context
212def nst_update2(ctx, name, content):
213 """updates a Network Slice Template (NST)
215 NAME: name or ID of the NSD/NSpkg
216 """
217 logger.debug("")
218 nst_update(ctx, name, content)
221def nst_delete(ctx, name, force):
222 logger.debug("")
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")
229@click.option(
230 "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
231)
232@click.pass_context
233def nst_delete1(ctx, name, force):
234 """deletes a Network Slice Template (NST)
236 NAME: name or ID of the NST/NSTpkg to be deleted
237 """
238 logger.debug("")
239 nst_delete(ctx, name, force)
242@click.command(
243 name="netslice-template-delete", short_help="deletes a Network Slice Template (NST)"
244)
245@click.argument("name")
246@click.option(
247 "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
248)
249@click.pass_context
250def nst_delete2(ctx, name, force):
251 """deletes a Network Slice Template (NST)
253 NAME: name or ID of the NST/NSTpkg to be deleted
254 """
255 logger.debug("")
256 nst_delete(ctx, name, force)