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')
220 @click.option('--ns', default
=None, help='NS instance id or name to restrict the VNF list')
222 def vnf_list(ctx
, ns
):
223 ''' list all VNF instances'''
226 check_client_version(ctx
.obj
, '--ns')
227 resp
= ctx
.obj
.vnf
.list(ns
)
229 resp
= ctx
.obj
.vnf
.list()
230 except ClientException
as inst
:
233 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
234 if fullclassname
== 'osmclient.sol005.client.Client':
243 name
= vnfr
['name'] if 'name' in vnfr
else '-'
248 vnfr
['member-vnf-index-ref'],
255 'operational status',
258 if 'mgmt-interface' not in vnfr
:
259 vnfr
['mgmt-interface'] = {}
260 vnfr
['mgmt-interface']['ip-address'] = None
264 vnfr
['operational-status'],
265 vnfr
['config-status']])
269 @cli.command(name
='ns-op-list')
270 @click.argument('name')
272 def ns_op_list(ctx
, name
):
273 '''shows the history of operations over a NS instance
275 NAME: name or ID of the NS instance
278 check_client_version(ctx
.obj
, ctx
.command
.name
)
279 resp
= ctx
.obj
.ns
.list_op(name
)
280 except ClientException
as inst
:
284 table
= PrettyTable(['id', 'operation', 'status'])
286 table
.add_row([op
['id'], op
['lcmOperationType'],
287 op
['operationState']])
295 def nsd_show(ctx
, name
, literal
):
297 resp
= ctx
.obj
.nsd
.get(name
)
298 #resp = ctx.obj.nsd.get_individual(name)
299 except ClientException
as inst
:
304 print yaml
.safe_dump(resp
)
307 table
= PrettyTable(['field', 'value'])
308 for k
, v
in resp
.items():
309 table
.add_row([k
, json
.dumps(v
, indent
=2)])
314 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
315 @click.option('--literal', is_flag
=True,
316 help='print literally, no pretty table')
317 @click.argument('name')
319 def nsd_show1(ctx
, name
, literal
):
320 '''shows the content of a NSD
322 NAME: name or ID of the NSD/NSpkg
324 nsd_show(ctx
, name
, literal
)
327 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
328 @click.option('--literal', is_flag
=True,
329 help='print literally, no pretty table')
330 @click.argument('name')
332 def nsd_show2(ctx
, name
, literal
):
333 '''shows the content of a NSD
335 NAME: name or ID of the NSD/NSpkg
337 nsd_show(ctx
, name
, literal
)
340 def vnfd_show(ctx
, name
, literal
):
342 resp
= ctx
.obj
.vnfd
.get(name
)
343 #resp = ctx.obj.vnfd.get_individual(name)
344 except ClientException
as inst
:
349 print yaml
.safe_dump(resp
)
352 table
= PrettyTable(['field', 'value'])
353 for k
, v
in resp
.items():
354 table
.add_row([k
, json
.dumps(v
, indent
=2)])
359 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
360 @click.option('--literal', is_flag
=True,
361 help='print literally, no pretty table')
362 @click.argument('name')
364 def vnfd_show1(ctx
, name
, literal
):
365 '''shows the content of a VNFD
367 NAME: name or ID of the VNFD/VNFpkg
369 vnfd_show(ctx
, name
, literal
)
372 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
373 @click.option('--literal', is_flag
=True,
374 help='print literally, no pretty table')
375 @click.argument('name')
377 def vnfd_show2(ctx
, name
, literal
):
378 '''shows the content of a VNFD
380 NAME: name or ID of the VNFD/VNFpkg
382 vnfd_show(ctx
, name
, literal
)
385 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
386 @click.argument('name')
387 @click.option('--literal', is_flag
=True,
388 help='print literally, no pretty table')
389 @click.option('--filter', default
=None)
391 def ns_show(ctx
, name
, literal
, filter):
392 '''shows the info of a NS instance
394 NAME: name or ID of the NS instance
397 ns
= ctx
.obj
.ns
.get(name
)
398 except ClientException
as inst
:
403 print yaml
.safe_dump(resp
)
406 table
= PrettyTable(['field', 'value'])
408 for k
, v
in ns
.items():
409 if filter is None or filter in k
:
410 table
.add_row([k
, json
.dumps(v
, indent
=2)])
412 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
413 if fullclassname
!= 'osmclient.sol005.client.Client':
414 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
415 nsr_optdata
= nsopdata
['nsr:nsr']
416 for k
, v
in nsr_optdata
.items():
417 if filter is None or filter in k
:
418 table
.add_row([k
, json
.dumps(v
, indent
=2)])
423 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
424 @click.argument('name')
425 @click.option('--literal', is_flag
=True,
426 help='print literally, no pretty table')
427 @click.option('--filter', default
=None)
429 def vnf_show(ctx
, name
, literal
, filter):
430 '''shows the info of a VNF instance
432 NAME: name or ID of the VNF instance
435 check_client_version(ctx
.obj
, ctx
.command
.name
)
436 resp
= ctx
.obj
.vnf
.get(name
)
437 except ClientException
as inst
:
442 print yaml
.safe_dump(resp
)
445 table
= PrettyTable(['field', 'value'])
446 for k
, v
in resp
.items():
447 if filter is None or filter in k
:
448 table
.add_row([k
, json
.dumps(v
, indent
=2)])
453 @cli.command(name
='vnf-monitoring-show')
454 @click.argument('vnf_name')
456 def vnf_monitoring_show(ctx
, vnf_name
):
458 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
459 resp
= ctx
.obj
.vnf
.get_monitoring(vnf_name
)
460 except ClientException
as inst
:
464 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
470 monitor
['value-integer'],
476 @cli.command(name
='ns-monitoring-show')
477 @click.argument('ns_name')
479 def ns_monitoring_show(ctx
, ns_name
):
481 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
482 resp
= ctx
.obj
.ns
.get_monitoring(ns_name
)
483 except ClientException
as inst
:
487 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
488 for key
, val
in resp
.items():
493 monitor
['value-integer'],
498 @cli.command(name
='ns-op-show', short_help
='shows the info of an operation')
499 @click.argument('id')
500 @click.option('--filter', default
=None)
502 def ns_op_show(ctx
, id, filter):
503 '''shows the detailed info of an operation
505 ID: operation identifier
508 check_client_version(ctx
.obj
, ctx
.command
.name
)
509 op_info
= ctx
.obj
.ns
.get_op(id)
510 except ClientException
as inst
:
514 table
= PrettyTable(['field', 'value'])
515 for k
, v
in op_info
.items():
516 if filter is None or filter in k
:
517 table
.add_row([k
, json
.dumps(v
, indent
=2)])
526 def nsd_create(ctx
, filename
, overwrite
):
528 check_client_version(ctx
.obj
, ctx
.command
.name
)
529 ctx
.obj
.nsd
.create(filename
, overwrite
)
530 except ClientException
as inst
:
535 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
536 @click.argument('filename')
537 @click.option('--overwrite', default
=None,
538 help='overwrites some fields in NSD')
540 def nsd_create1(ctx
, filename
, overwrite
):
541 '''creates a new NSD/NSpkg
543 FILENAME: NSD yaml file or NSpkg tar.gz file
545 nsd_create(ctx
, filename
, overwrite
)
548 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
549 @click.argument('filename')
550 @click.option('--overwrite', default
=None,
551 help='overwrites some fields in NSD')
553 def nsd_create2(ctx
, filename
, overwrite
):
554 '''creates a new NSD/NSpkg
556 FILENAME: NSD yaml file or NSpkg tar.gz file
558 nsd_create(ctx
, filename
, overwrite
)
561 def vnfd_create(ctx
, filename
, overwrite
):
563 check_client_version(ctx
.obj
, ctx
.command
.name
)
564 ctx
.obj
.vnfd
.create(filename
, overwrite
)
565 except ClientException
as inst
:
570 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
571 @click.argument('filename')
572 @click.option('--overwrite', default
=None,
573 help='overwrites some fields in VNFD')
575 def vnfd_create1(ctx
, filename
, overwrite
):
576 '''creates a new VNFD/VNFpkg
578 FILENAME: VNFD yaml file or VNFpkg tar.gz file
580 vnfd_create(ctx
, filename
, overwrite
)
583 @cli.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
584 @click.argument('filename')
585 @click.option('--overwrite', default
=None,
586 help='overwrites some fields in VNFD')
588 def vnfd_create2(ctx
, filename
, overwrite
):
589 '''creates a new VNFD/VNFpkg
591 FILENAME: VNFD yaml file or VNFpkg tar.gz file
593 vnfd_create(ctx
, filename
, overwrite
)
596 @cli.command(name
='ns-create')
597 @click.option('--ns_name',
599 @click.option('--nsd_name',
601 @click.option('--vim_account',
603 @click.option('--admin_status',
605 help='administration status')
606 @click.option('--ssh_keys',
608 help='comma separated list of keys to inject to vnfs')
609 @click.option('--config',
611 help='ns specific yaml configuration:\nvnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
612 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]')
621 '''creates a new NS instance'''
624 # check_client_version(ctx.obj, '--config', 'v1')
631 except ClientException
as inst
:
640 def nsd_update(ctx
, name
, content
):
642 check_client_version(ctx
.obj
, ctx
.command
.name
)
643 ctx
.obj
.nsd
.update(name
, content
)
644 except ClientException
as inst
:
648 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
649 @click.argument('name')
650 @click.option('--content', default
=None,
651 help='filename with the NSD/NSpkg replacing the current one')
653 def nsd_update1(ctx
, name
, content
):
654 '''updates a NSD/NSpkg
656 NAME: name or ID of the NSD/NSpkg
658 nsd_update(ctx
, name
, content
)
661 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
662 @click.argument('name')
663 @click.option('--content', default
=None,
664 help='filename with the NSD/NSpkg replacing the current one')
666 def nsd_update2(ctx
, name
, content
):
667 '''updates a NSD/NSpkg
669 NAME: name or ID of the NSD/NSpkg
671 nsd_update(ctx
, name
, content
)
674 def vnfd_update(ctx
, name
, content
):
676 check_client_version(ctx
.obj
, ctx
.command
.name
)
677 ctx
.obj
.vnfd
.update(name
, content
)
678 except ClientException
as inst
:
683 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
684 @click.argument('name')
685 @click.option('--content', default
=None,
686 help='filename with the VNFD/VNFpkg replacing the current one')
688 def vnfd_update1(ctx
, name
, content
):
689 '''updates a VNFD/VNFpkg
691 NAME: name or ID of the VNFD/VNFpkg
693 vnfd_update(ctx
, name
, content
)
696 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
697 @click.argument('name')
698 @click.option('--content', default
=None,
699 help='filename with the VNFD/VNFpkg replacing the current one')
701 def vnfd_update2(ctx
, name
, content
):
702 '''updates a VNFD/VNFpkg
704 NAME: VNFD yaml file or VNFpkg tar.gz file
706 vnfd_update(ctx
, name
, content
)
713 def nsd_delete(ctx
, name
, force
):
716 ctx
.obj
.nsd
.delete(name
)
718 check_client_version(ctx
.obj
, '--force')
719 ctx
.obj
.nsd
.delete(name
, force
)
720 except ClientException
as inst
:
725 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
726 @click.argument('name')
727 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
729 def nsd_delete1(ctx
, name
, force
):
730 '''deletes a NSD/NSpkg
732 NAME: name or ID of the NSD/NSpkg to be deleted
734 nsd_delete(ctx
, name
, force
)
737 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
738 @click.argument('name')
739 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
741 def nsd_delete2(ctx
, name
, force
):
742 '''deletes a NSD/NSpkg
744 NAME: name or ID of the NSD/NSpkg to be deleted
746 nsd_delete(ctx
, name
, force
)
749 def vnfd_delete(ctx
, name
, force
):
752 ctx
.obj
.vnfd
.delete(name
)
754 check_client_version(ctx
.obj
, '--force')
755 ctx
.obj
.vnfd
.delete(name
, force
)
756 except ClientException
as inst
:
761 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
762 @click.argument('name')
763 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
765 def vnfd_delete1(ctx
, name
, force
):
766 '''deletes a VNFD/VNFpkg
768 NAME: name or ID of the VNFD/VNFpkg to be deleted
770 vnfd_delete(ctx
, name
, force
)
773 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
774 @click.argument('name')
775 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
777 def vnfd_delete2(ctx
, name
, force
):
778 '''deletes a VNFD/VNFpkg
780 NAME: name or ID of the VNFD/VNFpkg to be deleted
782 vnfd_delete(ctx
, name
, force
)
785 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
786 @click.argument('name')
787 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
789 def ns_delete(ctx
, name
, force
):
790 '''deletes a NS instance
792 NAME: name or ID of the NS instance to be deleted
796 ctx
.obj
.ns
.delete(name
)
798 check_client_version(ctx
.obj
, '--force')
799 ctx
.obj
.ns
.delete(name
, force
)
800 except ClientException
as inst
:
809 @cli.command(name
='vim-create')
810 @click.option('--name',
812 help='Name to create datacenter')
813 @click.option('--user',
816 @click.option('--password',
819 confirmation_prompt
=True,
821 @click.option('--auth_url',
824 @click.option('--tenant',
826 help='VIM tenant name')
827 @click.option('--config',
829 help='VIM specific config parameters')
830 @click.option('--account_type',
833 @click.option('--description',
834 default
='no description',
835 help='human readable description')
836 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
837 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
850 '''creates a new VIM account
854 check_client_version(ctx
.obj
, '--sdn_controller')
856 check_client_version(ctx
.obj
, '--sdn_port_mapping')
858 vim
['vim-username'] = user
859 vim
['vim-password'] = password
860 vim
['vim-url'] = auth_url
861 vim
['vim-tenant-name'] = tenant
862 vim
['vim-type'] = account_type
863 vim
['description'] = description
864 vim
['config'] = config
865 if sdn_controller
or sdn_port_mapping
:
866 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
)
868 ctx
.obj
.vim
.create(name
, vim
)
869 except ClientException
as inst
:
874 @cli.command(name
='vim-update', short_help
='updates a VIM account')
875 @click.argument('name')
876 @click.option('--newname', help='New name for the VIM account')
877 @click.option('--user', help='VIM username')
878 @click.option('--password', help='VIM password')
879 @click.option('--auth_url', help='VIM url')
880 @click.option('--tenant', help='VIM tenant name')
881 @click.option('--config', help='VIM specific config parameters')
882 @click.option('--account_type', help='VIM type')
883 @click.option('--description', help='human readable description')
884 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
885 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
899 '''updates a VIM account
901 NAME: name or ID of the VIM account
904 check_client_version(ctx
.obj
, ctx
.command
.name
)
906 if newname
: vim
['name'] = newname
907 if user
: vim
['vim_user'] = user
908 if password
: vim
['vim_password'] = password
909 if auth_url
: vim
['vim_url'] = auth_url
910 if tenant
: vim
['vim-tenant-name'] = tenant
911 if account_type
: vim
['vim_type'] = account_type
912 if description
: vim
['description'] = description
913 if config
: vim
['config'] = config
914 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
)
915 except ClientException
as inst
:
920 @cli.command(name
='vim-delete')
921 @click.argument('name')
922 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
924 def vim_delete(ctx
, name
, force
):
925 '''deletes a VIM account
927 NAME: name or ID of the VIM account to be deleted
931 ctx
.obj
.vim
.delete(name
)
933 check_client_version(ctx
.obj
, '--force')
934 ctx
.obj
.vim
.delete(name
, force
)
935 except ClientException
as inst
:
940 @cli.command(name
='vim-list')
941 @click.option('--ro_update/--no_ro_update',
943 help='update list from RO')
944 @click.option('--filter', default
=None,
945 help='restricts the list to the VIM accounts matching the filter')
947 def vim_list(ctx
, ro_update
, filter):
948 '''list all VIM accounts'''
950 check_client_version(ctx
.obj
, '--filter')
952 check_client_version(ctx
.obj
, '--ro_update', 'v1')
953 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
954 if fullclassname
== 'osmclient.sol005.client.Client':
955 resp
= ctx
.obj
.vim
.list(filter)
957 resp
= ctx
.obj
.vim
.list(ro_update
)
958 table
= PrettyTable(['vim name', 'uuid'])
960 table
.add_row([vim
['name'], vim
['uuid']])
965 @cli.command(name
='vim-show')
966 @click.argument('name')
968 def vim_show(ctx
, name
):
969 '''shows the details of a VIM account
971 NAME: name or ID of the VIM account
974 resp
= ctx
.obj
.vim
.get(name
)
975 if 'vim_password' in resp
:
976 resp
['vim_password']='********'
977 except ClientException
as inst
:
981 table
= PrettyTable(['key', 'attribute'])
982 for k
, v
in resp
.items():
983 table
.add_row([k
, json
.dumps(v
, indent
=2)])
989 # SDN controller operations
992 @cli.command(name
='sdnc-create')
993 @click.option('--name',
995 help='Name to create sdn controller')
996 @click.option('--type',
998 help='SDN controller type')
999 @click.option('--sdn_controller_version',
1000 help='SDN controller username')
1001 @click.option('--ip_address',
1003 help='SDN controller IP address')
1004 @click.option('--port',
1006 help='SDN controller port')
1007 @click.option('--switch_dpid',
1009 help='Switch DPID (Openflow Datapath ID)')
1010 @click.option('--user',
1011 help='SDN controller username')
1012 @click.option('--password',
1014 confirmation_prompt
=True,
1015 help='SDN controller password')
1016 #@click.option('--description',
1017 # default='no description',
1018 # help='human readable description')
1020 def sdnc_create(ctx
,
1023 sdn_controller_version
,
1029 '''creates a new SDN controller
1032 sdncontroller
['name'] = name
1033 sdncontroller
['type'] = type
1034 sdncontroller
['ip'] = ip_address
1035 sdncontroller
['port'] = int(port
)
1036 sdncontroller
['dpid'] = switch_dpid
1037 if sdn_controller_version
:
1038 sdncontroller
['version'] = sdn_controller_version
1040 sdncontroller
['user'] = user
1042 sdncontroller
['password'] = password
1043 # sdncontroller['description'] = description
1045 check_client_version(ctx
.obj
, ctx
.command
.name
)
1046 ctx
.obj
.sdnc
.create(name
, sdncontroller
)
1047 except ClientException
as inst
:
1051 @cli.command(name
='sdnc-update', short_help
='updates an SDN controller')
1052 @click.argument('name')
1053 @click.option('--newname', help='New name for the SDN controller')
1054 @click.option('--type', help='SDN controller type')
1055 @click.option('--sdn_controller_version', help='SDN controller username')
1056 @click.option('--ip_address', help='SDN controller IP address')
1057 @click.option('--port', help='SDN controller port')
1058 @click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)')
1059 @click.option('--user', help='SDN controller username')
1060 @click.option('--password', help='SDN controller password')
1061 #@click.option('--description', default=None, help='human readable description')
1063 def sdnc_update(ctx
,
1067 sdn_controller_version
,
1073 '''updates an SDN controller
1075 NAME: name or ID of the SDN controller
1078 if newname
: sdncontroller
['name'] = newname
1079 if type: sdncontroller
['type'] = type
1080 if ip_address
: sdncontroller
['ip'] = ip_address
1081 if port
: sdncontroller
['port'] = int(port
)
1082 if switch_dpid
: sdncontroller
['dpid'] = switch_dpid
1083 # sdncontroller['description'] = description
1084 if sdn_controller_version
is not None:
1085 if sdn_controller_version
=="":
1086 sdncontroller
['version'] = None
1088 sdncontroller
['version'] = sdn_controller_version
1089 if user
is not None:
1091 sdncontroller
['user'] = None
1093 sdncontroller
['user'] = user
1094 if password
is not None:
1096 sdncontroller
['password'] = None
1098 sdncontroller
['password'] = user
1100 check_client_version(ctx
.obj
, ctx
.command
.name
)
1101 ctx
.obj
.sdnc
.update(name
, sdncontroller
)
1102 except ClientException
as inst
:
1107 @cli.command(name
='sdnc-delete')
1108 @click.argument('name')
1109 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1111 def sdnc_delete(ctx
, name
, force
):
1112 '''deletes an SDN controller
1114 NAME: name or ID of the SDN controller to be deleted
1117 check_client_version(ctx
.obj
, ctx
.command
.name
)
1118 ctx
.obj
.sdnc
.delete(name
, force
)
1119 except ClientException
as inst
:
1124 @cli.command(name
='sdnc-list')
1125 @click.option('--filter', default
=None,
1126 help='restricts the list to the SDN controllers matching the filter')
1128 def sdnc_list(ctx
, filter):
1129 '''list all SDN controllers'''
1131 check_client_version(ctx
.obj
, ctx
.command
.name
)
1132 resp
= ctx
.obj
.sdnc
.list(filter)
1133 except ClientException
as inst
:
1136 table
= PrettyTable(['name', 'id'])
1138 table
.add_row([sdnc
['name'], sdnc
['_id']])
1143 @cli.command(name
='sdnc-show')
1144 @click.argument('name')
1146 def sdnc_show(ctx
, name
):
1147 '''shows the details of an SDN controller
1149 NAME: name or ID of the SDN controller
1152 check_client_version(ctx
.obj
, ctx
.command
.name
)
1153 resp
= ctx
.obj
.sdnc
.get(name
)
1154 except ClientException
as inst
:
1158 table
= PrettyTable(['key', 'attribute'])
1159 for k
, v
in resp
.items():
1160 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1165 ####################
1166 # Fault Management operations
1167 ####################
1169 @cli.command(name
='ns-alarm-create')
1170 @click.argument('name')
1171 @click.option('--ns', prompt
=True, help='NS instance id or name')
1172 @click.option('--vnf', prompt
=True,
1173 help='VNF name (VNF member index as declared in the NSD)')
1174 @click.option('--vdu', prompt
=True,
1175 help='VDU name (VDU name as declared in the VNFD)')
1176 @click.option('--metric', prompt
=True,
1177 help='Name of the metric (e.g. cpu_utilization)')
1178 @click.option('--severity', default
='WARNING',
1179 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
1180 @click.option('--threshold_value', prompt
=True,
1181 help='threshold value that, when crossed, an alarm is triggered')
1182 @click.option('--threshold_operator', prompt
=True,
1183 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
1184 @click.option('--statistic', default
='AVERAGE',
1185 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
1187 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
1188 threshold_value
, threshold_operator
, statistic
):
1189 '''creates a new alarm for a NS instance'''
1190 ns_instance
= ctx
.obj
.ns
.get(ns
)
1192 alarm
['alarm_name'] = name
1193 alarm
['ns_id'] = ns_instance
['_id']
1194 alarm
['correlation_id'] = ns_instance
['_id']
1195 alarm
['vnf_member_index'] = vnf
1196 alarm
['vdu_name'] = vdu
1197 alarm
['metric_name'] = metric
1198 alarm
['severity'] = severity
1199 alarm
['threshold_value'] = int(threshold_value
)
1200 alarm
['operation'] = threshold_operator
1201 alarm
['statistic'] = statistic
1203 check_client_version(ctx
.obj
, ctx
.command
.name
)
1204 ctx
.obj
.ns
.create_alarm(alarm
)
1205 except ClientException
as inst
:
1210 #@cli.command(name='ns-alarm-delete')
1211 #@click.argument('name')
1212 #@click.pass_context
1213 #def ns_alarm_delete(ctx, name):
1214 # '''deletes an alarm
1216 # NAME: name of the alarm to be deleted
1219 # check_client_version(ctx.obj, ctx.command.name)
1220 # ctx.obj.ns.delete_alarm(name)
1221 # except ClientException as inst:
1222 # print(inst.message)
1226 ####################
1227 # Performance Management operations
1228 ####################
1230 @cli.command(name
='ns-metric-export')
1231 @click.option('--ns', prompt
=True, help='NS instance id or name')
1232 @click.option('--vnf', prompt
=True,
1233 help='VNF name (VNF member index as declared in the NSD)')
1234 @click.option('--vdu', prompt
=True,
1235 help='VDU name (VDU name as declared in the VNFD)')
1236 @click.option('--metric', prompt
=True,
1237 help='name of the metric (e.g. cpu_utilization)')
1238 #@click.option('--period', default='1w',
1239 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
1240 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
1242 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
1243 '''exports a metric to the internal OSM bus, which can be read by other apps
1245 ns_instance
= ctx
.obj
.ns
.get(ns
)
1247 metric_data
['ns_id'] = ns_instance
['_id']
1248 metric_data
['correlation_id'] = ns_instance
['_id']
1249 metric_data
['vnf_member_index'] = vnf
1250 metric_data
['vdu_name'] = vdu
1251 metric_data
['metric_name'] = metric
1252 metric_data
['collection_unit'] = 'WEEK'
1253 metric_data
['collection_period'] = 1
1255 check_client_version(ctx
.obj
, ctx
.command
.name
)
1257 print '{}'.format(ctx
.obj
.ns
.export_metric(metric_data
))
1261 print '{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
)
1262 time
.sleep(int(interval
))
1264 except ClientException
as inst
:
1269 ####################
1271 ####################
1273 @cli.command(name
='upload-package')
1274 @click.argument('filename')
1276 def upload_package(ctx
, filename
):
1277 '''uploads a VNF package or NS package
1279 FILENAME: VNF or NS package file (tar.gz)
1282 ctx
.obj
.package
.upload(filename
)
1283 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1284 if fullclassname
!= 'osmclient.sol005.client.Client':
1285 ctx
.obj
.package
.wait_for_upload(filename
)
1286 except ClientException
as inst
:
1291 @cli.command(name
='ns-scaling-show')
1292 @click.argument('ns_name')
1294 def show_ns_scaling(ctx
, ns_name
):
1295 '''shows the status of a NS scaling operation
1297 NS_NAME: name of the NS instance being scaled
1300 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1301 resp
= ctx
.obj
.ns
.list()
1302 except ClientException
as inst
:
1306 table
= PrettyTable(
1309 'operational status',
1314 if ns_name
== ns
['name']:
1315 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
1316 scaling_records
= nsopdata
['nsr:nsr']['scaling-group-record']
1317 for record
in scaling_records
:
1318 if 'instance' in record
:
1319 instances
= record
['instance']
1320 for inst
in instances
:
1322 [record
['scaling-group-name-ref'],
1323 inst
['instance-id'],
1325 time
.strftime('%Y-%m-%d %H:%M:%S',
1327 inst
['create-time'])),
1333 @cli.command(name
='ns-scale')
1334 @click.argument('ns_name')
1335 @click.option('--ns_scale_group', prompt
=True)
1336 @click.option('--index', prompt
=True)
1338 def ns_scale(ctx
, ns_name
, ns_scale_group
, index
):
1341 NS_NAME: name of the NS instance to be scaled
1344 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1345 ctx
.obj
.ns
.scale(ns_name
, ns_scale_group
, index
)
1346 except ClientException
as inst
:
1351 @cli.command(name
='config-agent-list')
1353 def config_agent_list(ctx
):
1354 '''list config agents'''
1356 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1357 except ClientException
as inst
:
1360 table
= PrettyTable(['name', 'account-type', 'details'])
1361 for account
in ctx
.obj
.vca
.list():
1364 account
['account-type'],
1370 @cli.command(name
='config-agent-delete')
1371 @click.argument('name')
1373 def config_agent_delete(ctx
, name
):
1374 '''deletes a config agent
1376 NAME: name of the config agent to be deleted
1379 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1380 ctx
.obj
.vca
.delete(name
)
1381 except ClientException
as inst
:
1386 @cli.command(name
='config-agent-add')
1387 @click.option('--name',
1389 @click.option('--account_type',
1391 @click.option('--server',
1393 @click.option('--user',
1395 @click.option('--secret',
1398 confirmation_prompt
=True)
1400 def config_agent_add(ctx
, name
, account_type
, server
, user
, secret
):
1401 '''adds a config agent'''
1403 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1404 ctx
.obj
.vca
.create(name
, account_type
, server
, user
, secret
)
1405 except ClientException
as inst
:
1409 @cli.command(name
='ro-dump')
1412 '''shows RO agent information'''
1413 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1414 resp
= ctx
.obj
.vim
.get_resource_orchestrator()
1415 table
= PrettyTable(['key', 'attribute'])
1416 for k
, v
in resp
.items():
1417 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1422 @cli.command(name
='vcs-list')
1425 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1426 resp
= ctx
.obj
.utils
.get_vcs_info()
1427 table
= PrettyTable(['component name', 'state'])
1428 for component
in resp
:
1429 table
.add_row([component
['component_name'], component
['state']])
1434 @cli.command(name
='ns-action')
1435 @click.argument('ns_name')
1436 @click.option('--vnf_name', default
=None)
1437 @click.option('--action_name', prompt
=True)
1438 @click.option('--params', prompt
=True)
1445 '''executes an action/primitive over a NS instance
1447 NS_NAME: name or ID of the NS instance
1450 check_client_version(ctx
.obj
, ctx
.command
.name
)
1453 op_data
['vnf_member_index'] = vnf_name
1454 op_data
['primitive'] = action_name
1455 op_data
['primitive_params'] = yaml
.load(params
)
1456 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
)
1458 except ClientException
as inst
:
1463 if __name__
== '__main__':