1 # Copyright 2017-2018 Sandvine
2 # Copyright 2018 Telefonica
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
22 from osmclient
import client
23 from osmclient
.common
.exceptions
import ClientException
24 from prettytable
import PrettyTable
31 def check_client_version(obj
, what
, version
='sol005'):
33 Checks the version of the client object and raises error if it not the expected.
35 :param obj: the client object
36 :what: the function or command under evaluation (used when an error is raised)
38 :raises ClientError: if the specified version does not match the client version
40 fullclassname
= obj
.__module
__ + "." + obj
.__class
__.__name
__
41 message
= 'The following commands or options are only supported with the option "--sol005": {}'.format(what
)
43 message
= 'The following commands or options are not supported when using option "--sol005": {}'.format(what
)
44 if fullclassname
!= 'osmclient.{}.client.Client'.format(version
):
45 raise ClientException(message
)
50 @click.option('--hostname',
52 envvar
='OSM_HOSTNAME',
53 help='hostname of server. ' +
54 'Also can set OSM_HOSTNAME in environment')
55 @click.option('--sol005/--no-sol005',
58 help='Use ETSI NFV SOL005 API (default) or the previous SO API. ' +
59 'Also can set OSM_SOL005 in environment')
60 @click.option('--user',
63 help='user (only from Release FOUR, defaults to admin). ' +
64 'Also can set OSM_USER in environment')
65 @click.option('--password',
67 envvar
='OSM_PASSWORD',
68 help='password (only from Release FOUR, defaults to admin). ' +
69 'Also can set OSM_PASSWORD in environment')
70 @click.option('--project',
73 help='project (only from Release FOUR, defaults to admin). ' +
74 'Also can set OSM_PROJECT in environment')
75 @click.option('--so-port',
78 help='hostname of server. ' +
79 'Also can set OSM_SO_PORT in environment')
80 @click.option('--so-project',
82 envvar
='OSM_SO_PROJECT',
83 help='Project Name in SO. ' +
84 'Also can set OSM_SO_PROJECT in environment')
85 @click.option('--ro-hostname',
87 envvar
='OSM_RO_HOSTNAME',
88 help='hostname of RO server. ' +
89 'Also can set OSM_RO_HOSTNAME in environment')
90 @click.option('--ro-port',
93 help='hostname of RO server. ' +
94 'Also can set OSM_RO_PORT in environment')
96 def cli(ctx
, hostname
, sol005
, user
, password
, project
, so_port
, so_project
, ro_hostname
, ro_port
):
99 "either hostname option or OSM_HOSTNAME " +
100 "environment variable needs to be specified"))
103 if so_port
is not None:
104 kwargs
['so_port']=so_port
105 if so_project
is not None:
106 kwargs
['so_project']=so_project
107 if ro_hostname
is not None:
108 kwargs
['ro_host']=ro_hostname
109 if ro_port
is not None:
110 kwargs
['ro_port']=ro_port
113 if password
is not None:
114 kwargs
['password']=password
115 if project
is not None:
116 kwargs
['project']=project
118 ctx
.obj
= client
.Client(host
=hostname
, sol005
=sol005
, **kwargs
)
125 @cli.command(name
='ns-list')
126 @click.option('--filter', default
=None,
127 help='restricts the list to the NS instances matching the filter.')
129 def ns_list(ctx
, filter):
130 """list all NS instances
134 --filter filterExpr Restricts the list to the NS instances matching the filter
137 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
138 concatenated using the "&" character:
141 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
142 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
143 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
145 value := scalar value
149 * zero or more occurrences
150 ? zero or one occurrence
151 [] grouping of expressions to be used with ? and *
152 "" quotation marks for marking string constants
156 "AttrName" is the name of one attribute in the data type that defines the representation
157 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
158 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
159 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
160 entries, it means that the operator "op" is applied to the attribute addressed by the last
161 <attrName> entry included in the concatenation. All simple filter expressions are combined
162 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
163 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
164 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
165 prefix". If an attribute referenced in an expression is an array, an object that contains a
166 corresponding array shall be considered to match the expression if any of the elements in the
167 array matches all expressions that have the same attribute prefix.
171 --filter admin-status=ENABLED
172 --filter nsd-ref=<NSD_NAME>
173 --filter nsd.vendor=<VENDOR>
174 --filter nsd.vendor=<VENDOR>&nsd-ref=<NSD_NAME>
175 --filter nsd.constituent-vnfd.vnfd-id-ref=<VNFD_NAME>
178 check_client_version(ctx
.obj
, '--filter')
179 resp
= ctx
.obj
.ns
.list(filter)
181 resp
= ctx
.obj
.ns
.list()
185 'operational status',
189 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
190 if fullclassname
== 'osmclient.sol005.client.Client':
192 nsr_name
= nsr
['name']
195 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
196 nsr
= nsopdata
['nsr:nsr']
197 nsr_name
= nsr
['name-ref']
198 nsr_id
= nsr
['ns-instance-config-ref']
199 opstatus
= nsr
['operational-status'] if 'operational-status' in nsr
else 'Not found'
200 configstatus
= nsr
['config-status'] if 'config-status' in nsr
else 'Not found'
201 detailed_status
= nsr
['detailed-status'] if 'detailed-status' in nsr
else 'Not found'
202 if configstatus
== "config_not_needed":
203 configstatus
= "configured (no charms)"
214 def nsd_list(ctx
, filter):
216 check_client_version(ctx
.obj
, '--filter')
217 resp
= ctx
.obj
.nsd
.list(filter)
219 resp
= ctx
.obj
.nsd
.list()
220 # print yaml.safe_dump(resp)
221 table
= PrettyTable(['nsd name', 'id'])
222 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
223 if fullclassname
== 'osmclient.sol005.client.Client':
225 name
= ns
['name'] if 'name' in ns
else '-'
226 table
.add_row([name
, ns
['_id']])
229 table
.add_row([ns
['name'], ns
['id']])
234 @cli.command(name
='nsd-list')
235 @click.option('--filter', default
=None,
236 help='restricts the list to the NSD/NSpkg matching the filter')
238 def nsd_list1(ctx
, filter):
239 """list all NSD/NS pkg in the system"""
240 nsd_list(ctx
, filter)
243 @cli.command(name
='nspkg-list')
244 @click.option('--filter', default
=None,
245 help='restricts the list to the NSD/NSpkg matching the filter')
247 def nsd_list2(ctx
, filter):
248 """list all NSD/NS pkg in the system"""
249 nsd_list(ctx
, filter)
252 def vnfd_list(ctx
, nf_type
, filter):
254 check_client_version(ctx
.obj
, '--nf_type')
256 check_client_version(ctx
.obj
, '--filter')
259 nf_filter
= "_admin.type=vnfd"
260 elif nf_type
== "pnf":
261 nf_filter
= "_admin.type=pnfd"
262 elif nf_type
== "hnf":
263 nf_filter
= "_admin.type=hnfd"
265 raise ClientException('wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf')
267 filter = '{}&{}'.format(nf_filter
, filter)
271 resp
= ctx
.obj
.vnfd
.list(filter)
273 resp
= ctx
.obj
.vnfd
.list()
274 # print yaml.safe_dump(resp)
275 table
= PrettyTable(['nfpkg name', 'id'])
276 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
277 if fullclassname
== 'osmclient.sol005.client.Client':
279 name
= vnfd
['name'] if 'name' in vnfd
else '-'
280 table
.add_row([name
, vnfd
['_id']])
283 table
.add_row([vnfd
['name'], vnfd
['id']])
288 @cli.command(name
='vnfd-list')
289 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
290 @click.option('--filter', default
=None,
291 help='restricts the list to the NF pkg matching the filter')
293 def vnfd_list1(ctx
, nf_type
, filter):
294 """list all VNFD/VNF pkg in the system"""
295 vnfd_list(ctx
, nf_type
, filter)
298 @cli.command(name
='vnfpkg-list')
299 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
300 @click.option('--filter', default
=None,
301 help='restricts the list to the NFpkg matching the filter')
303 def vnfd_list2(ctx
, nf_type
, filter):
304 """list all VNFD/VNF pkg in the system"""
305 vnfd_list(ctx
, nf_type
, filter)
308 @cli.command(name
='nfpkg-list')
309 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
310 @click.option('--filter', default
=None,
311 help='restricts the list to the NFpkg matching the filter')
313 def nfpkg_list(ctx
, nf_type
, filter):
314 """list all NF pkg (VNF pkg, PNF pkg, HNF pkg) in the system"""
316 check_client_version(ctx
.obj
, ctx
.command
.name
)
317 vnfd_list(ctx
, nf_type
, filter)
318 except ClientException
as inst
:
319 print((inst
.message
))
323 def vnf_list(ctx
, ns
, filter):
327 check_client_version(ctx
.obj
, '--ns')
329 check_client_version(ctx
.obj
, '--filter')
330 resp
= ctx
.obj
.vnf
.list(ns
, filter)
332 resp
= ctx
.obj
.vnf
.list()
333 except ClientException
as inst
:
334 print((inst
.message
))
336 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
337 if fullclassname
== 'osmclient.sol005.client.Client':
347 name
= vnfr
['name'] if 'name' in vnfr
else '-'
352 vnfr
['member-vnf-index-ref'],
354 vnfr
['vim-account-id'],
360 'operational status',
363 if 'mgmt-interface' not in vnfr
:
364 vnfr
['mgmt-interface'] = {}
365 vnfr
['mgmt-interface']['ip-address'] = None
369 vnfr
['operational-status'],
370 vnfr
['config-status']])
375 @cli.command(name
='vnf-list')
376 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
377 @click.option('--filter', default
=None,
378 help='restricts the list to the NF instances matching the filter.')
380 def vnf_list1(ctx
, ns
, filter):
381 """list all NF instances"""
382 vnf_list(ctx
, ns
, filter)
385 @cli.command(name
='nf-list')
386 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
387 @click.option('--filter', default
=None,
388 help='restricts the list to the NF instances matching the filter.')
390 def nf_list(ctx
, ns
, filter):
391 """list all NF instances
395 --ns TEXT NS instance id or name to restrict the VNF list
396 --filter filterExpr Restricts the list to the VNF instances matching the filter
399 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
400 concatenated using the "&" character:
403 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
404 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
405 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
407 value := scalar value
411 * zero or more occurrences
412 ? zero or one occurrence
413 [] grouping of expressions to be used with ? and *
414 "" quotation marks for marking string constants
418 "AttrName" is the name of one attribute in the data type that defines the representation
419 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
420 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
421 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
422 entries, it means that the operator "op" is applied to the attribute addressed by the last
423 <attrName> entry included in the concatenation. All simple filter expressions are combined
424 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
425 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
426 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
427 prefix". If an attribute referenced in an expression is an array, an object that contains a
428 corresponding array shall be considered to match the expression if any of the elements in the
429 array matches all expressions that have the same attribute prefix.
433 --filter vim-account-id=<VIM_ACCOUNT_ID>
434 --filter vnfd-ref=<VNFD_NAME>
435 --filter vdur.ip-address=<IP_ADDRESS>
436 --filter vnfd-ref=<VNFD_NAME>,vdur.ip-address=<IP_ADDRESS>
438 vnf_list(ctx
, ns
, filter)
441 @cli.command(name
='ns-op-list')
442 @click.argument('name')
444 def ns_op_list(ctx
, name
):
445 """shows the history of operations over a NS instance
447 NAME: name or ID of the NS instance
450 check_client_version(ctx
.obj
, ctx
.command
.name
)
451 resp
= ctx
.obj
.ns
.list_op(name
)
452 except ClientException
as inst
:
453 print((inst
.message
))
456 table
= PrettyTable(['id', 'operation', 'status'])
458 table
.add_row([op
['id'], op
['lcmOperationType'],
459 op
['operationState']])
464 def nsi_list(ctx
, filter):
465 """list all Network Slice Instances"""
467 check_client_version(ctx
.obj
, ctx
.command
.name
)
468 resp
= ctx
.obj
.nsi
.list(filter)
469 except ClientException
as inst
:
470 print((inst
.message
))
473 ['netslice instance name',
475 'operational status',
479 nsi_name
= nsi
['name']
481 opstatus
= nsi
['operational-status'] if 'operational-status' in nsi
else 'Not found'
482 configstatus
= nsi
['config-status'] if 'config-status' in nsi
else 'Not found'
483 detailed_status
= nsi
['detailed-status'] if 'detailed-status' in nsi
else 'Not found'
484 if configstatus
== "config_not_needed":
485 configstatus
= "configured (no charms)"
496 @cli.command(name
='nsi-list')
497 @click.option('--filter', default
=None,
498 help='restricts the list to the Network Slice Instances matching the filter')
500 def nsi_list1(ctx
, filter):
501 """list all Network Slice Instances (NSI)"""
502 nsi_list(ctx
, filter)
505 @cli.command(name
='netslice-instance-list')
506 @click.option('--filter', default
=None,
507 help='restricts the list to the Network Slice Instances matching the filter')
509 def nsi_list2(ctx
, filter):
510 """list all Network Slice Instances (NSI)"""
511 nsi_list(ctx
, filter)
514 def nst_list(ctx
, filter):
516 check_client_version(ctx
.obj
, ctx
.command
.name
)
517 resp
= ctx
.obj
.nst
.list(filter)
518 except ClientException
as inst
:
519 print((inst
.message
))
521 # print yaml.safe_dump(resp)
522 table
= PrettyTable(['nst name', 'id'])
524 name
= nst
['name'] if 'name' in nst
else '-'
525 table
.add_row([name
, nst
['_id']])
530 @cli.command(name
='nst-list')
531 @click.option('--filter', default
=None,
532 help='restricts the list to the NST matching the filter')
534 def nst_list1(ctx
, filter):
535 """list all Network Slice Templates (NST) in the system"""
536 nst_list(ctx
, filter)
539 @cli.command(name
='netslice-template-list')
540 @click.option('--filter', default
=None,
541 help='restricts the list to the NST matching the filter')
543 def nst_list2(ctx
, filter):
544 """list all Network Slice Templates (NST) in the system"""
545 nst_list(ctx
, filter)
548 def nsi_op_list(ctx
, name
):
550 check_client_version(ctx
.obj
, ctx
.command
.name
)
551 resp
= ctx
.obj
.nsi
.list_op(name
)
552 except ClientException
as inst
:
553 print((inst
.message
))
555 table
= PrettyTable(['id', 'operation', 'status'])
557 table
.add_row([op
['id'], op
['lcmOperationType'],
558 op
['operationState']])
563 @cli.command(name
='nsi-op-list')
564 @click.argument('name')
566 def nsi_op_list1(ctx
, name
):
567 """shows the history of operations over a Network Slice Instance (NSI)
569 NAME: name or ID of the Network Slice Instance
571 nsi_op_list(ctx
, name
)
574 @cli.command(name
='netslice-instance-op-list')
575 @click.argument('name')
577 def nsi_op_list2(ctx
, name
):
578 """shows the history of operations over a Network Slice Instance (NSI)
580 NAME: name or ID of the Network Slice Instance
582 nsi_op_list(ctx
, name
)
585 @cli.command(name
='pdu-list')
586 @click.option('--filter', default
=None,
587 help='restricts the list to the Physical Deployment Units matching the filter')
589 def pdu_list(ctx
, filter):
590 """list all Physical Deployment Units (PDU)"""
592 check_client_version(ctx
.obj
, ctx
.command
.name
)
593 resp
= ctx
.obj
.pdu
.list(filter)
594 except ClientException
as inst
:
595 print((inst
.message
))
603 pdu_name
= pdu
['name']
605 pdu_type
= pdu
['type']
606 pdu_ipaddress
= "None"
607 for iface
in pdu
['interfaces']:
609 pdu_ipaddress
= iface
['ip-address']
624 def nsd_show(ctx
, name
, literal
):
626 resp
= ctx
.obj
.nsd
.get(name
)
627 # resp = ctx.obj.nsd.get_individual(name)
628 except ClientException
as inst
:
629 print((inst
.message
))
633 print(yaml
.safe_dump(resp
))
636 table
= PrettyTable(['field', 'value'])
637 for k
, v
in list(resp
.items()):
638 table
.add_row([k
, json
.dumps(v
, indent
=2)])
643 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
644 @click.option('--literal', is_flag
=True,
645 help='print literally, no pretty table')
646 @click.argument('name')
648 def nsd_show1(ctx
, name
, literal
):
649 """shows the content of a NSD
651 NAME: name or ID of the NSD/NSpkg
653 nsd_show(ctx
, name
, literal
)
656 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
657 @click.option('--literal', is_flag
=True,
658 help='print literally, no pretty table')
659 @click.argument('name')
661 def nsd_show2(ctx
, name
, literal
):
662 """shows the content of a NSD
664 NAME: name or ID of the NSD/NSpkg
666 nsd_show(ctx
, name
, literal
)
669 def vnfd_show(ctx
, name
, literal
):
671 resp
= ctx
.obj
.vnfd
.get(name
)
672 # resp = ctx.obj.vnfd.get_individual(name)
673 except ClientException
as inst
:
674 print((inst
.message
))
678 print(yaml
.safe_dump(resp
))
681 table
= PrettyTable(['field', 'value'])
682 for k
, v
in list(resp
.items()):
683 table
.add_row([k
, json
.dumps(v
, indent
=2)])
688 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
689 @click.option('--literal', is_flag
=True,
690 help='print literally, no pretty table')
691 @click.argument('name')
693 def vnfd_show1(ctx
, name
, literal
):
694 """shows the content of a VNFD
696 NAME: name or ID of the VNFD/VNFpkg
698 vnfd_show(ctx
, name
, literal
)
701 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
702 @click.option('--literal', is_flag
=True,
703 help='print literally, no pretty table')
704 @click.argument('name')
706 def vnfd_show2(ctx
, name
, literal
):
707 """shows the content of a VNFD
709 NAME: name or ID of the VNFD/VNFpkg
711 vnfd_show(ctx
, name
, literal
)
714 @cli.command(name
='nfpkg-show', short_help
='shows the content of a NF Descriptor')
715 @click.option('--literal', is_flag
=True,
716 help='print literally, no pretty table')
717 @click.argument('name')
719 def nfpkg_show(ctx
, name
, literal
):
720 """shows the content of a NF Descriptor
722 NAME: name or ID of the NFpkg
724 vnfd_show(ctx
, name
, literal
)
727 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
728 @click.argument('name')
729 @click.option('--literal', is_flag
=True,
730 help='print literally, no pretty table')
731 @click.option('--filter', default
=None)
733 def ns_show(ctx
, name
, literal
, filter):
734 """shows the info of a NS instance
736 NAME: name or ID of the NS instance
739 ns
= ctx
.obj
.ns
.get(name
)
740 except ClientException
as inst
:
741 print((inst
.message
))
745 print(yaml
.safe_dump(ns
))
748 table
= PrettyTable(['field', 'value'])
750 for k
, v
in list(ns
.items()):
751 if filter is None or filter in k
:
752 table
.add_row([k
, json
.dumps(v
, indent
=2)])
754 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
755 if fullclassname
!= 'osmclient.sol005.client.Client':
756 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
757 nsr_optdata
= nsopdata
['nsr:nsr']
758 for k
, v
in list(nsr_optdata
.items()):
759 if filter is None or filter in k
:
760 table
.add_row([k
, json
.dumps(v
, indent
=2)])
765 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
766 @click.argument('name')
767 @click.option('--literal', is_flag
=True,
768 help='print literally, no pretty table')
769 @click.option('--filter', default
=None)
771 def vnf_show(ctx
, name
, literal
, filter):
772 """shows the info of a VNF instance
774 NAME: name or ID of the VNF instance
777 check_client_version(ctx
.obj
, ctx
.command
.name
)
778 resp
= ctx
.obj
.vnf
.get(name
)
779 except ClientException
as inst
:
780 print((inst
.message
))
784 print(yaml
.safe_dump(resp
))
787 table
= PrettyTable(['field', 'value'])
788 for k
, v
in list(resp
.items()):
789 if filter is None or filter in k
:
790 table
.add_row([k
, json
.dumps(v
, indent
=2)])
795 @cli.command(name
='vnf-monitoring-show')
796 @click.argument('vnf_name')
798 def vnf_monitoring_show(ctx
, vnf_name
):
800 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
801 resp
= ctx
.obj
.vnf
.get_monitoring(vnf_name
)
802 except ClientException
as inst
:
803 print((inst
.message
))
806 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
812 monitor
['value-integer'],
818 @cli.command(name
='ns-monitoring-show')
819 @click.argument('ns_name')
821 def ns_monitoring_show(ctx
, ns_name
):
823 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
824 resp
= ctx
.obj
.ns
.get_monitoring(ns_name
)
825 except ClientException
as inst
:
826 print((inst
.message
))
829 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
830 for key
, val
in list(resp
.items()):
835 monitor
['value-integer'],
841 @cli.command(name
='ns-op-show', short_help
='shows the info of an operation')
842 @click.argument('id')
843 @click.option('--filter', default
=None)
845 def ns_op_show(ctx
, id, filter):
846 """shows the detailed info of an operation
848 ID: operation identifier
851 check_client_version(ctx
.obj
, ctx
.command
.name
)
852 op_info
= ctx
.obj
.ns
.get_op(id)
853 except ClientException
as inst
:
854 print((inst
.message
))
857 table
= PrettyTable(['field', 'value'])
858 for k
, v
in list(op_info
.items()):
859 if filter is None or filter in k
:
860 table
.add_row([k
, json
.dumps(v
, indent
=2)])
865 def nst_show(ctx
, name
, literal
):
867 check_client_version(ctx
.obj
, ctx
.command
.name
)
868 resp
= ctx
.obj
.nst
.get(name
)
869 #resp = ctx.obj.nst.get_individual(name)
870 except ClientException
as inst
:
871 print((inst
.message
))
875 print(yaml
.safe_dump(resp
))
878 table
= PrettyTable(['field', 'value'])
879 for k
, v
in list(resp
.items()):
880 table
.add_row([k
, json
.dumps(v
, indent
=2)])
885 @cli.command(name
='nst-show', short_help
='shows the content of a Network Slice Template (NST)')
886 @click.option('--literal', is_flag
=True,
887 help='print literally, no pretty table')
888 @click.argument('name')
890 def nst_show1(ctx
, name
, literal
):
891 """shows the content of a Network Slice Template (NST)
893 NAME: name or ID of the NST
895 nst_show(ctx
, name
, literal
)
898 @cli.command(name
='netslice-template-show', short_help
='shows the content of a Network Slice Template (NST)')
899 @click.option('--literal', is_flag
=True,
900 help='print literally, no pretty table')
901 @click.argument('name')
903 def nst_show2(ctx
, name
, literal
):
904 """shows the content of a Network Slice Template (NST)
906 NAME: name or ID of the NST
908 nst_show(ctx
, name
, literal
)
911 def nsi_show(ctx
, name
, literal
, filter):
913 check_client_version(ctx
.obj
, ctx
.command
.name
)
914 nsi
= ctx
.obj
.nsi
.get(name
)
915 except ClientException
as inst
:
916 print((inst
.message
))
920 print(yaml
.safe_dump(nsi
))
923 table
= PrettyTable(['field', 'value'])
925 for k
, v
in list(nsi
.items()):
926 if filter is None or filter in k
:
927 table
.add_row([k
, json
.dumps(v
, indent
=2)])
933 @cli.command(name
='nsi-show', short_help
='shows the content of a Network Slice Instance (NSI)')
934 @click.argument('name')
935 @click.option('--literal', is_flag
=True,
936 help='print literally, no pretty table')
937 @click.option('--filter', default
=None)
939 def nsi_show1(ctx
, name
, literal
, filter):
940 """shows the content of a Network Slice Instance (NSI)
942 NAME: name or ID of the Network Slice Instance
944 nsi_show(ctx
, name
, literal
, filter)
947 @cli.command(name
='netslice-instance-show', short_help
='shows the content of a Network Slice Instance (NSI)')
948 @click.argument('name')
949 @click.option('--literal', is_flag
=True,
950 help='print literally, no pretty table')
951 @click.option('--filter', default
=None)
953 def nsi_show2(ctx
, name
, literal
, filter):
954 """shows the content of a Network Slice Instance (NSI)
956 NAME: name or ID of the Network Slice Instance
958 nsi_show(ctx
, name
, literal
, filter)
961 def nsi_op_show(ctx
, id, filter):
963 check_client_version(ctx
.obj
, ctx
.command
.name
)
964 op_info
= ctx
.obj
.nsi
.get_op(id)
965 except ClientException
as inst
:
966 print((inst
.message
))
969 table
= PrettyTable(['field', 'value'])
970 for k
, v
in list(op_info
.items()):
971 if filter is None or filter in k
:
972 table
.add_row([k
, json
.dumps(v
, indent
=2)])
977 @cli.command(name
='nsi-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
978 @click.argument('id')
979 @click.option('--filter', default
=None)
981 def nsi_op_show1(ctx
, id, filter):
982 """shows the info of an operation over a Network Slice Instance(NSI)
984 ID: operation identifier
986 nsi_op_show(ctx
, id, filter)
989 @cli.command(name
='netslice-instance-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
990 @click.argument('id')
991 @click.option('--filter', default
=None)
993 def nsi_op_show2(ctx
, id, filter):
994 """shows the info of an operation over a Network Slice Instance(NSI)
996 ID: operation identifier
998 nsi_op_show(ctx
, id, filter)
1001 @cli.command(name
='pdu-show', short_help
='shows the content of a Physical Deployment Unit (PDU)')
1002 @click.argument('name')
1003 @click.option('--literal', is_flag
=True,
1004 help='print literally, no pretty table')
1005 @click.option('--filter', default
=None)
1007 def pdu_show(ctx
, name
, literal
, filter):
1008 """shows the content of a Physical Deployment Unit (PDU)
1010 NAME: name or ID of the PDU
1013 check_client_version(ctx
.obj
, ctx
.command
.name
)
1014 pdu
= ctx
.obj
.pdu
.get(name
)
1015 except ClientException
as inst
:
1016 print((inst
.message
))
1020 print(yaml
.safe_dump(pdu
))
1023 table
= PrettyTable(['field', 'value'])
1025 for k
, v
in list(pdu
.items()):
1026 if filter is None or filter in k
:
1027 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1033 ####################
1035 ####################
1037 def nsd_create(ctx
, filename
, overwrite
):
1039 check_client_version(ctx
.obj
, ctx
.command
.name
)
1040 ctx
.obj
.nsd
.create(filename
, overwrite
)
1041 except ClientException
as inst
:
1042 print((inst
.message
))
1046 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
1047 @click.argument('filename')
1048 @click.option('--overwrite', default
=None,
1049 help='overwrites some fields in NSD')
1051 def nsd_create1(ctx
, filename
, overwrite
):
1052 """creates a new NSD/NSpkg
1054 FILENAME: NSD yaml file or NSpkg tar.gz file
1056 nsd_create(ctx
, filename
, overwrite
)
1059 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
1060 @click.argument('filename')
1061 @click.option('--overwrite', default
=None,
1062 help='overwrites some fields in NSD')
1064 def nsd_create2(ctx
, filename
, overwrite
):
1065 """creates a new NSD/NSpkg
1067 FILENAME: NSD yaml file or NSpkg tar.gz file
1069 nsd_create(ctx
, filename
, overwrite
)
1072 def vnfd_create(ctx
, filename
, overwrite
):
1074 check_client_version(ctx
.obj
, ctx
.command
.name
)
1075 ctx
.obj
.vnfd
.create(filename
, overwrite
)
1076 except ClientException
as inst
:
1077 print((inst
.message
))
1081 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
1082 @click.argument('filename')
1083 @click.option('--overwrite', default
=None,
1084 help='overwrites some fields in VNFD')
1086 def vnfd_create1(ctx
, filename
, overwrite
):
1087 """creates a new VNFD/VNFpkg
1089 FILENAME: VNFD yaml file or VNFpkg tar.gz file
1091 vnfd_create(ctx
, filename
, overwrite
)
1094 @cli.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
1095 @click.argument('filename')
1096 @click.option('--overwrite', default
=None,
1097 help='overwrites some fields in VNFD')
1099 def vnfd_create2(ctx
, filename
, overwrite
):
1100 """creates a new VNFD/VNFpkg
1102 FILENAME: VNFD yaml file or VNFpkg tar.gz file
1104 vnfd_create(ctx
, filename
, overwrite
)
1107 @cli.command(name
='nfpkg-create', short_help
='creates a new NFpkg')
1108 @click.argument('filename')
1109 @click.option('--overwrite', default
=None,
1110 help='overwrites some fields in NFD')
1112 def nfpkg_create(ctx
, filename
, overwrite
):
1113 """creates a new NFpkg
1115 FILENAME: NF Descriptor yaml file or NFpkg tar.gz file
1117 vnfd_create(ctx
, filename
, overwrite
)
1120 @cli.command(name
='ns-create', short_help
='creates a new Network Service instance')
1121 @click.option('--ns_name',
1122 prompt
=True, help='name of the NS instance')
1123 @click.option('--nsd_name',
1124 prompt
=True, help='name of the NS descriptor')
1125 @click.option('--vim_account',
1126 prompt
=True, help='default VIM account id or name for the deployment')
1127 @click.option('--admin_status',
1129 help='administration status')
1130 @click.option('--ssh_keys',
1132 help='comma separated list of public key files to inject to vnfs')
1133 @click.option('--config',
1135 help='ns specific yaml configuration')
1136 @click.option('--config_file',
1138 help='ns specific yaml configuration file')
1139 @click.option('--wait',
1143 help='do not return the control immediately, but keep it \
1144 until the operation is completed, or timeout')
1155 """creates a new NS instance"""
1158 check_client_version(ctx
.obj
, '--config_file')
1160 raise ClientException('"--config" option is incompatible with "--config_file" option')
1161 with
open(config_file
, 'r') as cf
:
1168 account
=vim_account
,
1170 except ClientException
as inst
:
1175 def nst_create(ctx
, filename
, overwrite
):
1177 check_client_version(ctx
.obj
, ctx
.command
.name
)
1178 ctx
.obj
.nst
.create(filename
, overwrite
)
1179 except ClientException
as inst
:
1180 print((inst
.message
))
1184 @cli.command(name
='nst-create', short_help
='creates a new Network Slice Template (NST)')
1185 @click.argument('filename')
1186 @click.option('--overwrite', default
=None,
1187 help='overwrites some fields in NST')
1189 def nst_create1(ctx
, filename
, overwrite
):
1190 """creates a new Network Slice Template (NST)
1192 FILENAME: NST yaml file or NSTpkg tar.gz file
1194 nst_create(ctx
, filename
, overwrite
)
1197 @cli.command(name
='netslice-template-create', short_help
='creates a new Network Slice Template (NST)')
1198 @click.argument('filename')
1199 @click.option('--overwrite', default
=None,
1200 help='overwrites some fields in NST')
1202 def nst_create2(ctx
, filename
, overwrite
):
1203 """creates a new Network Slice Template (NST)
1205 FILENAME: NST yaml file or NSTpkg tar.gz file
1207 nst_create(ctx
, filename
, overwrite
)
1210 def nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1211 """creates a new Network Slice Instance (NSI)"""
1213 check_client_version(ctx
.obj
, ctx
.command
.name
)
1216 raise ClientException('"--config" option is incompatible with "--config_file" option')
1217 with
open(config_file
, 'r') as cf
:
1219 ctx
.obj
.nsi
.create(nst_name
, nsi_name
, config
=config
, ssh_keys
=ssh_keys
,
1220 account
=vim_account
, wait
=wait
)
1221 except ClientException
as inst
:
1226 @cli.command(name
='nsi-create', short_help
='creates a new Network Slice Instance')
1227 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1228 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1229 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1230 @click.option('--ssh_keys', default
=None,
1231 help='comma separated list of keys to inject to vnfs')
1232 @click.option('--config', default
=None,
1233 help='Netslice specific yaml configuration:\n'
1234 'netslice_subnet: [\n'
1235 'id: TEXT, vim_account: TEXT,\n'
1236 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1237 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
1238 'additionalParamsForNsi: {param: value, ...}\n'
1239 'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
1241 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1243 @click.option('--config_file',
1245 help='nsi specific yaml configuration file')
1246 @click.option('--wait',
1250 help='do not return the control immediately, but keep it \
1251 until the operation is completed, or timeout')
1253 def nsi_create1(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1254 """creates a new Network Slice Instance (NSI)"""
1255 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
)
1258 @cli.command(name
='netslice-instance-create', short_help
='creates a new Network Slice Instance')
1259 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1260 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1261 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1262 @click.option('--ssh_keys', default
=None,
1263 help='comma separated list of keys to inject to vnfs')
1264 @click.option('--config', default
=None,
1265 help='Netslice specific yaml configuration:\n'
1266 'netslice_subnet: [\n'
1267 'id: TEXT, vim_account: TEXT,\n'
1268 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1269 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1271 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1273 @click.option('--config_file',
1275 help='nsi specific yaml configuration file')
1276 @click.option('--wait',
1280 help='do not return the control immediately, but keep it \
1281 until the operation is completed, or timeout')
1283 def nsi_create2(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1284 """creates a new Network Slice Instance (NSI)"""
1285 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
)
1288 @cli.command(name
='pdu-create', short_help
='adds a new Physical Deployment Unit to the catalog')
1289 @click.option('--name', help='name of the Physical Deployment Unit')
1290 @click.option('--pdu_type', help='type of PDU (e.g. router, firewall, FW001)')
1291 @click.option('--interface',
1292 help='interface(s) of the PDU: name=<NAME>,mgmt=<true|false>,ip-address=<IP_ADDRESS>'+
1293 '[,type=<overlay|underlay>][,mac-address=<MAC_ADDRESS>][,vim-network-name=<VIM_NET_NAME>]',
1295 @click.option('--description', help='human readable description')
1296 @click.option('--vim_account', help='list of VIM accounts (in the same VIM) that can reach this PDU', multiple
=True)
1297 @click.option('--descriptor_file', default
=None, help='PDU descriptor file (as an alternative to using the other arguments')
1299 def pdu_create(ctx
, name
, pdu_type
, interface
, description
, vim_account
, descriptor_file
):
1300 """creates a new Physical Deployment Unit (PDU)"""
1302 check_client_version(ctx
.obj
, ctx
.command
.name
)
1304 if not descriptor_file
:
1306 raise ClientException('in absence of descriptor file, option "--name" is mandatory')
1308 raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
1310 raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
1312 raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
1314 with
open(descriptor_file
, 'r') as df
:
1315 pdu
= yaml
.load(df
.read())
1316 if name
: pdu
["name"] = name
1317 if pdu_type
: pdu
["type"] = pdu_type
1318 if description
: pdu
["description"] = description
1319 if vim_account
: pdu
["vim_accounts"] = vim_account
1322 for iface
in interface
:
1323 new_iface
={k
:v
for k
,v
in [i
.split('=') for i
in iface
.split(',')]}
1324 new_iface
["mgmt"] = (new_iface
.get("mgmt","false").lower() == "true")
1325 ifaces_list
.append(new_iface
)
1326 pdu
["interfaces"] = ifaces_list
1327 ctx
.obj
.pdu
.create(pdu
)
1328 except ClientException
as inst
:
1329 print((inst
.message
))
1332 ####################
1334 ####################
1336 def nsd_update(ctx
, name
, content
):
1338 check_client_version(ctx
.obj
, ctx
.command
.name
)
1339 ctx
.obj
.nsd
.update(name
, content
)
1340 except ClientException
as inst
:
1341 print((inst
.message
))
1345 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
1346 @click.argument('name')
1347 @click.option('--content', default
=None,
1348 help='filename with the NSD/NSpkg replacing the current one')
1350 def nsd_update1(ctx
, name
, content
):
1351 """updates a NSD/NSpkg
1353 NAME: name or ID of the NSD/NSpkg
1355 nsd_update(ctx
, name
, content
)
1358 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
1359 @click.argument('name')
1360 @click.option('--content', default
=None,
1361 help='filename with the NSD/NSpkg replacing the current one')
1363 def nsd_update2(ctx
, name
, content
):
1364 """updates a NSD/NSpkg
1366 NAME: name or ID of the NSD/NSpkg
1368 nsd_update(ctx
, name
, content
)
1371 def vnfd_update(ctx
, name
, content
):
1373 check_client_version(ctx
.obj
, ctx
.command
.name
)
1374 ctx
.obj
.vnfd
.update(name
, content
)
1375 except ClientException
as inst
:
1376 print((inst
.message
))
1380 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
1381 @click.argument('name')
1382 @click.option('--content', default
=None,
1383 help='filename with the VNFD/VNFpkg replacing the current one')
1385 def vnfd_update1(ctx
, name
, content
):
1386 """updates a VNFD/VNFpkg
1388 NAME: name or ID of the VNFD/VNFpkg
1390 vnfd_update(ctx
, name
, content
)
1393 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
1394 @click.argument('name')
1395 @click.option('--content', default
=None,
1396 help='filename with the VNFD/VNFpkg replacing the current one')
1398 def vnfd_update2(ctx
, name
, content
):
1399 """updates a VNFD/VNFpkg
1401 NAME: VNFD yaml file or VNFpkg tar.gz file
1403 vnfd_update(ctx
, name
, content
)
1406 @cli.command(name
='nfpkg-update', short_help
='updates a NFpkg')
1407 @click.argument('name')
1408 @click.option('--content', default
=None,
1409 help='filename with the NFpkg replacing the current one')
1411 def nfpkg_update(ctx
, name
, content
):
1414 NAME: NF Descriptor yaml file or NFpkg tar.gz file
1416 vnfd_update(ctx
, name
, content
)
1419 def nst_update(ctx
, name
, content
):
1421 check_client_version(ctx
.obj
, ctx
.command
.name
)
1422 ctx
.obj
.nst
.update(name
, content
)
1423 except ClientException
as inst
:
1424 print((inst
.message
))
1428 @cli.command(name
='nst-update', short_help
='updates a Network Slice Template (NST)')
1429 @click.argument('name')
1430 @click.option('--content', default
=None,
1431 help='filename with the NST/NSTpkg replacing the current one')
1433 def nst_update1(ctx
, name
, content
):
1434 """updates a Network Slice Template (NST)
1436 NAME: name or ID of the NSD/NSpkg
1438 nst_update(ctx
, name
, content
)
1441 @cli.command(name
='netslice-template-update', short_help
='updates a Network Slice Template (NST)')
1442 @click.argument('name')
1443 @click.option('--content', default
=None,
1444 help='filename with the NST/NSTpkg replacing the current one')
1446 def nst_update2(ctx
, name
, content
):
1447 """updates a Network Slice Template (NST)
1449 NAME: name or ID of the NSD/NSpkg
1451 nst_update(ctx
, name
, content
)
1454 ####################
1456 ####################
1458 def nsd_delete(ctx
, name
, force
):
1461 ctx
.obj
.nsd
.delete(name
)
1463 check_client_version(ctx
.obj
, '--force')
1464 ctx
.obj
.nsd
.delete(name
, force
)
1465 except ClientException
as inst
:
1466 print((inst
.message
))
1470 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
1471 @click.argument('name')
1472 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1474 def nsd_delete1(ctx
, name
, force
):
1475 """deletes a NSD/NSpkg
1477 NAME: name or ID of the NSD/NSpkg to be deleted
1479 nsd_delete(ctx
, name
, force
)
1482 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
1483 @click.argument('name')
1484 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1486 def nsd_delete2(ctx
, name
, force
):
1487 """deletes a NSD/NSpkg
1489 NAME: name or ID of the NSD/NSpkg to be deleted
1491 nsd_delete(ctx
, name
, force
)
1494 def vnfd_delete(ctx
, name
, force
):
1497 ctx
.obj
.vnfd
.delete(name
)
1499 check_client_version(ctx
.obj
, '--force')
1500 ctx
.obj
.vnfd
.delete(name
, force
)
1501 except ClientException
as inst
:
1502 print((inst
.message
))
1506 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
1507 @click.argument('name')
1508 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1510 def vnfd_delete1(ctx
, name
, force
):
1511 """deletes a VNFD/VNFpkg
1513 NAME: name or ID of the VNFD/VNFpkg to be deleted
1515 vnfd_delete(ctx
, name
, force
)
1518 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
1519 @click.argument('name')
1520 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1522 def vnfd_delete2(ctx
, name
, force
):
1523 """deletes a VNFD/VNFpkg
1525 NAME: name or ID of the VNFD/VNFpkg to be deleted
1527 vnfd_delete(ctx
, name
, force
)
1530 @cli.command(name
='nfpkg-delete', short_help
='deletes a NFpkg')
1531 @click.argument('name')
1532 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1534 def nfpkg_delete(ctx
, name
, force
):
1537 NAME: name or ID of the NFpkg to be deleted
1539 vnfd_delete(ctx
, name
, force
)
1542 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
1543 @click.argument('name')
1544 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1545 @click.option('--wait',
1549 help='do not return the control immediately, but keep it \
1550 until the operation is completed, or timeout')
1552 def ns_delete(ctx
, name
, force
, wait
):
1553 """deletes a NS instance
1555 NAME: name or ID of the NS instance to be deleted
1559 ctx
.obj
.ns
.delete(name
, wait
=wait
)
1561 check_client_version(ctx
.obj
, '--force')
1562 ctx
.obj
.ns
.delete(name
, force
, wait
=wait
)
1563 except ClientException
as inst
:
1564 print((inst
.message
))
1568 def nst_delete(ctx
, name
, force
):
1570 check_client_version(ctx
.obj
, ctx
.command
.name
)
1571 ctx
.obj
.nst
.delete(name
, force
)
1572 except ClientException
as inst
:
1573 print((inst
.message
))
1577 @cli.command(name
='nst-delete', short_help
='deletes a Network Slice Template (NST)')
1578 @click.argument('name')
1579 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1581 def nst_delete1(ctx
, name
, force
):
1582 """deletes a Network Slice Template (NST)
1584 NAME: name or ID of the NST/NSTpkg to be deleted
1586 nst_delete(ctx
, name
, force
)
1589 @cli.command(name
='netslice-template-delete', short_help
='deletes a Network Slice Template (NST)')
1590 @click.argument('name')
1591 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1593 def nst_delete2(ctx
, name
, force
):
1594 """deletes a Network Slice Template (NST)
1596 NAME: name or ID of the NST/NSTpkg to be deleted
1598 nst_delete(ctx
, name
, force
)
1601 def nsi_delete(ctx
, name
, force
, wait
):
1603 check_client_version(ctx
.obj
, ctx
.command
.name
)
1604 ctx
.obj
.nsi
.delete(name
, force
, wait
=wait
)
1605 except ClientException
as inst
:
1606 print((inst
.message
))
1610 @cli.command(name
='nsi-delete', short_help
='deletes a Network Slice Instance (NSI)')
1611 @click.argument('name')
1612 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1613 @click.option('--wait',
1617 help='do not return the control immediately, but keep it \
1618 until the operation is completed, or timeout')
1620 def nsi_delete1(ctx
, name
, force
, wait
):
1621 """deletes a Network Slice Instance (NSI)
1623 NAME: name or ID of the Network Slice instance to be deleted
1625 nsi_delete(ctx
, name
, force
, wait
=wait
)
1628 @cli.command(name
='netslice-instance-delete', short_help
='deletes a Network Slice Instance (NSI)')
1629 @click.argument('name')
1630 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1632 def nsi_delete2(ctx
, name
, force
, wait
):
1633 """deletes a Network Slice Instance (NSI)
1635 NAME: name or ID of the Network Slice instance to be deleted
1637 nsi_delete(ctx
, name
, force
, wait
=wait
)
1640 @cli.command(name
='pdu-delete', short_help
='deletes a Physical Deployment Unit (PDU)')
1641 @click.argument('name')
1642 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1644 def pdu_delete(ctx
, name
, force
):
1645 """deletes a Physical Deployment Unit (PDU)
1647 NAME: name or ID of the PDU to be deleted
1650 check_client_version(ctx
.obj
, ctx
.command
.name
)
1651 ctx
.obj
.pdu
.delete(name
, force
)
1652 except ClientException
as inst
:
1653 print((inst
.message
))
1661 @cli.command(name
='vim-create')
1662 @click.option('--name',
1664 help='Name to create datacenter')
1665 @click.option('--user',
1667 help='VIM username')
1668 @click.option('--password',
1671 confirmation_prompt
=True,
1672 help='VIM password')
1673 @click.option('--auth_url',
1676 @click.option('--tenant',
1678 help='VIM tenant name')
1679 @click.option('--config',
1681 help='VIM specific config parameters')
1682 @click.option('--account_type',
1683 default
='openstack',
1685 @click.option('--description',
1686 default
='no description',
1687 help='human readable description')
1688 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1689 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1690 @click.option('--wait',
1694 help='do not return the control immediately, but keep it \
1695 until the operation is completed, or timeout')
1709 """creates a new VIM account"""
1712 check_client_version(ctx
.obj
, '--sdn_controller')
1713 if sdn_port_mapping
:
1714 check_client_version(ctx
.obj
, '--sdn_port_mapping')
1716 vim
['vim-username'] = user
1717 vim
['vim-password'] = password
1718 vim
['vim-url'] = auth_url
1719 vim
['vim-tenant-name'] = tenant
1720 vim
['vim-type'] = account_type
1721 vim
['description'] = description
1722 vim
['config'] = config
1723 if sdn_controller
or sdn_port_mapping
:
1724 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
, wait
=wait
)
1726 ctx
.obj
.vim
.create(name
, vim
, wait
=wait
)
1727 except ClientException
as inst
:
1728 print((inst
.message
))
1732 @cli.command(name
='vim-update', short_help
='updates a VIM account')
1733 @click.argument('name')
1734 @click.option('--newname', help='New name for the VIM account')
1735 @click.option('--user', help='VIM username')
1736 @click.option('--password', help='VIM password')
1737 @click.option('--auth_url', help='VIM url')
1738 @click.option('--tenant', help='VIM tenant name')
1739 @click.option('--config', help='VIM specific config parameters')
1740 @click.option('--account_type', help='VIM type')
1741 @click.option('--description', help='human readable description')
1742 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1743 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1744 @click.option('--wait',
1748 help='do not return the control immediately, but keep it \
1749 until the operation is completed, or timeout')
1764 """updates a VIM account
1766 NAME: name or ID of the VIM account
1769 check_client_version(ctx
.obj
, ctx
.command
.name
)
1771 if newname
: vim
['name'] = newname
1772 if user
: vim
['vim_user'] = user
1773 if password
: vim
['vim_password'] = password
1774 if auth_url
: vim
['vim_url'] = auth_url
1775 if tenant
: vim
['vim-tenant-name'] = tenant
1776 if account_type
: vim
['vim_type'] = account_type
1777 if description
: vim
['description'] = description
1778 if config
: vim
['config'] = config
1779 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
, wait
=wait
)
1780 except ClientException
as inst
:
1781 print((inst
.message
))
1785 @cli.command(name
='vim-delete')
1786 @click.argument('name')
1787 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1788 @click.option('--wait',
1792 help='do not return the control immediately, but keep it \
1793 until the operation is completed, or timeout')
1795 def vim_delete(ctx
, name
, force
, wait
):
1796 """deletes a VIM account
1798 NAME: name or ID of the VIM account to be deleted
1802 ctx
.obj
.vim
.delete(name
, wait
=wait
)
1804 check_client_version(ctx
.obj
, '--force')
1805 ctx
.obj
.vim
.delete(name
, force
, wait
=wait
)
1806 except ClientException
as inst
:
1807 print((inst
.message
))
1811 @cli.command(name
='vim-list')
1812 @click.option('--ro_update/--no_ro_update',
1814 help='update list from RO')
1815 @click.option('--filter', default
=None,
1816 help='restricts the list to the VIM accounts matching the filter')
1818 def vim_list(ctx
, ro_update
, filter):
1819 """list all VIM accounts"""
1821 check_client_version(ctx
.obj
, '--filter')
1823 check_client_version(ctx
.obj
, '--ro_update', 'v1')
1824 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1825 if fullclassname
== 'osmclient.sol005.client.Client':
1826 resp
= ctx
.obj
.vim
.list(filter)
1828 resp
= ctx
.obj
.vim
.list(ro_update
)
1829 table
= PrettyTable(['vim name', 'uuid'])
1831 table
.add_row([vim
['name'], vim
['uuid']])
1836 @cli.command(name
='vim-show')
1837 @click.argument('name')
1839 def vim_show(ctx
, name
):
1840 """shows the details of a VIM account
1842 NAME: name or ID of the VIM account
1845 resp
= ctx
.obj
.vim
.get(name
)
1846 if 'vim_password' in resp
:
1847 resp
['vim_password']='********'
1848 except ClientException
as inst
:
1849 print((inst
.message
))
1852 table
= PrettyTable(['key', 'attribute'])
1853 for k
, v
in list(resp
.items()):
1854 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1859 ####################
1861 ####################
1863 @cli.command(name
='wim-create')
1864 @click.option('--name',
1866 help='Name for the WIM account')
1867 @click.option('--user',
1868 help='WIM username')
1869 @click.option('--password',
1870 help='WIM password')
1871 @click.option('--url',
1874 # @click.option('--tenant',
1875 # help='wIM tenant name')
1876 @click.option('--config',
1878 help='WIM specific config parameters')
1879 @click.option('--wim_type',
1881 @click.option('--description',
1882 default
='no description',
1883 help='human readable description')
1884 @click.option('--wim_port_mapping', default
=None, help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge (WAN service endpoint id and info)")
1885 @click.option('--wait',
1889 help='do not return the control immediately, but keep it \
1890 until the operation is completed, or timeout')
1903 """creates a new WIM account"""
1905 check_client_version(ctx
.obj
, ctx
.command
.name
)
1906 # if sdn_controller:
1907 # check_client_version(ctx.obj, '--sdn_controller')
1908 # if sdn_port_mapping:
1909 # check_client_version(ctx.obj, '--sdn_port_mapping')
1911 if user
: wim
['user'] = user
1912 if password
: wim
['password'] = password
1913 if url
: wim
['wim_url'] = url
1914 # if tenant: wim['tenant'] = tenant
1915 wim
['wim_type'] = wim_type
1916 if description
: wim
['description'] = description
1917 if config
: wim
['config'] = config
1918 ctx
.obj
.wim
.create(name
, wim
, wim_port_mapping
, wait
=wait
)
1919 except ClientException
as inst
:
1920 print((inst
.message
))
1924 @cli.command(name
='wim-update', short_help
='updates a WIM account')
1925 @click.argument('name')
1926 @click.option('--newname', help='New name for the WIM account')
1927 @click.option('--user', help='WIM username')
1928 @click.option('--password', help='WIM password')
1929 @click.option('--url', help='WIM url')
1930 @click.option('--config', help='WIM specific config parameters')
1931 @click.option('--wim_type', help='WIM type')
1932 @click.option('--description', help='human readable description')
1933 @click.option('--wim_port_mapping', default
=None, help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge (WAN service endpoint id and info)")
1934 @click.option('--wait',
1938 help='do not return the control immediately, but keep it \
1939 until the operation is completed, or timeout')
1952 """updates a WIM account
1954 NAME: name or ID of the WIM account
1957 check_client_version(ctx
.obj
, ctx
.command
.name
)
1959 if newname
: wim
['name'] = newname
1960 if user
: wim
['user'] = user
1961 if password
: wim
['password'] = password
1962 if url
: wim
['url'] = url
1963 # if tenant: wim['tenant'] = tenant
1964 if wim_type
: wim
['wim_type'] = wim_type
1965 if description
: wim
['description'] = description
1966 if config
: wim
['config'] = config
1967 ctx
.obj
.wim
.update(name
, wim
, wim_port_mapping
, wait
=wait
)
1968 except ClientException
as inst
:
1969 print((inst
.message
))
1973 @cli.command(name
='wim-delete')
1974 @click.argument('name')
1975 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1976 @click.option('--wait',
1980 help='do not return the control immediately, but keep it \
1981 until the operation is completed, or timeout')
1983 def wim_delete(ctx
, name
, force
, wait
):
1984 """deletes a WIM account
1986 NAME: name or ID of the WIM account to be deleted
1989 check_client_version(ctx
.obj
, ctx
.command
.name
)
1990 ctx
.obj
.wim
.delete(name
, force
, wait
=wait
)
1991 except ClientException
as inst
:
1992 print((inst
.message
))
1996 @cli.command(name
='wim-list')
1997 @click.option('--filter', default
=None,
1998 help='restricts the list to the WIM accounts matching the filter')
2000 def wim_list(ctx
, filter):
2001 """list all WIM accounts"""
2003 check_client_version(ctx
.obj
, ctx
.command
.name
)
2004 resp
= ctx
.obj
.wim
.list(filter)
2005 table
= PrettyTable(['wim name', 'uuid'])
2007 table
.add_row([wim
['name'], wim
['uuid']])
2010 except ClientException
as inst
:
2011 print((inst
.message
))
2015 @cli.command(name
='wim-show')
2016 @click.argument('name')
2018 def wim_show(ctx
, name
):
2019 """shows the details of a WIM account
2021 NAME: name or ID of the WIM account
2024 check_client_version(ctx
.obj
, ctx
.command
.name
)
2025 resp
= ctx
.obj
.wim
.get(name
)
2026 if 'password' in resp
:
2027 resp
['wim_password']='********'
2028 except ClientException
as inst
:
2029 print((inst
.message
))
2032 table
= PrettyTable(['key', 'attribute'])
2033 for k
, v
in list(resp
.items()):
2034 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2039 ####################
2040 # SDN controller operations
2041 ####################
2043 @cli.command(name
='sdnc-create')
2044 @click.option('--name',
2046 help='Name to create sdn controller')
2047 @click.option('--type',
2049 help='SDN controller type')
2050 @click.option('--sdn_controller_version',
2051 help='SDN controller version')
2052 @click.option('--ip_address',
2054 help='SDN controller IP address')
2055 @click.option('--port',
2057 help='SDN controller port')
2058 @click.option('--switch_dpid',
2060 help='Switch DPID (Openflow Datapath ID)')
2061 @click.option('--user',
2062 help='SDN controller username')
2063 @click.option('--password',
2065 confirmation_prompt
=True,
2066 help='SDN controller password')
2067 #@click.option('--description',
2068 # default='no description',
2069 # help='human readable description')
2070 @click.option('--wait',
2074 help='do not return the control immediately, but keep it \
2075 until the operation is completed, or timeout')
2077 def sdnc_create(ctx
,
2080 sdn_controller_version
,
2087 """creates a new SDN controller"""
2089 sdncontroller
['name'] = name
2090 sdncontroller
['type'] = type
2091 sdncontroller
['ip'] = ip_address
2092 sdncontroller
['port'] = int(port
)
2093 sdncontroller
['dpid'] = switch_dpid
2094 if sdn_controller_version
:
2095 sdncontroller
['version'] = sdn_controller_version
2097 sdncontroller
['user'] = user
2099 sdncontroller
['password'] = password
2100 # sdncontroller['description'] = description
2102 check_client_version(ctx
.obj
, ctx
.command
.name
)
2103 ctx
.obj
.sdnc
.create(name
, sdncontroller
, wait
=wait
)
2104 except ClientException
as inst
:
2105 print((inst
.message
))
2108 @cli.command(name
='sdnc-update', short_help
='updates an SDN controller')
2109 @click.argument('name')
2110 @click.option('--newname', help='New name for the SDN controller')
2111 @click.option('--type', help='SDN controller type')
2112 @click.option('--sdn_controller_version', help='SDN controller username')
2113 @click.option('--ip_address', help='SDN controller IP address')
2114 @click.option('--port', help='SDN controller port')
2115 @click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)')
2116 @click.option('--user', help='SDN controller username')
2117 @click.option('--password', help='SDN controller password')
2118 #@click.option('--description', default=None, help='human readable description')
2119 @click.option('--wait',
2123 help='do not return the control immediately, but keep it \
2124 until the operation is completed, or timeout')
2126 def sdnc_update(ctx
,
2130 sdn_controller_version
,
2137 """updates an SDN controller
2139 NAME: name or ID of the SDN controller
2142 if newname
: sdncontroller
['name'] = newname
2143 if type: sdncontroller
['type'] = type
2144 if ip_address
: sdncontroller
['ip'] = ip_address
2145 if port
: sdncontroller
['port'] = int(port
)
2146 if switch_dpid
: sdncontroller
['dpid'] = switch_dpid
2147 # sdncontroller['description'] = description
2148 if sdn_controller_version
is not None:
2149 if sdn_controller_version
=="":
2150 sdncontroller
['version'] = None
2152 sdncontroller
['version'] = sdn_controller_version
2153 if user
is not None:
2155 sdncontroller
['user'] = None
2157 sdncontroller
['user'] = user
2158 if password
is not None:
2160 sdncontroller
['password'] = None
2162 sdncontroller
['password'] = user
2164 check_client_version(ctx
.obj
, ctx
.command
.name
)
2165 ctx
.obj
.sdnc
.update(name
, sdncontroller
, wait
=wait
)
2166 except ClientException
as inst
:
2167 print((inst
.message
))
2171 @cli.command(name
='sdnc-delete')
2172 @click.argument('name')
2173 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2174 @click.option('--wait',
2178 help='do not return the control immediately, but keep it \
2179 until the operation is completed, or timeout')
2181 def sdnc_delete(ctx
, name
, force
, wait
):
2182 """deletes an SDN controller
2184 NAME: name or ID of the SDN controller to be deleted
2187 check_client_version(ctx
.obj
, ctx
.command
.name
)
2188 ctx
.obj
.sdnc
.delete(name
, force
, wait
=wait
)
2189 except ClientException
as inst
:
2190 print((inst
.message
))
2194 @cli.command(name
='sdnc-list')
2195 @click.option('--filter', default
=None,
2196 help='restricts the list to the SDN controllers matching the filter')
2198 def sdnc_list(ctx
, filter):
2199 """list all SDN controllers"""
2201 check_client_version(ctx
.obj
, ctx
.command
.name
)
2202 resp
= ctx
.obj
.sdnc
.list(filter)
2203 except ClientException
as inst
:
2204 print((inst
.message
))
2206 table
= PrettyTable(['name', 'id'])
2208 table
.add_row([sdnc
['name'], sdnc
['_id']])
2213 @cli.command(name
='sdnc-show')
2214 @click.argument('name')
2216 def sdnc_show(ctx
, name
):
2217 """shows the details of an SDN controller
2219 NAME: name or ID of the SDN controller
2222 check_client_version(ctx
.obj
, ctx
.command
.name
)
2223 resp
= ctx
.obj
.sdnc
.get(name
)
2224 except ClientException
as inst
:
2225 print((inst
.message
))
2228 table
= PrettyTable(['key', 'attribute'])
2229 for k
, v
in list(resp
.items()):
2230 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2235 ####################
2236 # Project mgmt operations
2237 ####################
2239 @cli.command(name
='project-create')
2240 @click.argument('name')
2241 #@click.option('--description',
2242 # default='no description',
2243 # help='human readable description')
2245 def project_create(ctx
, name
):
2246 """Creates a new project
2248 NAME: name of the project
2251 project
['name'] = name
2253 check_client_version(ctx
.obj
, ctx
.command
.name
)
2254 ctx
.obj
.project
.create(name
, project
)
2255 except ClientException
as inst
:
2260 @cli.command(name
='project-delete')
2261 @click.argument('name')
2262 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2264 def project_delete(ctx
, name
):
2265 """deletes a project
2267 NAME: name or ID of the project to be deleted
2270 check_client_version(ctx
.obj
, ctx
.command
.name
)
2271 ctx
.obj
.project
.delete(name
)
2272 except ClientException
as inst
:
2277 @cli.command(name
='project-list')
2278 @click.option('--filter', default
=None,
2279 help='restricts the list to the projects matching the filter')
2281 def project_list(ctx
, filter):
2282 """list all projects"""
2284 check_client_version(ctx
.obj
, ctx
.command
.name
)
2285 resp
= ctx
.obj
.project
.list(filter)
2286 except ClientException
as inst
:
2289 table
= PrettyTable(['name', 'id'])
2291 table
.add_row([proj
['name'], proj
['_id']])
2296 @cli.command(name
='project-show')
2297 @click.argument('name')
2299 def project_show(ctx
, name
):
2300 """shows the details of a project
2302 NAME: name or ID of the project
2305 check_client_version(ctx
.obj
, ctx
.command
.name
)
2306 resp
= ctx
.obj
.project
.get(name
)
2307 except ClientException
as inst
:
2311 table
= PrettyTable(['key', 'attribute'])
2312 for k
, v
in resp
.items():
2313 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2318 @cli.command(name
='project-update')
2319 @click.argument('project')
2320 @click.option('--name',
2322 help='new name for the project')
2325 def project_update(ctx
, project
, name
):
2327 Update a project name
2330 :param project: id or name of the project to modify
2331 :param name: new name for the project
2335 project_changes
= {}
2336 project_changes
['name'] = name
2339 check_client_version(ctx
.obj
, ctx
.command
.name
)
2340 ctx
.obj
.project
.update(project
, project_changes
)
2341 except ClientException
as inst
:
2345 ####################
2346 # User mgmt operations
2347 ####################
2349 @cli.command(name
='user-create')
2350 @click.argument('username')
2351 @click.option('--password',
2354 confirmation_prompt
=True,
2355 help='user password')
2356 @click.option('--projects',
2357 # prompt="Comma separate list of projects",
2359 callback
=lambda ctx
, param
, value
: ''.join(value
).split(',') if all(len(x
)==1 for x
in value
) else value
,
2360 help='list of project ids that the user belongs to')
2361 @click.option('--project-role-mappings', 'project_role_mappings',
2362 default
=None, multiple
=True,
2363 help='creating user project/role(s) mapping')
2365 def user_create(ctx
, username
, password
, projects
, project_role_mappings
):
2366 """Creates a new user
2369 USERNAME: name of the user
2370 PASSWORD: password of the user
2371 PROJECTS: projects assigned to user (internal only)
2372 PROJECT_ROLE_MAPPING: roles in projects assigned to user (keystone)
2375 user
['username'] = username
2376 user
['password'] = password
2377 user
['projects'] = projects
2378 user
['project_role_mappings'] = project_role_mappings
2381 check_client_version(ctx
.obj
, ctx
.command
.name
)
2382 ctx
.obj
.user
.create(username
, user
)
2383 except ClientException
as inst
:
2388 @cli.command(name
='user-update')
2389 @click.argument('username')
2390 @click.option('--password',
2393 # confirmation_prompt=True,
2394 help='user password')
2395 @click.option('--set-username', 'set_username',
2397 help='change username')
2398 @click.option('--set-project', 'set_project',
2399 default
=None, multiple
=True,
2400 help='create/replace the project,role(s) mapping for this project: \'project,role1,role2,...\'')
2401 @click.option('--remove-project', 'remove_project',
2402 default
=None, multiple
=True,
2403 help='removes project from user: \'project\'')
2404 @click.option('--add-project-role', 'add_project_role',
2405 default
=None, multiple
=True,
2406 help='adds project,role(s) mapping: \'project,role1,role2,...\'')
2407 @click.option('--remove-project-role', 'remove_project_role',
2408 default
=None, multiple
=True,
2409 help='removes project,role(s) mapping: \'project,role1,role2,...\'')
2411 def user_update(ctx
, username
, password
, set_username
, set_project
, remove_project
,
2412 add_project_role
, remove_project_role
):
2413 """Update a user information
2416 USERNAME: name of the user
2417 PASSWORD: new password
2418 SET_USERNAME: new username
2419 SET_PROJECT: creating mappings for project/role(s)
2420 REMOVE_PROJECT: deleting mappings for project/role(s)
2421 ADD_PROJECT_ROLE: adding mappings for project/role(s)
2422 REMOVE_PROJECT_ROLE: removing mappings for project/role(s)
2425 user
['password'] = password
2426 user
['username'] = set_username
2427 user
['set-project'] = set_project
2428 user
['remove-project'] = remove_project
2429 user
['add-project-role'] = add_project_role
2430 user
['remove-project-role'] = remove_project_role
2433 check_client_version(ctx
.obj
, ctx
.command
.name
)
2434 ctx
.obj
.user
.update(username
, user
)
2435 except ClientException
as inst
:
2440 @cli.command(name
='user-delete')
2441 @click.argument('name')
2442 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2444 def user_delete(ctx
, name
):
2448 NAME: name or ID of the user to be deleted
2451 check_client_version(ctx
.obj
, ctx
.command
.name
)
2452 ctx
.obj
.user
.delete(name
)
2453 except ClientException
as inst
:
2458 @cli.command(name
='user-list')
2459 @click.option('--filter', default
=None,
2460 help='restricts the list to the users matching the filter')
2462 def user_list(ctx
, filter):
2463 """list all users"""
2465 check_client_version(ctx
.obj
, ctx
.command
.name
)
2466 resp
= ctx
.obj
.user
.list(filter)
2467 except ClientException
as inst
:
2470 table
= PrettyTable(['name', 'id'])
2472 table
.add_row([user
['username'], user
['_id']])
2477 @cli.command(name
='user-show')
2478 @click.argument('name')
2480 def user_show(ctx
, name
):
2481 """shows the details of a user
2483 NAME: name or ID of the user
2486 check_client_version(ctx
.obj
, ctx
.command
.name
)
2487 resp
= ctx
.obj
.user
.get(name
)
2488 if 'password' in resp
:
2489 resp
['password']='********'
2490 except ClientException
as inst
:
2494 table
= PrettyTable(['key', 'attribute'])
2495 for k
, v
in resp
.items():
2496 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2501 ####################
2502 # Fault Management operations
2503 ####################
2505 @cli.command(name
='ns-alarm-create')
2506 @click.argument('name')
2507 @click.option('--ns', prompt
=True, help='NS instance id or name')
2508 @click.option('--vnf', prompt
=True,
2509 help='VNF name (VNF member index as declared in the NSD)')
2510 @click.option('--vdu', prompt
=True,
2511 help='VDU name (VDU name as declared in the VNFD)')
2512 @click.option('--metric', prompt
=True,
2513 help='Name of the metric (e.g. cpu_utilization)')
2514 @click.option('--severity', default
='WARNING',
2515 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
2516 @click.option('--threshold_value', prompt
=True,
2517 help='threshold value that, when crossed, an alarm is triggered')
2518 @click.option('--threshold_operator', prompt
=True,
2519 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
2520 @click.option('--statistic', default
='AVERAGE',
2521 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
2523 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
2524 threshold_value
, threshold_operator
, statistic
):
2525 """creates a new alarm for a NS instance"""
2526 # TODO: Check how to validate threshold_value.
2527 # Should it be an integer (1-100), percentage, or decimal (0.01-1.00)?
2529 ns_instance
= ctx
.obj
.ns
.get(ns
)
2531 alarm
['alarm_name'] = name
2532 alarm
['ns_id'] = ns_instance
['_id']
2533 alarm
['correlation_id'] = ns_instance
['_id']
2534 alarm
['vnf_member_index'] = vnf
2535 alarm
['vdu_name'] = vdu
2536 alarm
['metric_name'] = metric
2537 alarm
['severity'] = severity
2538 alarm
['threshold_value'] = int(threshold_value
)
2539 alarm
['operation'] = threshold_operator
2540 alarm
['statistic'] = statistic
2541 check_client_version(ctx
.obj
, ctx
.command
.name
)
2542 ctx
.obj
.ns
.create_alarm(alarm
)
2543 except ClientException
as inst
:
2544 print((inst
.message
))
2548 #@cli.command(name='ns-alarm-delete')
2549 #@click.argument('name')
2550 #@click.pass_context
2551 #def ns_alarm_delete(ctx, name):
2552 # """deletes an alarm
2554 # NAME: name of the alarm to be deleted
2557 # check_client_version(ctx.obj, ctx.command.name)
2558 # ctx.obj.ns.delete_alarm(name)
2559 # except ClientException as inst:
2560 # print(inst.message)
2564 ####################
2565 # Performance Management operations
2566 ####################
2568 @cli.command(name
='ns-metric-export')
2569 @click.option('--ns', prompt
=True, help='NS instance id or name')
2570 @click.option('--vnf', prompt
=True,
2571 help='VNF name (VNF member index as declared in the NSD)')
2572 @click.option('--vdu', prompt
=True,
2573 help='VDU name (VDU name as declared in the VNFD)')
2574 @click.option('--metric', prompt
=True,
2575 help='name of the metric (e.g. cpu_utilization)')
2576 #@click.option('--period', default='1w',
2577 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
2578 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
2580 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
2581 """exports a metric to the internal OSM bus, which can be read by other apps"""
2582 # TODO: Check how to validate interval.
2583 # Should it be an integer (seconds), or should a suffix (s,m,h,d,w) also be permitted?
2585 ns_instance
= ctx
.obj
.ns
.get(ns
)
2587 metric_data
['ns_id'] = ns_instance
['_id']
2588 metric_data
['correlation_id'] = ns_instance
['_id']
2589 metric_data
['vnf_member_index'] = vnf
2590 metric_data
['vdu_name'] = vdu
2591 metric_data
['metric_name'] = metric
2592 metric_data
['collection_unit'] = 'WEEK'
2593 metric_data
['collection_period'] = 1
2594 check_client_version(ctx
.obj
, ctx
.command
.name
)
2596 print('{}'.format(ctx
.obj
.ns
.export_metric(metric_data
)))
2600 print('{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
))
2601 time
.sleep(int(interval
))
2603 except ClientException
as inst
:
2604 print((inst
.message
))
2608 ####################
2610 ####################
2612 @cli.command(name
='upload-package')
2613 @click.argument('filename')
2615 def upload_package(ctx
, filename
):
2616 """uploads a VNF package or NS package
2618 FILENAME: VNF or NS package file (tar.gz)
2621 ctx
.obj
.package
.upload(filename
)
2622 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
2623 if fullclassname
!= 'osmclient.sol005.client.Client':
2624 ctx
.obj
.package
.wait_for_upload(filename
)
2625 except ClientException
as inst
:
2626 print((inst
.message
))
2630 @cli.command(name
='ns-scaling-show')
2631 @click.argument('ns_name')
2633 def show_ns_scaling(ctx
, ns_name
):
2634 """shows the status of a NS scaling operation
2636 NS_NAME: name of the NS instance being scaled
2639 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2640 resp
= ctx
.obj
.ns
.list()
2641 except ClientException
as inst
:
2642 print((inst
.message
))
2645 table
= PrettyTable(
2648 'operational status',
2653 if ns_name
== ns
['name']:
2654 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
2655 scaling_records
= nsopdata
['nsr:nsr']['scaling-group-record']
2656 for record
in scaling_records
:
2657 if 'instance' in record
:
2658 instances
= record
['instance']
2659 for inst
in instances
:
2661 [record
['scaling-group-name-ref'],
2662 inst
['instance-id'],
2664 time
.strftime('%Y-%m-%d %H:%M:%S',
2666 inst
['create-time'])),
2672 @cli.command(name
='ns-scale')
2673 @click.argument('ns_name')
2674 @click.option('--ns_scale_group', prompt
=True)
2675 @click.option('--index', prompt
=True)
2676 @click.option('--wait',
2680 help='do not return the control immediately, but keep it \
2681 until the operation is completed, or timeout')
2683 def ns_scale(ctx
, ns_name
, ns_scale_group
, index
, wait
):
2686 NS_NAME: name of the NS instance to be scaled
2689 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2690 ctx
.obj
.ns
.scale(ns_name
, ns_scale_group
, index
, wait
=wait
)
2691 except ClientException
as inst
:
2692 print((inst
.message
))
2696 @cli.command(name
='config-agent-list')
2698 def config_agent_list(ctx
):
2699 """list config agents"""
2701 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2702 except ClientException
as inst
:
2703 print((inst
.message
))
2705 table
= PrettyTable(['name', 'account-type', 'details'])
2706 for account
in ctx
.obj
.vca
.list():
2709 account
['account-type'],
2715 @cli.command(name
='config-agent-delete')
2716 @click.argument('name')
2718 def config_agent_delete(ctx
, name
):
2719 """deletes a config agent
2721 NAME: name of the config agent to be deleted
2724 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2725 ctx
.obj
.vca
.delete(name
)
2726 except ClientException
as inst
:
2727 print((inst
.message
))
2731 @cli.command(name
='config-agent-add')
2732 @click.option('--name',
2734 @click.option('--account_type',
2736 @click.option('--server',
2738 @click.option('--user',
2740 @click.option('--secret',
2743 confirmation_prompt
=True)
2745 def config_agent_add(ctx
, name
, account_type
, server
, user
, secret
):
2746 """adds a config agent"""
2748 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2749 ctx
.obj
.vca
.create(name
, account_type
, server
, user
, secret
)
2750 except ClientException
as inst
:
2751 print((inst
.message
))
2755 @cli.command(name
='ro-dump')
2758 """shows RO agent information"""
2759 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2760 resp
= ctx
.obj
.vim
.get_resource_orchestrator()
2761 table
= PrettyTable(['key', 'attribute'])
2762 for k
, v
in list(resp
.items()):
2763 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2768 @cli.command(name
='vcs-list')
2771 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2772 resp
= ctx
.obj
.utils
.get_vcs_info()
2773 table
= PrettyTable(['component name', 'state'])
2774 for component
in resp
:
2775 table
.add_row([component
['component_name'], component
['state']])
2780 @cli.command(name
='ns-action')
2781 @click.argument('ns_name')
2782 @click.option('--vnf_name', default
=None)
2783 @click.option('--action_name', prompt
=True)
2784 @click.option('--params', prompt
=True)
2785 @click.option('--wait',
2789 help='do not return the control immediately, but keep it \
2790 until the operation is completed, or timeout')
2798 """executes an action/primitive over a NS instance
2800 NS_NAME: name or ID of the NS instance
2803 check_client_version(ctx
.obj
, ctx
.command
.name
)
2806 op_data
['vnf_member_index'] = vnf_name
2807 op_data
['primitive'] = action_name
2808 op_data
['primitive_params'] = yaml
.load(params
)
2809 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
, wait
=wait
)
2811 except ClientException
as inst
:
2812 print((inst
.message
))
2816 @cli.command(name
='vnf-scale')
2817 @click.argument('ns_name')
2818 @click.argument('vnf_name')
2819 @click.option('--scaling-group', prompt
=True, help="scaling-group-descriptor name to use")
2820 @click.option('--scale-in', default
=False, is_flag
=True, help="performs a scale in operation")
2821 @click.option('--scale-out', default
=False, is_flag
=True, help="performs a scale out operation (by default)")
2830 Executes a VNF scale (adding/removing VDUs)
2833 NS_NAME: name or ID of the NS instance.
2834 VNF_NAME: member-vnf-index in the NS to be scaled.
2837 check_client_version(ctx
.obj
, ctx
.command
.name
)
2838 if not scale_in
and not scale_out
:
2840 ctx
.obj
.ns
.scale_vnf(ns_name
, vnf_name
, scaling_group
, scale_in
, scale_out
)
2841 except ClientException
as inst
:
2842 print((inst
.message
))
2846 ##############################
2847 # Role Management Operations #
2848 ##############################
2850 @cli.command(name
='role-create', short_help
='creates a role')
2851 @click.argument('name')
2852 @click.option('--definition',
2854 help='role definition using a dictionary')
2856 def role_create(ctx
, name
, definition
):
2861 NAME: Name or ID of the role.
2862 DEFINITION: Definition of grant/denial of access to resources.
2865 check_client_version(ctx
.obj
, ctx
.command
.name
)
2866 ctx
.obj
.role
.create(name
, definition
)
2867 except ClientException
as inst
:
2872 @cli.command(name
='role-update', short_help
='updates a role')
2873 @click.argument('name')
2874 @click.option('--definition',
2876 help='add a new definition to the role')
2877 @click.option('--add',
2879 help='add a resource access grant/denial')
2880 @click.option('--remove',
2882 help='remove a resource access grant/denial')
2884 def role_update(ctx
, name
, definition
, add
, remove
):
2889 NAME: Name or ID of the role.
2890 DEFINITION: Definition overwrites the old definition.
2891 ADD: Grant/denial of access to resource to add.
2892 REMOVE: Grant/denial of access to resource to remove.
2895 check_client_version(ctx
.obj
, ctx
.command
.name
)
2896 ctx
.obj
.role
.update(name
, definition
, add
, remove
)
2897 except ClientException
as inst
:
2902 @cli.command(name
='role-delete', short_help
='deletes a role')
2903 @click.argument('name')
2904 # @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2906 def role_delete(ctx
, name
):
2911 NAME: Name or ID of the role.
2914 check_client_version(ctx
.obj
, ctx
.command
.name
)
2915 ctx
.obj
.role
.delete(name
)
2916 except ClientException
as inst
:
2921 @cli.command(name
='role-list', short_help
='list all roles')
2922 @click.option('--filter', default
=None,
2923 help='restricts the list to the projects matching the filter')
2925 def role_list(ctx
, filter):
2930 check_client_version(ctx
.obj
, ctx
.command
.name
)
2931 resp
= ctx
.obj
.role
.list(filter)
2932 except ClientException
as inst
:
2935 table
= PrettyTable(['name', 'id'])
2937 table
.add_row([role
['name'], role
['_id']])
2942 @cli.command(name
='role-show', short_help
='show specific role')
2943 @click.argument('name')
2945 def role_show(ctx
, name
):
2947 Shows the details of a role.
2950 NAME: Name or ID of the role.
2953 check_client_version(ctx
.obj
, ctx
.command
.name
)
2954 resp
= ctx
.obj
.role
.get(name
)
2955 except ClientException
as inst
:
2959 table
= PrettyTable(['key', 'attribute'])
2960 for k
, v
in resp
.items():
2961 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2966 if __name__
== '__main__':
2969 except pycurl
.error
as e
:
2971 print('Maybe "--hostname" option or OSM_HOSTNAME' +
2972 'environment variable needs to be specified')