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
, nf_type
, filter):
252 check_client_version(ctx
.obj
, '--nf_type')
254 check_client_version(ctx
.obj
, '--filter')
257 nf_filter
= "_admin.type=vnfd"
258 elif nf_type
== "pnf":
259 nf_filter
= "_admin.type=pnfd"
260 elif nf_type
== "hnf":
261 nf_filter
= "_admin.type=hnfd"
263 raise ClientException('wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf')
265 filter = '{}&{}'.format(nf_filter
, filter)
269 resp
= ctx
.obj
.vnfd
.list(filter)
271 resp
= ctx
.obj
.vnfd
.list()
272 #print yaml.safe_dump(resp)
273 table
= PrettyTable(['vnfd name', 'id'])
274 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
275 if fullclassname
== 'osmclient.sol005.client.Client':
277 name
= vnfd
['name'] if 'name' in vnfd
else '-'
278 table
.add_row([name
, vnfd
['_id']])
281 table
.add_row([vnfd
['name'], vnfd
['id']])
286 @cli.command(name
='vnfd-list')
287 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
288 @click.option('--filter', default
=None,
289 help='restricts the list to the NFpkg matching the filter')
291 def vnfd_list1(ctx
, nf_type
, filter):
292 '''list all VNFD/VNFpkg in the system'''
293 vnfd_list(ctx
, nf_type
, filter)
296 @cli.command(name
='vnfpkg-list')
297 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
298 @click.option('--filter', default
=None,
299 help='restricts the list to the NFpkg matching the filter')
301 def vnfd_list2(ctx
, nf_type
, filter):
302 '''list all VNFD/VNFpkg in the system'''
303 vnfd_list(ctx
, nf_type
, filter)
306 @cli.command(name
='nfpkg-list')
307 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
308 @click.option('--filter', default
=None,
309 help='restricts the list to the NFpkg matching the filter')
311 def nfpkg_list(ctx
, nf_type
, filter):
312 '''list all NFpkg (VNFpkg, PNFpkg, HNFpkg) in the system'''
314 check_client_version(ctx
.obj
, ctx
.command
.name
)
315 vnfd_list(ctx
,nf_type
,filter)
316 except ClientException
as inst
:
317 print((inst
.message
))
321 def vnf_list(ctx
, ns
, filter):
325 check_client_version(ctx
.obj
, '--ns')
327 check_client_version(ctx
.obj
, '--filter')
328 resp
= ctx
.obj
.vnf
.list(ns
, filter)
330 resp
= ctx
.obj
.vnf
.list()
331 except ClientException
as inst
:
332 print((inst
.message
))
334 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
335 if fullclassname
== 'osmclient.sol005.client.Client':
345 name
= vnfr
['name'] if 'name' in vnfr
else '-'
350 vnfr
['member-vnf-index-ref'],
352 vnfr
['vim-account-id'],
358 'operational status',
361 if 'mgmt-interface' not in vnfr
:
362 vnfr
['mgmt-interface'] = {}
363 vnfr
['mgmt-interface']['ip-address'] = None
367 vnfr
['operational-status'],
368 vnfr
['config-status']])
373 @cli.command(name
='vnf-list')
374 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
375 @click.option('--filter', default
=None,
376 help='restricts the list to the NF instances matching the filter.')
378 def vnf_list1(ctx
, ns
, filter):
379 '''list all NF instances'''
380 vnf_list(ctx
, ns
, filter)
383 @cli.command(name
='nf-list')
384 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
385 @click.option('--filter', default
=None,
386 help='restricts the list to the NF instances matching the filter.')
388 def nf_list(ctx
, ns
, filter):
389 '''list all NF instances
393 --ns TEXT NS instance id or name to restrict the VNF list
394 --filter filterExpr Restricts the list to the VNF instances matching the filter
397 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
398 concatenated using the "&" character:
401 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
402 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
403 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
405 value := scalar value
409 * zero or more occurrences
410 ? zero or one occurrence
411 [] grouping of expressions to be used with ? and *
412 "" quotation marks for marking string constants
416 "AttrName" is the name of one attribute in the data type that defines the representation
417 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
418 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
419 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
420 entries, it means that the operator "op" is applied to the attribute addressed by the last
421 <attrName> entry included in the concatenation. All simple filter expressions are combined
422 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
423 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
424 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
425 prefix". If an attribute referenced in an expression is an array, an object that contains a
426 corresponding array shall be considered to match the expression if any of the elements in the
427 array matches all expressions that have the same attribute prefix.
431 --filter vim-account-id=<VIM_ACCOUNT_ID>
432 --filter vnfd-ref=<VNFD_NAME>
433 --filter vdur.ip-address=<IP_ADDRESS>
434 --filter vnfd-ref=<VNFD_NAME>,vdur.ip-address=<IP_ADDRESS>
436 vnf_list(ctx
, ns
, filter)
439 @cli.command(name
='ns-op-list')
440 @click.argument('name')
442 def ns_op_list(ctx
, name
):
443 '''shows the history of operations over a NS instance
445 NAME: name or ID of the NS instance
448 check_client_version(ctx
.obj
, ctx
.command
.name
)
449 resp
= ctx
.obj
.ns
.list_op(name
)
450 except ClientException
as inst
:
451 print((inst
.message
))
454 table
= PrettyTable(['id', 'operation', 'status'])
456 table
.add_row([op
['id'], op
['lcmOperationType'],
457 op
['operationState']])
462 def nsi_list(ctx
, filter):
463 '''list all Network Slice Instances'''
465 check_client_version(ctx
.obj
, ctx
.command
.name
)
466 resp
= ctx
.obj
.nsi
.list(filter)
467 except ClientException
as inst
:
468 print((inst
.message
))
471 ['netslice instance name',
473 'operational status',
477 nsi_name
= nsi
['name']
479 opstatus
= nsi
['operational-status'] if 'operational-status' in nsi
else 'Not found'
480 configstatus
= nsi
['config-status'] if 'config-status' in nsi
else 'Not found'
481 detailed_status
= nsi
['detailed-status'] if 'detailed-status' in nsi
else 'Not found'
482 if configstatus
== "config_not_needed":
483 configstatus
= "configured (no charms)"
494 @cli.command(name
='nsi-list')
495 @click.option('--filter', default
=None,
496 help='restricts the list to the Network Slice Instances matching the filter')
498 def nsi_list1(ctx
, filter):
499 '''list all Network Slice Instances (NSI)'''
503 @cli.command(name
='netslice-instance-list')
504 @click.option('--filter', default
=None,
505 help='restricts the list to the Network Slice Instances matching the filter')
507 def nsi_list2(ctx
, filter):
508 '''list all Network Slice Instances (NSI)'''
512 def nst_list(ctx
, filter):
514 check_client_version(ctx
.obj
, ctx
.command
.name
)
515 resp
= ctx
.obj
.nst
.list(filter)
516 except ClientException
as inst
:
517 print((inst
.message
))
519 #print yaml.safe_dump(resp)
520 table
= PrettyTable(['nst name', 'id'])
522 name
= nst
['name'] if 'name' in nst
else '-'
523 table
.add_row([name
, nst
['_id']])
528 @cli.command(name
='nst-list')
529 @click.option('--filter', default
=None,
530 help='restricts the list to the NST matching the filter')
532 def nst_list1(ctx
, filter):
533 '''list all Network Slice Templates (NST) in the system'''
537 @cli.command(name
='netslice-template-list')
538 @click.option('--filter', default
=None,
539 help='restricts the list to the NST matching the filter')
541 def nst_list2(ctx
, filter):
542 '''list all Network Slice Templates (NST) in the system'''
546 def nsi_op_list(ctx
, name
):
548 check_client_version(ctx
.obj
, ctx
.command
.name
)
549 resp
= ctx
.obj
.nsi
.list_op(name
)
550 except ClientException
as inst
:
551 print((inst
.message
))
553 table
= PrettyTable(['id', 'operation', 'status'])
555 table
.add_row([op
['id'], op
['lcmOperationType'],
556 op
['operationState']])
561 @cli.command(name
='nsi-op-list')
562 @click.argument('name')
564 def nsi_op_list1(ctx
, name
):
565 '''shows the history of operations over a Network Slice Instance (NSI)
567 NAME: name or ID of the Network Slice Instance
569 nsi_op_list(ctx
,name
)
572 @cli.command(name
='netslice-instance-op-list')
573 @click.argument('name')
575 def nsi_op_list2(ctx
, name
):
576 '''shows the history of operations over a Network Slice Instance (NSI)
578 NAME: name or ID of the Network Slice Instance
580 nsi_op_list(ctx
,name
)
583 @cli.command(name
='pdu-list')
584 @click.option('--filter', default
=None,
585 help='restricts the list to the Physical Deployment Units matching the filter')
587 def pdu_list(ctx
, filter):
588 '''list all Physical Deployment Units (PDU)'''
590 check_client_version(ctx
.obj
, ctx
.command
.name
)
591 resp
= ctx
.obj
.pdu
.list(filter)
592 except ClientException
as inst
:
593 print((inst
.message
))
601 pdu_name
= pdu
['name']
603 pdu_type
= pdu
['type']
604 pdu_ipaddress
= "None"
605 for iface
in pdu
['interfaces']:
607 pdu_ipaddress
= iface
['ip-address']
622 def nsd_show(ctx
, name
, literal
):
624 resp
= ctx
.obj
.nsd
.get(name
)
625 #resp = ctx.obj.nsd.get_individual(name)
626 except ClientException
as inst
:
627 print((inst
.message
))
631 print(yaml
.safe_dump(resp
))
634 table
= PrettyTable(['field', 'value'])
635 for k
, v
in list(resp
.items()):
636 table
.add_row([k
, json
.dumps(v
, indent
=2)])
641 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
642 @click.option('--literal', is_flag
=True,
643 help='print literally, no pretty table')
644 @click.argument('name')
646 def nsd_show1(ctx
, name
, literal
):
647 '''shows the content of a NSD
649 NAME: name or ID of the NSD/NSpkg
651 nsd_show(ctx
, name
, literal
)
654 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
655 @click.option('--literal', is_flag
=True,
656 help='print literally, no pretty table')
657 @click.argument('name')
659 def nsd_show2(ctx
, name
, literal
):
660 '''shows the content of a NSD
662 NAME: name or ID of the NSD/NSpkg
664 nsd_show(ctx
, name
, literal
)
667 def vnfd_show(ctx
, name
, literal
):
669 resp
= ctx
.obj
.vnfd
.get(name
)
670 #resp = ctx.obj.vnfd.get_individual(name)
671 except ClientException
as inst
:
672 print((inst
.message
))
676 print(yaml
.safe_dump(resp
))
679 table
= PrettyTable(['field', 'value'])
680 for k
, v
in list(resp
.items()):
681 table
.add_row([k
, json
.dumps(v
, indent
=2)])
686 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
687 @click.option('--literal', is_flag
=True,
688 help='print literally, no pretty table')
689 @click.argument('name')
691 def vnfd_show1(ctx
, name
, literal
):
692 '''shows the content of a VNFD
694 NAME: name or ID of the VNFD/VNFpkg
696 vnfd_show(ctx
, name
, literal
)
699 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
700 @click.option('--literal', is_flag
=True,
701 help='print literally, no pretty table')
702 @click.argument('name')
704 def vnfd_show2(ctx
, name
, literal
):
705 '''shows the content of a VNFD
707 NAME: name or ID of the VNFD/VNFpkg
709 vnfd_show(ctx
, name
, literal
)
712 @cli.command(name
='nfpkg-show', short_help
='shows the content of a NF Descriptor')
713 @click.option('--literal', is_flag
=True,
714 help='print literally, no pretty table')
715 @click.argument('name')
717 def nfpkg_show(ctx
, name
, literal
):
718 '''shows the content of a NF Descriptor
720 NAME: name or ID of the NFpkg
722 vnfd_show(ctx
, name
, literal
)
725 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
726 @click.argument('name')
727 @click.option('--literal', is_flag
=True,
728 help='print literally, no pretty table')
729 @click.option('--filter', default
=None)
731 def ns_show(ctx
, name
, literal
, filter):
732 '''shows the info of a NS instance
734 NAME: name or ID of the NS instance
737 ns
= ctx
.obj
.ns
.get(name
)
738 except ClientException
as inst
:
739 print((inst
.message
))
743 print(yaml
.safe_dump(ns
))
746 table
= PrettyTable(['field', 'value'])
748 for k
, v
in list(ns
.items()):
749 if filter is None or filter in k
:
750 table
.add_row([k
, json
.dumps(v
, indent
=2)])
752 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
753 if fullclassname
!= 'osmclient.sol005.client.Client':
754 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
755 nsr_optdata
= nsopdata
['nsr:nsr']
756 for k
, v
in list(nsr_optdata
.items()):
757 if filter is None or filter in k
:
758 table
.add_row([k
, json
.dumps(v
, indent
=2)])
763 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
764 @click.argument('name')
765 @click.option('--literal', is_flag
=True,
766 help='print literally, no pretty table')
767 @click.option('--filter', default
=None)
769 def vnf_show(ctx
, name
, literal
, filter):
770 '''shows the info of a VNF instance
772 NAME: name or ID of the VNF instance
775 check_client_version(ctx
.obj
, ctx
.command
.name
)
776 resp
= ctx
.obj
.vnf
.get(name
)
777 except ClientException
as inst
:
778 print((inst
.message
))
782 print(yaml
.safe_dump(resp
))
785 table
= PrettyTable(['field', 'value'])
786 for k
, v
in list(resp
.items()):
787 if filter is None or filter in k
:
788 table
.add_row([k
, json
.dumps(v
, indent
=2)])
793 @cli.command(name
='vnf-monitoring-show')
794 @click.argument('vnf_name')
796 def vnf_monitoring_show(ctx
, vnf_name
):
798 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
799 resp
= ctx
.obj
.vnf
.get_monitoring(vnf_name
)
800 except ClientException
as inst
:
801 print((inst
.message
))
804 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
810 monitor
['value-integer'],
816 @cli.command(name
='ns-monitoring-show')
817 @click.argument('ns_name')
819 def ns_monitoring_show(ctx
, ns_name
):
821 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
822 resp
= ctx
.obj
.ns
.get_monitoring(ns_name
)
823 except ClientException
as inst
:
824 print((inst
.message
))
827 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
828 for key
, val
in list(resp
.items()):
833 monitor
['value-integer'],
839 @cli.command(name
='ns-op-show', short_help
='shows the info of an operation')
840 @click.argument('id')
841 @click.option('--filter', default
=None)
843 def ns_op_show(ctx
, id, filter):
844 '''shows the detailed info of an operation
846 ID: operation identifier
849 check_client_version(ctx
.obj
, ctx
.command
.name
)
850 op_info
= ctx
.obj
.ns
.get_op(id)
851 except ClientException
as inst
:
852 print((inst
.message
))
855 table
= PrettyTable(['field', 'value'])
856 for k
, v
in list(op_info
.items()):
857 if filter is None or filter in k
:
858 table
.add_row([k
, json
.dumps(v
, indent
=2)])
863 def nst_show(ctx
, name
, literal
):
865 check_client_version(ctx
.obj
, ctx
.command
.name
)
866 resp
= ctx
.obj
.nst
.get(name
)
867 #resp = ctx.obj.nst.get_individual(name)
868 except ClientException
as inst
:
869 print((inst
.message
))
873 print(yaml
.safe_dump(resp
))
876 table
= PrettyTable(['field', 'value'])
877 for k
, v
in list(resp
.items()):
878 table
.add_row([k
, json
.dumps(v
, indent
=2)])
883 @cli.command(name
='nst-show', short_help
='shows the content of a Network Slice Template (NST)')
884 @click.option('--literal', is_flag
=True,
885 help='print literally, no pretty table')
886 @click.argument('name')
888 def nst_show1(ctx
, name
, literal
):
889 '''shows the content of a Network Slice Template (NST)
891 NAME: name or ID of the NST
893 nst_show(ctx
, name
, literal
)
896 @cli.command(name
='netslice-template-show', short_help
='shows the content of a Network Slice Template (NST)')
897 @click.option('--literal', is_flag
=True,
898 help='print literally, no pretty table')
899 @click.argument('name')
901 def nst_show2(ctx
, name
, literal
):
902 '''shows the content of a Network Slice Template (NST)
904 NAME: name or ID of the NST
906 nst_show(ctx
, name
, literal
)
909 def nsi_show(ctx
, name
, literal
, filter):
911 check_client_version(ctx
.obj
, ctx
.command
.name
)
912 nsi
= ctx
.obj
.nsi
.get(name
)
913 except ClientException
as inst
:
914 print((inst
.message
))
918 print(yaml
.safe_dump(nsi
))
921 table
= PrettyTable(['field', 'value'])
923 for k
, v
in list(nsi
.items()):
924 if filter is None or filter in k
:
925 table
.add_row([k
, json
.dumps(v
, indent
=2)])
931 @cli.command(name
='nsi-show', short_help
='shows the content of a Network Slice Instance (NSI)')
932 @click.argument('name')
933 @click.option('--literal', is_flag
=True,
934 help='print literally, no pretty table')
935 @click.option('--filter', default
=None)
937 def nsi_show1(ctx
, name
, literal
, filter):
938 '''shows the content of a Network Slice Instance (NSI)
940 NAME: name or ID of the Network Slice Instance
942 nsi_show(ctx
, name
, literal
, filter)
945 @cli.command(name
='netslice-instance-show', short_help
='shows the content of a Network Slice Instance (NSI)')
946 @click.argument('name')
947 @click.option('--literal', is_flag
=True,
948 help='print literally, no pretty table')
949 @click.option('--filter', default
=None)
951 def nsi_show2(ctx
, name
, literal
, filter):
952 '''shows the content of a Network Slice Instance (NSI)
954 NAME: name or ID of the Network Slice Instance
956 nsi_show(ctx
, name
, literal
, filter)
959 def nsi_op_show(ctx
, id, filter):
961 check_client_version(ctx
.obj
, ctx
.command
.name
)
962 op_info
= ctx
.obj
.nsi
.get_op(id)
963 except ClientException
as inst
:
964 print((inst
.message
))
967 table
= PrettyTable(['field', 'value'])
968 for k
, v
in list(op_info
.items()):
969 if filter is None or filter in k
:
970 table
.add_row([k
, json
.dumps(v
, indent
=2)])
975 @cli.command(name
='nsi-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
976 @click.argument('id')
977 @click.option('--filter', default
=None)
979 def nsi_op_show1(ctx
, id, filter):
980 '''shows the info of an operation over a Network Slice Instance(NSI)
982 ID: operation identifier
984 nsi_op_show(ctx
, id, filter)
987 @cli.command(name
='netslice-instance-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
988 @click.argument('id')
989 @click.option('--filter', default
=None)
991 def nsi_op_show2(ctx
, id, filter):
992 '''shows the info of an operation over a Network Slice Instance(NSI)
994 ID: operation identifier
996 nsi_op_show(ctx
, id, filter)
999 @cli.command(name
='pdu-show', short_help
='shows the content of a Physical Deployment Unit (PDU)')
1000 @click.argument('name')
1001 @click.option('--literal', is_flag
=True,
1002 help='print literally, no pretty table')
1003 @click.option('--filter', default
=None)
1005 def pdu_show(ctx
, name
, literal
, filter):
1006 '''shows the content of a Physical Deployment Unit (PDU)
1008 NAME: name or ID of the PDU
1011 check_client_version(ctx
.obj
, ctx
.command
.name
)
1012 pdu
= ctx
.obj
.pdu
.get(name
)
1013 except ClientException
as inst
:
1014 print((inst
.message
))
1018 print(yaml
.safe_dump(pdu
))
1021 table
= PrettyTable(['field', 'value'])
1023 for k
, v
in list(pdu
.items()):
1024 if filter is None or filter in k
:
1025 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1031 ####################
1033 ####################
1035 def nsd_create(ctx
, filename
, overwrite
):
1037 check_client_version(ctx
.obj
, ctx
.command
.name
)
1038 ctx
.obj
.nsd
.create(filename
, overwrite
)
1039 except ClientException
as inst
:
1040 print((inst
.message
))
1044 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
1045 @click.argument('filename')
1046 @click.option('--overwrite', default
=None,
1047 help='overwrites some fields in NSD')
1049 def nsd_create1(ctx
, filename
, overwrite
):
1050 '''creates a new NSD/NSpkg
1052 FILENAME: NSD yaml file or NSpkg tar.gz file
1054 nsd_create(ctx
, filename
, overwrite
)
1057 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
1058 @click.argument('filename')
1059 @click.option('--overwrite', default
=None,
1060 help='overwrites some fields in NSD')
1062 def nsd_create2(ctx
, filename
, overwrite
):
1063 '''creates a new NSD/NSpkg
1065 FILENAME: NSD yaml file or NSpkg tar.gz file
1067 nsd_create(ctx
, filename
, overwrite
)
1070 def vnfd_create(ctx
, filename
, overwrite
):
1072 check_client_version(ctx
.obj
, ctx
.command
.name
)
1073 ctx
.obj
.vnfd
.create(filename
, overwrite
)
1074 except ClientException
as inst
:
1075 print((inst
.message
))
1079 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
1080 @click.argument('filename')
1081 @click.option('--overwrite', default
=None,
1082 help='overwrites some fields in VNFD')
1084 def vnfd_create1(ctx
, filename
, overwrite
):
1085 '''creates a new VNFD/VNFpkg
1087 FILENAME: VNFD yaml file or VNFpkg tar.gz file
1089 vnfd_create(ctx
, filename
, overwrite
)
1092 @cli.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
1093 @click.argument('filename')
1094 @click.option('--overwrite', default
=None,
1095 help='overwrites some fields in VNFD')
1097 def vnfd_create2(ctx
, filename
, overwrite
):
1098 '''creates a new VNFD/VNFpkg
1100 FILENAME: VNFD yaml file or VNFpkg tar.gz file
1102 vnfd_create(ctx
, filename
, overwrite
)
1105 @cli.command(name
='nfpkg-create', short_help
='creates a new NFpkg')
1106 @click.argument('filename')
1107 @click.option('--overwrite', default
=None,
1108 help='overwrites some fields in NFD')
1110 def nfpkg_create(ctx
, filename
, overwrite
):
1111 '''creates a new NFpkg
1113 FILENAME: NF Descriptor yaml file or NFpkg tar.gz file
1115 vnfd_create(ctx
, filename
, overwrite
)
1118 @cli.command(name
='ns-create', short_help
='creates a new Network Service instance')
1119 @click.option('--ns_name',
1120 prompt
=True, help='name of the NS instance')
1121 @click.option('--nsd_name',
1122 prompt
=True, help='name of the NS descriptor')
1123 @click.option('--vim_account',
1124 prompt
=True, help='default VIM account id or name for the deployment')
1125 @click.option('--admin_status',
1127 help='administration status')
1128 @click.option('--ssh_keys',
1130 help='comma separated list of public key files to inject to vnfs')
1131 @click.option('--config',
1133 help='ns specific yaml configuration')
1134 @click.option('--config_file',
1136 help='ns specific yaml configuration file')
1146 '''creates a new NS instance'''
1149 check_client_version(ctx
.obj
, '--config_file')
1151 raise ClientException('"--config" option is incompatible with "--config_file" option')
1152 with
open(config_file
, 'r') as cf
:
1159 account
=vim_account
)
1160 except ClientException
as inst
:
1161 print((inst
.message
))
1165 def nst_create(ctx
, filename
, overwrite
):
1167 check_client_version(ctx
.obj
, ctx
.command
.name
)
1168 ctx
.obj
.nst
.create(filename
, overwrite
)
1169 except ClientException
as inst
:
1170 print((inst
.message
))
1174 @cli.command(name
='nst-create', short_help
='creates a new Network Slice Template (NST)')
1175 @click.argument('filename')
1176 @click.option('--overwrite', default
=None,
1177 help='overwrites some fields in NST')
1179 def nst_create1(ctx
, filename
, overwrite
):
1180 '''creates a new Network Slice Template (NST)
1182 FILENAME: NST yaml file or NSTpkg tar.gz file
1184 nst_create(ctx
, filename
, overwrite
)
1187 @cli.command(name
='netslice-template-create', short_help
='creates a new Network Slice Template (NST)')
1188 @click.argument('filename')
1189 @click.option('--overwrite', default
=None,
1190 help='overwrites some fields in NST')
1192 def nst_create2(ctx
, filename
, overwrite
):
1193 '''creates a new Network Slice Template (NST)
1195 FILENAME: NST yaml file or NSTpkg tar.gz file
1197 nst_create(ctx
, filename
, overwrite
)
1200 def nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
):
1201 '''creates a new Network Slice Instance (NSI)'''
1203 check_client_version(ctx
.obj
, ctx
.command
.name
)
1206 raise ClientException('"--config" option is incompatible with "--config_file" option')
1207 with
open(config_file
, 'r') as cf
:
1209 ctx
.obj
.nsi
.create(nst_name
, nsi_name
, config
=config
, ssh_keys
=ssh_keys
,
1210 account
=vim_account
)
1211 except ClientException
as inst
:
1216 @cli.command(name
='nsi-create', short_help
='creates a new Network Slice Instance')
1217 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1218 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1219 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1220 @click.option('--ssh_keys', default
=None,
1221 help='comma separated list of keys to inject to vnfs')
1222 @click.option('--config', default
=None,
1223 help='Netslice specific yaml configuration:\n'
1224 'netslice_subnet: [\n'
1225 'id: TEXT, vim_account: TEXT,\n'
1226 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1227 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
1228 'additionalParamsForNsi: {param: value, ...}\n'
1229 'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
1231 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1233 @click.option('--config_file',
1235 help='nsi specific yaml configuration file')
1237 def nsi_create1(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
):
1238 '''creates a new Network Slice Instance (NSI)'''
1239 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
)
1242 @cli.command(name
='netslice-instance-create', short_help
='creates a new Network Slice Instance')
1243 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1244 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1245 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1246 @click.option('--ssh_keys', default
=None,
1247 help='comma separated list of keys to inject to vnfs')
1248 @click.option('--config', default
=None,
1249 help='Netslice specific yaml configuration:\n'
1250 'netslice_subnet: [\n'
1251 'id: TEXT, vim_account: TEXT,\n'
1252 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1253 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1255 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1257 @click.option('--config_file',
1259 help='nsi specific yaml configuration file')
1261 def nsi_create2(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
):
1262 '''creates a new Network Slice Instance (NSI)'''
1263 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
)
1266 @cli.command(name
='pdu-create', short_help
='adds a new Physical Deployment Unit to the catalog')
1267 @click.option('--name', help='name of the Physical Deployment Unit')
1268 @click.option('--pdu_type', help='type of PDU (e.g. router, firewall, FW001)')
1269 @click.option('--interface',
1270 help='interface(s) of the PDU: name=<NAME>,mgmt=<true|false>,ip-address=<IP_ADDRESS>'+
1271 '[,type=<overlay|underlay>][,mac-address=<MAC_ADDRESS>][,vim-network-name=<VIM_NET_NAME>]',
1273 @click.option('--description', help='human readable description')
1274 @click.option('--vim_account', help='list of VIM accounts (in the same VIM) that can reach this PDU', multiple
=True)
1275 @click.option('--descriptor_file', default
=None, help='PDU descriptor file (as an alternative to using the other arguments')
1277 def pdu_create(ctx
, name
, pdu_type
, interface
, description
, vim_account
, descriptor_file
):
1278 '''creates a new Physical Deployment Unit (PDU)'''
1280 check_client_version(ctx
.obj
, ctx
.command
.name
)
1282 if not descriptor_file
:
1284 raise ClientException('in absence of descriptor file, option "--name" is mandatory')
1286 raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
1288 raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
1290 raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
1292 with
open(descriptor_file
, 'r') as df
:
1293 pdu
= yaml
.load(df
.read())
1294 if name
: pdu
["name"] = name
1295 if pdu_type
: pdu
["type"] = pdu_type
1296 if description
: pdu
["description"] = description
1297 if vim_account
: pdu
["vim_accounts"] = vim_account
1300 for iface
in interface
:
1301 new_iface
={k
:v
for k
,v
in [i
.split('=') for i
in iface
.split(',')]}
1302 new_iface
["mgmt"] = (new_iface
.get("mgmt","false").lower() == "true")
1303 ifaces_list
.append(new_iface
)
1304 pdu
["interfaces"] = ifaces_list
1305 ctx
.obj
.pdu
.create(pdu
)
1306 except ClientException
as inst
:
1307 print((inst
.message
))
1311 ####################
1313 ####################
1315 def nsd_update(ctx
, name
, content
):
1317 check_client_version(ctx
.obj
, ctx
.command
.name
)
1318 ctx
.obj
.nsd
.update(name
, content
)
1319 except ClientException
as inst
:
1320 print((inst
.message
))
1324 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
1325 @click.argument('name')
1326 @click.option('--content', default
=None,
1327 help='filename with the NSD/NSpkg replacing the current one')
1329 def nsd_update1(ctx
, name
, content
):
1330 '''updates a NSD/NSpkg
1332 NAME: name or ID of the NSD/NSpkg
1334 nsd_update(ctx
, name
, content
)
1337 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
1338 @click.argument('name')
1339 @click.option('--content', default
=None,
1340 help='filename with the NSD/NSpkg replacing the current one')
1342 def nsd_update2(ctx
, name
, content
):
1343 '''updates a NSD/NSpkg
1345 NAME: name or ID of the NSD/NSpkg
1347 nsd_update(ctx
, name
, content
)
1350 def vnfd_update(ctx
, name
, content
):
1352 check_client_version(ctx
.obj
, ctx
.command
.name
)
1353 ctx
.obj
.vnfd
.update(name
, content
)
1354 except ClientException
as inst
:
1355 print((inst
.message
))
1359 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
1360 @click.argument('name')
1361 @click.option('--content', default
=None,
1362 help='filename with the VNFD/VNFpkg replacing the current one')
1364 def vnfd_update1(ctx
, name
, content
):
1365 '''updates a VNFD/VNFpkg
1367 NAME: name or ID of the VNFD/VNFpkg
1369 vnfd_update(ctx
, name
, content
)
1372 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
1373 @click.argument('name')
1374 @click.option('--content', default
=None,
1375 help='filename with the VNFD/VNFpkg replacing the current one')
1377 def vnfd_update2(ctx
, name
, content
):
1378 '''updates a VNFD/VNFpkg
1380 NAME: VNFD yaml file or VNFpkg tar.gz file
1382 vnfd_update(ctx
, name
, content
)
1385 @cli.command(name
='nfpkg-update', short_help
='updates a NFpkg')
1386 @click.argument('name')
1387 @click.option('--content', default
=None,
1388 help='filename with the NFpkg replacing the current one')
1390 def nfpkg_update(ctx
, name
, content
):
1393 NAME: NF Descriptor yaml file or NFpkg tar.gz file
1395 vnfd_update(ctx
, name
, content
)
1398 def nst_update(ctx
, name
, content
):
1400 check_client_version(ctx
.obj
, ctx
.command
.name
)
1401 ctx
.obj
.nst
.update(name
, content
)
1402 except ClientException
as inst
:
1403 print((inst
.message
))
1407 @cli.command(name
='nst-update', short_help
='updates a Network Slice Template (NST)')
1408 @click.argument('name')
1409 @click.option('--content', default
=None,
1410 help='filename with the NST/NSTpkg replacing the current one')
1412 def nst_update1(ctx
, name
, content
):
1413 '''updates a Network Slice Template (NST)
1415 NAME: name or ID of the NSD/NSpkg
1417 nst_update(ctx
, name
, content
)
1420 @cli.command(name
='netslice-template-update', short_help
='updates a Network Slice Template (NST)')
1421 @click.argument('name')
1422 @click.option('--content', default
=None,
1423 help='filename with the NST/NSTpkg replacing the current one')
1425 def nst_update2(ctx
, name
, content
):
1426 '''updates a Network Slice Template (NST)
1428 NAME: name or ID of the NSD/NSpkg
1430 nst_update(ctx
, name
, content
)
1433 ####################
1435 ####################
1437 def nsd_delete(ctx
, name
, force
):
1440 ctx
.obj
.nsd
.delete(name
)
1442 check_client_version(ctx
.obj
, '--force')
1443 ctx
.obj
.nsd
.delete(name
, force
)
1444 except ClientException
as inst
:
1445 print((inst
.message
))
1449 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
1450 @click.argument('name')
1451 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1453 def nsd_delete1(ctx
, name
, force
):
1454 '''deletes a NSD/NSpkg
1456 NAME: name or ID of the NSD/NSpkg to be deleted
1458 nsd_delete(ctx
, name
, force
)
1461 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
1462 @click.argument('name')
1463 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1465 def nsd_delete2(ctx
, name
, force
):
1466 '''deletes a NSD/NSpkg
1468 NAME: name or ID of the NSD/NSpkg to be deleted
1470 nsd_delete(ctx
, name
, force
)
1473 def vnfd_delete(ctx
, name
, force
):
1476 ctx
.obj
.vnfd
.delete(name
)
1478 check_client_version(ctx
.obj
, '--force')
1479 ctx
.obj
.vnfd
.delete(name
, force
)
1480 except ClientException
as inst
:
1481 print((inst
.message
))
1485 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
1486 @click.argument('name')
1487 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1489 def vnfd_delete1(ctx
, name
, force
):
1490 '''deletes a VNFD/VNFpkg
1492 NAME: name or ID of the VNFD/VNFpkg to be deleted
1494 vnfd_delete(ctx
, name
, force
)
1497 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
1498 @click.argument('name')
1499 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1501 def vnfd_delete2(ctx
, name
, force
):
1502 '''deletes a VNFD/VNFpkg
1504 NAME: name or ID of the VNFD/VNFpkg to be deleted
1506 vnfd_delete(ctx
, name
, force
)
1509 @cli.command(name
='nfpkg-delete', short_help
='deletes a NFpkg')
1510 @click.argument('name')
1511 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1513 def nfpkg_delete(ctx
, name
, force
):
1516 NAME: name or ID of the NFpkg to be deleted
1518 vnfd_delete(ctx
, name
, force
)
1521 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
1522 @click.argument('name')
1523 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1525 def ns_delete(ctx
, name
, force
):
1526 '''deletes a NS instance
1528 NAME: name or ID of the NS instance to be deleted
1532 ctx
.obj
.ns
.delete(name
)
1534 check_client_version(ctx
.obj
, '--force')
1535 ctx
.obj
.ns
.delete(name
, force
)
1536 except ClientException
as inst
:
1537 print((inst
.message
))
1541 def nst_delete(ctx
, name
, force
):
1543 check_client_version(ctx
.obj
, ctx
.command
.name
)
1544 ctx
.obj
.nst
.delete(name
, force
)
1545 except ClientException
as inst
:
1546 print((inst
.message
))
1550 @cli.command(name
='nst-delete', short_help
='deletes a Network Slice Template (NST)')
1551 @click.argument('name')
1552 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1554 def nst_delete1(ctx
, name
, force
):
1555 '''deletes a Network Slice Template (NST)
1557 NAME: name or ID of the NST/NSTpkg to be deleted
1559 nst_delete(ctx
, name
, force
)
1562 @cli.command(name
='netslice-template-delete', short_help
='deletes a Network Slice Template (NST)')
1563 @click.argument('name')
1564 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1566 def nst_delete2(ctx
, name
, force
):
1567 '''deletes a Network Slice Template (NST)
1569 NAME: name or ID of the NST/NSTpkg to be deleted
1571 nst_delete(ctx
, name
, force
)
1574 def nsi_delete(ctx
, name
, force
):
1576 check_client_version(ctx
.obj
, ctx
.command
.name
)
1577 ctx
.obj
.nsi
.delete(name
, force
)
1578 except ClientException
as inst
:
1579 print((inst
.message
))
1583 @cli.command(name
='nsi-delete', short_help
='deletes a Network Slice Instance (NSI)')
1584 @click.argument('name')
1585 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1587 def nsi_delete1(ctx
, name
, force
):
1588 '''deletes a Network Slice Instance (NSI)
1590 NAME: name or ID of the Network Slice instance to be deleted
1592 nsi_delete(ctx
, name
, force
)
1595 @cli.command(name
='netslice-instance-delete', short_help
='deletes a Network Slice Instance (NSI)')
1596 @click.argument('name')
1597 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1599 def nsi_delete2(ctx
, name
, force
):
1600 '''deletes a Network Slice Instance (NSI)
1602 NAME: name or ID of the Network Slice instance to be deleted
1604 nsi_delete(ctx
, name
, force
)
1607 @cli.command(name
='pdu-delete', short_help
='deletes a Physical Deployment Unit (PDU)')
1608 @click.argument('name')
1609 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1611 def pdu_delete(ctx
, name
, force
):
1612 '''deletes a Physical Deployment Unit (PDU)
1614 NAME: name or ID of the PDU to be deleted
1617 check_client_version(ctx
.obj
, ctx
.command
.name
)
1618 ctx
.obj
.pdu
.delete(name
, force
)
1619 except ClientException
as inst
:
1620 print((inst
.message
))
1624 ####################
1626 ####################
1628 @cli.command(name
='vim-create')
1629 @click.option('--name',
1631 help='Name to create datacenter')
1632 @click.option('--user',
1634 help='VIM username')
1635 @click.option('--password',
1638 confirmation_prompt
=True,
1639 help='VIM password')
1640 @click.option('--auth_url',
1643 @click.option('--tenant',
1645 help='VIM tenant name')
1646 @click.option('--config',
1648 help='VIM specific config parameters')
1649 @click.option('--account_type',
1650 default
='openstack',
1652 @click.option('--description',
1653 default
='no description',
1654 help='human readable description')
1655 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1656 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1669 '''creates a new VIM account
1673 check_client_version(ctx
.obj
, '--sdn_controller')
1674 if sdn_port_mapping
:
1675 check_client_version(ctx
.obj
, '--sdn_port_mapping')
1677 vim
['vim-username'] = user
1678 vim
['vim-password'] = password
1679 vim
['vim-url'] = auth_url
1680 vim
['vim-tenant-name'] = tenant
1681 vim
['vim-type'] = account_type
1682 vim
['description'] = description
1683 vim
['config'] = config
1684 if sdn_controller
or sdn_port_mapping
:
1685 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
)
1687 ctx
.obj
.vim
.create(name
, vim
)
1688 except ClientException
as inst
:
1689 print((inst
.message
))
1693 @cli.command(name
='vim-update', short_help
='updates a VIM account')
1694 @click.argument('name')
1695 @click.option('--newname', help='New name for the VIM account')
1696 @click.option('--user', help='VIM username')
1697 @click.option('--password', help='VIM password')
1698 @click.option('--auth_url', help='VIM url')
1699 @click.option('--tenant', help='VIM tenant name')
1700 @click.option('--config', help='VIM specific config parameters')
1701 @click.option('--account_type', help='VIM type')
1702 @click.option('--description', help='human readable description')
1703 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
1704 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
1718 '''updates a VIM account
1720 NAME: name or ID of the VIM account
1723 check_client_version(ctx
.obj
, ctx
.command
.name
)
1725 if newname
: vim
['name'] = newname
1726 if user
: vim
['vim_user'] = user
1727 if password
: vim
['vim_password'] = password
1728 if auth_url
: vim
['vim_url'] = auth_url
1729 if tenant
: vim
['vim-tenant-name'] = tenant
1730 if account_type
: vim
['vim_type'] = account_type
1731 if description
: vim
['description'] = description
1732 if config
: vim
['config'] = config
1733 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
)
1734 except ClientException
as inst
:
1735 print((inst
.message
))
1739 @cli.command(name
='vim-delete')
1740 @click.argument('name')
1741 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1743 def vim_delete(ctx
, name
, force
):
1744 '''deletes a VIM account
1746 NAME: name or ID of the VIM account to be deleted
1750 ctx
.obj
.vim
.delete(name
)
1752 check_client_version(ctx
.obj
, '--force')
1753 ctx
.obj
.vim
.delete(name
, force
)
1754 except ClientException
as inst
:
1755 print((inst
.message
))
1759 @cli.command(name
='vim-list')
1760 @click.option('--ro_update/--no_ro_update',
1762 help='update list from RO')
1763 @click.option('--filter', default
=None,
1764 help='restricts the list to the VIM accounts matching the filter')
1766 def vim_list(ctx
, ro_update
, filter):
1767 '''list all VIM accounts'''
1769 check_client_version(ctx
.obj
, '--filter')
1771 check_client_version(ctx
.obj
, '--ro_update', 'v1')
1772 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1773 if fullclassname
== 'osmclient.sol005.client.Client':
1774 resp
= ctx
.obj
.vim
.list(filter)
1776 resp
= ctx
.obj
.vim
.list(ro_update
)
1777 table
= PrettyTable(['vim name', 'uuid'])
1779 table
.add_row([vim
['name'], vim
['uuid']])
1784 @cli.command(name
='vim-show')
1785 @click.argument('name')
1787 def vim_show(ctx
, name
):
1788 '''shows the details of a VIM account
1790 NAME: name or ID of the VIM account
1793 resp
= ctx
.obj
.vim
.get(name
)
1794 if 'vim_password' in resp
:
1795 resp
['vim_password']='********'
1796 except ClientException
as inst
:
1797 print((inst
.message
))
1800 table
= PrettyTable(['key', 'attribute'])
1801 for k
, v
in list(resp
.items()):
1802 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1807 ####################
1809 ####################
1811 @cli.command(name
='wim-create')
1812 @click.option('--name',
1814 help='Name for the WIM account')
1815 @click.option('--user',
1816 help='WIM username')
1817 @click.option('--password',
1818 help='WIM password')
1819 @click.option('--url',
1822 # @click.option('--tenant',
1823 # help='wIM tenant name')
1824 @click.option('--config',
1826 help='WIM specific config parameters')
1827 @click.option('--wim_type',
1829 @click.option('--description',
1830 default
='no description',
1831 help='human readable description')
1832 @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)")
1844 '''creates a new WIM account
1847 check_client_version(ctx
.obj
, ctx
.command
.name
)
1848 # if sdn_controller:
1849 # check_client_version(ctx.obj, '--sdn_controller')
1850 # if sdn_port_mapping:
1851 # check_client_version(ctx.obj, '--sdn_port_mapping')
1853 if user
: wim
['user'] = user
1854 if password
: wim
['password'] = password
1855 if url
: wim
['wim_url'] = url
1856 # if tenant: wim['tenant'] = tenant
1857 wim
['wim_type'] = wim_type
1858 if description
: wim
['description'] = description
1859 if config
: wim
['config'] = config
1860 ctx
.obj
.wim
.create(name
, wim
, wim_port_mapping
)
1861 except ClientException
as inst
:
1862 print((inst
.message
))
1866 @cli.command(name
='wim-update', short_help
='updates a WIM account')
1867 @click.argument('name')
1868 @click.option('--newname', help='New name for the WIM account')
1869 @click.option('--user', help='WIM username')
1870 @click.option('--password', help='WIM password')
1871 @click.option('--url', help='WIM url')
1872 @click.option('--config', help='WIM specific config parameters')
1873 @click.option('--wim_type', help='WIM type')
1874 @click.option('--description', help='human readable description')
1875 @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)")
1887 '''updates a WIM account
1889 NAME: name or ID of the WIM account
1892 check_client_version(ctx
.obj
, ctx
.command
.name
)
1894 if newname
: wim
['name'] = newname
1895 if user
: wim
['user'] = user
1896 if password
: wim
['password'] = password
1897 if url
: wim
['url'] = url
1898 # if tenant: wim['tenant'] = tenant
1899 if wim_type
: wim
['wim_type'] = wim_type
1900 if description
: wim
['description'] = description
1901 if config
: wim
['config'] = config
1902 ctx
.obj
.wim
.update(name
, wim
, wim_port_mapping
)
1903 except ClientException
as inst
:
1904 print((inst
.message
))
1908 @cli.command(name
='wim-delete')
1909 @click.argument('name')
1910 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1912 def wim_delete(ctx
, name
, force
):
1913 '''deletes a WIM account
1915 NAME: name or ID of the WIM account to be deleted
1918 check_client_version(ctx
.obj
, ctx
.command
.name
)
1919 ctx
.obj
.wim
.delete(name
, force
)
1920 except ClientException
as inst
:
1921 print((inst
.message
))
1925 @cli.command(name
='wim-list')
1926 @click.option('--filter', default
=None,
1927 help='restricts the list to the WIM accounts matching the filter')
1929 def wim_list(ctx
, filter):
1930 '''list all WIM accounts'''
1932 check_client_version(ctx
.obj
, ctx
.command
.name
)
1933 resp
= ctx
.obj
.wim
.list(filter)
1934 table
= PrettyTable(['wim name', 'uuid'])
1936 table
.add_row([wim
['name'], wim
['uuid']])
1939 except ClientException
as inst
:
1940 print((inst
.message
))
1944 @cli.command(name
='wim-show')
1945 @click.argument('name')
1947 def wim_show(ctx
, name
):
1948 '''shows the details of a WIM account
1950 NAME: name or ID of the WIM account
1953 check_client_version(ctx
.obj
, ctx
.command
.name
)
1954 resp
= ctx
.obj
.wim
.get(name
)
1955 if 'password' in resp
:
1956 resp
['wim_password']='********'
1957 except ClientException
as inst
:
1958 print((inst
.message
))
1961 table
= PrettyTable(['key', 'attribute'])
1962 for k
, v
in list(resp
.items()):
1963 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1968 ####################
1969 # SDN controller operations
1970 ####################
1972 @cli.command(name
='sdnc-create')
1973 @click.option('--name',
1975 help='Name to create sdn controller')
1976 @click.option('--type',
1978 help='SDN controller type')
1979 @click.option('--sdn_controller_version',
1980 help='SDN controller username')
1981 @click.option('--ip_address',
1983 help='SDN controller IP address')
1984 @click.option('--port',
1986 help='SDN controller port')
1987 @click.option('--switch_dpid',
1989 help='Switch DPID (Openflow Datapath ID)')
1990 @click.option('--user',
1991 help='SDN controller username')
1992 @click.option('--password',
1994 confirmation_prompt
=True,
1995 help='SDN controller password')
1996 #@click.option('--description',
1997 # default='no description',
1998 # help='human readable description')
2000 def sdnc_create(ctx
,
2003 sdn_controller_version
,
2009 '''creates a new SDN controller
2012 sdncontroller
['name'] = name
2013 sdncontroller
['type'] = type
2014 sdncontroller
['ip'] = ip_address
2015 sdncontroller
['port'] = int(port
)
2016 sdncontroller
['dpid'] = switch_dpid
2017 if sdn_controller_version
:
2018 sdncontroller
['version'] = sdn_controller_version
2020 sdncontroller
['user'] = user
2022 sdncontroller
['password'] = password
2023 # sdncontroller['description'] = description
2025 check_client_version(ctx
.obj
, ctx
.command
.name
)
2026 ctx
.obj
.sdnc
.create(name
, sdncontroller
)
2027 except ClientException
as inst
:
2028 print((inst
.message
))
2031 @cli.command(name
='sdnc-update', short_help
='updates an SDN controller')
2032 @click.argument('name')
2033 @click.option('--newname', help='New name for the SDN controller')
2034 @click.option('--type', help='SDN controller type')
2035 @click.option('--sdn_controller_version', help='SDN controller username')
2036 @click.option('--ip_address', help='SDN controller IP address')
2037 @click.option('--port', help='SDN controller port')
2038 @click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)')
2039 @click.option('--user', help='SDN controller username')
2040 @click.option('--password', help='SDN controller password')
2041 #@click.option('--description', default=None, help='human readable description')
2043 def sdnc_update(ctx
,
2047 sdn_controller_version
,
2053 '''updates an SDN controller
2055 NAME: name or ID of the SDN controller
2058 if newname
: sdncontroller
['name'] = newname
2059 if type: sdncontroller
['type'] = type
2060 if ip_address
: sdncontroller
['ip'] = ip_address
2061 if port
: sdncontroller
['port'] = int(port
)
2062 if switch_dpid
: sdncontroller
['dpid'] = switch_dpid
2063 # sdncontroller['description'] = description
2064 if sdn_controller_version
is not None:
2065 if sdn_controller_version
=="":
2066 sdncontroller
['version'] = None
2068 sdncontroller
['version'] = sdn_controller_version
2069 if user
is not None:
2071 sdncontroller
['user'] = None
2073 sdncontroller
['user'] = user
2074 if password
is not None:
2076 sdncontroller
['password'] = None
2078 sdncontroller
['password'] = user
2080 check_client_version(ctx
.obj
, ctx
.command
.name
)
2081 ctx
.obj
.sdnc
.update(name
, sdncontroller
)
2082 except ClientException
as inst
:
2083 print((inst
.message
))
2087 @cli.command(name
='sdnc-delete')
2088 @click.argument('name')
2089 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2091 def sdnc_delete(ctx
, name
, force
):
2092 '''deletes an SDN controller
2094 NAME: name or ID of the SDN controller to be deleted
2097 check_client_version(ctx
.obj
, ctx
.command
.name
)
2098 ctx
.obj
.sdnc
.delete(name
, force
)
2099 except ClientException
as inst
:
2100 print((inst
.message
))
2104 @cli.command(name
='sdnc-list')
2105 @click.option('--filter', default
=None,
2106 help='restricts the list to the SDN controllers matching the filter')
2108 def sdnc_list(ctx
, filter):
2109 '''list all SDN controllers'''
2111 check_client_version(ctx
.obj
, ctx
.command
.name
)
2112 resp
= ctx
.obj
.sdnc
.list(filter)
2113 except ClientException
as inst
:
2114 print((inst
.message
))
2116 table
= PrettyTable(['name', 'id'])
2118 table
.add_row([sdnc
['name'], sdnc
['_id']])
2123 @cli.command(name
='sdnc-show')
2124 @click.argument('name')
2126 def sdnc_show(ctx
, name
):
2127 '''shows the details of an SDN controller
2129 NAME: name or ID of the SDN controller
2132 check_client_version(ctx
.obj
, ctx
.command
.name
)
2133 resp
= ctx
.obj
.sdnc
.get(name
)
2134 except ClientException
as inst
:
2135 print((inst
.message
))
2138 table
= PrettyTable(['key', 'attribute'])
2139 for k
, v
in list(resp
.items()):
2140 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2145 ####################
2146 # Project mgmt operations
2147 ####################
2149 @cli.command(name
='project-create')
2150 @click.argument('name')
2151 #@click.option('--description',
2152 # default='no description',
2153 # help='human readable description')
2155 def project_create(ctx
, name
):
2156 '''Creates a new project
2158 NAME: name of the project
2161 project
['name'] = name
2163 check_client_version(ctx
.obj
, ctx
.command
.name
)
2164 ctx
.obj
.project
.create(name
, project
)
2165 except ClientException
as inst
:
2169 @cli.command(name
='project-delete')
2170 @click.argument('name')
2171 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2173 def project_delete(ctx
, name
):
2174 '''deletes a project
2176 NAME: name or ID of the project to be deleted
2179 check_client_version(ctx
.obj
, ctx
.command
.name
)
2180 ctx
.obj
.project
.delete(name
)
2181 except ClientException
as inst
:
2186 @cli.command(name
='project-list')
2187 @click.option('--filter', default
=None,
2188 help='restricts the list to the projects matching the filter')
2190 def project_list(ctx
, filter):
2191 '''list all projects'''
2193 check_client_version(ctx
.obj
, ctx
.command
.name
)
2194 resp
= ctx
.obj
.project
.list(filter)
2195 except ClientException
as inst
:
2198 table
= PrettyTable(['name', 'id'])
2200 table
.add_row([proj
['name'], proj
['_id']])
2205 @cli.command(name
='project-show')
2206 @click.argument('name')
2208 def project_show(ctx
, name
):
2209 '''shows the details of a project
2211 NAME: name or ID of the project
2214 check_client_version(ctx
.obj
, ctx
.command
.name
)
2215 resp
= ctx
.obj
.project
.get(name
)
2216 except ClientException
as inst
:
2220 table
= PrettyTable(['key', 'attribute'])
2221 for k
, v
in resp
.items():
2222 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2227 ####################
2228 # User mgmt operations
2229 ####################
2231 @cli.command(name
='user-create')
2232 @click.argument('username')
2233 @click.option('--password',
2236 confirmation_prompt
=True,
2237 help='user password')
2238 @click.option('--projects',
2240 help='list of project ids that the user belongs to')
2241 #@click.option('--description',
2242 # default='no description',
2243 # help='human readable description')
2245 def user_create(ctx
, username
, password
, projects
):
2246 '''Creates a new user
2248 USERNAME: name of the user
2251 user
['username'] = username
2252 user
['password'] = password
2253 user
['projects'] = projects
2255 check_client_version(ctx
.obj
, ctx
.command
.name
)
2256 ctx
.obj
.user
.create(username
, user
)
2257 except ClientException
as inst
:
2261 @cli.command(name
='user-delete')
2262 @click.argument('name')
2263 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
2265 def user_delete(ctx
, name
):
2268 NAME: name or ID of the user to be deleted
2271 check_client_version(ctx
.obj
, ctx
.command
.name
)
2272 ctx
.obj
.user
.delete(name
)
2273 except ClientException
as inst
:
2278 @cli.command(name
='user-list')
2279 @click.option('--filter', default
=None,
2280 help='restricts the list to the users matching the filter')
2282 def user_list(ctx
, filter):
2283 '''list all users'''
2285 check_client_version(ctx
.obj
, ctx
.command
.name
)
2286 resp
= ctx
.obj
.user
.list(filter)
2287 except ClientException
as inst
:
2290 table
= PrettyTable(['name', 'id'])
2292 table
.add_row([user
['name'], user
['_id']])
2297 @cli.command(name
='user-show')
2298 @click.argument('name')
2300 def user_show(ctx
, name
):
2301 '''shows the details of a user
2303 NAME: name or ID of the user
2306 check_client_version(ctx
.obj
, ctx
.command
.name
)
2307 resp
= ctx
.obj
.user
.get(name
)
2308 if 'password' in resp
:
2309 resp
['password']='********'
2310 except ClientException
as inst
:
2314 table
= PrettyTable(['key', 'attribute'])
2315 for k
, v
in resp
.items():
2316 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2321 ####################
2322 # Fault Management operations
2323 ####################
2325 @cli.command(name
='ns-alarm-create')
2326 @click.argument('name')
2327 @click.option('--ns', prompt
=True, help='NS instance id or name')
2328 @click.option('--vnf', prompt
=True,
2329 help='VNF name (VNF member index as declared in the NSD)')
2330 @click.option('--vdu', prompt
=True,
2331 help='VDU name (VDU name as declared in the VNFD)')
2332 @click.option('--metric', prompt
=True,
2333 help='Name of the metric (e.g. cpu_utilization)')
2334 @click.option('--severity', default
='WARNING',
2335 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
2336 @click.option('--threshold_value', prompt
=True,
2337 help='threshold value that, when crossed, an alarm is triggered')
2338 @click.option('--threshold_operator', prompt
=True,
2339 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
2340 @click.option('--statistic', default
='AVERAGE',
2341 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
2343 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
2344 threshold_value
, threshold_operator
, statistic
):
2345 '''creates a new alarm for a NS instance'''
2346 ns_instance
= ctx
.obj
.ns
.get(ns
)
2348 alarm
['alarm_name'] = name
2349 alarm
['ns_id'] = ns_instance
['_id']
2350 alarm
['correlation_id'] = ns_instance
['_id']
2351 alarm
['vnf_member_index'] = vnf
2352 alarm
['vdu_name'] = vdu
2353 alarm
['metric_name'] = metric
2354 alarm
['severity'] = severity
2355 alarm
['threshold_value'] = int(threshold_value
)
2356 alarm
['operation'] = threshold_operator
2357 alarm
['statistic'] = statistic
2359 check_client_version(ctx
.obj
, ctx
.command
.name
)
2360 ctx
.obj
.ns
.create_alarm(alarm
)
2361 except ClientException
as inst
:
2362 print((inst
.message
))
2366 #@cli.command(name='ns-alarm-delete')
2367 #@click.argument('name')
2368 #@click.pass_context
2369 #def ns_alarm_delete(ctx, name):
2370 # '''deletes an alarm
2372 # NAME: name of the alarm to be deleted
2375 # check_client_version(ctx.obj, ctx.command.name)
2376 # ctx.obj.ns.delete_alarm(name)
2377 # except ClientException as inst:
2378 # print(inst.message)
2382 ####################
2383 # Performance Management operations
2384 ####################
2386 @cli.command(name
='ns-metric-export')
2387 @click.option('--ns', prompt
=True, help='NS instance id or name')
2388 @click.option('--vnf', prompt
=True,
2389 help='VNF name (VNF member index as declared in the NSD)')
2390 @click.option('--vdu', prompt
=True,
2391 help='VDU name (VDU name as declared in the VNFD)')
2392 @click.option('--metric', prompt
=True,
2393 help='name of the metric (e.g. cpu_utilization)')
2394 #@click.option('--period', default='1w',
2395 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
2396 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
2398 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
2399 '''exports a metric to the internal OSM bus, which can be read by other apps
2401 ns_instance
= ctx
.obj
.ns
.get(ns
)
2403 metric_data
['ns_id'] = ns_instance
['_id']
2404 metric_data
['correlation_id'] = ns_instance
['_id']
2405 metric_data
['vnf_member_index'] = vnf
2406 metric_data
['vdu_name'] = vdu
2407 metric_data
['metric_name'] = metric
2408 metric_data
['collection_unit'] = 'WEEK'
2409 metric_data
['collection_period'] = 1
2411 check_client_version(ctx
.obj
, ctx
.command
.name
)
2413 print('{}'.format(ctx
.obj
.ns
.export_metric(metric_data
)))
2417 print('{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
))
2418 time
.sleep(int(interval
))
2420 except ClientException
as inst
:
2421 print((inst
.message
))
2425 ####################
2427 ####################
2429 @cli.command(name
='upload-package')
2430 @click.argument('filename')
2432 def upload_package(ctx
, filename
):
2433 '''uploads a VNF package or NS package
2435 FILENAME: VNF or NS package file (tar.gz)
2438 ctx
.obj
.package
.upload(filename
)
2439 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
2440 if fullclassname
!= 'osmclient.sol005.client.Client':
2441 ctx
.obj
.package
.wait_for_upload(filename
)
2442 except ClientException
as inst
:
2443 print((inst
.message
))
2447 @cli.command(name
='ns-scaling-show')
2448 @click.argument('ns_name')
2450 def show_ns_scaling(ctx
, ns_name
):
2451 '''shows the status of a NS scaling operation
2453 NS_NAME: name of the NS instance being scaled
2456 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2457 resp
= ctx
.obj
.ns
.list()
2458 except ClientException
as inst
:
2459 print((inst
.message
))
2462 table
= PrettyTable(
2465 'operational status',
2470 if ns_name
== ns
['name']:
2471 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
2472 scaling_records
= nsopdata
['nsr:nsr']['scaling-group-record']
2473 for record
in scaling_records
:
2474 if 'instance' in record
:
2475 instances
= record
['instance']
2476 for inst
in instances
:
2478 [record
['scaling-group-name-ref'],
2479 inst
['instance-id'],
2481 time
.strftime('%Y-%m-%d %H:%M:%S',
2483 inst
['create-time'])),
2489 @cli.command(name
='ns-scale')
2490 @click.argument('ns_name')
2491 @click.option('--ns_scale_group', prompt
=True)
2492 @click.option('--index', prompt
=True)
2494 def ns_scale(ctx
, ns_name
, ns_scale_group
, index
):
2497 NS_NAME: name of the NS instance to be scaled
2500 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2501 ctx
.obj
.ns
.scale(ns_name
, ns_scale_group
, index
)
2502 except ClientException
as inst
:
2503 print((inst
.message
))
2507 @cli.command(name
='config-agent-list')
2509 def config_agent_list(ctx
):
2510 '''list config agents'''
2512 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2513 except ClientException
as inst
:
2514 print((inst
.message
))
2516 table
= PrettyTable(['name', 'account-type', 'details'])
2517 for account
in ctx
.obj
.vca
.list():
2520 account
['account-type'],
2526 @cli.command(name
='config-agent-delete')
2527 @click.argument('name')
2529 def config_agent_delete(ctx
, name
):
2530 '''deletes a config agent
2532 NAME: name of the config agent to be deleted
2535 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2536 ctx
.obj
.vca
.delete(name
)
2537 except ClientException
as inst
:
2538 print((inst
.message
))
2542 @cli.command(name
='config-agent-add')
2543 @click.option('--name',
2545 @click.option('--account_type',
2547 @click.option('--server',
2549 @click.option('--user',
2551 @click.option('--secret',
2554 confirmation_prompt
=True)
2556 def config_agent_add(ctx
, name
, account_type
, server
, user
, secret
):
2557 '''adds a config agent'''
2559 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2560 ctx
.obj
.vca
.create(name
, account_type
, server
, user
, secret
)
2561 except ClientException
as inst
:
2562 print((inst
.message
))
2565 @cli.command(name
='ro-dump')
2568 '''shows RO agent information'''
2569 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2570 resp
= ctx
.obj
.vim
.get_resource_orchestrator()
2571 table
= PrettyTable(['key', 'attribute'])
2572 for k
, v
in list(resp
.items()):
2573 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2578 @cli.command(name
='vcs-list')
2581 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
2582 resp
= ctx
.obj
.utils
.get_vcs_info()
2583 table
= PrettyTable(['component name', 'state'])
2584 for component
in resp
:
2585 table
.add_row([component
['component_name'], component
['state']])
2590 @cli.command(name
='ns-action')
2591 @click.argument('ns_name')
2592 @click.option('--vnf_name', default
=None)
2593 @click.option('--action_name', prompt
=True)
2594 @click.option('--params', prompt
=True)
2601 '''executes an action/primitive over a NS instance
2603 NS_NAME: name or ID of the NS instance
2606 check_client_version(ctx
.obj
, ctx
.command
.name
)
2609 op_data
['vnf_member_index'] = vnf_name
2610 op_data
['primitive'] = action_name
2611 op_data
['primitive_params'] = yaml
.load(params
)
2612 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
)
2614 except ClientException
as inst
:
2615 print((inst
.message
))
2619 @cli.command(name
='vnf-scale')
2620 @click.argument('ns_name')
2621 @click.argument('vnf_name')
2622 @click.option('--scaling-group', prompt
=True, help="scaling-group-descriptor name to use")
2623 @click.option('--scale-in', default
=False, is_flag
=True, help="performs a scale in operation")
2624 @click.option('--scale-out', default
=False, is_flag
=True, help="performs a scale out operation (by default)")
2632 '''executes a VNF scale (adding/removing VDUs)
2635 NS_NAME: name or ID of the NS instance.
2636 VNF_NAME: member-vnf-index in the NS to be scaled.
2639 check_client_version(ctx
.obj
, ctx
.command
.name
)
2640 if not scale_in
and not scale_out
:
2642 ctx
.obj
.ns
.scale_vnf(ns_name
, vnf_name
, scaling_group
, scale_in
, scale_out
)
2643 except ClientException
as inst
:
2644 print((inst
.message
))
2648 if __name__
== '__main__':
2651 except pycurl
.error
as e
:
2653 print('Maybe "--hostname" option or OSM_HOSTNAME' +
2654 'environment variable needs to be specified')