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
.common
.exceptions
import ClientException
18 from osmclient
.cli_commands
import utils
19 from prettytable
import PrettyTable
24 logger
= logging
.getLogger("osmclient")
27 def nsi_list(ctx
, filter):
28 """list all Network Slice Instances"""
30 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
32 filter = "&".join(filter)
33 resp
= ctx
.obj
.nsi
.list(filter)
36 "netslice instance name",
44 nsi_name
= nsi
["name"]
47 nsi
["operational-status"] if "operational-status" in nsi
else "Not found"
49 configstatus
= nsi
["config-status"] if "config-status" in nsi
else "Not found"
51 nsi
["detailed-status"] if "detailed-status" in nsi
else "Not found"
53 if configstatus
== "config_not_needed":
54 configstatus
= "configured (no charms)"
55 table
.add_row([nsi_name
, nsi_id
, opstatus
, configstatus
, detailed_status
])
60 @click.command(name
="nsi-list", short_help
="list all Network Slice Instances (NSI)")
65 help="restricts the list to the Network Slice Instances matching the filter",
68 def nsi_list1(ctx
, filter):
69 """list all Network Slice Instances (NSI)"""
75 name
="netslice-instance-list", short_help
="list all Network Slice Instances (NSI)"
81 help="restricts the list to the Network Slice Instances matching the filter",
84 def nsi_list2(ctx
, filter):
85 """list all Network Slice Instances (NSI)"""
90 def nsi_show(ctx
, name
, literal
, filter):
92 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
93 nsi
= ctx
.obj
.nsi
.get(name
)
96 print(yaml
.safe_dump(nsi
, indent
=4, default_flow_style
=False))
99 table
= PrettyTable(["field", "value"])
101 for k
, v
in list(nsi
.items()):
102 if not filter or k
in filter:
103 table
.add_row([k
, json
.dumps(v
, indent
=2)])
110 name
="nsi-show", short_help
="shows the content of a Network Slice Instance (NSI)"
112 @click.argument("name")
113 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
117 help="restricts the information to the fields in the filter",
120 def nsi_show1(ctx
, name
, literal
, filter):
121 """shows the content of a Network Slice Instance (NSI)
123 NAME: name or ID of the Network Slice Instance
126 nsi_show(ctx
, name
, literal
, filter)
130 name
="netslice-instance-show",
131 short_help
="shows the content of a Network Slice Instance (NSI)",
133 @click.argument("name")
134 @click.option("--literal", is_flag
=True, help="print literally, no pretty table")
138 help="restricts the information to the fields in the filter",
141 def nsi_show2(ctx
, name
, literal
, filter):
142 """shows the content of a Network Slice Instance (NSI)
144 NAME: name or ID of the Network Slice Instance
147 nsi_show(ctx
, name
, literal
, filter)
151 ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
153 """creates a new Network Slice Instance (NSI)"""
155 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
158 raise ClientException(
159 '"--config" option is incompatible with "--config_file" option'
161 with
open(config_file
, "r") as cf
:
173 @click.command(name
="nsi-create", short_help
="creates a new Network Slice Instance")
174 @click.option("--nsi_name", prompt
=True, help="name of the Network Slice Instance")
175 @click.option("--nst_name", prompt
=True, help="name of the Network Slice Template")
179 help="default VIM account id or name for the deployment",
182 "--ssh_keys", default
=None, help="comma separated list of keys to inject to vnfs"
187 help="Netslice specific yaml configuration:\n"
188 "netslice_subnet: [\n"
189 "id: TEXT, vim_account: TEXT,\n"
190 "vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n"
191 "vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n"
192 "additionalParamsForNsi: {param: value, ...}\n"
193 "additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n"
195 "netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]",
198 "--config_file", default
=None, help="nsi specific yaml configuration file"
205 help="do not return the control immediately, but keep it "
206 "until the operation is completed, or timeout",
210 ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
212 """creates a new Network Slice Instance (NSI)"""
215 ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
220 name
="netslice-instance-create", short_help
="creates a new Network Slice Instance"
222 @click.option("--nsi_name", prompt
=True, help="name of the Network Slice Instance")
223 @click.option("--nst_name", prompt
=True, help="name of the Network Slice Template")
227 help="default VIM account id or name for the deployment",
230 "--ssh_keys", default
=None, help="comma separated list of keys to inject to vnfs"
235 help="Netslice specific yaml configuration:\n"
236 "netslice_subnet: [\n"
237 "id: TEXT, vim_account: TEXT,\n"
238 "vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n"
239 "vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]"
241 "netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]",
244 "--config_file", default
=None, help="nsi specific yaml configuration file"
251 help="do not return the control immediately, but keep it "
252 "until the operation is completed, or timeout",
256 ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
258 """creates a new Network Slice Instance (NSI)"""
261 ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
265 def nsi_delete(ctx
, name
, force
, wait
):
267 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
268 ctx
.obj
.nsi
.delete(name
, force
, wait
=wait
)
271 @click.command(name
="nsi-delete", short_help
="deletes a Network Slice Instance (NSI)")
272 @click.argument("name")
274 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
281 help="do not return the control immediately, but keep it "
282 "until the operation is completed, or timeout",
285 def nsi_delete1(ctx
, name
, force
, wait
):
286 """deletes a Network Slice Instance (NSI)
288 NAME: name or ID of the Network Slice instance to be deleted
291 nsi_delete(ctx
, name
, force
, wait
=wait
)
295 name
="netslice-instance-delete", short_help
="deletes a Network Slice Instance (NSI)"
297 @click.argument("name")
299 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
302 def nsi_delete2(ctx
, name
, force
, wait
):
303 """deletes a Network Slice Instance (NSI)
305 NAME: name or ID of the Network Slice instance to be deleted
308 nsi_delete(ctx
, name
, force
, wait
=wait
)