Code Coverage

Cobertura Coverage Report > osmclient.cli_commands >

netslice_template.py

Trend

Classes100%
 
Lines55%
   
Conditionals100%
 

File Coverage summary

NameClassesLinesConditionals
netslice_template.py
100%
1/1
55%
62/113
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
netslice_template.py
55%
62/113
N/A

Source

osmclient/cli_commands/netslice_template.py
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.
15
16 1 import click
17 1 from osmclient.cli_commands import utils
18 1 from prettytable import PrettyTable
19 1 import yaml
20 1 import json
21 1 import logging
22
23 1 logger = logging.getLogger("osmclient")
24
25
26 1 def nst_list(ctx, filter):
27 0     logger.debug("")
28 0     utils.check_client_version(ctx.obj, ctx.command.name)
29 0     if filter:
30 0         filter = "&".join(filter)
31 0     resp = ctx.obj.nst.list(filter)
32 0     table = PrettyTable(["nst name", "id"])
33 0     for nst in resp:
34 0         name = nst["name"] if "name" in nst else "-"
35 0         table.add_row([name, nst["_id"]])
36 0     table.align = "l"
37 0     print(table)
38
39
40 1 @click.command(name="nst-list", short_help="list all Network Slice Templates (NST)")
41 1 @click.option(
42     "--filter",
43     default=None,
44     multiple=True,
45     help="restricts the list to the NST matching the filter",
46 )
47 1 @click.pass_context
48 1 def nst_list1(ctx, filter):
49     """list all Network Slice Templates (NST) in the system"""
50 0     logger.debug("")
51 0     nst_list(ctx, filter)
52
53
54 1 @click.command(
55     name="netslice-template-list", short_help="list all Network Slice Templates (NST)"
56 )
57 1 @click.option(
58     "--filter",
59     default=None,
60     multiple=True,
61     help="restricts the list to the NST matching the filter",
62 )
63 1 @click.pass_context
64 1 def nst_list2(ctx, filter):
65     """list all Network Slice Templates (NST) in the system"""
66 0     logger.debug("")
67 0     nst_list(ctx, filter)
68
69
70 1 def nst_show(ctx, name, literal):
71 0     logger.debug("")
72 0     utils.check_client_version(ctx.obj, ctx.command.name)
73 0     resp = ctx.obj.nst.get(name)
74     # resp = ctx.obj.nst.get_individual(name)
75
76 0     if literal:
77 0         print(yaml.safe_dump(resp, indent=4, default_flow_style=False))
78 0         return
79
80 0     table = PrettyTable(["field", "value"])
81 0     for k, v in list(resp.items()):
82 0         table.add_row([k, utils.wrap_text(json.dumps(v, indent=2), 100)])
83 0     table.align = "l"
84 0     print(table)
85
86
87 1 @click.command(
88     name="nst-show", short_help="shows the content of a Network Slice Template (NST)"
89 )
90 1 @click.option("--literal", is_flag=True, help="print literally, no pretty table")
91 1 @click.argument("name")
92 1 @click.pass_context
93 1 def nst_show1(ctx, name, literal):
94     """shows the content of a Network Slice Template (NST)
95
96     NAME: name or ID of the NST
97     """
98 0     logger.debug("")
99 0     nst_show(ctx, name, literal)
100
101
102 1 @click.command(
103     name="netslice-template-show",
104     short_help="shows the content of a Network Slice Template (NST)",
105 )
106 1 @click.option("--literal", is_flag=True, help="print literally, no pretty table")
107 1 @click.argument("name")
108 1 @click.pass_context
109 1 def nst_show2(ctx, name, literal):
110     """shows the content of a Network Slice Template (NST)
111
112     NAME: name or ID of the NST
113     """
114 0     logger.debug("")
115 0     nst_show(ctx, name, literal)
116
117
118 1 def nst_create(ctx, filename, overwrite):
119 0     logger.debug("")
120 0     utils.check_client_version(ctx.obj, ctx.command.name)
121 0     ctx.obj.nst.create(filename, overwrite)
122
123
124 1 @click.command(
125     name="nst-create", short_help="creates a new Network Slice Template (NST)"
126 )
127 1 @click.argument("filename")
128 1 @click.option(
129     "--overwrite",
130     "overwrite",
131     default=None,  # hidden=True,
132     help="Deprecated. Use override",
133 )
134 1 @click.option(
135     "--override",
136     "overwrite",
137     default=None,
138     help="overrides fields in descriptor, format: "
139     '"key1.key2...=value[;key3...=value;...]"',
140 )
141 1 @click.pass_context
142 1 def nst_create1(ctx, filename, overwrite):
143     """creates a new Network Slice Template (NST)
144
145     FILENAME: NST package folder, NST yaml file or NSTpkg tar.gz file
146     """
147 0     logger.debug("")
148 0     nst_create(ctx, filename, overwrite)
149
150
151 1 @click.command(
152     name="netslice-template-create",
153     short_help="creates a new Network Slice Template (NST)",
154 )
155 1 @click.argument("filename")
156 1 @click.option(
157     "--overwrite",
158     "overwrite",
159     default=None,  # hidden=True,
160     help="Deprecated. Use override",
161 )
162 1 @click.option(
163     "--override",
164     "overwrite",
165     default=None,
166     help="overrides fields in descriptor, format: "
167     '"key1.key2...=value[;key3...=value;...]"',
168 )
169 1 @click.pass_context
170 1 def nst_create2(ctx, filename, overwrite):
171     """creates a new Network Slice Template (NST)
172
173     FILENAME: NST yaml file or NSTpkg tar.gz file
174     """
175 0     logger.debug("")
176 0     nst_create(ctx, filename, overwrite)
177
178
179 1 def nst_update(ctx, name, content):
180 0     logger.debug("")
181 0     utils.check_client_version(ctx.obj, ctx.command.name)
182 0     ctx.obj.nst.update(name, content)
183
184
185 1 @click.command(name="nst-update", short_help="updates a Network Slice Template (NST)")
186 1 @click.argument("name")
187 1 @click.option(
188     "--content",
189     default=None,
190     help="filename with the NST/NSTpkg replacing the current one",
191 )
192 1 @click.pass_context
193 1 def nst_update1(ctx, name, content):
194     """updates a Network Slice Template (NST)
195
196     NAME: name or ID of the NSD/NSpkg
197     """
198 0     logger.debug("")
199 0     nst_update(ctx, name, content)
200
201
202 1 @click.command(
203     name="netslice-template-update", short_help="updates a Network Slice Template (NST)"
204 )
205 1 @click.argument("name")
206 1 @click.option(
207     "--content",
208     default=None,
209     help="filename with the NST/NSTpkg replacing the current one",
210 )
211 1 @click.pass_context
212 1 def nst_update2(ctx, name, content):
213     """updates a Network Slice Template (NST)
214
215     NAME: name or ID of the NSD/NSpkg
216     """
217 0     logger.debug("")
218 0     nst_update(ctx, name, content)
219
220
221 1 def nst_delete(ctx, name, force):
222 0     logger.debug("")
223 0     utils.check_client_version(ctx.obj, ctx.command.name)
224 0     ctx.obj.nst.delete(name, force)
225
226
227 1 @click.command(name="nst-delete", short_help="deletes a Network Slice Template (NST)")
228 1 @click.argument("name")
229 1 @click.option(
230     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
231 )
232 1 @click.pass_context
233 1 def nst_delete1(ctx, name, force):
234     """deletes a Network Slice Template (NST)
235
236     NAME: name or ID of the NST/NSTpkg to be deleted
237     """
238 0     logger.debug("")
239 0     nst_delete(ctx, name, force)
240
241
242 1 @click.command(
243     name="netslice-template-delete", short_help="deletes a Network Slice Template (NST)"
244 )
245 1 @click.argument("name")
246 1 @click.option(
247     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
248 )
249 1 @click.pass_context
250 1 def nst_delete2(ctx, name, force):
251     """deletes a Network Slice Template (NST)
252
253     NAME: name or ID of the NST/NSTpkg to be deleted
254     """
255 0     logger.debug("")
256 0     nst_delete(ctx, name, force)