23f258e92fe592da13861bd9b71224b7c5821615
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
29 def check_client_version(obj
, what
, version
='sol005'):
31 Checks the version of the client object and raises error if it not the expected.
33 :param obj: the client object
34 :what: the function or command under evaluation (used when an error is raised)
36 :raises ClientError: if the specified version does not match the client version
38 fullclassname
= obj
.__module
__ + "." + obj
.__class
__.__name
__
39 message
= 'The following commands or options are only supported with the option "--sol005": {}'.format(what
)
41 message
= 'The following commands or options are not supported when using option "--sol005": {}'.format(what
)
42 if fullclassname
!= 'osmclient.{}.client.Client'.format(version
):
43 raise ClientException(message
)
47 @click.option('--hostname',
49 envvar
='OSM_HOSTNAME',
50 help='hostname of server. ' +
51 'Also can set OSM_HOSTNAME in environment')
52 @click.option('--so-port',
55 help='hostname of server. ' +
56 'Also can set OSM_SO_PORT in environment')
57 @click.option('--so-project',
59 envvar
='OSM_SO_PROJECT',
60 help='Project Name in SO. ' +
61 'Also can set OSM_SO_PROJECT in environment')
62 @click.option('--ro-hostname',
64 envvar
='OSM_RO_HOSTNAME',
65 help='hostname of RO server. ' +
66 'Also can set OSM_RO_HOSTNAME in environment')
67 @click.option('--ro-port',
70 help='hostname of RO server. ' +
71 'Also can set OSM_RO_PORT in environment')
72 @click.option('--sol005',
75 help='Use ETSI NFV SOL005 API')
77 def cli(ctx
, hostname
, so_port
, so_project
, ro_hostname
, ro_port
, sol005
):
80 "either hostname option or OSM_HOSTNAME " +
81 "environment variable needs to be specified")
84 if so_port
is not None:
85 kwargs
['so_port']=so_port
86 if so_project
is not None:
87 kwargs
['so_project']=so_project
88 if ro_hostname
is not None:
89 kwargs
['ro_host']=ro_hostname
90 if ro_port
is not None:
91 kwargs
['ro_port']=ro_port
93 ctx
.obj
= client
.Client(host
=hostname
, sol005
=sol005
, **kwargs
)
100 @cli.command(name
='ns-list')
101 @click.option('--filter', default
=None,
102 help='restricts the list to the NS instances matching the filter')
104 def ns_list(ctx
, filter):
105 '''list all NS instances'''
107 check_client_version(ctx
.obj
, '--filter')
108 resp
= ctx
.obj
.ns
.list(filter)
110 resp
= ctx
.obj
.ns
.list()
114 'operational status',
118 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
119 if fullclassname
== 'osmclient.sol005.client.Client':
121 nsr_name
= nsr
['name']
124 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
125 nsr
= nsopdata
['nsr:nsr']
126 nsr_name
= nsr
['name-ref']
127 nsr_id
= nsr
['ns-instance-config-ref']
128 opstatus
= nsr
['operational-status'] if 'operational-status' in nsr
else 'Not found'
129 configstatus
= nsr
['config-status'] if 'config-status' in nsr
else 'Not found'
130 detailed_status
= nsr
['detailed-status'] if 'detailed-status' in nsr
else 'Not found'
131 if configstatus
== "config_not_needed":
132 configstatus
= "configured (no charms)"
143 def nsd_list(ctx
, filter):
145 check_client_version(ctx
.obj
, '--filter')
146 resp
= ctx
.obj
.nsd
.list(filter)
148 resp
= ctx
.obj
.nsd
.list()
149 #print yaml.safe_dump(resp)
150 table
= PrettyTable(['nsd name', 'id'])
151 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
152 if fullclassname
== 'osmclient.sol005.client.Client':
154 name
= ns
['name'] if 'name' in ns
else '-'
155 table
.add_row([name
, ns
['_id']])
158 table
.add_row([ns
['name'], ns
['id']])
163 @cli.command(name
='nsd-list')
164 @click.option('--filter', default
=None,
165 help='restricts the list to the NSD/NSpkg matching the filter')
167 def nsd_list1(ctx
, filter):
168 '''list all NSD/NSpkg in the system'''
172 @cli.command(name
='nspkg-list')
173 @click.option('--filter', default
=None,
174 help='restricts the list to the NSD/NSpkg matching the filter')
176 def nsd_list2(ctx
, filter):
177 '''list all NSD/NSpkg in the system'''
181 def vnfd_list(ctx
, filter):
183 check_client_version(ctx
.obj
, '--filter')
184 resp
= ctx
.obj
.vnfd
.list(filter)
186 resp
= ctx
.obj
.vnfd
.list()
187 #print yaml.safe_dump(resp)
188 table
= PrettyTable(['vnfd name', 'id'])
189 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
190 if fullclassname
== 'osmclient.sol005.client.Client':
192 name
= vnfd
['name'] if 'name' in vnfd
else '-'
193 table
.add_row([name
, vnfd
['_id']])
196 table
.add_row([vnfd
['name'], vnfd
['id']])
201 @cli.command(name
='vnfd-list')
202 @click.option('--filter', default
=None,
203 help='restricts the list to the VNFD/VNFpkg matching the filter')
205 def vnfd_list1(ctx
, filter):
206 '''list all VNFD/VNFpkg in the system'''
207 vnfd_list(ctx
,filter)
210 @cli.command(name
='vnfpkg-list')
211 @click.option('--filter', default
=None,
212 help='restricts the list to the VNFD/VNFpkg matching the filter')
214 def vnfd_list2(ctx
, filter):
215 '''list all VNFD/VNFpkg in the system'''
216 vnfd_list(ctx
,filter)
219 @cli.command(name
='vnf-list')
222 ''' list all VNF instances'''
224 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
225 resp
= ctx
.obj
.vnf
.list()
226 except ClientException
as inst
:
232 'operational status',
235 if 'mgmt-interface' not in vnfr
:
236 vnfr
['mgmt-interface'] = {}
237 vnfr
['mgmt-interface']['ip-address'] = None
241 vnfr
['operational-status'],
242 vnfr
['config-status']])
246 @cli.command(name
='ns-op-list')
247 @click.argument('name')
249 def ns_op_list(ctx
, name
):
250 '''shows the history of operations over a NS instance
252 NAME: name or ID of the NS instance
255 check_client_version(ctx
.obj
, ctx
.command
.name
)
256 resp
= ctx
.obj
.ns
.list_op(name
)
257 except ClientException
as inst
:
261 table
= PrettyTable(['id', 'operation', 'status'])
263 table
.add_row([op
['id'], op
['lcmOperationType'],
264 op
['operationState']])
272 def nsd_show(ctx
, name
, literal
):
274 resp
= ctx
.obj
.nsd
.get(name
)
275 #resp = ctx.obj.nsd.get_individual(name)
276 except ClientException
as inst
:
281 print yaml
.safe_dump(resp
)
284 table
= PrettyTable(['field', 'value'])
285 for k
, v
in resp
.items():
286 table
.add_row([k
, json
.dumps(v
, indent
=2)])
291 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
292 @click.option('--literal', is_flag
=True,
293 help='print literally, no pretty table')
294 @click.argument('name')
296 def nsd_show1(ctx
, name
, literal
):
297 '''shows the content of a NSD
299 NAME: name or ID of the NSD/NSpkg
301 nsd_show(ctx
, name
, literal
)
304 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
305 @click.option('--literal', is_flag
=True,
306 help='print literally, no pretty table')
307 @click.argument('name')
309 def nsd_show2(ctx
, name
, literal
):
310 '''shows the content of a NSD
312 NAME: name or ID of the NSD/NSpkg
314 nsd_show(ctx
, name
, literal
)
317 def vnfd_show(ctx
, name
, literal
):
319 resp
= ctx
.obj
.vnfd
.get(name
)
320 #resp = ctx.obj.vnfd.get_individual(name)
321 except ClientException
as inst
:
326 print yaml
.safe_dump(resp
)
329 table
= PrettyTable(['field', 'value'])
330 for k
, v
in resp
.items():
331 table
.add_row([k
, json
.dumps(v
, indent
=2)])
336 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
337 @click.option('--literal', is_flag
=True,
338 help='print literally, no pretty table')
339 @click.argument('name')
341 def vnfd_show1(ctx
, name
, literal
):
342 '''shows the content of a VNFD
344 NAME: name or ID of the VNFD/VNFpkg
346 vnfd_show(ctx
, name
, literal
)
349 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
350 @click.option('--literal', is_flag
=True,
351 help='print literally, no pretty table')
352 @click.argument('name')
354 def vnfd_show2(ctx
, name
, literal
):
355 '''shows the content of a VNFD
357 NAME: name or ID of the VNFD/VNFpkg
359 vnfd_show(ctx
, name
, literal
)
362 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
363 @click.argument('name')
364 @click.option('--literal', is_flag
=True,
365 help='print literally, no pretty table')
366 @click.option('--filter', default
=None)
368 def ns_show(ctx
, name
, literal
, filter):
369 '''shows the info of a NS instance
371 NAME: name or ID of the NS instance
374 ns
= ctx
.obj
.ns
.get(name
)
375 except ClientException
as inst
:
380 print yaml
.safe_dump(resp
)
383 table
= PrettyTable(['field', 'value'])
385 for k
, v
in ns
.items():
386 if filter is None or filter in k
:
387 table
.add_row([k
, json
.dumps(v
, indent
=2)])
389 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
390 if fullclassname
!= 'osmclient.sol005.client.Client':
391 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
392 nsr_optdata
= nsopdata
['nsr:nsr']
393 for k
, v
in nsr_optdata
.items():
394 if filter is None or filter in k
:
395 table
.add_row([k
, json
.dumps(v
, indent
=2)])
400 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
401 @click.argument('name')
402 @click.option('--literal', is_flag
=True,
403 help='print literally, no pretty table')
404 @click.option('--filter', default
=None)
406 def vnf_show(ctx
, name
, literal
, filter):
407 '''shows the info of a VNF instance
409 NAME: name or ID of the VNF instance
412 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
413 resp
= ctx
.obj
.vnf
.get(name
)
414 except ClientException
as inst
:
419 print yaml
.safe_dump(resp
)
422 table
= PrettyTable(['field', 'value'])
423 for k
, v
in resp
.items():
424 if filter is None or filter in k
:
425 table
.add_row([k
, json
.dumps(v
, indent
=2)])
430 @cli.command(name
='vnf-monitoring-show')
431 @click.argument('vnf_name')
433 def vnf_monitoring_show(ctx
, vnf_name
):
435 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
436 resp
= ctx
.obj
.vnf
.get_monitoring(vnf_name
)
437 except ClientException
as inst
:
441 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
447 monitor
['value-integer'],
453 @cli.command(name
='ns-monitoring-show')
454 @click.argument('ns_name')
456 def ns_monitoring_show(ctx
, ns_name
):
458 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
459 resp
= ctx
.obj
.ns
.get_monitoring(ns_name
)
460 except ClientException
as inst
:
464 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
465 for key
, val
in resp
.items():
470 monitor
['value-integer'],
475 @cli.command(name
='ns-op-show', short_help
='shows the info of an operation')
476 @click.argument('id')
477 @click.option('--filter', default
=None)
479 def ns_op_show(ctx
, id, filter):
480 '''shows the detailed info of an operation
482 ID: operation identifier
485 check_client_version(ctx
.obj
, ctx
.command
.name
)
486 op_info
= ctx
.obj
.ns
.get_op(id)
487 except ClientException
as inst
:
491 table
= PrettyTable(['field', 'value'])
492 for k
, v
in op_info
.items():
493 if filter is None or filter in k
:
494 table
.add_row([k
, json
.dumps(v
, indent
=2)])
503 def nsd_create(ctx
, filename
, overwrite
):
505 check_client_version(ctx
.obj
, ctx
.command
.name
)
506 ctx
.obj
.nsd
.create(filename
, overwrite
)
507 except ClientException
as inst
:
512 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
513 @click.argument('filename')
514 @click.option('--overwrite', default
=None,
515 help='overwrites some fields in NSD')
517 def nsd_create1(ctx
, filename
, overwrite
):
518 '''creates a new NSD/NSpkg
520 FILENAME: NSD yaml file or NSpkg tar.gz file
522 nsd_create(ctx
, filename
, overwrite
)
525 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
526 @click.argument('filename')
527 @click.option('--overwrite', default
=None,
528 help='overwrites some fields in NSD')
530 def nsd_create2(ctx
, filename
, overwrite
):
531 '''creates a new NSD/NSpkg
533 FILENAME: NSD yaml file or NSpkg tar.gz file
535 nsd_create(ctx
, filename
, overwrite
)
538 def vnfd_create(ctx
, filename
, overwrite
):
540 check_client_version(ctx
.obj
, ctx
.command
.name
)
541 ctx
.obj
.vnfd
.create(filename
, overwrite
)
542 except ClientException
as inst
:
547 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
548 @click.argument('filename')
549 @click.option('--overwrite', default
=None,
550 help='overwrites some fields in VNFD')
552 def vnfd_create1(ctx
, filename
, overwrite
):
553 '''creates a new VNFD/VNFpkg
555 FILENAME: VNFD yaml file or VNFpkg tar.gz file
557 vnfd_create(ctx
, filename
, overwrite
)
560 @cli.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
561 @click.argument('filename')
562 @click.option('--overwrite', default
=None,
563 help='overwrites some fields in VNFD')
565 def vnfd_create2(ctx
, filename
, overwrite
):
566 '''creates a new VNFD/VNFpkg
568 FILENAME: VNFD yaml file or VNFpkg tar.gz file
570 vnfd_create(ctx
, filename
, overwrite
)
573 @cli.command(name
='ns-create')
574 @click.option('--ns_name',
576 @click.option('--nsd_name',
578 @click.option('--vim_account',
580 @click.option('--admin_status',
582 help='administration status')
583 @click.option('--ssh_keys',
585 help='comma separated list of keys to inject to vnfs')
586 @click.option('--config',
588 help='ns specific yaml configuration:\nvnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
589 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]')
598 '''creates a new NS instance'''
601 # check_client_version(ctx.obj, '--config', 'v1')
608 except ClientException
as inst
:
617 def nsd_update(ctx
, name
, content
):
619 check_client_version(ctx
.obj
, ctx
.command
.name
)
620 ctx
.obj
.nsd
.update(name
, content
)
621 except ClientException
as inst
:
625 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
626 @click.argument('name')
627 @click.option('--content', default
=None,
628 help='filename with the NSD/NSpkg replacing the current one')
630 def nsd_update1(ctx
, name
, content
):
631 '''updates a NSD/NSpkg
633 NAME: name or ID of the NSD/NSpkg
635 nsd_update(ctx
, name
, content
)
638 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
639 @click.argument('name')
640 @click.option('--content', default
=None,
641 help='filename with the NSD/NSpkg replacing the current one')
643 def nsd_update2(ctx
, name
, content
):
644 '''updates a NSD/NSpkg
646 NAME: name or ID of the NSD/NSpkg
648 nsd_update(ctx
, name
, content
)
651 def vnfd_update(ctx
, name
, content
):
653 check_client_version(ctx
.obj
, ctx
.command
.name
)
654 ctx
.obj
.vnfd
.update(name
, content
)
655 except ClientException
as inst
:
660 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
661 @click.argument('name')
662 @click.option('--content', default
=None,
663 help='filename with the VNFD/VNFpkg replacing the current one')
665 def vnfd_update1(ctx
, name
, content
):
666 '''updates a VNFD/VNFpkg
668 NAME: name or ID of the VNFD/VNFpkg
670 vnfd_update(ctx
, name
, content
)
673 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
674 @click.argument('name')
675 @click.option('--content', default
=None,
676 help='filename with the VNFD/VNFpkg replacing the current one')
678 def vnfd_update2(ctx
, name
, content
):
679 '''updates a VNFD/VNFpkg
681 NAME: VNFD yaml file or VNFpkg tar.gz file
683 vnfd_update(ctx
, name
, content
)
690 def nsd_delete(ctx
, name
):
692 ctx
.obj
.nsd
.delete(name
)
693 except ClientException
as inst
:
698 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
699 @click.argument('name')
701 def nsd_delete1(ctx
, name
):
702 '''deletes a NSD/NSpkg
704 NAME: name or ID of the NSD/NSpkg to be deleted
706 nsd_delete(ctx
, name
)
709 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
710 @click.argument('name')
712 def nsd_delete2(ctx
, name
):
713 '''deletes a NSD/NSpkg
715 NAME: name or ID of the NSD/NSpkg to be deleted
717 nsd_delete(ctx
, name
)
720 def vnfd_delete(ctx
, name
):
722 ctx
.obj
.vnfd
.delete(name
)
723 except ClientException
as inst
:
728 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
729 @click.argument('name')
731 def vnfd_delete1(ctx
, name
):
732 '''deletes a VNFD/VNFpkg
734 NAME: name or ID of the VNFD/VNFpkg to be deleted
736 vnfd_delete(ctx
, name
)
739 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
740 @click.argument('name')
742 def vnfd_delete2(ctx
, name
):
743 '''deletes a VNFD/VNFpkg
745 NAME: name or ID of the VNFD/VNFpkg to be deleted
747 vnfd_delete(ctx
, name
)
750 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
751 @click.argument('name')
753 def ns_delete(ctx
, name
):
754 '''deletes a NS instance
756 NAME: name or ID of the NS instance to be deleted
759 ctx
.obj
.ns
.delete(name
)
760 except ClientException
as inst
:
769 @cli.command(name
='vim-create')
770 @click.option('--name',
772 help='Name to create datacenter')
773 @click.option('--user',
776 @click.option('--password',
779 confirmation_prompt
=True,
781 @click.option('--auth_url',
784 @click.option('--tenant',
786 help='VIM tenant name')
787 @click.option('--config',
789 help='VIM specific config parameters')
790 @click.option('--account_type',
793 @click.option('--description',
794 default
='no description',
795 help='human readable description')
806 '''creates a new VIM account
809 vim
['vim-username'] = user
810 vim
['vim-password'] = password
811 vim
['vim-url'] = auth_url
812 vim
['vim-tenant-name'] = tenant
813 vim
['config'] = config
814 vim
['vim-type'] = account_type
815 vim
['description'] = description
817 ctx
.obj
.vim
.create(name
, vim
)
818 except ClientException
as inst
:
823 @cli.command(name
='vim-update', short_help
='updates a VIM account')
824 @click.argument('name')
825 @click.option('--newname', default
=None, help='New name for the VIM account')
826 @click.option('--user', default
=None, help='VIM username')
827 @click.option('--password', default
=None, help='VIM password')
828 @click.option('--auth_url', default
=None, help='VIM url')
829 @click.option('--tenant', default
=None, help='VIM tenant name')
830 @click.option('--config', default
=None, help='VIM specific config parameters')
831 @click.option('--account_type', default
=None, help='VIM type')
832 @click.option('--description', default
=None, help='human readable description')
844 '''updates a VIM account
846 NAME: name or ID of the VIM account
850 vim
['name'] = newname
851 vim
['vim_user'] = user
852 vim
['vim_password'] = password
853 vim
['vim_url'] = auth_url
854 vim
['vim-tenant-name'] = tenant
855 vim
['config'] = config
856 vim
['vim_type'] = account_type
857 vim
['description'] = description
859 check_client_version(ctx
.obj
, ctx
.command
.name
)
860 ctx
.obj
.vim
.update(name
, vim
)
861 except ClientException
as inst
:
866 @cli.command(name
='vim-delete')
867 @click.argument('name')
869 def vim_delete(ctx
, name
):
870 '''deletes a VIM account
872 NAME: name or ID of the VIM account to be deleted
875 ctx
.obj
.vim
.delete(name
)
876 except ClientException
as inst
:
881 @cli.command(name
='vim-list')
882 @click.option('--ro_update/--no_ro_update',
884 help='update list from RO')
885 @click.option('--filter', default
=None,
886 help='restricts the list to the VIM accounts matching the filter')
888 def vim_list(ctx
, ro_update
, filter):
889 '''list all VIM accounts'''
891 check_client_version(ctx
.obj
, '--filter')
893 check_client_version(ctx
.obj
, '--ro_update', 'v1')
894 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
895 if fullclassname
== 'osmclient.sol005.client.Client':
896 resp
= ctx
.obj
.vim
.list(filter)
898 resp
= ctx
.obj
.vim
.list(ro_update
)
899 table
= PrettyTable(['vim name', 'uuid'])
901 table
.add_row([vim
['name'], vim
['uuid']])
906 @cli.command(name
='vim-show')
907 @click.argument('name')
909 def vim_show(ctx
, name
):
910 '''shows the details of a VIM account
912 NAME: name or ID of the VIM account
915 resp
= ctx
.obj
.vim
.get(name
)
916 if 'vim_password' in resp
:
917 resp
['vim_password']='********'
918 except ClientException
as inst
:
922 table
= PrettyTable(['key', 'attribute'])
923 for k
, v
in resp
.items():
924 table
.add_row([k
, json
.dumps(v
, indent
=2)])
933 @cli.command(name
='upload-package')
934 @click.argument('filename')
936 def upload_package(ctx
, filename
):
937 '''uploads a VNF package or NS package
939 FILENAME: VNF or NS package file (tar.gz)
942 ctx
.obj
.package
.upload(filename
)
943 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
944 if fullclassname
!= 'osmclient.sol005.client.Client':
945 ctx
.obj
.package
.wait_for_upload(filename
)
946 except ClientException
as inst
:
951 @cli.command(name
='ns-scaling-show')
952 @click.argument('ns_name')
954 def show_ns_scaling(ctx
, ns_name
):
955 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
956 resp
= ctx
.obj
.ns
.list()
961 'operational status',
966 if ns_name
== ns
['name']:
967 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
968 scaling_records
= nsopdata
['nsr:nsr']['scaling-group-record']
969 for record
in scaling_records
:
970 if 'instance' in record
:
971 instances
= record
['instance']
972 for inst
in instances
:
974 [record
['scaling-group-name-ref'],
977 time
.strftime('%Y-%m-%d %H:%M:%S',
979 inst
['create-time'])),
985 @cli.command(name
='ns-scale')
986 @click.argument('ns_name')
987 @click.option('--ns_scale_group', prompt
=True)
988 @click.option('--index', prompt
=True)
990 def ns_scale(ctx
, ns_name
, ns_scale_group
, index
):
991 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
992 ctx
.obj
.ns
.scale(ns_name
, ns_scale_group
, index
)
995 @cli.command(name
='config-agent-list')
997 def config_agent_list(ctx
):
998 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
999 table
= PrettyTable(['name', 'account-type', 'details'])
1000 for account
in ctx
.obj
.vca
.list():
1003 account
['account-type'],
1009 @cli.command(name
='config-agent-delete')
1010 @click.argument('name')
1012 def config_agent_delete(ctx
, name
):
1014 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1015 ctx
.obj
.vca
.delete(name
)
1016 except ClientException
as inst
:
1021 @cli.command(name
='config-agent-add')
1022 @click.option('--name',
1024 @click.option('--account_type',
1026 @click.option('--server',
1028 @click.option('--user',
1030 @click.option('--secret',
1033 confirmation_prompt
=True)
1035 def config_agent_add(ctx
, name
, account_type
, server
, user
, secret
):
1037 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1038 ctx
.obj
.vca
.create(name
, account_type
, server
, user
, secret
)
1039 except ClientException
as inst
:
1043 @cli.command(name
='ro-dump')
1046 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1047 resp
= ctx
.obj
.vim
.get_resource_orchestrator()
1048 table
= PrettyTable(['key', 'attribute'])
1049 for k
, v
in resp
.items():
1050 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1055 @cli.command(name
='vcs-list')
1058 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1059 resp
= ctx
.obj
.utils
.get_vcs_info()
1060 table
= PrettyTable(['component name', 'state'])
1061 for component
in resp
:
1062 table
.add_row([component
['component_name'], component
['state']])
1067 @cli.command(name
='ns-action')
1068 @click.argument('ns_name')
1069 @click.option('--vnf_name', default
=None)
1070 @click.option('--action_name', prompt
=True)
1071 @click.option('--params', prompt
=True)
1077 '''executes an action/primitive over a NS instance
1079 NS_NAME: name or ID of the NS instance
1082 check_client_version(ctx
.obj
, ctx
.command
.name
)
1085 op_data
['vnf_member_index'] = vnf_name
1086 op_data
['primitive'] = action_name
1087 op_data
['primitive_params'] = yaml
.load(params
)
1088 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
)
1090 except ClientException
as inst
:
1095 if __name__
== '__main__':