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
30 def check_client_version(obj
, what
, version
='sol005'):
32 Checks the version of the client object and raises error if it not the expected.
34 :param obj: the client object
35 :what: the function or command under evaluation (used when an error is raised)
37 :raises ClientError: if the specified version does not match the client version
39 fullclassname
= obj
.__module
__ + "." + obj
.__class
__.__name
__
40 message
= 'The following commands or options are only supported with the option "--sol005": {}'.format(what
)
42 message
= 'The following commands or options are not supported when using option "--sol005": {}'.format(what
)
43 if fullclassname
!= 'osmclient.{}.client.Client'.format(version
):
44 raise ClientException(message
)
48 @click.option('--hostname',
50 envvar
='OSM_HOSTNAME',
51 help='hostname of server. ' +
52 'Also can set OSM_HOSTNAME in environment')
53 @click.option('--sol005/--no-sol005',
56 help='Use ETSI NFV SOL005 API (default) or the previous SO API. ' +
57 'Also can set OSM_SOL005 in environment')
58 @click.option('--user',
61 help='user (only from Release FOUR, defaults to admin). ' +
62 'Also can set OSM_USER in environment')
63 @click.option('--password',
65 envvar
='OSM_PASSWORD',
66 help='password (only from Release FOUR, defaults to admin). ' +
67 'Also can set OSM_PASSWORD in environment')
68 @click.option('--project',
71 help='project (only from Release FOUR, defaults to admin). ' +
72 'Also can set OSM_PROJECT in environment')
73 @click.option('--so-port',
76 help='hostname of server. ' +
77 'Also can set OSM_SO_PORT in environment')
78 @click.option('--so-project',
80 envvar
='OSM_SO_PROJECT',
81 help='Project Name in SO. ' +
82 'Also can set OSM_SO_PROJECT in environment')
83 @click.option('--ro-hostname',
85 envvar
='OSM_RO_HOSTNAME',
86 help='hostname of RO server. ' +
87 'Also can set OSM_RO_HOSTNAME in environment')
88 @click.option('--ro-port',
91 help='hostname of RO server. ' +
92 'Also can set OSM_RO_PORT in environment')
94 def cli(ctx
, hostname
, sol005
, user
, password
, project
, so_port
, so_project
, ro_hostname
, ro_port
):
97 "either hostname option or OSM_HOSTNAME " +
98 "environment variable needs to be specified"))
101 if so_port
is not None:
102 kwargs
['so_port']=so_port
103 if so_project
is not None:
104 kwargs
['so_project']=so_project
105 if ro_hostname
is not None:
106 kwargs
['ro_host']=ro_hostname
107 if ro_port
is not None:
108 kwargs
['ro_port']=ro_port
111 if password
is not None:
112 kwargs
['password']=password
113 if project
is not None:
114 kwargs
['project']=project
116 ctx
.obj
= client
.Client(host
=hostname
, sol005
=sol005
, **kwargs
)
123 @cli.command(name
='ns-list')
124 @click.option('--filter', default
=None,
125 help='restricts the list to the NS instances matching the filter.')
127 def ns_list(ctx
, filter):
128 '''list all NS instances
132 --filter filterExpr Restricts the list to the NS instances matching the filter
135 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
136 concatenated using the "&" character:
139 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
140 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
141 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
143 value := scalar value
147 * zero or more occurrences
148 ? zero or one occurrence
149 [] grouping of expressions to be used with ? and *
150 "" quotation marks for marking string constants
154 "AttrName" is the name of one attribute in the data type that defines the representation
155 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
156 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
157 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
158 entries, it means that the operator "op" is applied to the attribute addressed by the last
159 <attrName> entry included in the concatenation. All simple filter expressions are combined
160 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
161 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
162 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
163 prefix". If an attribute referenced in an expression is an array, an object that contains a
164 corresponding array shall be considered to match the expression if any of the elements in the
165 array matches all expressions that have the same attribute prefix.
169 --filter admin-status=ENABLED
170 --filter nsd-ref=<NSD_NAME>
171 --filter nsd.vendor=<VENDOR>
172 --filter nsd.vendor=<VENDOR>&nsd-ref=<NSD_NAME>
173 --filter nsd.constituent-vnfd.vnfd-id-ref=<VNFD_NAME>
176 check_client_version(ctx
.obj
, '--filter')
177 resp
= ctx
.obj
.ns
.list(filter)
179 resp
= ctx
.obj
.ns
.list()
183 'operational status',
187 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
188 if fullclassname
== 'osmclient.sol005.client.Client':
190 nsr_name
= nsr
['name']
193 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
194 nsr
= nsopdata
['nsr:nsr']
195 nsr_name
= nsr
['name-ref']
196 nsr_id
= nsr
['ns-instance-config-ref']
197 opstatus
= nsr
['operational-status'] if 'operational-status' in nsr
else 'Not found'
198 configstatus
= nsr
['config-status'] if 'config-status' in nsr
else 'Not found'
199 detailed_status
= nsr
['detailed-status'] if 'detailed-status' in nsr
else 'Not found'
200 if configstatus
== "config_not_needed":
201 configstatus
= "configured (no charms)"
212 def nsd_list(ctx
, filter):
214 check_client_version(ctx
.obj
, '--filter')
215 resp
= ctx
.obj
.nsd
.list(filter)
217 resp
= ctx
.obj
.nsd
.list()
218 #print yaml.safe_dump(resp)
219 table
= PrettyTable(['nsd name', 'id'])
220 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
221 if fullclassname
== 'osmclient.sol005.client.Client':
223 name
= ns
['name'] if 'name' in ns
else '-'
224 table
.add_row([name
, ns
['_id']])
227 table
.add_row([ns
['name'], ns
['id']])
232 @cli.command(name
='nsd-list')
233 @click.option('--filter', default
=None,
234 help='restricts the list to the NSD/NSpkg matching the filter')
236 def nsd_list1(ctx
, filter):
237 '''list all NSD/NSpkg in the system'''
241 @cli.command(name
='nspkg-list')
242 @click.option('--filter', default
=None,
243 help='restricts the list to the NSD/NSpkg matching the filter')
245 def nsd_list2(ctx
, filter):
246 '''list all NSD/NSpkg in the system'''
250 def vnfd_list(ctx
, filter):
252 check_client_version(ctx
.obj
, '--filter')
253 resp
= ctx
.obj
.vnfd
.list(filter)
255 resp
= ctx
.obj
.vnfd
.list()
256 #print yaml.safe_dump(resp)
257 table
= PrettyTable(['vnfd name', 'id'])
258 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
259 if fullclassname
== 'osmclient.sol005.client.Client':
261 name
= vnfd
['name'] if 'name' in vnfd
else '-'
262 table
.add_row([name
, vnfd
['_id']])
265 table
.add_row([vnfd
['name'], vnfd
['id']])
270 @cli.command(name
='vnfd-list')
271 @click.option('--filter', default
=None,
272 help='restricts the list to the VNFD/VNFpkg matching the filter')
274 def vnfd_list1(ctx
, filter):
275 '''list all VNFD/VNFpkg in the system'''
276 vnfd_list(ctx
,filter)
279 @cli.command(name
='vnfpkg-list')
280 @click.option('--filter', default
=None,
281 help='restricts the list to the VNFD/VNFpkg matching the filter')
283 def vnfd_list2(ctx
, filter):
284 '''list all VNFD/VNFpkg in the system'''
285 vnfd_list(ctx
,filter)
288 @cli.command(name
='vnf-list')
289 @click.option('--ns', default
=None, help='NS instance id or name to restrict the VNF list')
290 @click.option('--filter', default
=None,
291 help='restricts the list to the VNF instances matching the filter.')
293 def vnf_list(ctx
, ns
, filter):
294 '''list all VNF instances
298 --ns TEXT NS instance id or name to restrict the VNF list
299 --filter filterExpr Restricts the list to the VNF instances matching the filter
302 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
303 concatenated using the "&" character:
306 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
307 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
308 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
310 value := scalar value
314 * zero or more occurrences
315 ? zero or one occurrence
316 [] grouping of expressions to be used with ? and *
317 "" quotation marks for marking string constants
321 "AttrName" is the name of one attribute in the data type that defines the representation
322 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
323 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
324 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
325 entries, it means that the operator "op" is applied to the attribute addressed by the last
326 <attrName> entry included in the concatenation. All simple filter expressions are combined
327 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
328 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
329 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
330 prefix". If an attribute referenced in an expression is an array, an object that contains a
331 corresponding array shall be considered to match the expression if any of the elements in the
332 array matches all expressions that have the same attribute prefix.
336 --filter vim-account-id=<VIM_ACCOUNT_ID>
337 --filter vnfd-ref=<VNFD_NAME>
338 --filter vdur.ip-address=<IP_ADDRESS>
339 --filter vnfd-ref=<VNFD_NAME>,vdur.ip-address=<IP_ADDRESS>
344 check_client_version(ctx
.obj
, '--ns')
346 check_client_version(ctx
.obj
, '--filter')
347 resp
= ctx
.obj
.vnf
.list(ns
, filter)
349 resp
= ctx
.obj
.vnf
.list()
350 except ClientException
as inst
:
351 print((inst
.message
))
353 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
354 if fullclassname
== 'osmclient.sol005.client.Client':
364 name
= vnfr
['name'] if 'name' in vnfr
else '-'
369 vnfr
['member-vnf-index-ref'],
371 vnfr
['vim-account-id'],
377 'operational status',
380 if 'mgmt-interface' not in vnfr
:
381 vnfr
['mgmt-interface'] = {}
382 vnfr
['mgmt-interface']['ip-address'] = None
386 vnfr
['operational-status'],
387 vnfr
['config-status']])
391 @cli.command(name
='ns-op-list')
392 @click.argument('name')
394 def ns_op_list(ctx
, name
):
395 '''shows the history of operations over a NS instance
397 NAME: name or ID of the NS instance
400 check_client_version(ctx
.obj
, ctx
.command
.name
)
401 resp
= ctx
.obj
.ns
.list_op(name
)
402 except ClientException
as inst
:
403 print((inst
.message
))
406 table
= PrettyTable(['id', 'operation', 'status'])
408 table
.add_row([op
['id'], op
['lcmOperationType'],
409 op
['operationState']])
414 def nsi_list(ctx
, filter):
415 '''list all Network Slice Instances'''
417 check_client_version(ctx
.obj
, ctx
.command
.name
)
418 resp
= ctx
.obj
.nsi
.list(filter)
419 except ClientException
as inst
:
420 print((inst
.message
))
423 ['netslice instance name',
425 'operational status',
429 nsi_name
= nsi
['name']
431 opstatus
= nsi
['operational-status'] if 'operational-status' in nsi
else 'Not found'
432 configstatus
= nsi
['config-status'] if 'config-status' in nsi
else 'Not found'
433 detailed_status
= nsi
['detailed-status'] if 'detailed-status' in nsi
else 'Not found'
434 if configstatus
== "config_not_needed":
435 configstatus
= "configured (no charms)"
446 @cli.command(name
='nsi-list')
447 @click.option('--filter', default
=None,
448 help='restricts the list to the Network Slice Instances matching the filter')
450 def nsi_list1(ctx
, filter):
451 '''list all Network Slice Instances (NSI)'''
455 @cli.command(name
='netslice-instance-list')
456 @click.option('--filter', default
=None,
457 help='restricts the list to the Network Slice Instances matching the filter')
459 def nsi_list2(ctx
, filter):
460 '''list all Network Slice Instances (NSI)'''
464 def nst_list(ctx
, filter):
466 check_client_version(ctx
.obj
, ctx
.command
.name
)
467 resp
= ctx
.obj
.nst
.list(filter)
468 except ClientException
as inst
:
469 print((inst
.message
))
471 #print yaml.safe_dump(resp)
472 table
= PrettyTable(['nst name', 'id'])
474 name
= nst
['name'] if 'name' in nst
else '-'
475 table
.add_row([name
, nst
['_id']])
480 @cli.command(name
='nst-list')
481 @click.option('--filter', default
=None,
482 help='restricts the list to the NST matching the filter')
484 def nst_list1(ctx
, filter):
485 '''list all Network Slice Templates (NST) in the system'''
489 @cli.command(name
='netslice-template-list')
490 @click.option('--filter', default
=None,
491 help='restricts the list to the NST matching the filter')
493 def nst_list2(ctx
, filter):
494 '''list all Network Slice Templates (NST) in the system'''
498 def nsi_op_list(ctx
, name
):
500 check_client_version(ctx
.obj
, ctx
.command
.name
)
501 resp
= ctx
.obj
.nsi
.list_op(name
)
502 except ClientException
as inst
:
503 print((inst
.message
))
505 table
= PrettyTable(['id', 'operation', 'status'])
507 table
.add_row([op
['id'], op
['lcmOperationType'],
508 op
['operationState']])
513 @cli.command(name
='nsi-op-list')
514 @click.argument('name')
516 def nsi_op_list1(ctx
, name
):
517 '''shows the history of operations over a Network Slice Instance (NSI)
519 NAME: name or ID of the Network Slice Instance
521 nsi_op_list(ctx
,name
)
524 @cli.command(name
='netslice-instance-op-list')
525 @click.argument('name')
527 def nsi_op_list2(ctx
, name
):
528 '''shows the history of operations over a Network Slice Instance (NSI)
530 NAME: name or ID of the Network Slice Instance
532 nsi_op_list(ctx
,name
)
539 def nsd_show(ctx
, name
, literal
):
541 resp
= ctx
.obj
.nsd
.get(name
)
542 #resp = ctx.obj.nsd.get_individual(name)
543 except ClientException
as inst
:
544 print((inst
.message
))
548 print(yaml
.safe_dump(resp
))
551 table
= PrettyTable(['field', 'value'])
552 for k
, v
in list(resp
.items()):
553 table
.add_row([k
, json
.dumps(v
, indent
=2)])
558 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
559 @click.option('--literal', is_flag
=True,
560 help='print literally, no pretty table')
561 @click.argument('name')
563 def nsd_show1(ctx
, name
, literal
):
564 '''shows the content of a NSD
566 NAME: name or ID of the NSD/NSpkg
568 nsd_show(ctx
, name
, literal
)
571 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
572 @click.option('--literal', is_flag
=True,
573 help='print literally, no pretty table')
574 @click.argument('name')
576 def nsd_show2(ctx
, name
, literal
):
577 '''shows the content of a NSD
579 NAME: name or ID of the NSD/NSpkg
581 nsd_show(ctx
, name
, literal
)
584 def vnfd_show(ctx
, name
, literal
):
586 resp
= ctx
.obj
.vnfd
.get(name
)
587 #resp = ctx.obj.vnfd.get_individual(name)
588 except ClientException
as inst
:
589 print((inst
.message
))
593 print(yaml
.safe_dump(resp
))
596 table
= PrettyTable(['field', 'value'])
597 for k
, v
in list(resp
.items()):
598 table
.add_row([k
, json
.dumps(v
, indent
=2)])
603 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
604 @click.option('--literal', is_flag
=True,
605 help='print literally, no pretty table')
606 @click.argument('name')
608 def vnfd_show1(ctx
, name
, literal
):
609 '''shows the content of a VNFD
611 NAME: name or ID of the VNFD/VNFpkg
613 vnfd_show(ctx
, name
, literal
)
616 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
617 @click.option('--literal', is_flag
=True,
618 help='print literally, no pretty table')
619 @click.argument('name')
621 def vnfd_show2(ctx
, name
, literal
):
622 '''shows the content of a VNFD
624 NAME: name or ID of the VNFD/VNFpkg
626 vnfd_show(ctx
, name
, literal
)
629 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
630 @click.argument('name')
631 @click.option('--literal', is_flag
=True,
632 help='print literally, no pretty table')
633 @click.option('--filter', default
=None)
635 def ns_show(ctx
, name
, literal
, filter):
636 '''shows the info of a NS instance
638 NAME: name or ID of the NS instance
641 ns
= ctx
.obj
.ns
.get(name
)
642 except ClientException
as inst
:
643 print((inst
.message
))
647 print(yaml
.safe_dump(ns
))
650 table
= PrettyTable(['field', 'value'])
652 for k
, v
in list(ns
.items()):
653 if filter is None or filter in k
:
654 table
.add_row([k
, json
.dumps(v
, indent
=2)])
656 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
657 if fullclassname
!= 'osmclient.sol005.client.Client':
658 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
659 nsr_optdata
= nsopdata
['nsr:nsr']
660 for k
, v
in list(nsr_optdata
.items()):
661 if filter is None or filter in k
:
662 table
.add_row([k
, json
.dumps(v
, indent
=2)])
667 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
668 @click.argument('name')
669 @click.option('--literal', is_flag
=True,
670 help='print literally, no pretty table')
671 @click.option('--filter', default
=None)
673 def vnf_show(ctx
, name
, literal
, filter):
674 '''shows the info of a VNF instance
676 NAME: name or ID of the VNF instance
679 check_client_version(ctx
.obj
, ctx
.command
.name
)
680 resp
= ctx
.obj
.vnf
.get(name
)
681 except ClientException
as inst
:
682 print((inst
.message
))
686 print(yaml
.safe_dump(resp
))
689 table
= PrettyTable(['field', 'value'])
690 for k
, v
in list(resp
.items()):
691 if filter is None or filter in k
:
692 table
.add_row([k
, json
.dumps(v
, indent
=2)])
697 @cli.command(name
='vnf-monitoring-show')
698 @click.argument('vnf_name')
700 def vnf_monitoring_show(ctx
, vnf_name
):
702 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
703 resp
= ctx
.obj
.vnf
.get_monitoring(vnf_name
)
704 except ClientException
as inst
:
705 print((inst
.message
))
708 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
714 monitor
['value-integer'],
720 @cli.command(name
='ns-monitoring-show')
721 @click.argument('ns_name')
723 def ns_monitoring_show(ctx
, ns_name
):
725 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
726 resp
= ctx
.obj
.ns
.get_monitoring(ns_name
)
727 except ClientException
as inst
:
728 print((inst
.message
))
731 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
732 for key
, val
in list(resp
.items()):
737 monitor
['value-integer'],
743 @cli.command(name
='ns-op-show', short_help
='shows the info of an operation')
744 @click.argument('id')
745 @click.option('--filter', default
=None)
747 def ns_op_show(ctx
, id, filter):
748 '''shows the detailed info of an operation
750 ID: operation identifier
753 check_client_version(ctx
.obj
, ctx
.command
.name
)
754 op_info
= ctx
.obj
.ns
.get_op(id)
755 except ClientException
as inst
:
756 print((inst
.message
))
759 table
= PrettyTable(['field', 'value'])
760 for k
, v
in list(op_info
.items()):
761 if filter is None or filter in k
:
762 table
.add_row([k
, json
.dumps(v
, indent
=2)])
767 def nst_show(ctx
, name
, literal
):
769 check_client_version(ctx
.obj
, ctx
.command
.name
)
770 resp
= ctx
.obj
.nst
.get(name
)
771 #resp = ctx.obj.nst.get_individual(name)
772 except ClientException
as inst
:
773 print((inst
.message
))
777 print(yaml
.safe_dump(resp
))
780 table
= PrettyTable(['field', 'value'])
781 for k
, v
in list(resp
.items()):
782 table
.add_row([k
, json
.dumps(v
, indent
=2)])
787 @cli.command(name
='nst-show', short_help
='shows the content of a Network Slice Template (NST)')
788 @click.option('--literal', is_flag
=True,
789 help='print literally, no pretty table')
790 @click.argument('name')
792 def nst_show1(ctx
, name
, literal
):
793 '''shows the content of a Network Slice Template (NST)
795 NAME: name or ID of the NST
797 nst_show(ctx
, name
, literal
)
800 @cli.command(name
='netslice-template-show', short_help
='shows the content of a Network Slice Template (NST)')
801 @click.option('--literal', is_flag
=True,
802 help='print literally, no pretty table')
803 @click.argument('name')
805 def nst_show2(ctx
, name
, literal
):
806 '''shows the content of a Network Slice Template (NST)
808 NAME: name or ID of the NST
810 nst_show(ctx
, name
, literal
)
813 def nsi_show(ctx
, name
, literal
, filter):
815 check_client_version(ctx
.obj
, ctx
.command
.name
)
816 nsi
= ctx
.obj
.nsi
.get(name
)
817 except ClientException
as inst
:
818 print((inst
.message
))
822 print(yaml
.safe_dump(nsi
))
825 table
= PrettyTable(['field', 'value'])
827 for k
, v
in list(nsi
.items()):
828 if filter is None or filter in k
:
829 table
.add_row([k
, json
.dumps(v
, indent
=2)])
835 @cli.command(name
='nsi-show', short_help
='shows the content of a Network Slice Instance (NSI)')
836 @click.argument('name')
837 @click.option('--literal', is_flag
=True,
838 help='print literally, no pretty table')
839 @click.option('--filter', default
=None)
841 def nsi_show1(ctx
, name
, literal
, filter):
842 '''shows the content of a Network Slice Instance (NSI)
844 NAME: name or ID of the Network Slice Instance
846 nsi_show(ctx
, name
, literal
, filter)
849 @cli.command(name
='netslice-instance-show', short_help
='shows the content of a Network Slice Instance (NSI)')
850 @click.argument('name')
851 @click.option('--literal', is_flag
=True,
852 help='print literally, no pretty table')
853 @click.option('--filter', default
=None)
855 def nsi_show2(ctx
, name
, literal
, filter):
856 '''shows the content of a Network Slice Instance (NSI)
858 NAME: name or ID of the Network Slice Instance
860 nsi_show(ctx
, name
, literal
, filter)
863 def nsi_op_show(ctx
, id, filter):
865 check_client_version(ctx
.obj
, ctx
.command
.name
)
866 op_info
= ctx
.obj
.nsi
.get_op(id)
867 except ClientException
as inst
:
868 print((inst
.message
))
871 table
= PrettyTable(['field', 'value'])
872 for k
, v
in list(op_info
.items()):
873 if filter is None or filter in k
:
874 table
.add_row([k
, json
.dumps(v
, indent
=2)])
879 @cli.command(name
='nsi-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
880 @click.argument('id')
881 @click.option('--filter', default
=None)
883 def nsi_op_show1(ctx
, id, filter):
884 '''shows the info of an operation over a Network Slice Instance(NSI)
886 ID: operation identifier
888 nsi_op_show(ctx
, id, filter)
891 @cli.command(name
='netslice-instance-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
892 @click.argument('id')
893 @click.option('--filter', default
=None)
895 def nsi_op_show2(ctx
, id, filter):
896 '''shows the info of an operation over a Network Slice Instance(NSI)
898 ID: operation identifier
900 nsi_op_show(ctx
, id, filter)
907 def nsd_create(ctx
, filename
, overwrite
):
909 check_client_version(ctx
.obj
, ctx
.command
.name
)
910 ctx
.obj
.nsd
.create(filename
, overwrite
)
911 except ClientException
as inst
:
912 print((inst
.message
))
916 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
917 @click.argument('filename')
918 @click.option('--overwrite', default
=None,
919 help='overwrites some fields in NSD')
921 def nsd_create1(ctx
, filename
, overwrite
):
922 '''creates a new NSD/NSpkg
924 FILENAME: NSD yaml file or NSpkg tar.gz file
926 nsd_create(ctx
, filename
, overwrite
)
929 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
930 @click.argument('filename')
931 @click.option('--overwrite', default
=None,
932 help='overwrites some fields in NSD')
934 def nsd_create2(ctx
, filename
, overwrite
):
935 '''creates a new NSD/NSpkg
937 FILENAME: NSD yaml file or NSpkg tar.gz file
939 nsd_create(ctx
, filename
, overwrite
)
942 def vnfd_create(ctx
, filename
, overwrite
):
944 check_client_version(ctx
.obj
, ctx
.command
.name
)
945 ctx
.obj
.vnfd
.create(filename
, overwrite
)
946 except ClientException
as inst
:
947 print((inst
.message
))
951 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
952 @click.argument('filename')
953 @click.option('--overwrite', default
=None,
954 help='overwrites some fields in VNFD')
956 def vnfd_create1(ctx
, filename
, overwrite
):
957 '''creates a new VNFD/VNFpkg
959 FILENAME: VNFD yaml file or VNFpkg tar.gz file
961 vnfd_create(ctx
, filename
, overwrite
)
964 @cli.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
965 @click.argument('filename')
966 @click.option('--overwrite', default
=None,
967 help='overwrites some fields in VNFD')
969 def vnfd_create2(ctx
, filename
, overwrite
):
970 '''creates a new VNFD/VNFpkg
972 FILENAME: VNFD yaml file or VNFpkg tar.gz file
974 vnfd_create(ctx
, filename
, overwrite
)
977 @cli.command(name
='ns-create', short_help
='creates a new Network Service instance')
978 @click.option('--ns_name',
979 prompt
=True, help='name of the NS instance')
980 @click.option('--nsd_name',
981 prompt
=True, help='name of the NS descriptor')
982 @click.option('--vim_account',
983 prompt
=True, help='default VIM account id or name for the deployment')
984 @click.option('--admin_status',
986 help='administration status')
987 @click.option('--ssh_keys',
989 help='comma separated list of public key files to inject to vnfs')
990 @click.option('--config',
992 help='ns specific yaml configuration')
993 @click.option('--config_file',
995 help='ns specific yaml configuration file')
1005 '''creates a new NS instance'''
1008 check_client_version(ctx
.obj
, '--config_file')
1010 raise ClientException('"--config" option is incompatible with "--config_file" option')
1011 with
open(config_file
, 'r') as cf
:
1018 account
=vim_account
)
1019 except ClientException
as inst
:
1020 print((inst
.message
))
1024 def nst_create(ctx
, filename
, overwrite
):
1026 check_client_version(ctx
.obj
, ctx
.command
.name
)
1027 ctx
.obj
.nst
.create(filename
, overwrite
)
1028 except ClientException
as inst
:
1029 print((inst
.message
))
1033 @cli.command(name
='nst-create', short_help
='creates a new Network Slice Template (NST)')
1034 @click.argument('filename')
1035 @click.option('--overwrite', default
=None,
1036 help='overwrites some fields in NST')
1038 def nst_create1(ctx
, filename
, overwrite
):
1039 '''creates a new Network Slice Template (NST)
1041 FILENAME: NST yaml file or NSTpkg tar.gz file
1043 nst_create(ctx
, filename
, overwrite
)
1046 @cli.command(name
='netslice-template-create', short_help
='creates a new Network Slice Template (NST)')
1047 @click.argument('filename')
1048 @click.option('--overwrite', default
=None,
1049 help='overwrites some fields in NST')
1051 def nst_create2(ctx
, filename
, overwrite
):
1052 '''creates a new Network Slice Template (NST)
1054 FILENAME: NST yaml file or NSTpkg tar.gz file
1056 nst_create(ctx
, filename
, overwrite
)
1059 def nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
):
1060 '''creates a new Network Slice Instance (NSI)'''
1062 check_client_version(ctx
.obj
, ctx
.command
.name
)
1065 raise ClientException('"--config" option is incompatible with "--config_file" option')
1066 with
open(config_file
, 'r') as cf
:
1068 ctx
.obj
.nsi
.create(nst_name
, nsi_name
, config
=config
, ssh_keys
=ssh_keys
,
1069 account
=vim_account
)
1070 except ClientException
as inst
:
1071 print((inst
.message
))
1075 @cli.command(name
='nsi-create', short_help
='creates a new Network Slice Instance')
1076 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1077 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1078 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1079 @click.option('--ssh_keys', default
=None,
1080 help='comma separated list of keys to inject to vnfs')
1081 @click.option('--config', default
=None,
1082 help='Netslice specific yaml configuration:\n'
1083 'netslice_subnet: [\n'
1084 'id: TEXT, vim_account: TEXT,\n'
1085 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1086 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1088 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1090 @click.option('--config_file',
1092 help='nsi specific yaml configuration file')
1094 def nsi_create1(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
):
1095 '''creates a new Network Slice Instance (NSI)'''
1096 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
)
1099 @cli.command(name
='netslice-instance-create', short_help
='creates a new Network Slice Instance')
1100 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1101 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1102 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1103 @click.option('--ssh_keys', default
=None,
1104 help='comma separated list of keys to inject to vnfs')
1105 @click.option('--config', default
=None,
1106 help='Netslice specific yaml configuration:\n'
1107 'netslice_subnet: [\n'
1108 'id: TEXT, vim_account: TEXT,\n'
1109 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1110 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1112 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1114 @click.option('--config_file',
1116 help='nsi specific yaml configuration file')
1118 def nsi_create2(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
):
1119 '''creates a new Network Slice Instance (NSI)'''
1120 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
)
1123 ####################
1125 ####################
1127 def nsd_update(ctx
, name
, content
):
1129 check_client_version(ctx
.obj
, ctx
.command
.name
)
1130 ctx
.obj
.nsd
.update(name
, content
)
1131 except ClientException
as inst
:
1132 print((inst
.message
))
1136 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
1137 @click.argument('name')
1138 @click.option('--content', default
=None,
1139 help='filename with the NSD/NSpkg replacing the current one')
1141 def nsd_update1(ctx
, name
, content
):
1142 '''updates a NSD/NSpkg
1144 NAME: name or ID of the NSD/NSpkg
1146 nsd_update(ctx
, name
, content
)
1149 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
1150 @click.argument('name')
1151 @click.option('--content', default
=None,
1152 help='filename with the NSD/NSpkg replacing the current one')
1154 def nsd_update2(ctx
, name
, content
):
1155 '''updates a NSD/NSpkg
1157 NAME: name or ID of the NSD/NSpkg
1159 nsd_update(ctx
, name
, content
)
1162 def vnfd_update(ctx
, name
, content
):
1164 check_client_version(ctx
.obj
, ctx
.command
.name
)
1165 ctx
.obj
.vnfd
.update(name
, content
)
1166 except ClientException
as inst
:
1167 print((inst
.message
))
1171 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
1172 @click.argument('name')
1173 @click.option('--content', default
=None,
1174 help='filename with the VNFD/VNFpkg replacing the current one')
1176 def vnfd_update1(ctx
, name
, content
):
1177 '''updates a VNFD/VNFpkg
1179 NAME: name or ID of the VNFD/VNFpkg
1181 vnfd_update(ctx
, name
, content
)
1184 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
1185 @click.argument('name')
1186 @click.option('--content', default
=None,
1187 help='filename with the VNFD/VNFpkg replacing the current one')
1189 def vnfd_update2(ctx
, name
, content
):
1190 '''updates a VNFD/VNFpkg
1192 NAME: VNFD yaml file or VNFpkg tar.gz file
1194 vnfd_update(ctx
, name
, content
)
1197 def nst_update(ctx
, name
, content
):
1199 check_client_version(ctx
.obj
, ctx
.command
.name
)
1200 ctx
.obj
.nst
.update(name
, content
)
1201 except ClientException
as inst
:
1202 print((inst
.message
))
1206 @cli.command(name
='nst-update', short_help
='updates a Network Slice Template (NST)')
1207 @click.argument('name')
1208 @click.option('--content', default
=None,
1209 help='filename with the NST/NSTpkg replacing the current one')
1211 def nst_update1(ctx
, name
, content
):
1212 '''updates a Network Slice Template (NST)
1214 NAME: name or ID of the NSD/NSpkg
1216 nst_update(ctx
, name
, content
)
1219 @cli.command(name
='netslice-template-update', short_help
='updates a Network Slice Template (NST)')
1220 @click.argument('name')
1221 @click.option('--content', default
=None,
1222 help='filename with the NST/NSTpkg replacing the current one')
1224 def nst_update2(ctx
, name
, content
):
1225 '''updates a Network Slice Template (NST)
1227 NAME: name or ID of the NSD/NSpkg
1229 nst_update(ctx
, name
, content
)
1232 ####################
1234 ####################
1236 def nsd_delete(ctx
, name
, force
):
1239 ctx
.obj
.nsd
.delete(name
)
1241 check_client_version(ctx
.obj
, '--force')
1242 ctx
.obj
.nsd
.delete(name
, force
)
1243 except ClientException
as inst
:
1244 print((inst
.message
))
1248 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
1249 @click.argument('name')
1250 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1252 def nsd_delete1(ctx
, name
, force
):
1253 '''deletes a NSD/NSpkg
1255 NAME: name or ID of the NSD/NSpkg to be deleted
1257 nsd_delete(ctx
, name
, force
)
1260 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
1261 @click.argument('name')
1262 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1264 def nsd_delete2(ctx
, name
, force
):
1265 '''deletes a NSD/NSpkg
1267 NAME: name or ID of the NSD/NSpkg to be deleted
1269 nsd_delete(ctx
, name
, force
)
1272 def vnfd_delete(ctx
, name
, force
):
1275 ctx
.obj
.vnfd
.delete(name
)
1277 check_client_version(ctx
.obj
, '--force')
1278 ctx
.obj
.vnfd
.delete(name
, force
)
1279 except ClientException
as inst
:
1280 print((inst
.message
))
1284 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
1285 @click.argument('name')
1286 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1288 def vnfd_delete1(ctx
, name
, force
):
1289 '''deletes a VNFD/VNFpkg
1291 NAME: name or ID of the VNFD/VNFpkg to be deleted
1293 vnfd_delete(ctx
, name
, force
)
1296 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
1297 @click.argument('name')
1298 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1300 def vnfd_delete2(ctx
, name
, force
):
1301 '''deletes a VNFD/VNFpkg
1303 NAME: name or ID of the VNFD/VNFpkg to be deleted
1305 vnfd_delete(ctx
, name
, force
)
1308 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
1309 @click.argument('name')
1310 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1312 def ns_delete(ctx
, name
, force
):
1313 '''deletes a NS instance
1315 NAME: name or ID of the NS instance to be deleted
1319 ctx
.obj
.ns
.delete(name
)
1321 check_client_version(ctx
.obj
, '--force')
1322 ctx
.obj
.ns
.delete(name
, force
)
1323 except ClientException
as inst
:
1324 print((inst
.message
))
1328 def nst_delete(ctx
, name
, force
):
1330 check_client_version(ctx
.obj
, ctx
.command
.name
)
1331 ctx
.obj
.nst
.delete(name
, force
)
1332 except ClientException
as inst
:
1333 print((inst
.message
))
1337 @cli.command(name
='nst-delete', short_help
='deletes a Network Slice Template (NST)')
1338 @click.argument('name')
1339 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1341 def nst_delete1(ctx
, name
, force
):
1342 '''deletes a Network Slice Template (NST)
1344 NAME: name or ID of the NST/NSTpkg to be deleted
1346 nst_delete(ctx
, name
, force
)
1349 @cli.command(name
='netslice-template-delete', short_help
='deletes a Network Slice Template (NST)')
1350 @click.argument('name')
1351 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1353 def nst_delete2(ctx
, name
, force
):
1354 '''deletes a Network Slice Template (NST)
1356 NAME: name or ID of the NST/NSTpkg to be deleted
1358 nst_delete(ctx
, name
, force
)
1361 def nsi_delete(ctx
, name
, force
):
1363 check_client_version(ctx
.obj
, ctx
.command
.name
)
1364 ctx
.obj
.nsi
.delete(name
, force
)
1365 except ClientException
as inst
:
1366 print((inst
.message
))
1370 @cli.command(name
='nsi-delete', short_help
='deletes a Network Slice Instance (NSI)')
1371 @click.argument('name')
1372 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1374 def nsi_delete1(ctx
, name
, force
):
1375 '''deletes a Network Slice Instance (NSI)
1377 NAME: name or ID of the Network Slice instance to be deleted
1379 nsi_delete(ctx
, name
, force
)
1382 @cli.command(name
='netslice-instance-delete', short_help
='deletes a Network Slice Instance (NSI)')
1383 @click.argument('name')
1384 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1386 def nsi_delete2(ctx
, name
, force
):
1387 '''deletes a Network Slice Instance (NSI)
1389 NAME: name or ID of the Network Slice instance to be deleted
1391 nsi_delete(ctx
, name
, force
)
1394 ####################
1396 ####################
1398 @cli.command(name
='vim-create')
1399 @click.option('--name',
1401 help='Name to create datacenter')
1402 @click.option('--user',
1404 help='VIM username')
1405 @click.option('--password',
1408 confirmation_prompt
=True,
1409 help='VIM password')
1410 @click.option('--auth_url',
1413 @click.option('--tenant',
1415 help='VIM tenant name')
1416 @click.option('--config',
1418 help='VIM specific config parameters')
1419 @click.option('--account_type',
1420 default
='openstack',
1422 @click.option('--description',
1423 default
='no description',
1424 help='human readable description')
1425 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1426 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1439 '''creates a new VIM account
1443 check_client_version(ctx
.obj
, '--sdn_controller')
1444 if sdn_port_mapping
:
1445 check_client_version(ctx
.obj
, '--sdn_port_mapping')
1447 vim
['vim-username'] = user
1448 vim
['vim-password'] = password
1449 vim
['vim-url'] = auth_url
1450 vim
['vim-tenant-name'] = tenant
1451 vim
['vim-type'] = account_type
1452 vim
['description'] = description
1453 vim
['config'] = config
1454 if sdn_controller
or sdn_port_mapping
:
1455 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
)
1457 ctx
.obj
.vim
.create(name
, vim
)
1458 except ClientException
as inst
:
1459 print((inst
.message
))
1463 @cli.command(name
='vim-update', short_help
='updates a VIM account')
1464 @click.argument('name')
1465 @click.option('--newname', help='New name for the VIM account')
1466 @click.option('--user', help='VIM username')
1467 @click.option('--password', help='VIM password')
1468 @click.option('--auth_url', help='VIM url')
1469 @click.option('--tenant', help='VIM tenant name')
1470 @click.option('--config', help='VIM specific config parameters')
1471 @click.option('--account_type', help='VIM type')
1472 @click.option('--description', help='human readable description')
1473 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1474 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1488 '''updates a VIM account
1490 NAME: name or ID of the VIM account
1493 check_client_version(ctx
.obj
, ctx
.command
.name
)
1495 if newname
: vim
['name'] = newname
1496 if user
: vim
['vim_user'] = user
1497 if password
: vim
['vim_password'] = password
1498 if auth_url
: vim
['vim_url'] = auth_url
1499 if tenant
: vim
['vim-tenant-name'] = tenant
1500 if account_type
: vim
['vim_type'] = account_type
1501 if description
: vim
['description'] = description
1502 if config
: vim
['config'] = config
1503 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
)
1504 except ClientException
as inst
:
1505 print((inst
.message
))
1509 @cli.command(name
='vim-delete')
1510 @click.argument('name')
1511 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1513 def vim_delete(ctx
, name
, force
):
1514 '''deletes a VIM account
1516 NAME: name or ID of the VIM account to be deleted
1520 ctx
.obj
.vim
.delete(name
)
1522 check_client_version(ctx
.obj
, '--force')
1523 ctx
.obj
.vim
.delete(name
, force
)
1524 except ClientException
as inst
:
1525 print((inst
.message
))
1529 @cli.command(name
='vim-list')
1530 @click.option('--ro_update/--no_ro_update',
1532 help='update list from RO')
1533 @click.option('--filter', default
=None,
1534 help='restricts the list to the VIM accounts matching the filter')
1536 def vim_list(ctx
, ro_update
, filter):
1537 '''list all VIM accounts'''
1539 check_client_version(ctx
.obj
, '--filter')
1541 check_client_version(ctx
.obj
, '--ro_update', 'v1')
1542 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1543 if fullclassname
== 'osmclient.sol005.client.Client':
1544 resp
= ctx
.obj
.vim
.list(filter)
1546 resp
= ctx
.obj
.vim
.list(ro_update
)
1547 table
= PrettyTable(['vim name', 'uuid'])
1549 table
.add_row([vim
['name'], vim
['uuid']])
1554 @cli.command(name
='vim-show')
1555 @click.argument('name')
1557 def vim_show(ctx
, name
):
1558 '''shows the details of a VIM account
1560 NAME: name or ID of the VIM account
1563 resp
= ctx
.obj
.vim
.get(name
)
1564 if 'vim_password' in resp
:
1565 resp
['vim_password']='********'
1566 except ClientException
as inst
:
1567 print((inst
.message
))
1570 table
= PrettyTable(['key', 'attribute'])
1571 for k
, v
in list(resp
.items()):
1572 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1577 ####################
1578 # SDN controller operations
1579 ####################
1581 @cli.command(name
='sdnc-create')
1582 @click.option('--name',
1584 help='Name to create sdn controller')
1585 @click.option('--type',
1587 help='SDN controller type')
1588 @click.option('--sdn_controller_version',
1589 help='SDN controller username')
1590 @click.option('--ip_address',
1592 help='SDN controller IP address')
1593 @click.option('--port',
1595 help='SDN controller port')
1596 @click.option('--switch_dpid',
1598 help='Switch DPID (Openflow Datapath ID)')
1599 @click.option('--user',
1600 help='SDN controller username')
1601 @click.option('--password',
1603 confirmation_prompt
=True,
1604 help='SDN controller password')
1605 #@click.option('--description',
1606 # default='no description',
1607 # help='human readable description')
1609 def sdnc_create(ctx
,
1612 sdn_controller_version
,
1618 '''creates a new SDN controller
1621 sdncontroller
['name'] = name
1622 sdncontroller
['type'] = type
1623 sdncontroller
['ip'] = ip_address
1624 sdncontroller
['port'] = int(port
)
1625 sdncontroller
['dpid'] = switch_dpid
1626 if sdn_controller_version
:
1627 sdncontroller
['version'] = sdn_controller_version
1629 sdncontroller
['user'] = user
1631 sdncontroller
['password'] = password
1632 # sdncontroller['description'] = description
1634 check_client_version(ctx
.obj
, ctx
.command
.name
)
1635 ctx
.obj
.sdnc
.create(name
, sdncontroller
)
1636 except ClientException
as inst
:
1637 print((inst
.message
))
1640 @cli.command(name
='sdnc-update', short_help
='updates an SDN controller')
1641 @click.argument('name')
1642 @click.option('--newname', help='New name for the SDN controller')
1643 @click.option('--type', help='SDN controller type')
1644 @click.option('--sdn_controller_version', help='SDN controller username')
1645 @click.option('--ip_address', help='SDN controller IP address')
1646 @click.option('--port', help='SDN controller port')
1647 @click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)')
1648 @click.option('--user', help='SDN controller username')
1649 @click.option('--password', help='SDN controller password')
1650 #@click.option('--description', default=None, help='human readable description')
1652 def sdnc_update(ctx
,
1656 sdn_controller_version
,
1662 '''updates an SDN controller
1664 NAME: name or ID of the SDN controller
1667 if newname
: sdncontroller
['name'] = newname
1668 if type: sdncontroller
['type'] = type
1669 if ip_address
: sdncontroller
['ip'] = ip_address
1670 if port
: sdncontroller
['port'] = int(port
)
1671 if switch_dpid
: sdncontroller
['dpid'] = switch_dpid
1672 # sdncontroller['description'] = description
1673 if sdn_controller_version
is not None:
1674 if sdn_controller_version
=="":
1675 sdncontroller
['version'] = None
1677 sdncontroller
['version'] = sdn_controller_version
1678 if user
is not None:
1680 sdncontroller
['user'] = None
1682 sdncontroller
['user'] = user
1683 if password
is not None:
1685 sdncontroller
['password'] = None
1687 sdncontroller
['password'] = user
1689 check_client_version(ctx
.obj
, ctx
.command
.name
)
1690 ctx
.obj
.sdnc
.update(name
, sdncontroller
)
1691 except ClientException
as inst
:
1692 print((inst
.message
))
1696 @cli.command(name
='sdnc-delete')
1697 @click.argument('name')
1698 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1700 def sdnc_delete(ctx
, name
, force
):
1701 '''deletes an SDN controller
1703 NAME: name or ID of the SDN controller to be deleted
1706 check_client_version(ctx
.obj
, ctx
.command
.name
)
1707 ctx
.obj
.sdnc
.delete(name
, force
)
1708 except ClientException
as inst
:
1709 print((inst
.message
))
1713 @cli.command(name
='sdnc-list')
1714 @click.option('--filter', default
=None,
1715 help='restricts the list to the SDN controllers matching the filter')
1717 def sdnc_list(ctx
, filter):
1718 '''list all SDN controllers'''
1720 check_client_version(ctx
.obj
, ctx
.command
.name
)
1721 resp
= ctx
.obj
.sdnc
.list(filter)
1722 except ClientException
as inst
:
1723 print((inst
.message
))
1725 table
= PrettyTable(['name', 'id'])
1727 table
.add_row([sdnc
['name'], sdnc
['_id']])
1732 @cli.command(name
='sdnc-show')
1733 @click.argument('name')
1735 def sdnc_show(ctx
, name
):
1736 '''shows the details of an SDN controller
1738 NAME: name or ID of the SDN controller
1741 check_client_version(ctx
.obj
, ctx
.command
.name
)
1742 resp
= ctx
.obj
.sdnc
.get(name
)
1743 except ClientException
as inst
:
1744 print((inst
.message
))
1747 table
= PrettyTable(['key', 'attribute'])
1748 for k
, v
in list(resp
.items()):
1749 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1754 ####################
1755 # Project mgmt operations
1756 ####################
1758 @cli.command(name
='project-create')
1759 @click.argument('name')
1760 #@click.option('--description',
1761 # default='no description',
1762 # help='human readable description')
1764 def project_create(ctx
, name
):
1765 '''Creates a new project
1767 NAME: name of the project
1770 project
['name'] = name
1772 check_client_version(ctx
.obj
, ctx
.command
.name
)
1773 ctx
.obj
.project
.create(name
, project
)
1774 except ClientException
as inst
:
1778 @cli.command(name
='project-delete')
1779 @click.argument('name')
1780 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
1782 def project_delete(ctx
, name
):
1783 '''deletes a project
1785 NAME: name or ID of the project to be deleted
1788 check_client_version(ctx
.obj
, ctx
.command
.name
)
1789 ctx
.obj
.project
.delete(name
)
1790 except ClientException
as inst
:
1795 @cli.command(name
='project-list')
1796 @click.option('--filter', default
=None,
1797 help='restricts the list to the projects matching the filter')
1799 def project_list(ctx
, filter):
1800 '''list all projects'''
1802 check_client_version(ctx
.obj
, ctx
.command
.name
)
1803 resp
= ctx
.obj
.project
.list(filter)
1804 except ClientException
as inst
:
1807 table
= PrettyTable(['name', 'id'])
1809 table
.add_row([proj
['name'], proj
['_id']])
1814 @cli.command(name
='project-show')
1815 @click.argument('name')
1817 def project_show(ctx
, name
):
1818 '''shows the details of a project
1820 NAME: name or ID of the project
1823 check_client_version(ctx
.obj
, ctx
.command
.name
)
1824 resp
= ctx
.obj
.project
.get(name
)
1825 except ClientException
as inst
:
1829 table
= PrettyTable(['key', 'attribute'])
1830 for k
, v
in resp
.items():
1831 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1836 ####################
1837 # User mgmt operations
1838 ####################
1840 @cli.command(name
='user-create')
1841 @click.argument('username')
1842 @click.option('--password',
1845 confirmation_prompt
=True,
1846 help='user password')
1847 @click.option('--projects',
1849 help='list of project ids that the user belongs to')
1850 #@click.option('--description',
1851 # default='no description',
1852 # help='human readable description')
1854 def user_create(ctx
, username
, password
, projects
):
1855 '''Creates a new user
1857 USERNAME: name of the user
1860 user
['username'] = username
1861 user
['password'] = password
1862 user
['projects'] = projects
1864 check_client_version(ctx
.obj
, ctx
.command
.name
)
1865 ctx
.obj
.user
.create(username
, user
)
1866 except ClientException
as inst
:
1870 @cli.command(name
='user-delete')
1871 @click.argument('name')
1872 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
1874 def user_delete(ctx
, name
):
1877 NAME: name or ID of the user to be deleted
1880 check_client_version(ctx
.obj
, ctx
.command
.name
)
1881 ctx
.obj
.user
.delete(name
)
1882 except ClientException
as inst
:
1887 @cli.command(name
='user-list')
1888 @click.option('--filter', default
=None,
1889 help='restricts the list to the users matching the filter')
1891 def user_list(ctx
, filter):
1892 '''list all users'''
1894 check_client_version(ctx
.obj
, ctx
.command
.name
)
1895 resp
= ctx
.obj
.user
.list(filter)
1896 except ClientException
as inst
:
1899 table
= PrettyTable(['name', 'id'])
1901 table
.add_row([user
['name'], user
['_id']])
1906 @cli.command(name
='user-show')
1907 @click.argument('name')
1909 def user_show(ctx
, name
):
1910 '''shows the details of a user
1912 NAME: name or ID of the user
1915 check_client_version(ctx
.obj
, ctx
.command
.name
)
1916 resp
= ctx
.obj
.user
.get(name
)
1917 if 'password' in resp
:
1918 resp
['password']='********'
1919 except ClientException
as inst
:
1923 table
= PrettyTable(['key', 'attribute'])
1924 for k
, v
in resp
.items():
1925 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1930 ####################
1931 # Fault Management operations
1932 ####################
1934 @cli.command(name
='ns-alarm-create')
1935 @click.argument('name')
1936 @click.option('--ns', prompt
=True, help='NS instance id or name')
1937 @click.option('--vnf', prompt
=True,
1938 help='VNF name (VNF member index as declared in the NSD)')
1939 @click.option('--vdu', prompt
=True,
1940 help='VDU name (VDU name as declared in the VNFD)')
1941 @click.option('--metric', prompt
=True,
1942 help='Name of the metric (e.g. cpu_utilization)')
1943 @click.option('--severity', default
='WARNING',
1944 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
1945 @click.option('--threshold_value', prompt
=True,
1946 help='threshold value that, when crossed, an alarm is triggered')
1947 @click.option('--threshold_operator', prompt
=True,
1948 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
1949 @click.option('--statistic', default
='AVERAGE',
1950 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
1952 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
1953 threshold_value
, threshold_operator
, statistic
):
1954 '''creates a new alarm for a NS instance'''
1955 ns_instance
= ctx
.obj
.ns
.get(ns
)
1957 alarm
['alarm_name'] = name
1958 alarm
['ns_id'] = ns_instance
['_id']
1959 alarm
['correlation_id'] = ns_instance
['_id']
1960 alarm
['vnf_member_index'] = vnf
1961 alarm
['vdu_name'] = vdu
1962 alarm
['metric_name'] = metric
1963 alarm
['severity'] = severity
1964 alarm
['threshold_value'] = int(threshold_value
)
1965 alarm
['operation'] = threshold_operator
1966 alarm
['statistic'] = statistic
1968 check_client_version(ctx
.obj
, ctx
.command
.name
)
1969 ctx
.obj
.ns
.create_alarm(alarm
)
1970 except ClientException
as inst
:
1971 print((inst
.message
))
1975 #@cli.command(name='ns-alarm-delete')
1976 #@click.argument('name')
1977 #@click.pass_context
1978 #def ns_alarm_delete(ctx, name):
1979 # '''deletes an alarm
1981 # NAME: name of the alarm to be deleted
1984 # check_client_version(ctx.obj, ctx.command.name)
1985 # ctx.obj.ns.delete_alarm(name)
1986 # except ClientException as inst:
1987 # print(inst.message)
1991 ####################
1992 # Performance Management operations
1993 ####################
1995 @cli.command(name
='ns-metric-export')
1996 @click.option('--ns', prompt
=True, help='NS instance id or name')
1997 @click.option('--vnf', prompt
=True,
1998 help='VNF name (VNF member index as declared in the NSD)')
1999 @click.option('--vdu', prompt
=True,
2000 help='VDU name (VDU name as declared in the VNFD)')
2001 @click.option('--metric', prompt
=True,
2002 help='name of the metric (e.g. cpu_utilization)')
2003 #@click.option('--period', default='1w',
2004 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
2005 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
2007 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
2008 '''exports a metric to the internal OSM bus, which can be read by other apps
2010 ns_instance
= ctx
.obj
.ns
.get(ns
)
2012 metric_data
['ns_id'] = ns_instance
['_id']
2013 metric_data
['correlation_id'] = ns_instance
['_id']
2014 metric_data
['vnf_member_index'] = vnf
2015 metric_data
['vdu_name'] = vdu
2016 metric_data
['metric_name'] = metric
2017 metric_data
['collection_unit'] = 'WEEK'
2018 metric_data
['collection_period'] = 1
2020 check_client_version(ctx
.obj
, ctx
.command
.name
)
2022 print('{}'.format(ctx
.obj
.ns
.export_metric(metric_data
)))
2026 print('{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
))
2027 time
.sleep(int(interval
))
2029 except ClientException
as inst
:
2030 print((inst
.message
))
2034 ####################
2036 ####################
2038 @cli.command(name
='upload-package')
2039 @click.argument('filename')
2041 def upload_package(ctx
, filename
):
2042 '''uploads a VNF package or NS package
2044 FILENAME: VNF or NS package file (tar.gz)
2047 ctx
.obj
.package
.upload(filename
)
2048 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
2049 if fullclassname
!= 'osmclient.sol005.client.Client':
2050 ctx
.obj
.package
.wait_for_upload(filename
)
2051 except ClientException
as inst
:
2052 print((inst
.message
))
2056 @cli.command(name
='ns-scaling-show')
2057 @click.argument('ns_name')
2059 def show_ns_scaling(ctx
, ns_name
):
2060 '''shows the status of a NS scaling operation
2062 NS_NAME: name of the NS instance being scaled
2065 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2066 resp
= ctx
.obj
.ns
.list()
2067 except ClientException
as inst
:
2068 print((inst
.message
))
2071 table
= PrettyTable(
2074 'operational status',
2079 if ns_name
== ns
['name']:
2080 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
2081 scaling_records
= nsopdata
['nsr:nsr']['scaling-group-record']
2082 for record
in scaling_records
:
2083 if 'instance' in record
:
2084 instances
= record
['instance']
2085 for inst
in instances
:
2087 [record
['scaling-group-name-ref'],
2088 inst
['instance-id'],
2090 time
.strftime('%Y-%m-%d %H:%M:%S',
2092 inst
['create-time'])),
2098 @cli.command(name
='ns-scale')
2099 @click.argument('ns_name')
2100 @click.option('--ns_scale_group', prompt
=True)
2101 @click.option('--index', prompt
=True)
2103 def ns_scale(ctx
, ns_name
, ns_scale_group
, index
):
2106 NS_NAME: name of the NS instance to be scaled
2109 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2110 ctx
.obj
.ns
.scale(ns_name
, ns_scale_group
, index
)
2111 except ClientException
as inst
:
2112 print((inst
.message
))
2116 @cli.command(name
='config-agent-list')
2118 def config_agent_list(ctx
):
2119 '''list config agents'''
2121 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2122 except ClientException
as inst
:
2123 print((inst
.message
))
2125 table
= PrettyTable(['name', 'account-type', 'details'])
2126 for account
in ctx
.obj
.vca
.list():
2129 account
['account-type'],
2135 @cli.command(name
='config-agent-delete')
2136 @click.argument('name')
2138 def config_agent_delete(ctx
, name
):
2139 '''deletes a config agent
2141 NAME: name of the config agent to be deleted
2144 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2145 ctx
.obj
.vca
.delete(name
)
2146 except ClientException
as inst
:
2147 print((inst
.message
))
2151 @cli.command(name
='config-agent-add')
2152 @click.option('--name',
2154 @click.option('--account_type',
2156 @click.option('--server',
2158 @click.option('--user',
2160 @click.option('--secret',
2163 confirmation_prompt
=True)
2165 def config_agent_add(ctx
, name
, account_type
, server
, user
, secret
):
2166 '''adds a config agent'''
2168 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2169 ctx
.obj
.vca
.create(name
, account_type
, server
, user
, secret
)
2170 except ClientException
as inst
:
2171 print((inst
.message
))
2174 @cli.command(name
='ro-dump')
2177 '''shows RO agent information'''
2178 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2179 resp
= ctx
.obj
.vim
.get_resource_orchestrator()
2180 table
= PrettyTable(['key', 'attribute'])
2181 for k
, v
in list(resp
.items()):
2182 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2187 @cli.command(name
='vcs-list')
2190 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2191 resp
= ctx
.obj
.utils
.get_vcs_info()
2192 table
= PrettyTable(['component name', 'state'])
2193 for component
in resp
:
2194 table
.add_row([component
['component_name'], component
['state']])
2199 @cli.command(name
='ns-action')
2200 @click.argument('ns_name')
2201 @click.option('--vnf_name', default
=None)
2202 @click.option('--action_name', prompt
=True)
2203 @click.option('--params', prompt
=True)
2210 '''executes an action/primitive over a NS instance
2212 NS_NAME: name or ID of the NS instance
2215 check_client_version(ctx
.obj
, ctx
.command
.name
)
2218 op_data
['vnf_member_index'] = vnf_name
2219 op_data
['primitive'] = action_name
2220 op_data
['primitive_params'] = yaml
.load(params
)
2221 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
)
2223 except ClientException
as inst
:
2224 print((inst
.message
))
2228 @cli.command(name
='vnf-scale')
2229 @click.argument('ns_name')
2230 @click.argument('vnf_name')
2231 @click.option('--scaling-group', prompt
=True, help="scaling-group-descriptor name to use")
2232 @click.option('--scale-in', default
=False, is_flag
=True, help="performs a scale in operation")
2233 @click.option('--scale-out', default
=False, is_flag
=True, help="performs a scale out operation (by default)")
2241 '''executes a VNF scale (adding/removing VDUs)
2244 NS_NAME: name or ID of the NS instance.
2245 VNF_NAME: member-vnf-index in the NS to be scaled.
2248 check_client_version(ctx
.obj
, ctx
.command
.name
)
2249 if not scale_in
and not scale_out
:
2251 ctx
.obj
.ns
.scale_vnf(ns_name
, vnf_name
, scaling_group
, scale_in
, scale_out
)
2252 except ClientException
as inst
:
2253 print((inst
.message
))
2257 if __name__
== '__main__':
2260 except pycurl
.error
as e
:
2262 print('Maybe "--hostname" option or OSM_HOSTNAME' +
2263 'environment variable needs to be specified')