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
:
236 'operational status',
239 if 'mgmt-interface' not in vnfr
:
240 vnfr
['mgmt-interface'] = {}
241 vnfr
['mgmt-interface']['ip-address'] = None
245 vnfr
['operational-status'],
246 vnfr
['config-status']])
250 @cli.command(name
='ns-op-list')
251 @click.argument('name')
253 def ns_op_list(ctx
, name
):
254 '''shows the history of operations over a NS instance
256 NAME: name or ID of the NS instance
259 check_client_version(ctx
.obj
, ctx
.command
.name
)
260 resp
= ctx
.obj
.ns
.list_op(name
)
261 except ClientException
as inst
:
265 table
= PrettyTable(['id', 'operation', 'status'])
267 table
.add_row([op
['id'], op
['lcmOperationType'],
268 op
['operationState']])
276 def nsd_show(ctx
, name
, literal
):
278 resp
= ctx
.obj
.nsd
.get(name
)
279 #resp = ctx.obj.nsd.get_individual(name)
280 except ClientException
as inst
:
285 print yaml
.safe_dump(resp
)
288 table
= PrettyTable(['field', 'value'])
289 for k
, v
in resp
.items():
290 table
.add_row([k
, json
.dumps(v
, indent
=2)])
295 @cli.command(name
='nsd-show', short_help
='shows the content of a NSD')
296 @click.option('--literal', is_flag
=True,
297 help='print literally, no pretty table')
298 @click.argument('name')
300 def nsd_show1(ctx
, name
, literal
):
301 '''shows the content of a NSD
303 NAME: name or ID of the NSD/NSpkg
305 nsd_show(ctx
, name
, literal
)
308 @cli.command(name
='nspkg-show', short_help
='shows the content of a NSD')
309 @click.option('--literal', is_flag
=True,
310 help='print literally, no pretty table')
311 @click.argument('name')
313 def nsd_show2(ctx
, name
, literal
):
314 '''shows the content of a NSD
316 NAME: name or ID of the NSD/NSpkg
318 nsd_show(ctx
, name
, literal
)
321 def vnfd_show(ctx
, name
, literal
):
323 resp
= ctx
.obj
.vnfd
.get(name
)
324 #resp = ctx.obj.vnfd.get_individual(name)
325 except ClientException
as inst
:
330 print yaml
.safe_dump(resp
)
333 table
= PrettyTable(['field', 'value'])
334 for k
, v
in resp
.items():
335 table
.add_row([k
, json
.dumps(v
, indent
=2)])
340 @cli.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
341 @click.option('--literal', is_flag
=True,
342 help='print literally, no pretty table')
343 @click.argument('name')
345 def vnfd_show1(ctx
, name
, literal
):
346 '''shows the content of a VNFD
348 NAME: name or ID of the VNFD/VNFpkg
350 vnfd_show(ctx
, name
, literal
)
353 @cli.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
354 @click.option('--literal', is_flag
=True,
355 help='print literally, no pretty table')
356 @click.argument('name')
358 def vnfd_show2(ctx
, name
, literal
):
359 '''shows the content of a VNFD
361 NAME: name or ID of the VNFD/VNFpkg
363 vnfd_show(ctx
, name
, literal
)
366 @cli.command(name
='ns-show', short_help
='shows the info of a NS instance')
367 @click.argument('name')
368 @click.option('--literal', is_flag
=True,
369 help='print literally, no pretty table')
370 @click.option('--filter', default
=None)
372 def ns_show(ctx
, name
, literal
, filter):
373 '''shows the info of a NS instance
375 NAME: name or ID of the NS instance
378 ns
= ctx
.obj
.ns
.get(name
)
379 except ClientException
as inst
:
384 print yaml
.safe_dump(resp
)
387 table
= PrettyTable(['field', 'value'])
389 for k
, v
in ns
.items():
390 if filter is None or filter in k
:
391 table
.add_row([k
, json
.dumps(v
, indent
=2)])
393 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
394 if fullclassname
!= 'osmclient.sol005.client.Client':
395 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
396 nsr_optdata
= nsopdata
['nsr:nsr']
397 for k
, v
in nsr_optdata
.items():
398 if filter is None or filter in k
:
399 table
.add_row([k
, json
.dumps(v
, indent
=2)])
404 @cli.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
405 @click.argument('name')
406 @click.option('--literal', is_flag
=True,
407 help='print literally, no pretty table')
408 @click.option('--filter', default
=None)
410 def vnf_show(ctx
, name
, literal
, filter):
411 '''shows the info of a VNF instance
413 NAME: name or ID of the VNF instance
416 check_client_version(ctx
.obj
, ctx
.command
.name
)
417 resp
= ctx
.obj
.vnf
.get(name
)
418 except ClientException
as inst
:
423 print yaml
.safe_dump(resp
)
426 table
= PrettyTable(['field', 'value'])
427 for k
, v
in resp
.items():
428 if filter is None or filter in k
:
429 table
.add_row([k
, json
.dumps(v
, indent
=2)])
434 @cli.command(name
='vnf-monitoring-show')
435 @click.argument('vnf_name')
437 def vnf_monitoring_show(ctx
, vnf_name
):
439 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
440 resp
= ctx
.obj
.vnf
.get_monitoring(vnf_name
)
441 except ClientException
as inst
:
445 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
451 monitor
['value-integer'],
457 @cli.command(name
='ns-monitoring-show')
458 @click.argument('ns_name')
460 def ns_monitoring_show(ctx
, ns_name
):
462 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
463 resp
= ctx
.obj
.ns
.get_monitoring(ns_name
)
464 except ClientException
as inst
:
468 table
= PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
469 for key
, val
in resp
.items():
474 monitor
['value-integer'],
479 @cli.command(name
='ns-op-show', short_help
='shows the info of an operation')
480 @click.argument('id')
481 @click.option('--filter', default
=None)
483 def ns_op_show(ctx
, id, filter):
484 '''shows the detailed info of an operation
486 ID: operation identifier
489 check_client_version(ctx
.obj
, ctx
.command
.name
)
490 op_info
= ctx
.obj
.ns
.get_op(id)
491 except ClientException
as inst
:
495 table
= PrettyTable(['field', 'value'])
496 for k
, v
in op_info
.items():
497 if filter is None or filter in k
:
498 table
.add_row([k
, json
.dumps(v
, indent
=2)])
507 def nsd_create(ctx
, filename
, overwrite
):
509 check_client_version(ctx
.obj
, ctx
.command
.name
)
510 ctx
.obj
.nsd
.create(filename
, overwrite
)
511 except ClientException
as inst
:
516 @cli.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
517 @click.argument('filename')
518 @click.option('--overwrite', default
=None,
519 help='overwrites some fields in NSD')
521 def nsd_create1(ctx
, filename
, overwrite
):
522 '''creates a new NSD/NSpkg
524 FILENAME: NSD yaml file or NSpkg tar.gz file
526 nsd_create(ctx
, filename
, overwrite
)
529 @cli.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
530 @click.argument('filename')
531 @click.option('--overwrite', default
=None,
532 help='overwrites some fields in NSD')
534 def nsd_create2(ctx
, filename
, overwrite
):
535 '''creates a new NSD/NSpkg
537 FILENAME: NSD yaml file or NSpkg tar.gz file
539 nsd_create(ctx
, filename
, overwrite
)
542 def vnfd_create(ctx
, filename
, overwrite
):
544 check_client_version(ctx
.obj
, ctx
.command
.name
)
545 ctx
.obj
.vnfd
.create(filename
, overwrite
)
546 except ClientException
as inst
:
551 @cli.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
552 @click.argument('filename')
553 @click.option('--overwrite', default
=None,
554 help='overwrites some fields in VNFD')
556 def vnfd_create1(ctx
, filename
, overwrite
):
557 '''creates a new VNFD/VNFpkg
559 FILENAME: VNFD yaml file or VNFpkg tar.gz file
561 vnfd_create(ctx
, filename
, overwrite
)
564 @cli.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
565 @click.argument('filename')
566 @click.option('--overwrite', default
=None,
567 help='overwrites some fields in VNFD')
569 def vnfd_create2(ctx
, filename
, overwrite
):
570 '''creates a new VNFD/VNFpkg
572 FILENAME: VNFD yaml file or VNFpkg tar.gz file
574 vnfd_create(ctx
, filename
, overwrite
)
577 @cli.command(name
='ns-create')
578 @click.option('--ns_name',
580 @click.option('--nsd_name',
582 @click.option('--vim_account',
584 @click.option('--admin_status',
586 help='administration status')
587 @click.option('--ssh_keys',
589 help='comma separated list of keys to inject to vnfs')
590 @click.option('--config',
592 help='ns specific yaml configuration:\nvnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
593 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]')
602 '''creates a new NS instance'''
605 # check_client_version(ctx.obj, '--config', 'v1')
612 except ClientException
as inst
:
621 def nsd_update(ctx
, name
, content
):
623 check_client_version(ctx
.obj
, ctx
.command
.name
)
624 ctx
.obj
.nsd
.update(name
, content
)
625 except ClientException
as inst
:
629 @cli.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
630 @click.argument('name')
631 @click.option('--content', default
=None,
632 help='filename with the NSD/NSpkg replacing the current one')
634 def nsd_update1(ctx
, name
, content
):
635 '''updates a NSD/NSpkg
637 NAME: name or ID of the NSD/NSpkg
639 nsd_update(ctx
, name
, content
)
642 @cli.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
643 @click.argument('name')
644 @click.option('--content', default
=None,
645 help='filename with the NSD/NSpkg replacing the current one')
647 def nsd_update2(ctx
, name
, content
):
648 '''updates a NSD/NSpkg
650 NAME: name or ID of the NSD/NSpkg
652 nsd_update(ctx
, name
, content
)
655 def vnfd_update(ctx
, name
, content
):
657 check_client_version(ctx
.obj
, ctx
.command
.name
)
658 ctx
.obj
.vnfd
.update(name
, content
)
659 except ClientException
as inst
:
664 @cli.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
665 @click.argument('name')
666 @click.option('--content', default
=None,
667 help='filename with the VNFD/VNFpkg replacing the current one')
669 def vnfd_update1(ctx
, name
, content
):
670 '''updates a VNFD/VNFpkg
672 NAME: name or ID of the VNFD/VNFpkg
674 vnfd_update(ctx
, name
, content
)
677 @cli.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
678 @click.argument('name')
679 @click.option('--content', default
=None,
680 help='filename with the VNFD/VNFpkg replacing the current one')
682 def vnfd_update2(ctx
, name
, content
):
683 '''updates a VNFD/VNFpkg
685 NAME: VNFD yaml file or VNFpkg tar.gz file
687 vnfd_update(ctx
, name
, content
)
694 def nsd_delete(ctx
, name
, force
):
697 ctx
.obj
.nsd
.delete(name
)
699 check_client_version(ctx
.obj
, '--force')
700 ctx
.obj
.nsd
.delete(name
, force
)
701 except ClientException
as inst
:
706 @cli.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
707 @click.argument('name')
708 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
710 def nsd_delete1(ctx
, name
, force
):
711 '''deletes a NSD/NSpkg
713 NAME: name or ID of the NSD/NSpkg to be deleted
715 nsd_delete(ctx
, name
, force
)
718 @cli.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
719 @click.argument('name')
720 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
722 def nsd_delete2(ctx
, name
, force
):
723 '''deletes a NSD/NSpkg
725 NAME: name or ID of the NSD/NSpkg to be deleted
727 nsd_delete(ctx
, name
, force
)
730 def vnfd_delete(ctx
, name
, force
):
733 ctx
.obj
.vnfd
.delete(name
)
735 check_client_version(ctx
.obj
, '--force')
736 ctx
.obj
.vnfd
.delete(name
, force
)
737 except ClientException
as inst
:
742 @cli.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
743 @click.argument('name')
744 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
746 def vnfd_delete1(ctx
, name
, force
):
747 '''deletes a VNFD/VNFpkg
749 NAME: name or ID of the VNFD/VNFpkg to be deleted
751 vnfd_delete(ctx
, name
, force
)
754 @cli.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
755 @click.argument('name')
756 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
758 def vnfd_delete2(ctx
, name
, force
):
759 '''deletes a VNFD/VNFpkg
761 NAME: name or ID of the VNFD/VNFpkg to be deleted
763 vnfd_delete(ctx
, name
, force
)
766 @cli.command(name
='ns-delete', short_help
='deletes a NS instance')
767 @click.argument('name')
768 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
770 def ns_delete(ctx
, name
, force
):
771 '''deletes a NS instance
773 NAME: name or ID of the NS instance to be deleted
777 ctx
.obj
.ns
.delete(name
)
779 check_client_version(ctx
.obj
, '--force')
780 ctx
.obj
.ns
.delete(name
, force
)
781 except ClientException
as inst
:
790 @cli.command(name
='vim-create')
791 @click.option('--name',
793 help='Name to create datacenter')
794 @click.option('--user',
797 @click.option('--password',
800 confirmation_prompt
=True,
802 @click.option('--auth_url',
805 @click.option('--tenant',
807 help='VIM tenant name')
808 @click.option('--config',
810 help='VIM specific config parameters')
811 @click.option('--account_type',
814 @click.option('--description',
815 default
='no description',
816 help='human readable description')
817 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
818 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
831 '''creates a new VIM account
835 check_client_version(ctx
.obj
, '--sdn_controller')
837 check_client_version(ctx
.obj
, '--sdn_port_mapping')
839 vim
['vim-username'] = user
840 vim
['vim-password'] = password
841 vim
['vim-url'] = auth_url
842 vim
['vim-tenant-name'] = tenant
843 vim
['vim-type'] = account_type
844 vim
['description'] = description
845 vim
['config'] = config
846 if sdn_controller
or sdn_port_mapping
:
847 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
)
849 ctx
.obj
.vim
.create(name
, vim
)
850 except ClientException
as inst
:
855 @cli.command(name
='vim-update', short_help
='updates a VIM account')
856 @click.argument('name')
857 @click.option('--newname', help='New name for the VIM account')
858 @click.option('--user', help='VIM username')
859 @click.option('--password', help='VIM password')
860 @click.option('--auth_url', help='VIM url')
861 @click.option('--tenant', help='VIM tenant name')
862 @click.option('--config', help='VIM specific config parameters')
863 @click.option('--account_type', help='VIM type')
864 @click.option('--description', help='human readable description')
865 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
866 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
880 '''updates a VIM account
882 NAME: name or ID of the VIM account
885 check_client_version(ctx
.obj
, ctx
.command
.name
)
887 if newname
: vim
['name'] = newname
888 if user
: vim
['vim_user'] = user
889 if password
: vim
['vim_password'] = password
890 if auth_url
: vim
['vim_url'] = auth_url
891 if tenant
: vim
['vim-tenant-name'] = tenant
892 if account_type
: vim
['vim_type'] = account_type
893 if description
: vim
['description'] = description
894 if config
: vim
['config'] = config
895 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
)
896 except ClientException
as inst
:
901 @cli.command(name
='vim-delete')
902 @click.argument('name')
903 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
905 def vim_delete(ctx
, name
, force
):
906 '''deletes a VIM account
908 NAME: name or ID of the VIM account to be deleted
912 ctx
.obj
.vim
.delete(name
)
914 check_client_version(ctx
.obj
, '--force')
915 ctx
.obj
.vim
.delete(name
, force
)
916 except ClientException
as inst
:
921 @cli.command(name
='vim-list')
922 @click.option('--ro_update/--no_ro_update',
924 help='update list from RO')
925 @click.option('--filter', default
=None,
926 help='restricts the list to the VIM accounts matching the filter')
928 def vim_list(ctx
, ro_update
, filter):
929 '''list all VIM accounts'''
931 check_client_version(ctx
.obj
, '--filter')
933 check_client_version(ctx
.obj
, '--ro_update', 'v1')
934 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
935 if fullclassname
== 'osmclient.sol005.client.Client':
936 resp
= ctx
.obj
.vim
.list(filter)
938 resp
= ctx
.obj
.vim
.list(ro_update
)
939 table
= PrettyTable(['vim name', 'uuid'])
941 table
.add_row([vim
['name'], vim
['uuid']])
946 @cli.command(name
='vim-show')
947 @click.argument('name')
949 def vim_show(ctx
, name
):
950 '''shows the details of a VIM account
952 NAME: name or ID of the VIM account
955 resp
= ctx
.obj
.vim
.get(name
)
956 if 'vim_password' in resp
:
957 resp
['vim_password']='********'
958 except ClientException
as inst
:
962 table
= PrettyTable(['key', 'attribute'])
963 for k
, v
in resp
.items():
964 table
.add_row([k
, json
.dumps(v
, indent
=2)])
970 # SDN controller operations
973 @cli.command(name
='sdnc-create')
974 @click.option('--name',
976 help='Name to create sdn controller')
977 @click.option('--type',
979 help='SDN controller type')
980 @click.option('--sdn_controller_version',
981 help='SDN controller username')
982 @click.option('--ip_address',
984 help='SDN controller IP address')
985 @click.option('--port',
987 help='SDN controller port')
988 @click.option('--switch_dpid',
990 help='Switch DPID (Openflow Datapath ID)')
991 @click.option('--user',
992 help='SDN controller username')
993 @click.option('--password',
995 confirmation_prompt
=True,
996 help='SDN controller password')
997 #@click.option('--description',
998 # default='no description',
999 # help='human readable description')
1001 def sdnc_create(ctx
,
1004 sdn_controller_version
,
1010 '''creates a new SDN controller
1013 sdncontroller
['name'] = name
1014 sdncontroller
['type'] = type
1015 sdncontroller
['ip'] = ip_address
1016 sdncontroller
['port'] = int(port
)
1017 sdncontroller
['dpid'] = switch_dpid
1018 if sdn_controller_version
:
1019 sdncontroller
['version'] = sdn_controller_version
1021 sdncontroller
['user'] = user
1023 sdncontroller
['password'] = password
1024 # sdncontroller['description'] = description
1026 check_client_version(ctx
.obj
, ctx
.command
.name
)
1027 ctx
.obj
.sdnc
.create(name
, sdncontroller
)
1028 except ClientException
as inst
:
1032 @cli.command(name
='sdnc-update', short_help
='updates an SDN controller')
1033 @click.argument('name')
1034 @click.option('--newname', help='New name for the SDN controller')
1035 @click.option('--type', help='SDN controller type')
1036 @click.option('--sdn_controller_version', help='SDN controller username')
1037 @click.option('--ip_address', help='SDN controller IP address')
1038 @click.option('--port', help='SDN controller port')
1039 @click.option('--switch_dpid', help='Switch DPID (Openflow Datapath ID)')
1040 @click.option('--user', help='SDN controller username')
1041 @click.option('--password', help='SDN controller password')
1042 #@click.option('--description', default=None, help='human readable description')
1044 def sdnc_update(ctx
,
1048 sdn_controller_version
,
1054 '''updates an SDN controller
1056 NAME: name or ID of the SDN controller
1059 if newname
: sdncontroller
['name'] = newname
1060 if type: sdncontroller
['type'] = type
1061 if ip_address
: sdncontroller
['ip'] = ip_address
1062 if port
: sdncontroller
['port'] = int(port
)
1063 if switch_dpid
: sdncontroller
['dpid'] = switch_dpid
1064 # sdncontroller['description'] = description
1065 if sdn_controller_version
is not None:
1066 if sdn_controller_version
=="":
1067 sdncontroller
['version'] = None
1069 sdncontroller
['version'] = sdn_controller_version
1070 if user
is not None:
1072 sdncontroller
['user'] = None
1074 sdncontroller
['user'] = user
1075 if password
is not None:
1077 sdncontroller
['password'] = None
1079 sdncontroller
['password'] = user
1081 check_client_version(ctx
.obj
, ctx
.command
.name
)
1082 ctx
.obj
.sdnc
.update(name
, sdncontroller
)
1083 except ClientException
as inst
:
1088 @cli.command(name
='sdnc-delete')
1089 @click.argument('name')
1090 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1092 def sdnc_delete(ctx
, name
, force
):
1093 '''deletes an SDN controller
1095 NAME: name or ID of the SDN controller to be deleted
1098 check_client_version(ctx
.obj
, ctx
.command
.name
)
1099 ctx
.obj
.sdnc
.delete(name
, force
)
1100 except ClientException
as inst
:
1105 @cli.command(name
='sdnc-list')
1106 @click.option('--filter', default
=None,
1107 help='restricts the list to the SDN controllers matching the filter')
1109 def sdnc_list(ctx
, filter):
1110 '''list all SDN controllers'''
1112 check_client_version(ctx
.obj
, ctx
.command
.name
)
1113 resp
= ctx
.obj
.sdnc
.list(filter)
1114 except ClientException
as inst
:
1117 table
= PrettyTable(['name', 'id'])
1119 table
.add_row([sdnc
['name'], sdnc
['_id']])
1124 @cli.command(name
='sdnc-show')
1125 @click.argument('name')
1127 def sdnc_show(ctx
, name
):
1128 '''shows the details of an SDN controller
1130 NAME: name or ID of the SDN controller
1133 check_client_version(ctx
.obj
, ctx
.command
.name
)
1134 resp
= ctx
.obj
.sdnc
.get(name
)
1135 except ClientException
as inst
:
1139 table
= PrettyTable(['key', 'attribute'])
1140 for k
, v
in resp
.items():
1141 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1146 ####################
1147 # Fault Management operations
1148 ####################
1150 @cli.command(name
='ns-alarm-create')
1151 @click.argument('name')
1152 @click.option('--ns', prompt
=True, help='NS instance id or name')
1153 @click.option('--vnf', prompt
=True,
1154 help='VNF name (VNF member index as declared in the NSD)')
1155 @click.option('--vdu', prompt
=True,
1156 help='VDU name (VDU name as declared in the VNFD)')
1157 @click.option('--metric', prompt
=True,
1158 help='Name of the metric (e.g. cpu_utilization)')
1159 @click.option('--severity', default
='WARNING',
1160 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
1161 @click.option('--threshold_value', prompt
=True,
1162 help='threshold value that, when crossed, an alarm is triggered')
1163 @click.option('--threshold_operator', prompt
=True,
1164 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
1165 @click.option('--statistic', default
='AVERAGE',
1166 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
1168 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
1169 threshold_value
, threshold_operator
, statistic
):
1170 '''creates a new alarm for a NS instance'''
1171 ns_instance
= ctx
.obj
.ns
.get(ns
)
1173 alarm
['alarm_name'] = name
1174 alarm
['ns_id'] = ns_instance
['_id']
1175 alarm
['correlation_id'] = ns_instance
['_id']
1176 alarm
['vnf_member_index'] = vnf
1177 alarm
['vdu_name'] = vdu
1178 alarm
['metric_name'] = metric
1179 alarm
['severity'] = severity
1180 alarm
['threshold_value'] = int(threshold_value
)
1181 alarm
['operation'] = threshold_operator
1182 alarm
['statistic'] = statistic
1184 check_client_version(ctx
.obj
, ctx
.command
.name
)
1185 ctx
.obj
.ns
.create_alarm(alarm
)
1186 except ClientException
as inst
:
1191 #@cli.command(name='ns-alarm-delete')
1192 #@click.argument('name')
1193 #@click.pass_context
1194 #def ns_alarm_delete(ctx, name):
1195 # '''deletes an alarm
1197 # NAME: name of the alarm to be deleted
1200 # check_client_version(ctx.obj, ctx.command.name)
1201 # ctx.obj.ns.delete_alarm(name)
1202 # except ClientException as inst:
1203 # print(inst.message)
1207 ####################
1208 # Performance Management operations
1209 ####################
1211 @cli.command(name
='ns-metric-export')
1212 @click.option('--ns', prompt
=True, help='NS instance id or name')
1213 @click.option('--vnf', prompt
=True,
1214 help='VNF name (VNF member index as declared in the NSD)')
1215 @click.option('--vdu', prompt
=True,
1216 help='VDU name (VDU name as declared in the VNFD)')
1217 @click.option('--metric', prompt
=True,
1218 help='name of the metric (e.g. cpu_utilization)')
1219 #@click.option('--period', default='1w',
1220 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
1221 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
1223 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
1224 '''exports a metric to the internal OSM bus, which can be read by other apps
1226 ns_instance
= ctx
.obj
.ns
.get(ns
)
1228 metric_data
['ns_id'] = ns_instance
['_id']
1229 metric_data
['correlation_id'] = ns_instance
['_id']
1230 metric_data
['vnf_member_index'] = vnf
1231 metric_data
['vdu_name'] = vdu
1232 metric_data
['metric_name'] = metric
1233 metric_data
['collection_unit'] = 'WEEK'
1234 metric_data
['collection_period'] = 1
1236 check_client_version(ctx
.obj
, ctx
.command
.name
)
1238 print '{}'.format(ctx
.obj
.ns
.export_metric(metric_data
))
1242 print '{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
)
1243 time
.sleep(int(interval
))
1245 except ClientException
as inst
:
1250 ####################
1252 ####################
1254 @cli.command(name
='upload-package')
1255 @click.argument('filename')
1257 def upload_package(ctx
, filename
):
1258 '''uploads a VNF package or NS package
1260 FILENAME: VNF or NS package file (tar.gz)
1263 ctx
.obj
.package
.upload(filename
)
1264 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1265 if fullclassname
!= 'osmclient.sol005.client.Client':
1266 ctx
.obj
.package
.wait_for_upload(filename
)
1267 except ClientException
as inst
:
1272 @cli.command(name
='ns-scaling-show')
1273 @click.argument('ns_name')
1275 def show_ns_scaling(ctx
, ns_name
):
1276 '''shows the status of a NS scaling operation
1278 NS_NAME: name of the NS instance being scaled
1281 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1282 resp
= ctx
.obj
.ns
.list()
1283 except ClientException
as inst
:
1287 table
= PrettyTable(
1290 'operational status',
1295 if ns_name
== ns
['name']:
1296 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
1297 scaling_records
= nsopdata
['nsr:nsr']['scaling-group-record']
1298 for record
in scaling_records
:
1299 if 'instance' in record
:
1300 instances
= record
['instance']
1301 for inst
in instances
:
1303 [record
['scaling-group-name-ref'],
1304 inst
['instance-id'],
1306 time
.strftime('%Y-%m-%d %H:%M:%S',
1308 inst
['create-time'])),
1314 @cli.command(name
='ns-scale')
1315 @click.argument('ns_name')
1316 @click.option('--ns_scale_group', prompt
=True)
1317 @click.option('--index', prompt
=True)
1319 def ns_scale(ctx
, ns_name
, ns_scale_group
, index
):
1322 NS_NAME: name of the NS instance to be scaled
1325 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1326 ctx
.obj
.ns
.scale(ns_name
, ns_scale_group
, index
)
1327 except ClientException
as inst
:
1332 @cli.command(name
='config-agent-list')
1334 def config_agent_list(ctx
):
1335 '''list config agents'''
1337 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1338 except ClientException
as inst
:
1341 table
= PrettyTable(['name', 'account-type', 'details'])
1342 for account
in ctx
.obj
.vca
.list():
1345 account
['account-type'],
1351 @cli.command(name
='config-agent-delete')
1352 @click.argument('name')
1354 def config_agent_delete(ctx
, name
):
1355 '''deletes a config agent
1357 NAME: name of the config agent to be deleted
1360 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1361 ctx
.obj
.vca
.delete(name
)
1362 except ClientException
as inst
:
1367 @cli.command(name
='config-agent-add')
1368 @click.option('--name',
1370 @click.option('--account_type',
1372 @click.option('--server',
1374 @click.option('--user',
1376 @click.option('--secret',
1379 confirmation_prompt
=True)
1381 def config_agent_add(ctx
, name
, account_type
, server
, user
, secret
):
1382 '''adds a config agent'''
1384 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1385 ctx
.obj
.vca
.create(name
, account_type
, server
, user
, secret
)
1386 except ClientException
as inst
:
1390 @cli.command(name
='ro-dump')
1393 '''shows RO agent information'''
1394 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1395 resp
= ctx
.obj
.vim
.get_resource_orchestrator()
1396 table
= PrettyTable(['key', 'attribute'])
1397 for k
, v
in resp
.items():
1398 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1403 @cli.command(name
='vcs-list')
1406 check_client_version(ctx
.obj
, ctx
.command
.name
, 'v1')
1407 resp
= ctx
.obj
.utils
.get_vcs_info()
1408 table
= PrettyTable(['component name', 'state'])
1409 for component
in resp
:
1410 table
.add_row([component
['component_name'], component
['state']])
1415 @cli.command(name
='ns-action')
1416 @click.argument('ns_name')
1417 @click.option('--vnf_name', default
=None)
1418 @click.option('--action_name', prompt
=True)
1419 @click.option('--params', prompt
=True)
1426 '''executes an action/primitive over a NS instance
1428 NS_NAME: name or ID of the NS instance
1431 check_client_version(ctx
.obj
, ctx
.command
.name
)
1434 op_data
['vnf_member_index'] = vnf_name
1435 op_data
['primitive'] = action_name
1436 op_data
['primitive_params'] = yaml
.load(params
)
1437 ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
)
1439 except ClientException
as inst
:
1444 if __name__
== '__main__':