6e8bd8808a322b2f070b6434b120e29d348b2d27
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
32 def check_client_version(obj
, what
, version
='sol005'):
34 Checks the version of the client object and raises error if it not the expected.
36 :param obj: the client object
37 :what: the function or command under evaluation (used when an error is raised)
39 :raises ClientError: if the specified version does not match the client version
41 fullclassname
= obj
.__module
__ + "." + obj
.__class
__.__name
__
42 message
= 'The following commands or options are only supported with the option "--sol005": {}'.format(what
)
44 message
= 'The following commands or options are not supported when using option "--sol005": {}'.format(what
)
45 if fullclassname
!= 'osmclient.{}.client.Client'.format(version
):
46 raise ClientException(message
)
50 CONTEXT_SETTINGS
= dict(help_option_names
=['-h', '--help'], max_content_width
=160)
52 @click.group(context_settings
=CONTEXT_SETTINGS
)
53 @click.option('--hostname',
55 envvar
='OSM_HOSTNAME',
56 help='hostname of server. ' +
57 'Also can set OSM_HOSTNAME in environment')
58 #@click.option('--sol005/--no-sol005',
60 # envvar='OSM_SOL005',
61 # help='Use ETSI NFV SOL005 API (default) or the previous SO API. ' +
62 # 'Also can set OSM_SOL005 in environment')
63 @click.option('--user',
66 help='user (defaults to admin). ' +
67 'Also can set OSM_USER in environment')
68 @click.option('--password',
70 envvar
='OSM_PASSWORD',
71 help='password (defaults to admin). ' +
72 'Also can set OSM_PASSWORD in environment')
73 @click.option('--project',
76 help='project (defaults to admin). ' +
77 'Also can set OSM_PROJECT in environment')
78 #@click.option('--so-port',
80 # envvar='OSM_SO_PORT',
81 # help='hostname of server. ' +
82 # 'Also can set OSM_SO_PORT in environment')
83 #@click.option('--so-project',
85 # envvar='OSM_SO_PROJECT',
86 # help='Project Name in SO. ' +
87 # 'Also can set OSM_SO_PROJECT in environment')
88 #@click.option('--ro-hostname',
90 # envvar='OSM_RO_HOSTNAME',
91 # help='hostname of RO server. ' +
92 # 'Also can set OSM_RO_HOSTNAME in environment')
93 #@click.option('--ro-port',
95 # envvar='OSM_RO_PORT',
96 # help='hostname of RO server. ' +
97 # 'Also can set OSM_RO_PORT in environment')
99 def cli(ctx
, hostname
, user
, password
, project
):
102 "either hostname option or OSM_HOSTNAME " +
103 "environment variable needs to be specified"))
106 # if so_port is not None:
107 # kwargs['so_port']=so_port
108 # if so_project is not None:
109 # kwargs['so_project']=so_project
110 # if ro_hostname is not None:
111 # kwargs['ro_host']=ro_hostname
112 # if ro_port is not None:
113 # kwargs['ro_port']=ro_port
114 sol005
= os
.getenv('OSM_SOL005', True)
117 if password
is not None:
118 kwargs
['password']=password
119 if project
is not None:
120 kwargs
['project']=project
122 ctx
.obj
= client
.Client(host
=hostname
, sol005
=sol005
, **kwargs
)
129 @cli.command(name
='ns-list', short_help
='list all NS instances')
130 @click.option('--filter', default
=None,
131 help='restricts the list to the NS instances matching the filter.')
133 def ns_list(ctx
, filter):
134 """list all NS instances
138 --filter filterExpr Restricts the list to the NS instances matching the filter
141 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
142 concatenated using the "&" character:
145 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
146 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
147 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
149 value := scalar value
153 * zero or more occurrences
154 ? zero or one occurrence
155 [] grouping of expressions to be used with ? and *
156 "" quotation marks for marking string constants
160 "AttrName" is the name of one attribute in the data type that defines the representation
161 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
162 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
163 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
164 entries, it means that the operator "op" is applied to the attribute addressed by the last
165 <attrName> entry included in the concatenation. All simple filter expressions are combined
166 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
167 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
168 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
169 prefix". If an attribute referenced in an expression is an array, an object that contains a
170 corresponding array shall be considered to match the expression if any of the elements in the
171 array matches all expressions that have the same attribute prefix.
175 --filter admin-status=ENABLED
176 --filter nsd-ref=<NSD_NAME>
177 --filter nsd.vendor=<VENDOR>
178 --filter nsd.vendor=<VENDOR>&nsd-ref=<NSD_NAME>
179 --filter nsd.constituent-vnfd.vnfd-id-ref=<VNFD_NAME>
182 check_client_version(ctx
.obj
, '--filter')
183 resp
= ctx
.obj
.ns
.list(filter)
185 resp
= ctx
.obj
.ns
.list()
189 'operational status',
193 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
194 if fullclassname
== 'osmclient.sol005.client.Client':
196 nsr_name
= nsr
['name']
199 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
200 nsr
= nsopdata
['nsr:nsr']
201 nsr_name
= nsr
['name-ref']
202 nsr_id
= nsr
['ns-instance-config-ref']
203 opstatus
= nsr
['operational-status'] if 'operational-status' in nsr
else 'Not found'
204 configstatus
= nsr
['config-status'] if 'config-status' in nsr
else 'Not found'
205 detailed_status
= nsr
['detailed-status'] if 'detailed-status' in nsr
else 'Not found'
206 if configstatus
== "config_not_needed":
207 configstatus
= "configured (no charms)"
218 def nsd_list(ctx
, filter):
220 check_client_version(ctx
.obj
, '--filter')
221 resp
= ctx
.obj
.nsd
.list(filter)
223 resp
= ctx
.obj
.nsd
.list()
224 # print(yaml.safe_dump(resp))
225 table
= PrettyTable(['nsd name', 'id'])
226 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
227 if fullclassname
== 'osmclient.sol005.client.Client':
229 name
= ns
['name'] if 'name' in ns
else '-'
230 table
.add_row([name
, ns
['_id']])
233 table
.add_row([ns
['name'], ns
['id']])
238 @cli.command(name
='nsd-list', short_help
='list all NS packages')
239 @click.option('--filter', default
=None,
240 help='restricts the list to the NSD/NSpkg matching the filter')
242 def nsd_list1(ctx
, filter):
243 """list all NSD/NS pkg in the system"""
244 nsd_list(ctx
, filter)
247 @cli.command(name
='nspkg-list', short_help
='list all NS packages')
248 @click.option('--filter', default
=None,
249 help='restricts the list to the NSD/NSpkg matching the filter')
251 def nsd_list2(ctx
, filter):
252 """list all NS packages"""
253 nsd_list(ctx
, filter)
256 def vnfd_list(ctx
, nf_type
, filter):
258 check_client_version(ctx
.obj
, '--nf_type')
260 check_client_version(ctx
.obj
, '--filter')
263 nf_filter
= "_admin.type=vnfd"
264 elif nf_type
== "pnf":
265 nf_filter
= "_admin.type=pnfd"
266 elif nf_type
== "hnf":
267 nf_filter
= "_admin.type=hnfd"
269 raise ClientException('wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf')
271 filter = '{}&{}'.format(nf_filter
, filter)
275 resp
= ctx
.obj
.vnfd
.list(filter)
277 resp
= ctx
.obj
.vnfd
.list()
278 # print(yaml.safe_dump(resp))
279 table
= PrettyTable(['nfpkg name', 'id'])
280 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
281 if fullclassname
== 'osmclient.sol005.client.Client':
283 name
= vnfd
['name'] if 'name' in vnfd
else '-'
284 table
.add_row([name
, vnfd
['_id']])
287 table
.add_row([vnfd
['name'], vnfd
['id']])
292 @cli.command(name
='vnfd-list', short_help
='list all xNF packages (VNF, HNF, PNF)')
293 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
294 @click.option('--filter', default
=None,
295 help='restricts the list to the NF pkg matching the filter')
297 def vnfd_list1(ctx
, nf_type
, filter):
298 """list all xNF packages (VNF, HNF, PNF)"""
299 vnfd_list(ctx
, nf_type
, filter)
302 @cli.command(name
='vnfpkg-list', short_help
='list all xNF packages (VNF, HNF, PNF)')
303 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
304 @click.option('--filter', default
=None,
305 help='restricts the list to the NFpkg matching the filter')
307 def vnfd_list2(ctx
, nf_type
, filter):
308 """list all xNF packages (VNF, HNF, PNF)"""
309 vnfd_list(ctx
, nf_type
, filter)
312 @cli.command(name
='nfpkg-list', short_help
='list all xNF packages (VNF, HNF, PNF)')
313 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
314 @click.option('--filter', default
=None,
315 help='restricts the list to the NFpkg matching the filter')
317 def nfpkg_list(ctx
, nf_type
, filter):
318 """list all xNF packages (VNF, HNF, PNF)"""
320 check_client_version(ctx
.obj
, ctx
.command
.name
)
321 vnfd_list(ctx
, nf_type
, filter)
322 except ClientException
as inst
:
323 print((inst
.message
))
327 def vnf_list(ctx
, ns
, filter):
331 check_client_version(ctx
.obj
, '--ns')
333 check_client_version(ctx
.obj
, '--filter')
334 resp
= ctx
.obj
.vnf
.list(ns
, filter)
336 resp
= ctx
.obj
.vnf
.list()
337 except ClientException
as inst
:
338 print((inst
.message
))
340 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
341 if fullclassname
== 'osmclient.sol005.client.Client':
351 name
= vnfr
['name'] if 'name' in vnfr
else '-'
356 vnfr
['member-vnf-index-ref'],
358 vnfr
['vim-account-id'],
364 'operational status',
367 if 'mgmt-interface' not in vnfr
:
368 vnfr
['mgmt-interface'] = {}
369 vnfr
['mgmt-interface']['ip-address'] = None
373 vnfr
['operational-status'],
374 vnfr
['config-status']])
379 @cli.command(name
='vnf-list', short_help
='list all NF instances')
380 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
381 @click.option('--filter', default
=None,
382 help='restricts the list to the NF instances matching the filter.')
384 def vnf_list1(ctx
, ns
, filter):
385 """list all NF instances"""
386 vnf_list(ctx
, ns
, filter)
389 @cli.command(name
='nf-list', short_help
='list all NF instances')
390 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
391 @click.option('--filter', default
=None,
392 help='restricts the list to the NF instances matching the filter.')
394 def nf_list(ctx
, ns
, filter):
395 """list all NF instances
399 --ns TEXT NS instance id or name to restrict the VNF list
400 --filter filterExpr Restricts the list to the VNF instances matching the filter
403 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
404 concatenated using the "&" character:
407 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
408 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
409 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
411 value := scalar value
415 * zero or more occurrences
416 ? zero or one occurrence
417 [] grouping of expressions to be used with ? and *
418 "" quotation marks for marking string constants
422 "AttrName" is the name of one attribute in the data type that defines the representation
423 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
424 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
425 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
426 entries, it means that the operator "op" is applied to the attribute addressed by the last
427 <attrName> entry included in the concatenation. All simple filter expressions are combined
428 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
429 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
430 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
431 prefix". If an attribute referenced in an expression is an array, an object that contains a
432 corresponding array shall be considered to match the expression if any of the elements in the
433 array matches all expressions that have the same attribute prefix.
437 --filter vim-account-id=<VIM_ACCOUNT_ID>
438 --filter vnfd-ref=<VNFD_NAME>
439 --filter vdur.ip-address=<IP_ADDRESS>
440 --filter vnfd-ref=<VNFD_NAME>,vdur.ip-address=<IP_ADDRESS>
442 vnf_list(ctx
, ns
, filter)
445 @cli.command(name
='ns-op-list', short_help
='shows the history of operations over a NS instance')
446 @click.argument('name')
448 def ns_op_list(ctx
, name
):
449 """shows the history of operations over a NS instance
451 NAME: name or ID of the NS instance
454 check_client_version(ctx
.obj
, ctx
.command
.name
)
455 resp
= ctx
.obj
.ns
.list_op(name
)
456 except ClientException
as inst
:
457 print((inst
.message
))
460 table
= PrettyTable(['id', 'operation', 'status'])
462 table
.add_row([op
['id'], op
['lcmOperationType'],
463 op
['operationState']])
468 def nsi_list(ctx
, filter):
469 """list all Network Slice Instances"""
471 check_client_version(ctx
.obj
, ctx
.command
.name
)
472 resp
= ctx
.obj
.nsi
.list(filter)
473 except ClientException
as inst
:
474 print((inst
.message
))
477 ['netslice instance name',
479 'operational status',
483 nsi_name
= nsi
['name']
485 opstatus
= nsi
['operational-status'] if 'operational-status' in nsi
else 'Not found'
486 configstatus
= nsi
['config-status'] if 'config-status' in nsi
else 'Not found'
487 detailed_status
= nsi
['detailed-status'] if 'detailed-status' in nsi
else 'Not found'
488 if configstatus
== "config_not_needed":
489 configstatus
= "configured (no charms)"
500 @cli.command(name
='nsi-list', short_help
='list all Network Slice Instances (NSI)')
501 @click.option('--filter', default
=None,
502 help='restricts the list to the Network Slice Instances matching the filter')
504 def nsi_list1(ctx
, filter):
505 """list all Network Slice Instances (NSI)"""
506 nsi_list(ctx
, filter)
509 @cli.command(name
='netslice-instance-list', short_help
='list all Network Slice Instances (NSI)')
510 @click.option('--filter', default
=None,
511 help='restricts the list to the Network Slice Instances matching the filter')
513 def nsi_list2(ctx
, filter):
514 """list all Network Slice Instances (NSI)"""
515 nsi_list(ctx
, filter)
518 def nst_list(ctx
, filter):
520 check_client_version(ctx
.obj
, ctx
.command
.name
)
521 resp
= ctx
.obj
.nst
.list(filter)
522 except ClientException
as inst
:
523 print((inst
.message
))
525 # print(yaml.safe_dump(resp))
526 table
= PrettyTable(['nst name', 'id'])
528 name
= nst
['name'] if 'name' in nst
else '-'
529 table
.add_row([name
, nst
['_id']])
534 @cli.command(name
='nst-list', short_help
='list all Network Slice Templates (NST)')
535 @click.option('--filter', default
=None,
536 help='restricts the list to the NST matching the filter')
538 def nst_list1(ctx
, filter):
539 """list all Network Slice Templates (NST) in the system"""
540 nst_list(ctx
, filter)
543 @cli.command(name
='netslice-template-list', short_help
='list all Network Slice Templates (NST)')
544 @click.option('--filter', default
=None,
545 help='restricts the list to the NST matching the filter')
547 def nst_list2(ctx
, filter):
548 """list all Network Slice Templates (NST) in the system"""
549 nst_list(ctx
, filter)
552 def nsi_op_list(ctx
, name
):
554 check_client_version(ctx
.obj
, ctx
.command
.name
)
555 resp
= ctx
.obj
.nsi
.list_op(name
)
556 except ClientException
as inst
:
557 print((inst
.message
))
559 table
= PrettyTable(['id', 'operation', 'status'])
561 table
.add_row([op
['id'], op
['lcmOperationType'],
562 op
['operationState']])
567 @cli.command(name
='nsi-op-list', short_help
='shows the history of operations over a Network Slice Instance (NSI)')
568 @click.argument('name')
570 def nsi_op_list1(ctx
, name
):
571 """shows the history of operations over a Network Slice Instance (NSI)
573 NAME: name or ID of the Network Slice Instance
575 nsi_op_list(ctx
, name
)
578 @cli.command(name
='netslice-instance-op-list', short_help
='shows the history of operations over a Network Slice Instance (NSI)')
579 @click.argument('name')
581 def nsi_op_list2(ctx
, name
):
582 """shows the history of operations over a Network Slice Instance (NSI)
584 NAME: name or ID of the Network Slice Instance
586 nsi_op_list(ctx
, name
)
589 @cli.command(name
='pdu-list', short_help
='list all Physical Deployment Units (PDU)')
590 @click.option('--filter', default
=None,
591 help='restricts the list to the Physical Deployment Units matching the filter')
593 def pdu_list(ctx
, filter):
594 """list all Physical Deployment Units (PDU)"""
596 check_client_version(ctx
.obj
, ctx
.command
.name
)
597 resp
= ctx
.obj
.pdu
.list(filter)
598 except ClientException
as inst
:
599 print((inst
.message
))
607 pdu_name
= pdu
['name']
609 pdu_type
= pdu
['type']
610 pdu_ipaddress
= "None"
611 for iface
in pdu
['interfaces']:
613 pdu_ipaddress
= iface
['ip-address']
628 def nsd_show(ctx
, name
, literal
):
630 resp
= ctx
.obj
.nsd
.get(name
)
631 # resp = ctx.obj.nsd.get_individual(name)
632 except ClientException
as inst
:
633 print((inst
.message
))
637 print(yaml
.safe_dump(resp
))
640 table
= PrettyTable(['field', 'value'])
641 for k
, v
in list(resp
.items()):
642 table
.add_row([k
, json
.dumps(v
, indent
=2)])
647 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
648 @click.option('--literal', is_flag
=True,
649 help='print literally, no pretty table')
650 @click.argument('name')
652 def nsd_show1(ctx
, name
, literal
):
653 """shows the content of a NSD
655 NAME: name or ID of the NSD/NSpkg
657 nsd_show(ctx
, name
, literal
)
660 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
661 @click.option('--literal', is_flag
=True,
662 help='print literally, no pretty table')
663 @click.argument('name')
665 def nsd_show2(ctx
, name
, literal
):
666 """shows the content of a NSD
668 NAME: name or ID of the NSD/NSpkg
670 nsd_show(ctx
, name
, literal
)
673 def vnfd_show(ctx
, name
, literal
):
675 resp
= ctx
.obj
.vnfd
.get(name
)
676 # resp = ctx.obj.vnfd.get_individual(name)
677 except ClientException
as inst
:
678 print((inst
.message
))
682 print(yaml
.safe_dump(resp
))
685 table
= PrettyTable(['field', 'value'])
686 for k
, v
in list(resp
.items()):
687 table
.add_row([k
, json
.dumps(v
, indent
=2)])
692 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
693 @click.option('--literal', is_flag
=True,
694 help='print literally, no pretty table')
695 @click.argument('name')
697 def vnfd_show1(ctx
, name
, literal
):
698 """shows the content of a VNFD
700 NAME: name or ID of the VNFD/VNFpkg
702 vnfd_show(ctx
, name
, literal
)
705 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
706 @click.option('--literal', is_flag
=True,
707 help='print literally, no pretty table')
708 @click.argument('name')
710 def vnfd_show2(ctx
, name
, literal
):
711 """shows the content of a VNFD
713 NAME: name or ID of the VNFD/VNFpkg
715 vnfd_show(ctx
, name
, literal
)
718 @cli.command(name
='nfpkg-show', short_help
='shows the content of a NF Descriptor')
719 @click.option('--literal', is_flag
=True,
720 help='print literally, no pretty table')
721 @click.argument('name')
723 def nfpkg_show(ctx
, name
, literal
):
724 """shows the content of a NF Descriptor
726 NAME: name or ID of the NFpkg
728 vnfd_show(ctx
, name
, literal
)
731 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
732 @click.argument('name')
733 @click.option('--literal', is_flag
=True,
734 help='print literally, no pretty table')
735 @click.option('--filter', default
=None)
737 def ns_show(ctx
, name
, literal
, filter):
738 """shows the info of a NS instance
740 NAME: name or ID of the NS instance
743 ns
= ctx
.obj
.ns
.get(name
)
744 except ClientException
as inst
:
745 print((inst
.message
))
749 print(yaml
.safe_dump(ns
))
752 table
= PrettyTable(['field', 'value'])
754 for k
, v
in list(ns
.items()):
755 if filter is None or filter in k
:
756 table
.add_row([k
, json
.dumps(v
, indent
=2)])
758 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
759 if fullclassname
!= 'osmclient.sol005.client.Client':
760 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
761 nsr_optdata
= nsopdata
['nsr:nsr']
762 for k
, v
in list(nsr_optdata
.items()):
763 if filter is None or filter in k
:
764 table
.add_row([k
, json
.dumps(v
, indent
=2)])
769 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
770 @click.argument('name')
771 @click.option('--literal', is_flag
=True,
772 help='print literally, no pretty table')
773 @click.option('--filter', default
=None)
775 def vnf_show(ctx
, name
, literal
, filter):
776 """shows the info of a VNF instance
778 NAME: name or ID of the VNF instance
781 check_client_version(ctx
.obj
, ctx
.command
.name
)
782 resp
= ctx
.obj
.vnf
.get(name
)
783 except ClientException
as inst
:
784 print((inst
.message
))
788 print(yaml
.safe_dump(resp
))
791 table
= PrettyTable(['field', 'value'])
792 for k
, v
in list(resp
.items()):
793 if filter is None or filter in k
:
794 table
.add_row([k
, json
.dumps(v
, indent
=2)])
799 #@cli.command(name='vnf-monitoring-show')
800 #@click.argument('vnf_name')
802 #def vnf_monitoring_show(ctx, vnf_name):
804 # check_client_version(ctx.obj, ctx.command.name, 'v1')
805 # resp = ctx.obj.vnf.get_monitoring(vnf_name)
806 # except ClientException as inst:
807 # print((inst.message))
810 # table = PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
811 # if resp is not None:
812 # for monitor in resp:
816 # monitor['value-integer'],
822 #@cli.command(name='ns-monitoring-show')
823 #@click.argument('ns_name')
825 #def ns_monitoring_show(ctx, ns_name):
827 # check_client_version(ctx.obj, ctx.command.name, 'v1')
828 # resp = ctx.obj.ns.get_monitoring(ns_name)
829 # except ClientException as inst:
830 # print((inst.message))
833 # table = PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
834 # for key, val in list(resp.items()):
835 # for monitor in val:
839 # monitor['value-integer'],
845 @cli.command(name
='ns-op-show', short_help
='shows the info of a NS operation')
846 @click.argument('id')
847 @click.option('--filter', default
=None)
849 def ns_op_show(ctx
, id, filter):
850 """shows the detailed info of a NS operation
852 ID: operation identifier
855 check_client_version(ctx
.obj
, ctx
.command
.name
)
856 op_info
= ctx
.obj
.ns
.get_op(id)
857 except ClientException
as inst
:
858 print((inst
.message
))
861 table
= PrettyTable(['field', 'value'])
862 for k
, v
in list(op_info
.items()):
863 if filter is None or filter in k
:
864 table
.add_row([k
, json
.dumps(v
, indent
=2)])
869 def nst_show(ctx
, name
, literal
):
871 check_client_version(ctx
.obj
, ctx
.command
.name
)
872 resp
= ctx
.obj
.nst
.get(name
)
873 #resp = ctx.obj.nst.get_individual(name)
874 except ClientException
as inst
:
875 print((inst
.message
))
879 print(yaml
.safe_dump(resp
))
882 table
= PrettyTable(['field', 'value'])
883 for k
, v
in list(resp
.items()):
884 table
.add_row([k
, json
.dumps(v
, indent
=2)])
889 @cli.command(name
='nst-show', short_help
='shows the content of a Network Slice Template (NST)')
890 @click.option('--literal', is_flag
=True,
891 help='print literally, no pretty table')
892 @click.argument('name')
894 def nst_show1(ctx
, name
, literal
):
895 """shows the content of a Network Slice Template (NST)
897 NAME: name or ID of the NST
899 nst_show(ctx
, name
, literal
)
902 @cli.command(name
='netslice-template-show', short_help
='shows the content of a Network Slice Template (NST)')
903 @click.option('--literal', is_flag
=True,
904 help='print literally, no pretty table')
905 @click.argument('name')
907 def nst_show2(ctx
, name
, literal
):
908 """shows the content of a Network Slice Template (NST)
910 NAME: name or ID of the NST
912 nst_show(ctx
, name
, literal
)
915 def nsi_show(ctx
, name
, literal
, filter):
917 check_client_version(ctx
.obj
, ctx
.command
.name
)
918 nsi
= ctx
.obj
.nsi
.get(name
)
919 except ClientException
as inst
:
920 print((inst
.message
))
924 print(yaml
.safe_dump(nsi
))
927 table
= PrettyTable(['field', 'value'])
929 for k
, v
in list(nsi
.items()):
930 if filter is None or filter in k
:
931 table
.add_row([k
, json
.dumps(v
, indent
=2)])
937 @cli.command(name
='nsi-show', short_help
='shows the content of a Network Slice Instance (NSI)')
938 @click.argument('name')
939 @click.option('--literal', is_flag
=True,
940 help='print literally, no pretty table')
941 @click.option('--filter', default
=None)
943 def nsi_show1(ctx
, name
, literal
, filter):
944 """shows the content of a Network Slice Instance (NSI)
946 NAME: name or ID of the Network Slice Instance
948 nsi_show(ctx
, name
, literal
, filter)
951 @cli.command(name
='netslice-instance-show', short_help
='shows the content of a Network Slice Instance (NSI)')
952 @click.argument('name')
953 @click.option('--literal', is_flag
=True,
954 help='print literally, no pretty table')
955 @click.option('--filter', default
=None)
957 def nsi_show2(ctx
, name
, literal
, filter):
958 """shows the content of a Network Slice Instance (NSI)
960 NAME: name or ID of the Network Slice Instance
962 nsi_show(ctx
, name
, literal
, filter)
965 def nsi_op_show(ctx
, id, filter):
967 check_client_version(ctx
.obj
, ctx
.command
.name
)
968 op_info
= ctx
.obj
.nsi
.get_op(id)
969 except ClientException
as inst
:
970 print((inst
.message
))
973 table
= PrettyTable(['field', 'value'])
974 for k
, v
in list(op_info
.items()):
975 if filter is None or filter in k
:
976 table
.add_row([k
, json
.dumps(v
, indent
=2)])
981 @cli.command(name
='nsi-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
982 @click.argument('id')
983 @click.option('--filter', default
=None)
985 def nsi_op_show1(ctx
, id, filter):
986 """shows the info of an operation over a Network Slice Instance(NSI)
988 ID: operation identifier
990 nsi_op_show(ctx
, id, filter)
993 @cli.command(name
='netslice-instance-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
994 @click.argument('id')
995 @click.option('--filter', default
=None)
997 def nsi_op_show2(ctx
, id, filter):
998 """shows the info of an operation over a Network Slice Instance(NSI)
1000 ID: operation identifier
1002 nsi_op_show(ctx
, id, filter)
1005 @cli.command(name
='pdu-show', short_help
='shows the content of a Physical Deployment Unit (PDU)')
1006 @click.argument('name')
1007 @click.option('--literal', is_flag
=True,
1008 help='print literally, no pretty table')
1009 @click.option('--filter', default
=None)
1011 def pdu_show(ctx
, name
, literal
, filter):
1012 """shows the content of a Physical Deployment Unit (PDU)
1014 NAME: name or ID of the PDU
1017 check_client_version(ctx
.obj
, ctx
.command
.name
)
1018 pdu
= ctx
.obj
.pdu
.get(name
)
1019 except ClientException
as inst
:
1020 print((inst
.message
))
1024 print(yaml
.safe_dump(pdu
))
1027 table
= PrettyTable(['field', 'value'])
1029 for k
, v
in list(pdu
.items()):
1030 if filter is None or filter in k
:
1031 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1037 ####################
1039 ####################
1041 def nsd_create(ctx
, filename
, overwrite
):
1043 check_client_version(ctx
.obj
, ctx
.command
.name
)
1044 ctx
.obj
.nsd
.create(filename
, overwrite
)
1045 except ClientException
as inst
:
1046 print((inst
.message
))
1050 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
1051 @click.argument('filename')
1052 @click.option('--overwrite', 'overwrite', default
=None,
1053 help='overwrite deprecated, use override')
1054 @click.option('--override', 'overwrite', default
=None,
1055 help='overrides fields in descriptor, format: '
1056 '"key1.key2...=value[;key3...=value;...]"')
1058 def nsd_create1(ctx
, filename
, overwrite
):
1059 """creates a new NSD/NSpkg
1061 FILENAME: NSD yaml file or NSpkg tar.gz file
1063 nsd_create(ctx
, filename
, overwrite
)
1066 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
1067 @click.argument('filename')
1068 @click.option('--overwrite', 'overwrite', default
=None,
1069 help='overwrite deprecated, use override')
1070 @click.option('--override', 'overwrite', default
=None,
1071 help='overrides fields in descriptor, format: '
1072 '"key1.key2...=value[;key3...=value;...]"')
1074 def nsd_create2(ctx
, filename
, overwrite
):
1075 """creates a new NSD/NSpkg
1077 FILENAME: NSD yaml file or NSpkg tar.gz file
1079 nsd_create(ctx
, filename
, overwrite
)
1082 def vnfd_create(ctx
, filename
, overwrite
):
1084 check_client_version(ctx
.obj
, ctx
.command
.name
)
1085 ctx
.obj
.vnfd
.create(filename
, overwrite
)
1086 except ClientException
as inst
:
1087 print((inst
.message
))
1091 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
1092 @click.argument('filename')
1093 @click.option('--overwrite', 'overwrite', default
=None,
1094 help='overwrite deprecated, use override')
1095 @click.option('--override', 'overwrite', default
=None,
1096 help='overrides fields in descriptor, format: '
1097 '"key1.key2...=value[;key3...=value;...]"')
1099 def vnfd_create1(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
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
1108 @click.argument('filename')
1109 @click.option('--overwrite', 'overwrite', default
=None,
1110 help='overwrite deprecated, use override')
1111 @click.option('--override', 'overwrite', default
=None,
1112 help='overrides fields in descriptor, format: '
1113 '"key1.key2...=value[;key3...=value;...]"')
1115 def vnfd_create2(ctx
, filename
, overwrite
):
1116 """creates a new VNFD/VNFpkg
1118 FILENAME: VNFD yaml file or VNFpkg tar.gz file
1120 vnfd_create(ctx
, filename
, overwrite
)
1123 @cli.command(name
='nfpkg-create', short_help
='creates a new NFpkg')
1124 @click.argument('filename')
1125 @click.option('--overwrite', 'overwrite', default
=None,
1126 help='overwrite deprecated, use override')
1127 @click.option('--override', 'overwrite', default
=None,
1128 help='overrides fields in descriptor, format: '
1129 '"key1.key2...=value[;key3...=value;...]"')
1131 def nfpkg_create(ctx
, filename
, overwrite
):
1132 """creates a new NFpkg
1134 FILENAME: NF Descriptor yaml file or NFpkg tar.gz file
1136 vnfd_create(ctx
, filename
, overwrite
)
1139 @cli.command(name
='ns-create', short_help
='creates a new Network Service instance')
1140 @click.option('--ns_name',
1141 prompt
=True, help='name of the NS instance')
1142 @click.option('--nsd_name',
1143 prompt
=True, help='name of the NS descriptor')
1144 @click.option('--vim_account',
1145 prompt
=True, help='default VIM account id or name for the deployment')
1146 @click.option('--admin_status',
1148 help='administration status')
1149 @click.option('--ssh_keys',
1151 help='comma separated list of public key files to inject to vnfs')
1152 @click.option('--config',
1154 help='ns specific yaml configuration')
1155 @click.option('--config_file',
1157 help='ns specific yaml configuration file')
1158 @click.option('--wait',
1162 help='do not return the control immediately, but keep it \
1163 until the operation is completed, or timeout')
1174 """creates a new NS instance"""
1177 check_client_version(ctx
.obj
, '--config_file')
1179 raise ClientException('"--config" option is incompatible with "--config_file" option')
1180 with
open(config_file
, 'r') as cf
:
1187 account
=vim_account
,
1189 except ClientException
as inst
:
1194 def nst_create(ctx
, filename
, overwrite
):
1196 check_client_version(ctx
.obj
, ctx
.command
.name
)
1197 ctx
.obj
.nst
.create(filename
, overwrite
)
1198 except ClientException
as inst
:
1199 print((inst
.message
))
1203 @cli.command(name
='nst-create', short_help
='creates a new Network Slice Template (NST)')
1204 @click.argument('filename')
1205 @click.option('--overwrite', 'overwrite', default
=None,
1206 help='overwrites deprecated use override')
1207 @click.option('--override', 'overwrite' ,default
=None,
1208 help='overrides fields in descriptor, format: '
1209 '"key1.key2...=value[;key3...=value;...]"')
1211 def nst_create1(ctx
, filename
, overwrite
):
1212 """creates a new Network Slice Template (NST)
1214 FILENAME: NST yaml file or NSTpkg tar.gz file
1216 nst_create(ctx
, filename
, overwrite
)
1219 @cli.command(name
='netslice-template-create', short_help
='creates a new Network Slice Template (NST)')
1220 @click.argument('filename')
1221 @click.option('--overwrite', 'overwrite', default
=None,
1222 help='overwrites deprecated use override')
1223 @click.option('--override', 'overwrite', default
=None,
1224 help='overrides fields in descriptor, format: '
1225 '"key1.key2...=value[;key3...=value;...]"')
1227 def nst_create2(ctx
, filename
, overwrite
):
1228 """creates a new Network Slice Template (NST)
1230 FILENAME: NST yaml file or NSTpkg tar.gz file
1232 nst_create(ctx
, filename
, overwrite
)
1235 def nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1236 """creates a new Network Slice Instance (NSI)"""
1238 check_client_version(ctx
.obj
, ctx
.command
.name
)
1241 raise ClientException('"--config" option is incompatible with "--config_file" option')
1242 with
open(config_file
, 'r') as cf
:
1244 ctx
.obj
.nsi
.create(nst_name
, nsi_name
, config
=config
, ssh_keys
=ssh_keys
,
1245 account
=vim_account
, wait
=wait
)
1246 except ClientException
as inst
:
1251 @cli.command(name
='nsi-create', short_help
='creates a new Network Slice Instance')
1252 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1253 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1254 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1255 @click.option('--ssh_keys', default
=None,
1256 help='comma separated list of keys to inject to vnfs')
1257 @click.option('--config', default
=None,
1258 help='Netslice specific yaml configuration:\n'
1259 'netslice_subnet: [\n'
1260 'id: TEXT, vim_account: TEXT,\n'
1261 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1262 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
1263 'additionalParamsForNsi: {param: value, ...}\n'
1264 'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
1266 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1268 @click.option('--config_file',
1270 help='nsi specific yaml configuration file')
1271 @click.option('--wait',
1275 help='do not return the control immediately, but keep it \
1276 until the operation is completed, or timeout')
1278 def nsi_create1(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1279 """creates a new Network Slice Instance (NSI)"""
1280 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
)
1283 @cli.command(name
='netslice-instance-create', short_help
='creates a new Network Slice Instance')
1284 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1285 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1286 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1287 @click.option('--ssh_keys', default
=None,
1288 help='comma separated list of keys to inject to vnfs')
1289 @click.option('--config', default
=None,
1290 help='Netslice specific yaml configuration:\n'
1291 'netslice_subnet: [\n'
1292 'id: TEXT, vim_account: TEXT,\n'
1293 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1294 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1296 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1298 @click.option('--config_file',
1300 help='nsi specific yaml configuration file')
1301 @click.option('--wait',
1305 help='do not return the control immediately, but keep it \
1306 until the operation is completed, or timeout')
1308 def nsi_create2(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1309 """creates a new Network Slice Instance (NSI)"""
1310 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
)
1313 @cli.command(name
='pdu-create', short_help
='adds a new Physical Deployment Unit to the catalog')
1314 @click.option('--name', help='name of the Physical Deployment Unit')
1315 @click.option('--pdu_type', help='type of PDU (e.g. router, firewall, FW001)')
1316 @click.option('--interface',
1317 help='interface(s) of the PDU: name=<NAME>,mgmt=<true|false>,ip-address=<IP_ADDRESS>'+
1318 '[,type=<overlay|underlay>][,mac-address=<MAC_ADDRESS>][,vim-network-name=<VIM_NET_NAME>]',
1320 @click.option('--description', help='human readable description')
1321 @click.option('--vim_account', help='list of VIM accounts (in the same VIM) that can reach this PDU', multiple
=True)
1322 @click.option('--descriptor_file', default
=None, help='PDU descriptor file (as an alternative to using the other arguments')
1324 def pdu_create(ctx
, name
, pdu_type
, interface
, description
, vim_account
, descriptor_file
):
1325 """creates a new Physical Deployment Unit (PDU)"""
1327 check_client_version(ctx
.obj
, ctx
.command
.name
)
1329 if not descriptor_file
:
1331 raise ClientException('in absence of descriptor file, option "--name" is mandatory')
1333 raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
1335 raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
1337 raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
1339 with
open(descriptor_file
, 'r') as df
:
1340 pdu
= yaml
.safe_load(df
.read())
1341 if name
: pdu
["name"] = name
1342 if pdu_type
: pdu
["type"] = pdu_type
1343 if description
: pdu
["description"] = description
1344 if vim_account
: pdu
["vim_accounts"] = vim_account
1347 for iface
in interface
:
1348 new_iface
={k
:v
for k
,v
in [i
.split('=') for i
in iface
.split(',')]}
1349 new_iface
["mgmt"] = (new_iface
.get("mgmt","false").lower() == "true")
1350 ifaces_list
.append(new_iface
)
1351 pdu
["interfaces"] = ifaces_list
1352 ctx
.obj
.pdu
.create(pdu
)
1353 except ClientException
as inst
:
1354 print((inst
.message
))
1357 ####################
1359 ####################
1361 def nsd_update(ctx
, name
, content
):
1363 check_client_version(ctx
.obj
, ctx
.command
.name
)
1364 ctx
.obj
.nsd
.update(name
, content
)
1365 except ClientException
as inst
:
1366 print((inst
.message
))
1370 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
1371 @click.argument('name')
1372 @click.option('--content', default
=None,
1373 help='filename with the NSD/NSpkg replacing the current one')
1375 def nsd_update1(ctx
, name
, content
):
1376 """updates a NSD/NSpkg
1378 NAME: name or ID of the NSD/NSpkg
1380 nsd_update(ctx
, name
, content
)
1383 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
1384 @click.argument('name')
1385 @click.option('--content', default
=None,
1386 help='filename with the NSD/NSpkg replacing the current one')
1388 def nsd_update2(ctx
, name
, content
):
1389 """updates a NSD/NSpkg
1391 NAME: name or ID of the NSD/NSpkg
1393 nsd_update(ctx
, name
, content
)
1396 def vnfd_update(ctx
, name
, content
):
1398 check_client_version(ctx
.obj
, ctx
.command
.name
)
1399 ctx
.obj
.vnfd
.update(name
, content
)
1400 except ClientException
as inst
:
1401 print((inst
.message
))
1405 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
1406 @click.argument('name')
1407 @click.option('--content', default
=None,
1408 help='filename with the VNFD/VNFpkg replacing the current one')
1410 def vnfd_update1(ctx
, name
, content
):
1411 """updates a VNFD/VNFpkg
1413 NAME: name or ID of the VNFD/VNFpkg
1415 vnfd_update(ctx
, name
, content
)
1418 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
1419 @click.argument('name')
1420 @click.option('--content', default
=None,
1421 help='filename with the VNFD/VNFpkg replacing the current one')
1423 def vnfd_update2(ctx
, name
, content
):
1424 """updates a VNFD/VNFpkg
1426 NAME: VNFD yaml file or VNFpkg tar.gz file
1428 vnfd_update(ctx
, name
, content
)
1431 @cli.command(name
='nfpkg-update', short_help
='updates a NFpkg')
1432 @click.argument('name')
1433 @click.option('--content', default
=None,
1434 help='filename with the NFpkg replacing the current one')
1436 def nfpkg_update(ctx
, name
, content
):
1439 NAME: NF Descriptor yaml file or NFpkg tar.gz file
1441 vnfd_update(ctx
, name
, content
)
1444 def nst_update(ctx
, name
, content
):
1446 check_client_version(ctx
.obj
, ctx
.command
.name
)
1447 ctx
.obj
.nst
.update(name
, content
)
1448 except ClientException
as inst
:
1449 print((inst
.message
))
1453 @cli.command(name
='nst-update', short_help
='updates a Network Slice Template (NST)')
1454 @click.argument('name')
1455 @click.option('--content', default
=None,
1456 help='filename with the NST/NSTpkg replacing the current one')
1458 def nst_update1(ctx
, name
, content
):
1459 """updates a Network Slice Template (NST)
1461 NAME: name or ID of the NSD/NSpkg
1463 nst_update(ctx
, name
, content
)
1466 @cli.command(name
='netslice-template-update', short_help
='updates a Network Slice Template (NST)')
1467 @click.argument('name')
1468 @click.option('--content', default
=None,
1469 help='filename with the NST/NSTpkg replacing the current one')
1471 def nst_update2(ctx
, name
, content
):
1472 """updates a Network Slice Template (NST)
1474 NAME: name or ID of the NSD/NSpkg
1476 nst_update(ctx
, name
, content
)
1479 ####################
1481 ####################
1483 def nsd_delete(ctx
, name
, force
):
1486 ctx
.obj
.nsd
.delete(name
)
1488 check_client_version(ctx
.obj
, '--force')
1489 ctx
.obj
.nsd
.delete(name
, force
)
1490 except ClientException
as inst
:
1491 print((inst
.message
))
1495 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
1496 @click.argument('name')
1497 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1499 def nsd_delete1(ctx
, name
, force
):
1500 """deletes a NSD/NSpkg
1502 NAME: name or ID of the NSD/NSpkg to be deleted
1504 nsd_delete(ctx
, name
, force
)
1507 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
1508 @click.argument('name')
1509 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1511 def nsd_delete2(ctx
, name
, force
):
1512 """deletes a NSD/NSpkg
1514 NAME: name or ID of the NSD/NSpkg to be deleted
1516 nsd_delete(ctx
, name
, force
)
1519 def vnfd_delete(ctx
, name
, force
):
1522 ctx
.obj
.vnfd
.delete(name
)
1524 check_client_version(ctx
.obj
, '--force')
1525 ctx
.obj
.vnfd
.delete(name
, force
)
1526 except ClientException
as inst
:
1527 print((inst
.message
))
1531 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
1532 @click.argument('name')
1533 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1535 def vnfd_delete1(ctx
, name
, force
):
1536 """deletes a VNFD/VNFpkg
1538 NAME: name or ID of the VNFD/VNFpkg to be deleted
1540 vnfd_delete(ctx
, name
, force
)
1543 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
1544 @click.argument('name')
1545 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1547 def vnfd_delete2(ctx
, name
, force
):
1548 """deletes a VNFD/VNFpkg
1550 NAME: name or ID of the VNFD/VNFpkg to be deleted
1552 vnfd_delete(ctx
, name
, force
)
1555 @cli.command(name
='nfpkg-delete', short_help
='deletes a NFpkg')
1556 @click.argument('name')
1557 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1559 def nfpkg_delete(ctx
, name
, force
):
1562 NAME: name or ID of the NFpkg to be deleted
1564 vnfd_delete(ctx
, name
, force
)
1567 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
1568 @click.argument('name')
1569 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1570 @click.option('--wait',
1574 help='do not return the control immediately, but keep it \
1575 until the operation is completed, or timeout')
1577 def ns_delete(ctx
, name
, force
, wait
):
1578 """deletes a NS instance
1580 NAME: name or ID of the NS instance to be deleted
1584 ctx
.obj
.ns
.delete(name
, wait
=wait
)
1586 check_client_version(ctx
.obj
, '--force')
1587 ctx
.obj
.ns
.delete(name
, force
, wait
=wait
)
1588 except ClientException
as inst
:
1589 print((inst
.message
))
1593 def nst_delete(ctx
, name
, force
):
1595 check_client_version(ctx
.obj
, ctx
.command
.name
)
1596 ctx
.obj
.nst
.delete(name
, force
)
1597 except ClientException
as inst
:
1598 print((inst
.message
))
1602 @cli.command(name
='nst-delete', short_help
='deletes a Network Slice Template (NST)')
1603 @click.argument('name')
1604 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1606 def nst_delete1(ctx
, name
, force
):
1607 """deletes a Network Slice Template (NST)
1609 NAME: name or ID of the NST/NSTpkg to be deleted
1611 nst_delete(ctx
, name
, force
)
1614 @cli.command(name
='netslice-template-delete', short_help
='deletes a Network Slice Template (NST)')
1615 @click.argument('name')
1616 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1618 def nst_delete2(ctx
, name
, force
):
1619 """deletes a Network Slice Template (NST)
1621 NAME: name or ID of the NST/NSTpkg to be deleted
1623 nst_delete(ctx
, name
, force
)
1626 def nsi_delete(ctx
, name
, force
, wait
):
1628 check_client_version(ctx
.obj
, ctx
.command
.name
)
1629 ctx
.obj
.nsi
.delete(name
, force
, wait
=wait
)
1630 except ClientException
as inst
:
1631 print((inst
.message
))
1635 @cli.command(name
='nsi-delete', short_help
='deletes a Network Slice Instance (NSI)')
1636 @click.argument('name')
1637 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1638 @click.option('--wait',
1642 help='do not return the control immediately, but keep it \
1643 until the operation is completed, or timeout')
1645 def nsi_delete1(ctx
, name
, force
, wait
):
1646 """deletes a Network Slice Instance (NSI)
1648 NAME: name or ID of the Network Slice instance to be deleted
1650 nsi_delete(ctx
, name
, force
, wait
=wait
)
1653 @cli.command(name
='netslice-instance-delete', short_help
='deletes a Network Slice Instance (NSI)')
1654 @click.argument('name')
1655 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1657 def nsi_delete2(ctx
, name
, force
, wait
):
1658 """deletes a Network Slice Instance (NSI)
1660 NAME: name or ID of the Network Slice instance to be deleted
1662 nsi_delete(ctx
, name
, force
, wait
=wait
)
1665 @cli.command(name
='pdu-delete', short_help
='deletes a Physical Deployment Unit (PDU)')
1666 @click.argument('name')
1667 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1669 def pdu_delete(ctx
, name
, force
):
1670 """deletes a Physical Deployment Unit (PDU)
1672 NAME: name or ID of the PDU to be deleted
1675 check_client_version(ctx
.obj
, ctx
.command
.name
)
1676 ctx
.obj
.pdu
.delete(name
, force
)
1677 except ClientException
as inst
:
1678 print((inst
.message
))
1686 @cli.command(name
='vim-create', short_help
='creates a new VIM account')
1687 @click.option('--name',
1689 help='Name to create datacenter')
1690 @click.option('--user',
1692 help='VIM username')
1693 @click.option('--password',
1696 confirmation_prompt
=True,
1697 help='VIM password')
1698 @click.option('--auth_url',
1701 @click.option('--tenant',
1703 help='VIM tenant name')
1704 @click.option('--config',
1706 help='VIM specific config parameters')
1707 @click.option('--account_type',
1708 default
='openstack',
1710 @click.option('--description',
1711 default
='no description',
1712 help='human readable description')
1713 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1714 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1715 @click.option('--wait',
1719 help='do not return the control immediately, but keep it \
1720 until the operation is completed, or timeout')
1734 """creates a new VIM account"""
1737 check_client_version(ctx
.obj
, '--sdn_controller')
1738 if sdn_port_mapping
:
1739 check_client_version(ctx
.obj
, '--sdn_port_mapping')
1741 vim
['vim-username'] = user
1742 vim
['vim-password'] = password
1743 vim
['vim-url'] = auth_url
1744 vim
['vim-tenant-name'] = tenant
1745 vim
['vim-type'] = account_type
1746 vim
['description'] = description
1747 vim
['config'] = config
1748 if sdn_controller
or sdn_port_mapping
:
1749 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
, wait
=wait
)
1751 ctx
.obj
.vim
.create(name
, vim
, wait
=wait
)
1752 except ClientException
as inst
:
1753 print((inst
.message
))
1757 @cli.command(name
='vim-update', short_help
='updates a VIM account')
1758 @click.argument('name')
1759 @click.option('--newname', help='New name for the VIM account')
1760 @click.option('--user', help='VIM username')
1761 @click.option('--password', help='VIM password')
1762 @click.option('--auth_url', help='VIM url')
1763 @click.option('--tenant', help='VIM tenant name')
1764 @click.option('--config', help='VIM specific config parameters')
1765 @click.option('--account_type', help='VIM type')
1766 @click.option('--description', help='human readable description')
1767 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1768 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1769 @click.option('--wait',
1773 help='do not return the control immediately, but keep it \
1774 until the operation is completed, or timeout')
1789 """updates a VIM account
1791 NAME: name or ID of the VIM account
1794 check_client_version(ctx
.obj
, ctx
.command
.name
)
1796 if newname
: vim
['name'] = newname
1797 if user
: vim
['vim_user'] = user
1798 if password
: vim
['vim_password'] = password
1799 if auth_url
: vim
['vim_url'] = auth_url
1800 if tenant
: vim
['vim-tenant-name'] = tenant
1801 if account_type
: vim
['vim_type'] = account_type
1802 if description
: vim
['description'] = description
1803 if config
: vim
['config'] = config
1804 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
, wait
=wait
)
1805 except ClientException
as inst
:
1806 print((inst
.message
))
1810 @cli.command(name
='vim-delete', short_help
='deletes a VIM account')
1811 @click.argument('name')
1812 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1813 @click.option('--wait',
1817 help='do not return the control immediately, but keep it \
1818 until the operation is completed, or timeout')
1820 def vim_delete(ctx
, name
, force
, wait
):
1821 """deletes a VIM account
1823 NAME: name or ID of the VIM account to be deleted
1827 ctx
.obj
.vim
.delete(name
, wait
=wait
)
1829 check_client_version(ctx
.obj
, '--force')
1830 ctx
.obj
.vim
.delete(name
, force
, wait
=wait
)
1831 except ClientException
as inst
:
1832 print((inst
.message
))
1836 @cli.command(name
='vim-list', short_help
='list all VIM accounts')
1837 #@click.option('--ro_update/--no_ro_update',
1839 # help='update list from RO')
1840 @click.option('--filter', default
=None,
1841 help='restricts the list to the VIM accounts matching the filter')
1843 def vim_list(ctx
, filter):
1844 """list all VIM accounts"""
1846 check_client_version(ctx
.obj
, '--filter')
1848 # check_client_version(ctx.obj, '--ro_update', 'v1')
1849 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1850 if fullclassname
== 'osmclient.sol005.client.Client':
1851 resp
= ctx
.obj
.vim
.list(filter)
1853 # resp = ctx.obj.vim.list(ro_update)
1854 table
= PrettyTable(['vim name', 'uuid'])
1856 table
.add_row([vim
['name'], vim
['uuid']])
1861 @cli.command(name
='vim-show', short_help
='shows the details of a VIM account')
1862 @click.argument('name')
1864 def vim_show(ctx
, name
):
1865 """shows the details of a VIM account
1867 NAME: name or ID of the VIM account
1870 resp
= ctx
.obj
.vim
.get(name
)
1871 if 'vim_password' in resp
:
1872 resp
['vim_password']='********'
1873 except ClientException
as inst
:
1874 print((inst
.message
))
1877 table
= PrettyTable(['key', 'attribute'])
1878 for k
, v
in list(resp
.items()):
1879 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1884 ####################
1886 ####################
1888 @cli.command(name
='wim-create', short_help
='creates a new WIM account')
1889 @click.option('--name',
1891 help='Name for the WIM account')
1892 @click.option('--user',
1893 help='WIM username')
1894 @click.option('--password',
1895 help='WIM password')
1896 @click.option('--url',
1899 # @click.option('--tenant',
1900 # help='wIM tenant name')
1901 @click.option('--config',
1903 help='WIM specific config parameters')
1904 @click.option('--wim_type',
1906 @click.option('--description',
1907 default
='no description',
1908 help='human readable description')
1909 @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)")
1910 @click.option('--wait',
1914 help='do not return the control immediately, but keep it \
1915 until the operation is completed, or timeout')
1928 """creates a new WIM account"""
1930 check_client_version(ctx
.obj
, ctx
.command
.name
)
1931 # if sdn_controller:
1932 # check_client_version(ctx.obj, '--sdn_controller')
1933 # if sdn_port_mapping:
1934 # check_client_version(ctx.obj, '--sdn_port_mapping')
1936 if user
: wim
['user'] = user
1937 if password
: wim
['password'] = password
1938 if url
: wim
['wim_url'] = url
1939 # if tenant: wim['tenant'] = tenant
1940 wim
['wim_type'] = wim_type
1941 if description
: wim
['description'] = description
1942 if config
: wim
['config'] = config
1943 ctx
.obj
.wim
.create(name
, wim
, wim_port_mapping
, wait
=wait
)
1944 except ClientException
as inst
:
1945 print((inst
.message
))
1949 @cli.command(name
='wim-update', short_help
='updates a WIM account')
1950 @click.argument('name')
1951 @click.option('--newname', help='New name for the WIM account')
1952 @click.option('--user', help='WIM username')
1953 @click.option('--password', help='WIM password')
1954 @click.option('--url', help='WIM url')
1955 @click.option('--config', help='WIM specific config parameters')
1956 @click.option('--wim_type', help='WIM type')
1957 @click.option('--description', help='human readable description')
1958 @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)")
1959 @click.option('--wait',
1963 help='do not return the control immediately, but keep it \
1964 until the operation is completed, or timeout')
1977 """updates a WIM account
1979 NAME: name or ID of the WIM account
1982 check_client_version(ctx
.obj
, ctx
.command
.name
)
1984 if newname
: wim
['name'] = newname
1985 if user
: wim
['user'] = user
1986 if password
: wim
['password'] = password
1987 if url
: wim
['url'] = url
1988 # if tenant: wim['tenant'] = tenant
1989 if wim_type
: wim
['wim_type'] = wim_type
1990 if description
: wim
['description'] = description
1991 if config
: wim
['config'] = config
1992 ctx
.obj
.wim
.update(name
, wim
, wim_port_mapping
, wait
=wait
)
1993 except ClientException
as inst
:
1994 print((inst
.message
))
1998 @cli.command(name
='wim-delete', short_help
='deletes a WIM account')
1999 @click.argument('name')
2000 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2001 @click.option('--wait',
2005 help='do not return the control immediately, but keep it \
2006 until the operation is completed, or timeout')
2008 def wim_delete(ctx
, name
, force
, wait
):
2009 """deletes a WIM account
2011 NAME: name or ID of the WIM account to be deleted
2014 check_client_version(ctx
.obj
, ctx
.command
.name
)
2015 ctx
.obj
.wim
.delete(name
, force
, wait
=wait
)
2016 except ClientException
as inst
:
2017 print((inst
.message
))
2021 @cli.command(name
='wim-list', short_help
='list all WIM accounts')
2022 @click.option('--filter', default
=None,
2023 help='restricts the list to the WIM accounts matching the filter')
2025 def wim_list(ctx
, filter):
2026 """list all WIM accounts"""
2028 check_client_version(ctx
.obj
, ctx
.command
.name
)
2029 resp
= ctx
.obj
.wim
.list(filter)
2030 table
= PrettyTable(['wim name', 'uuid'])
2032 table
.add_row([wim
['name'], wim
['uuid']])
2035 except ClientException
as inst
:
2036 print((inst
.message
))
2040 @cli.command(name
='wim-show', short_help
='shows the details of a WIM account')
2041 @click.argument('name')
2043 def wim_show(ctx
, name
):
2044 """shows the details of a WIM account
2046 NAME: name or ID of the WIM account
2049 check_client_version(ctx
.obj
, ctx
.command
.name
)
2050 resp
= ctx
.obj
.wim
.get(name
)
2051 if 'password' in resp
:
2052 resp
['wim_password']='********'
2053 except ClientException
as inst
:
2054 print((inst
.message
))
2057 table
= PrettyTable(['key', 'attribute'])
2058 for k
, v
in list(resp
.items()):
2059 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2064 ####################
2065 # SDN controller operations
2066 ####################
2068 @cli.command(name
='sdnc-create', short_help
='creates a new SDN controller')
2069 @click.option('--name',
2071 help='Name to create sdn controller')
2072 @click.option('--type',
2074 help='SDN controller type')
2075 @click.option('--sdn_controller_version',
2076 help='SDN controller version')
2077 @click.option('--ip_address',
2079 help='SDN controller IP address')
2080 @click.option('--port',
2082 help='SDN controller port')
2083 @click.option('--switch_dpid',
2085 help='Switch DPID (Openflow Datapath ID)')
2086 @click.option('--user',
2087 help='SDN controller username')
2088 @click.option('--password',
2090 confirmation_prompt
=True,
2091 help='SDN controller password')
2092 #@click.option('--description',
2093 # default='no description',
2094 # help='human readable description')
2095 @click.option('--wait',
2099 help='do not return the control immediately, but keep it \
2100 until the operation is completed, or timeout')
2102 def sdnc_create(ctx
,
2105 sdn_controller_version
,
2112 """creates a new SDN controller"""
2114 sdncontroller
['name'] = name
2115 sdncontroller
['type'] = type
2116 sdncontroller
['ip'] = ip_address
2117 sdncontroller
['port'] = int(port
)
2118 sdncontroller
['dpid'] = switch_dpid
2119 if sdn_controller_version
:
2120 sdncontroller
['version'] = sdn_controller_version
2122 sdncontroller
['user'] = user
2124 sdncontroller
['password'] = password
2125 # sdncontroller['description'] = description
2127 check_client_version(ctx
.obj
, ctx
.command
.name
)
2128 ctx
.obj
.sdnc
.create(name
, sdncontroller
, wait
=wait
)
2129 except ClientException
as inst
:
2130 print((inst
.message
))
2133 @cli.command(name
='sdnc-update', short_help
='updates an SDN controller')
2134 @click.argument('name')
2135 @click.option('--newname', help='New name for the SDN controller')
2136 @click.option('--type', help='SDN controller type')
2137 @click.option('--sdn_controller_version', help='SDN controller username')
2138 @click.option('--ip_address', help='SDN controller IP address')
2139 @click.option('--port', help='SDN controller port')
2140 @click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)')
2141 @click.option('--user', help='SDN controller username')
2142 @click.option('--password', help='SDN controller password')
2143 #@click.option('--description', default=None, help='human readable description')
2144 @click.option('--wait',
2148 help='do not return the control immediately, but keep it \
2149 until the operation is completed, or timeout')
2151 def sdnc_update(ctx
,
2155 sdn_controller_version
,
2162 """updates an SDN controller
2164 NAME: name or ID of the SDN controller
2167 if newname
: sdncontroller
['name'] = newname
2168 if type: sdncontroller
['type'] = type
2169 if ip_address
: sdncontroller
['ip'] = ip_address
2170 if port
: sdncontroller
['port'] = int(port
)
2171 if switch_dpid
: sdncontroller
['dpid'] = switch_dpid
2172 # sdncontroller['description'] = description
2173 if sdn_controller_version
is not None:
2174 if sdn_controller_version
=="":
2175 sdncontroller
['version'] = None
2177 sdncontroller
['version'] = sdn_controller_version
2178 if user
is not None:
2180 sdncontroller
['user'] = None
2182 sdncontroller
['user'] = user
2183 if password
is not None:
2185 sdncontroller
['password'] = None
2187 sdncontroller
['password'] = user
2189 check_client_version(ctx
.obj
, ctx
.command
.name
)
2190 ctx
.obj
.sdnc
.update(name
, sdncontroller
, wait
=wait
)
2191 except ClientException
as inst
:
2192 print((inst
.message
))
2196 @cli.command(name
='sdnc-delete', short_help
='deletes an SDN controller')
2197 @click.argument('name')
2198 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2199 @click.option('--wait',
2203 help='do not return the control immediately, but keep it \
2204 until the operation is completed, or timeout')
2206 def sdnc_delete(ctx
, name
, force
, wait
):
2207 """deletes an SDN controller
2209 NAME: name or ID of the SDN controller to be deleted
2212 check_client_version(ctx
.obj
, ctx
.command
.name
)
2213 ctx
.obj
.sdnc
.delete(name
, force
, wait
=wait
)
2214 except ClientException
as inst
:
2215 print((inst
.message
))
2219 @cli.command(name
='sdnc-list', short_help
='list all SDN controllers')
2220 @click.option('--filter', default
=None,
2221 help='restricts the list to the SDN controllers matching the filter')
2223 def sdnc_list(ctx
, filter):
2224 """list all SDN controllers"""
2226 check_client_version(ctx
.obj
, ctx
.command
.name
)
2227 resp
= ctx
.obj
.sdnc
.list(filter)
2228 except ClientException
as inst
:
2229 print((inst
.message
))
2231 table
= PrettyTable(['sdnc name', 'id'])
2233 table
.add_row([sdnc
['name'], sdnc
['_id']])
2238 @cli.command(name
='sdnc-show', short_help
='shows the details of an SDN controller')
2239 @click.argument('name')
2241 def sdnc_show(ctx
, name
):
2242 """shows the details of an SDN controller
2244 NAME: name or ID of the SDN controller
2247 check_client_version(ctx
.obj
, ctx
.command
.name
)
2248 resp
= ctx
.obj
.sdnc
.get(name
)
2249 except ClientException
as inst
:
2250 print((inst
.message
))
2253 table
= PrettyTable(['key', 'attribute'])
2254 for k
, v
in list(resp
.items()):
2255 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2260 ####################
2261 # Project mgmt operations
2262 ####################
2264 @cli.command(name
='project-create', short_help
='creates a new project')
2265 @click.argument('name')
2266 #@click.option('--description',
2267 # default='no description',
2268 # help='human readable description')
2270 def project_create(ctx
, name
):
2271 """Creates a new project
2273 NAME: name of the project
2276 project
['name'] = name
2278 check_client_version(ctx
.obj
, ctx
.command
.name
)
2279 ctx
.obj
.project
.create(name
, project
)
2280 except ClientException
as inst
:
2285 @cli.command(name
='project-delete', short_help
='deletes a project')
2286 @click.argument('name')
2287 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2289 def project_delete(ctx
, name
):
2290 """deletes a project
2292 NAME: name or ID of the project to be deleted
2295 check_client_version(ctx
.obj
, ctx
.command
.name
)
2296 ctx
.obj
.project
.delete(name
)
2297 except ClientException
as inst
:
2302 @cli.command(name
='project-list', short_help
='list all projects')
2303 @click.option('--filter', default
=None,
2304 help='restricts the list to the projects matching the filter')
2306 def project_list(ctx
, filter):
2307 """list all projects"""
2309 check_client_version(ctx
.obj
, ctx
.command
.name
)
2310 resp
= ctx
.obj
.project
.list(filter)
2311 except ClientException
as inst
:
2314 table
= PrettyTable(['name', 'id'])
2316 table
.add_row([proj
['name'], proj
['_id']])
2321 @cli.command(name
='project-show', short_help
='shows the details of a project')
2322 @click.argument('name')
2324 def project_show(ctx
, name
):
2325 """shows the details of a project
2327 NAME: name or ID of the project
2330 check_client_version(ctx
.obj
, ctx
.command
.name
)
2331 resp
= ctx
.obj
.project
.get(name
)
2332 except ClientException
as inst
:
2336 table
= PrettyTable(['key', 'attribute'])
2337 for k
, v
in resp
.items():
2338 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2343 @cli.command(name
='project-update', short_help
='updates a project (only the name can be updated)')
2344 @click.argument('project')
2345 @click.option('--name',
2347 help='new name for the project')
2350 def project_update(ctx
, project
, name
):
2352 Update a project name
2355 :param project: id or name of the project to modify
2356 :param name: new name for the project
2360 project_changes
= {}
2361 project_changes
['name'] = name
2364 check_client_version(ctx
.obj
, ctx
.command
.name
)
2365 ctx
.obj
.project
.update(project
, project_changes
)
2366 except ClientException
as inst
:
2370 ####################
2371 # User mgmt operations
2372 ####################
2374 @cli.command(name
='user-create', short_help
='creates a new user')
2375 @click.argument('username')
2376 @click.option('--password',
2379 confirmation_prompt
=True,
2380 help='user password')
2381 @click.option('--projects',
2382 # prompt="Comma separate list of projects",
2384 callback
=lambda ctx
, param
, value
: ''.join(value
).split(',') if all(len(x
)==1 for x
in value
) else value
,
2385 help='list of project ids that the user belongs to')
2386 @click.option('--project-role-mappings', 'project_role_mappings',
2387 default
=None, multiple
=True,
2388 help='creating user project/role(s) mapping')
2390 def user_create(ctx
, username
, password
, projects
, project_role_mappings
):
2391 """Creates a new user
2394 USERNAME: name of the user
2395 PASSWORD: password of the user
2396 PROJECTS: projects assigned to user (internal only)
2397 PROJECT_ROLE_MAPPING: roles in projects assigned to user (keystone)
2400 user
['username'] = username
2401 user
['password'] = password
2402 user
['projects'] = projects
2403 user
['project_role_mappings'] = project_role_mappings
2406 check_client_version(ctx
.obj
, ctx
.command
.name
)
2407 ctx
.obj
.user
.create(username
, user
)
2408 except ClientException
as inst
:
2413 @cli.command(name
='user-update', short_help
='updates user information')
2414 @click.argument('username')
2415 @click.option('--password',
2418 # confirmation_prompt=True,
2419 help='user password')
2420 @click.option('--set-username', 'set_username',
2422 help='change username')
2423 @click.option('--set-project', 'set_project',
2424 default
=None, multiple
=True,
2425 help='create/replace the project,role(s) mapping for this project: \'project,role1,role2,...\'')
2426 @click.option('--remove-project', 'remove_project',
2427 default
=None, multiple
=True,
2428 help='removes project from user: \'project\'')
2429 @click.option('--add-project-role', 'add_project_role',
2430 default
=None, multiple
=True,
2431 help='adds project,role(s) mapping: \'project,role1,role2,...\'')
2432 @click.option('--remove-project-role', 'remove_project_role',
2433 default
=None, multiple
=True,
2434 help='removes project,role(s) mapping: \'project,role1,role2,...\'')
2436 def user_update(ctx
, username
, password
, set_username
, set_project
, remove_project
,
2437 add_project_role
, remove_project_role
):
2438 """Update a user information
2441 USERNAME: name of the user
2442 PASSWORD: new password
2443 SET_USERNAME: new username
2444 SET_PROJECT: creating mappings for project/role(s)
2445 REMOVE_PROJECT: deleting mappings for project/role(s)
2446 ADD_PROJECT_ROLE: adding mappings for project/role(s)
2447 REMOVE_PROJECT_ROLE: removing mappings for project/role(s)
2450 user
['password'] = password
2451 user
['username'] = set_username
2452 user
['set-project'] = set_project
2453 user
['remove-project'] = remove_project
2454 user
['add-project-role'] = add_project_role
2455 user
['remove-project-role'] = remove_project_role
2458 check_client_version(ctx
.obj
, ctx
.command
.name
)
2459 ctx
.obj
.user
.update(username
, user
)
2460 except ClientException
as inst
:
2465 @cli.command(name
='user-delete', short_help
='deletes a user')
2466 @click.argument('name')
2467 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2469 def user_delete(ctx
, name
):
2473 NAME: name or ID of the user to be deleted
2476 check_client_version(ctx
.obj
, ctx
.command
.name
)
2477 ctx
.obj
.user
.delete(name
)
2478 except ClientException
as inst
:
2483 @cli.command(name
='user-list', short_help
='list all users')
2484 @click.option('--filter', default
=None,
2485 help='restricts the list to the users matching the filter')
2487 def user_list(ctx
, filter):
2488 """list all users"""
2490 check_client_version(ctx
.obj
, ctx
.command
.name
)
2491 resp
= ctx
.obj
.user
.list(filter)
2492 except ClientException
as inst
:
2495 table
= PrettyTable(['name', 'id'])
2497 table
.add_row([user
['username'], user
['_id']])
2502 @cli.command(name
='user-show', short_help
='shows the details of a user')
2503 @click.argument('name')
2505 def user_show(ctx
, name
):
2506 """shows the details of a user
2508 NAME: name or ID of the user
2511 check_client_version(ctx
.obj
, ctx
.command
.name
)
2512 resp
= ctx
.obj
.user
.get(name
)
2513 if 'password' in resp
:
2514 resp
['password']='********'
2515 except ClientException
as inst
:
2519 table
= PrettyTable(['key', 'attribute'])
2520 for k
, v
in resp
.items():
2521 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2526 ####################
2527 # Fault Management operations
2528 ####################
2530 @cli.command(name
='ns-alarm-create')
2531 @click.argument('name')
2532 @click.option('--ns', prompt
=True, help='NS instance id or name')
2533 @click.option('--vnf', prompt
=True,
2534 help='VNF name (VNF member index as declared in the NSD)')
2535 @click.option('--vdu', prompt
=True,
2536 help='VDU name (VDU name as declared in the VNFD)')
2537 @click.option('--metric', prompt
=True,
2538 help='Name of the metric (e.g. cpu_utilization)')
2539 @click.option('--severity', default
='WARNING',
2540 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
2541 @click.option('--threshold_value', prompt
=True,
2542 help='threshold value that, when crossed, an alarm is triggered')
2543 @click.option('--threshold_operator', prompt
=True,
2544 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
2545 @click.option('--statistic', default
='AVERAGE',
2546 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
2548 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
2549 threshold_value
, threshold_operator
, statistic
):
2550 """creates a new alarm for a NS instance"""
2551 # TODO: Check how to validate threshold_value.
2552 # Should it be an integer (1-100), percentage, or decimal (0.01-1.00)?
2554 ns_instance
= ctx
.obj
.ns
.get(ns
)
2556 alarm
['alarm_name'] = name
2557 alarm
['ns_id'] = ns_instance
['_id']
2558 alarm
['correlation_id'] = ns_instance
['_id']
2559 alarm
['vnf_member_index'] = vnf
2560 alarm
['vdu_name'] = vdu
2561 alarm
['metric_name'] = metric
2562 alarm
['severity'] = severity
2563 alarm
['threshold_value'] = int(threshold_value
)
2564 alarm
['operation'] = threshold_operator
2565 alarm
['statistic'] = statistic
2566 check_client_version(ctx
.obj
, ctx
.command
.name
)
2567 ctx
.obj
.ns
.create_alarm(alarm
)
2568 except ClientException
as inst
:
2569 print((inst
.message
))
2573 #@cli.command(name='ns-alarm-delete')
2574 #@click.argument('name')
2575 #@click.pass_context
2576 #def ns_alarm_delete(ctx, name):
2577 # """deletes an alarm
2579 # NAME: name of the alarm to be deleted
2582 # check_client_version(ctx.obj, ctx.command.name)
2583 # ctx.obj.ns.delete_alarm(name)
2584 # except ClientException as inst:
2585 # print(inst.message)
2589 ####################
2590 # Performance Management operations
2591 ####################
2593 @cli.command(name
='ns-metric-export', short_help
='exports a metric to the internal OSM bus, which can be read by other apps')
2594 @click.option('--ns', prompt
=True, help='NS instance id or name')
2595 @click.option('--vnf', prompt
=True,
2596 help='VNF name (VNF member index as declared in the NSD)')
2597 @click.option('--vdu', prompt
=True,
2598 help='VDU name (VDU name as declared in the VNFD)')
2599 @click.option('--metric', prompt
=True,
2600 help='name of the metric (e.g. cpu_utilization)')
2601 #@click.option('--period', default='1w',
2602 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
2603 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
2605 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
2606 """exports a metric to the internal OSM bus, which can be read by other apps"""
2607 # TODO: Check how to validate interval.
2608 # Should it be an integer (seconds), or should a suffix (s,m,h,d,w) also be permitted?
2610 ns_instance
= ctx
.obj
.ns
.get(ns
)
2612 metric_data
['ns_id'] = ns_instance
['_id']
2613 metric_data
['correlation_id'] = ns_instance
['_id']
2614 metric_data
['vnf_member_index'] = vnf
2615 metric_data
['vdu_name'] = vdu
2616 metric_data
['metric_name'] = metric
2617 metric_data
['collection_unit'] = 'WEEK'
2618 metric_data
['collection_period'] = 1
2619 check_client_version(ctx
.obj
, ctx
.command
.name
)
2621 print('{}'.format(ctx
.obj
.ns
.export_metric(metric_data
)))
2625 print('{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
))
2626 time
.sleep(int(interval
))
2628 except ClientException
as inst
:
2629 print((inst
.message
))
2633 ####################
2635 ####################
2637 @cli.command(name
='upload-package', short_help
='uploads a VNF package or NS package')
2638 @click.argument('filename')
2640 def upload_package(ctx
, filename
):
2641 """uploads a VNF package or NS package
2643 FILENAME: VNF or NS package file (tar.gz)
2646 ctx
.obj
.package
.upload(filename
)
2647 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
2648 if fullclassname
!= 'osmclient.sol005.client.Client':
2649 ctx
.obj
.package
.wait_for_upload(filename
)
2650 except ClientException
as inst
:
2651 print((inst
.message
))
2655 #@cli.command(name='ns-scaling-show')
2656 #@click.argument('ns_name')
2657 #@click.pass_context
2658 #def show_ns_scaling(ctx, ns_name):
2659 # """shows the status of a NS scaling operation
2661 # NS_NAME: name of the NS instance being scaled
2664 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2665 # resp = ctx.obj.ns.list()
2666 # except ClientException as inst:
2667 # print((inst.message))
2670 # table = PrettyTable(
2673 # 'operational status',
2678 # if ns_name == ns['name']:
2679 # nsopdata = ctx.obj.ns.get_opdata(ns['id'])
2680 # scaling_records = nsopdata['nsr:nsr']['scaling-group-record']
2681 # for record in scaling_records:
2682 # if 'instance' in record:
2683 # instances = record['instance']
2684 # for inst in instances:
2686 # [record['scaling-group-name-ref'],
2687 # inst['instance-id'],
2688 # inst['op-status'],
2689 # time.strftime('%Y-%m-%d %H:%M:%S',
2691 # inst['create-time'])),
2697 #@cli.command(name='ns-scale')
2698 #@click.argument('ns_name')
2699 #@click.option('--ns_scale_group', prompt=True)
2700 #@click.option('--index', prompt=True)
2701 #@click.option('--wait',
2705 # help='do not return the control immediately, but keep it \
2706 # until the operation is completed, or timeout')
2707 #@click.pass_context
2708 #def ns_scale(ctx, ns_name, ns_scale_group, index, wait):
2711 # NS_NAME: name of the NS instance to be scaled
2714 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2715 # ctx.obj.ns.scale(ns_name, ns_scale_group, index, wait=wait)
2716 # except ClientException as inst:
2717 # print((inst.message))
2721 #@cli.command(name='config-agent-list')
2722 #@click.pass_context
2723 #def config_agent_list(ctx):
2724 # """list config agents"""
2726 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2727 # except ClientException as inst:
2728 # print((inst.message))
2730 # table = PrettyTable(['name', 'account-type', 'details'])
2731 # for account in ctx.obj.vca.list():
2734 # account['account-type'],
2740 #@cli.command(name='config-agent-delete')
2741 #@click.argument('name')
2742 #@click.pass_context
2743 #def config_agent_delete(ctx, name):
2744 # """deletes a config agent
2746 # NAME: name of the config agent to be deleted
2749 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2750 # ctx.obj.vca.delete(name)
2751 # except ClientException as inst:
2752 # print((inst.message))
2756 #@cli.command(name='config-agent-add')
2757 #@click.option('--name',
2759 #@click.option('--account_type',
2761 #@click.option('--server',
2763 #@click.option('--user',
2765 #@click.option('--secret',
2768 # confirmation_prompt=True)
2769 #@click.pass_context
2770 #def config_agent_add(ctx, name, account_type, server, user, secret):
2771 # """adds a config agent"""
2773 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2774 # ctx.obj.vca.create(name, account_type, server, user, secret)
2775 # except ClientException as inst:
2776 # print((inst.message))
2780 #@cli.command(name='ro-dump')
2781 #@click.pass_context
2783 # """shows RO agent information"""
2784 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2785 # resp = ctx.obj.vim.get_resource_orchestrator()
2786 # table = PrettyTable(['key', 'attribute'])
2787 # for k, v in list(resp.items()):
2788 # table.add_row([k, json.dumps(v, indent=2)])
2793 #@cli.command(name='vcs-list')
2794 #@click.pass_context
2796 # check_client_version(ctx.obj, ctx.command.name, 'v1')
2797 # resp = ctx.obj.utils.get_vcs_info()
2798 # table = PrettyTable(['component name', 'state'])
2799 # for component in resp:
2800 # table.add_row([component['component_name'], component['state']])
2805 @cli.command(name
='ns-action', short_help
='executes an action/primitive over a NS instance')
2806 @click.argument('ns_name')
2807 @click.option('--vnf_name', default
=None, help='member-vnf-index if the target is a vnf instead of a ns)')
2808 @click.option('--vdu_id', default
=None, help='vdu-id if the target is a vdu o a vnf')
2809 @click.option('--vdu_count', default
=None, help='number of vdu instance of this vdu_id')
2810 @click.option('--action_name', prompt
=True)
2811 @click.option('--params', default
=None)
2812 @click.option('--wait',
2816 help='do not return the control immediately, but keep it \
2817 until the operation is completed, or timeout')
2827 """executes an action/primitive over a NS instance
2829 NS_NAME: name or ID of the NS instance
2832 check_client_version(ctx
.obj
, ctx
.command
.name
)
2835 op_data
['member_vnf_index'] = vnf_name
2837 op_data
['vdu_id'] = vdu_id
2839 op_data
['vdu_count_index'] = vdu_count
2840 op_data
['primitive'] = action_name
2842 op_data
['primitive_params'] = yaml
.safe_load(params
)
2844 op_data
['primitive_params'] = {}
2845 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
, wait
=wait
)
2847 except ClientException
as inst
:
2852 @cli.command(name
='vnf-scale', short_help
='executes a VNF scale (adding/removing VDUs)')
2853 @click.argument('ns_name')
2854 @click.argument('vnf_name')
2855 @click.option('--scaling-group', prompt
=True, help="scaling-group-descriptor name to use")
2856 @click.option('--scale-in', default
=False, is_flag
=True, help="performs a scale in operation")
2857 @click.option('--scale-out', default
=False, is_flag
=True, help="performs a scale out operation (by default)")
2866 Executes a VNF scale (adding/removing VDUs)
2869 NS_NAME: name or ID of the NS instance.
2870 VNF_NAME: member-vnf-index in the NS to be scaled.
2873 check_client_version(ctx
.obj
, ctx
.command
.name
)
2874 if not scale_in
and not scale_out
:
2876 ctx
.obj
.ns
.scale_vnf(ns_name
, vnf_name
, scaling_group
, scale_in
, scale_out
)
2877 except ClientException
as inst
:
2878 print((inst
.message
))
2882 ##############################
2883 # Role Management Operations #
2884 ##############################
2886 @cli.command(name
='role-create', short_help
='creates a new role')
2887 @click.argument('name')
2888 @click.option('--permissions',
2890 help='role permissions using a dictionary')
2892 def role_create(ctx
, name
, permissions
):
2897 NAME: Name or ID of the role.
2898 DEFINITION: Definition of grant/denial of access to resources.
2901 check_client_version(ctx
.obj
, ctx
.command
.name
)
2902 ctx
.obj
.role
.create(name
, permissions
)
2903 except ClientException
as inst
:
2908 @cli.command(name
='role-update', short_help
='updates a role')
2909 @click.argument('name')
2910 @click.option('--set-name',
2912 help='change name of rle')
2913 # @click.option('--permissions',
2915 # help='provide a yaml format dictionary with incremental changes. Values can be bool or None to delete')
2916 @click.option('--add',
2918 help='yaml format dictionary with permission: True/False to access grant/denial')
2919 @click.option('--remove',
2921 help='yaml format list to remove a permission')
2923 def role_update(ctx
, name
, set_name
, add
, remove
):
2928 NAME: Name or ID of the role.
2929 DEFINITION: Definition overwrites the old definition.
2930 ADD: Grant/denial of access to resource to add.
2931 REMOVE: Grant/denial of access to resource to remove.
2934 check_client_version(ctx
.obj
, ctx
.command
.name
)
2935 ctx
.obj
.role
.update(name
, set_name
, None, add
, remove
)
2936 except ClientException
as inst
:
2941 @cli.command(name
='role-delete', short_help
='deletes a role')
2942 @click.argument('name')
2943 # @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2945 def role_delete(ctx
, name
):
2950 NAME: Name or ID of the role.
2953 check_client_version(ctx
.obj
, ctx
.command
.name
)
2954 ctx
.obj
.role
.delete(name
)
2955 except ClientException
as inst
:
2960 @cli.command(name
='role-list', short_help
='list all roles')
2961 @click.option('--filter', default
=None,
2962 help='restricts the list to the projects matching the filter')
2964 def role_list(ctx
, filter):
2969 check_client_version(ctx
.obj
, ctx
.command
.name
)
2970 resp
= ctx
.obj
.role
.list(filter)
2971 except ClientException
as inst
:
2974 table
= PrettyTable(['name', 'id'])
2976 table
.add_row([role
['name'], role
['_id']])
2981 @cli.command(name
='role-show', short_help
='show specific role')
2982 @click.argument('name')
2984 def role_show(ctx
, name
):
2986 Shows the details of a role.
2989 NAME: Name or ID of the role.
2992 check_client_version(ctx
.obj
, ctx
.command
.name
)
2993 resp
= ctx
.obj
.role
.get(name
)
2994 except ClientException
as inst
:
2998 table
= PrettyTable(['key', 'attribute'])
2999 for k
, v
in resp
.items():
3000 table
.add_row([k
, json
.dumps(v
, indent
=2)])
3004 if __name__
== '__main__':
3007 except pycurl
.error
as e
:
3009 print('Maybe "--hostname" option or OSM_HOSTNAME' +
3010 'environment variable needs to be specified')