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
33 from datetime
import datetime
38 CONTEXT_SETTINGS
= dict(help_option_names
=['-h', '--help'], max_content_width
=160)
40 def wrap_text(text
, width
):
41 wrapper
= textwrap
.TextWrapper(width
=width
)
42 lines
= text
.splitlines()
43 return "\n".join(map(wrapper
.fill
, lines
))
46 def trunc_text(text
, length
):
47 if len(text
) > length
:
48 return text
[:(length
- 3)] + '...'
53 def check_client_version(obj
, what
, version
='sol005'):
55 Checks the version of the client object and raises error if it not the expected.
57 :param obj: the client object
58 :what: the function or command under evaluation (used when an error is raised)
60 :raises ClientError: if the specified version does not match the client version
63 fullclassname
= obj
.__module
__ + "." + obj
.__class
__.__name
__
64 message
= 'The following commands or options are only supported with the option "--sol005": {}'.format(what
)
66 message
= 'The following commands or options are not supported when using option "--sol005": {}'.format(what
)
67 if fullclassname
!= 'osmclient.{}.client.Client'.format(version
):
68 raise ClientException(message
)
72 @click.group(context_settings
=dict(help_option_names
=['-h', '--help'], max_content_width
=160))
73 @click.option('--hostname',
75 envvar
='OSM_HOSTNAME',
76 help='hostname of server. ' +
77 'Also can set OSM_HOSTNAME in environment')
78 #@click.option('--sol005/--no-sol005',
80 # envvar='OSM_SOL005',
81 # help='Use ETSI NFV SOL005 API (default) or the previous SO API. ' +
82 # 'Also can set OSM_SOL005 in environment')
83 @click.option('--user',
86 help='user (defaults to admin). ' +
87 'Also can set OSM_USER in environment')
88 @click.option('--password',
90 envvar
='OSM_PASSWORD',
91 help='password (defaults to admin). ' +
92 'Also can set OSM_PASSWORD in environment')
93 @click.option('--project',
96 help='project (defaults to admin). ' +
97 'Also can set OSM_PROJECT in environment')
98 @click.option('-v', '--verbose', count
=True,
99 help='increase verbosity (-v INFO, -vv VERBOSE, -vvv DEBUG)')
100 @click.option('--all-projects',
103 help='include all projects')
104 @click.option('--public/--no-public', default
=None,
105 help='flag for public items (packages, instances, VIM accounts, etc.)')
106 @click.option('--project-domain-name', 'project_domain_name',
108 envvar
='OSM_PROJECT_DOMAIN_NAME',
109 help='project domain name for keystone authentication (default to None). ' +
110 'Also can set OSM_PROJECT_DOMAIN_NAME in environment')
111 @click.option('--user-domain-name', 'user_domain_name',
113 envvar
='OSM_USER_DOMAIN_NAME',
114 help='user domain name for keystone authentication (default to None). ' +
115 'Also can set OSM_USER_DOMAIN_NAME in environment')
116 #@click.option('--so-port',
118 # envvar='OSM_SO_PORT',
119 # help='hostname of server. ' +
120 # 'Also can set OSM_SO_PORT in environment')
121 #@click.option('--so-project',
123 # envvar='OSM_SO_PROJECT',
124 # help='Project Name in SO. ' +
125 # 'Also can set OSM_SO_PROJECT in environment')
126 #@click.option('--ro-hostname',
128 # envvar='OSM_RO_HOSTNAME',
129 # help='hostname of RO server. ' +
130 # 'Also can set OSM_RO_HOSTNAME in environment')
131 #@click.option('--ro-port',
133 # envvar='OSM_RO_PORT',
134 # help='hostname of RO server. ' +
135 # 'Also can set OSM_RO_PORT in environment')
137 def cli_osm(ctx
, **kwargs
):
139 hostname
= kwargs
.pop("hostname", None)
142 "either hostname option or OSM_HOSTNAME " +
143 "environment variable needs to be specified"))
146 kwargs
= {k
: v
for k
, v
in kwargs
.items() if v
is not None}
147 # if so_port is not None:
148 # kwargs['so_port']=so_port
149 # if so_project is not None:
150 # kwargs['so_project']=so_project
151 # if ro_hostname is not None:
152 # kwargs['ro_host']=ro_hostname
153 # if ro_port is not None:
154 # kwargs['ro_port']=ro_port
155 sol005
= os
.getenv('OSM_SOL005', True)
156 # if user is not None:
157 # kwargs['user']=user
158 # if password is not None:
159 # kwargs['password']=password
160 # if project is not None:
161 # kwargs['project']=project
163 # kwargs['all_projects']=all_projects
164 # if public is not None:
165 # kwargs['public']=public
166 ctx
.obj
= client
.Client(host
=hostname
, sol005
=sol005
, **kwargs
)
167 logger
= logging
.getLogger('osmclient')
174 @cli_osm.command(name
='ns-list', short_help
='list all NS instances')
175 @click.option('--filter', default
=None,
176 help='restricts the list to the NS instances matching the filter.')
177 @click.option('--long', is_flag
=True,
178 help='get more details of the NS (project, vim, deployment status, configuration status.')
180 def ns_list(ctx
, filter, long):
181 """list all NS instances
185 --filter filterExpr Restricts the list to the NS instances matching the filter
188 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
189 concatenated using the "&" character:
192 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
193 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
194 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
196 value := scalar value
200 * zero or more occurrences
201 ? zero or one occurrence
202 [] grouping of expressions to be used with ? and *
203 "" quotation marks for marking string constants
207 "AttrName" is the name of one attribute in the data type that defines the representation
208 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
209 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
210 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
211 entries, it means that the operator "op" is applied to the attribute addressed by the last
212 <attrName> entry included in the concatenation. All simple filter expressions are combined
213 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
214 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
215 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
216 prefix". If an attribute referenced in an expression is an array, an object that contains a
217 corresponding array shall be considered to match the expression if any of the elements in the
218 array matches all expressions that have the same attribute prefix.
222 --filter admin-status=ENABLED
223 --filter nsd-ref=<NSD_NAME>
224 --filter nsd.vendor=<VENDOR>
225 --filter nsd.vendor=<VENDOR>&nsd-ref=<NSD_NAME>
226 --filter nsd.constituent-vnfd.vnfd-id-ref=<VNFD_NAME>
228 def summarize_deployment_status(status_dict
):
233 net_list
= status_dict
.get('nets',[])
236 if net
['status'] not in status_nets
:
237 status_nets
[net
['status']] = 1
239 status_nets
[net
['status']] +=1
241 for k
,v
in status_nets
.items():
242 message
+= "{}:{},".format(k
,v
)
243 message
+= "TOTAL:{}".format(n_nets
)
244 summary
+= "{}".format(message
)
249 vnf_list
= status_dict
['vnfs']
251 member_vnf_index
= vnf
['member_vnf_index']
252 if member_vnf_index
not in status_vnfs
:
253 status_vnfs
[member_vnf_index
] = {}
254 for vm
in vnf
['vms']:
256 if vm
['status'] not in status_vms
:
257 status_vms
[vm
['status']] = 1
259 status_vms
[vm
['status']] +=1
260 if vm
['status'] not in status_vnfs
[member_vnf_index
]:
261 status_vnfs
[member_vnf_index
][vm
['status']] = 1
263 status_vnfs
[member_vnf_index
][vm
['status']] += 1
265 for k
,v
in status_vms
.items():
266 message
+= "{}:{},".format(k
,v
)
267 message
+= "TOTAL:{}".format(n_vms
)
268 summary
+= "\n{}".format(message
)
270 for k
,v
in status_vnfs
.items():
272 message
= "\n {} VMs: ".format(k
)
273 for k2
,v2
in v
.items():
274 message
+= "{}:{},".format(k2
,v2
)
276 message
+= "TOTAL:{}".format(total
)
280 def summarize_config_status(ee_list
):
285 if ee
['elementType'] not in status_ee
:
286 status_ee
[ee
['elementType']] = {}
287 status_ee
[ee
['elementType']][ee
['status']] = 1
289 if ee
['status'] in status_ee
[ee
['elementType']]:
290 status_ee
[ee
['elementType']][ee
['status']] += 1
292 status_ee
[ee
['elementType']][ee
['status']] = 1
294 for elementType
in ["KDU", "VDU", "PDU", "VNF", "NS"]:
295 if elementType
in status_ee
:
298 for k
,v
in status_ee
[elementType
].items():
299 message
+= "{}:{},".format(k
,v
)
301 message
+= "TOTAL:{}\n".format(total
)
302 summary
+= "{}: {}".format(elementType
, message
)
303 summary
+= "TOTAL Exec. Env.: {}".format(n_ee
)
307 check_client_version(ctx
.obj
, '--filter')
308 resp
= ctx
.obj
.ns
.list(filter)
310 resp
= ctx
.obj
.ns
.list()
322 'configuration status'])
323 project_list
= ctx
.obj
.project
.list()
324 vim_list
= ctx
.obj
.vim
.list()
334 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
335 if fullclassname
== 'osmclient.sol005.client.Client':
337 nsr_name
= nsr
['name']
339 date
= datetime
.fromtimestamp(nsr
['create-time']).strftime("%Y-%m-%dT%H:%M:%S")
340 ns_state
= nsr
['nsState']
342 deployment_status
= summarize_deployment_status(nsr
['deploymentStatus'])
343 config_status
= summarize_config_status(nsr
['configurationStatus'])
344 project_id
= nsr
.get('_admin').get('projects_read')[0]
346 for p
in project_list
:
347 if p
['_id'] == project_id
:
348 project_name
= p
['name']
350 #project = '{} ({})'.format(project_name, project_id)
351 project
= project_name
352 vim_id
= nsr
.get('datacenter')
355 if v
['uuid'] == vim_id
:
358 #vim = '{} ({})'.format(vim_name, vim_id)
360 current_operation
= "{} ({})".format(nsr
['currentOperation'],nsr
['currentOperationID'])
361 error_details
= "N/A"
362 if ns_state
== "BROKEN" or ns_state
== "DEGRADED" or nsr
['errorDescription']:
363 error_details
= "{}\nDetail: {}".format(nsr
['errorDescription'], nsr
['errorDetail'])
365 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
366 nsr
= nsopdata
['nsr:nsr']
367 nsr_name
= nsr
['name-ref']
368 nsr_id
= nsr
['ns-instance-config-ref']
371 deployment_status
= nsr
['operational-status'] if 'operational-status' in nsr
else 'Not found'
372 ns_state
= deployment_status
373 config_status
= nsr
.get('config-status', 'Not found')
374 current_operation
= "Unknown"
375 error_details
= nsr
.get('detailed-status', 'Not found')
376 if config_status
== "config_not_needed":
377 config_status
= "configured (no charms)"
386 wrap_text(text
=error_details
,width
=40),
398 wrap_text(text
=error_details
,width
=40)])
401 print('To get the history of all operations over a NS, run "osm ns-op-list NS_ID"')
402 print('For more details on the current operation, run "osm ns-op-show OPERATION_ID"')
404 def nsd_list(ctx
, filter, long):
407 check_client_version(ctx
.obj
, '--filter')
408 resp
= ctx
.obj
.nsd
.list(filter)
410 resp
= ctx
.obj
.nsd
.list()
411 # print(yaml.safe_dump(resp))
412 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
413 if fullclassname
== 'osmclient.sol005.client.Client':
415 table
= PrettyTable(['nsd name', 'id', 'onboarding state', 'operational state',
416 'usage state', 'date', 'last update'])
418 table
= PrettyTable(['nsd name', 'id'])
420 name
= nsd
.get('name','-')
422 onb_state
= nsd
['_admin'].get('onboardingState','-')
423 op_state
= nsd
['_admin'].get('operationalState','-')
424 usage_state
= nsd
['_admin'].get('usageState','-')
425 date
= datetime
.fromtimestamp(nsd
['_admin']['created']).strftime("%Y-%m-%dT%H:%M:%S")
426 last_update
= datetime
.fromtimestamp(nsd
['_admin']['modified']).strftime("%Y-%m-%dT%H:%M:%S")
427 table
.add_row([name
, nsd
['_id'], onb_state
, op_state
, usage_state
, date
, last_update
])
429 table
.add_row([name
, nsd
['_id']])
431 table
= PrettyTable(['nsd name', 'id'])
433 table
.add_row([nsd
['name'], nsd
['id']])
438 @cli_osm.command(name
='nsd-list', short_help
='list all NS packages')
439 @click.option('--filter', default
=None,
440 help='restricts the list to the NSD/NSpkg matching the filter')
441 @click.option('--long', is_flag
=True, help='get more details')
443 def nsd_list1(ctx
, filter, long):
444 """list all NSD/NS pkg in the system"""
446 nsd_list(ctx
, filter, long)
449 @cli_osm.command(name
='nspkg-list', short_help
='list all NS packages')
450 @click.option('--filter', default
=None,
451 help='restricts the list to the NSD/NSpkg matching the filter')
452 @click.option('--long', is_flag
=True, help='get more details')
454 def nsd_list2(ctx
, filter, long):
455 """list all NS packages"""
457 nsd_list(ctx
, filter, long)
460 def vnfd_list(ctx
, nf_type
, filter, long):
463 check_client_version(ctx
.obj
, '--nf_type')
465 check_client_version(ctx
.obj
, '--filter')
468 nf_filter
= "_admin.type=vnfd"
469 elif nf_type
== "pnf":
470 nf_filter
= "_admin.type=pnfd"
471 elif nf_type
== "hnf":
472 nf_filter
= "_admin.type=hnfd"
474 raise ClientException('wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf')
476 filter = '{}&{}'.format(nf_filter
, filter)
480 resp
= ctx
.obj
.vnfd
.list(filter)
482 resp
= ctx
.obj
.vnfd
.list()
483 # print(yaml.safe_dump(resp))
484 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
485 if fullclassname
== 'osmclient.sol005.client.Client':
487 table
= PrettyTable(['nfpkg name', 'id', 'onboarding state', 'operational state',
488 'usage state', 'date', 'last update'])
490 table
= PrettyTable(['nfpkg name', 'id'])
492 name
= vnfd
['name'] if 'name' in vnfd
else '-'
494 onb_state
= vnfd
['_admin'].get('onboardingState','-')
495 op_state
= vnfd
['_admin'].get('operationalState','-')
496 usage_state
= vnfd
['_admin'].get('usageState','-')
497 date
= datetime
.fromtimestamp(vnfd
['_admin']['created']).strftime("%Y-%m-%dT%H:%M:%S")
498 last_update
= datetime
.fromtimestamp(vnfd
['_admin']['modified']).strftime("%Y-%m-%dT%H:%M:%S")
499 table
.add_row([name
, vnfd
['_id'], onb_state
, op_state
, usage_state
, date
, last_update
])
501 table
.add_row([name
, vnfd
['_id']])
503 table
= PrettyTable(['nfpkg name', 'id'])
505 table
.add_row([vnfd
['name'], vnfd
['id']])
510 @cli_osm.command(name
='vnfd-list', short_help
='list all xNF packages (VNF, HNF, PNF)')
511 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
512 @click.option('--filter', default
=None,
513 help='restricts the list to the NF pkg matching the filter')
514 @click.option('--long', is_flag
=True, help='get more details')
516 def vnfd_list1(ctx
, nf_type
, filter, long):
517 """list all xNF packages (VNF, HNF, PNF)"""
519 vnfd_list(ctx
, nf_type
, filter, long)
522 @cli_osm.command(name
='vnfpkg-list', short_help
='list all xNF packages (VNF, HNF, PNF)')
523 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
524 @click.option('--filter', default
=None,
525 help='restricts the list to the NFpkg matching the filter')
526 @click.option('--long', is_flag
=True, help='get more details')
528 def vnfd_list2(ctx
, nf_type
, filter, long):
529 """list all xNF packages (VNF, HNF, PNF)"""
531 vnfd_list(ctx
, nf_type
, filter, long)
534 @cli_osm.command(name
='nfpkg-list', short_help
='list all xNF packages (VNF, HNF, PNF)')
535 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
536 @click.option('--filter', default
=None,
537 help='restricts the list to the NFpkg matching the filter')
538 @click.option('--long', is_flag
=True, help='get more details')
540 def nfpkg_list(ctx
, nf_type
, filter, long):
541 """list all xNF packages (VNF, HNF, PNF)"""
544 check_client_version(ctx
.obj
, ctx
.command
.name
)
545 vnfd_list(ctx
, nf_type
, filter, long)
546 # except ClientException as e:
551 def vnf_list(ctx
, ns
, filter, long):
555 check_client_version(ctx
.obj
, '--ns')
557 check_client_version(ctx
.obj
, '--filter')
558 resp
= ctx
.obj
.vnf
.list(ns
, filter)
560 resp
= ctx
.obj
.vnf
.list()
561 # except ClientException as e:
564 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
565 if fullclassname
== 'osmclient.sol005.client.Client':
566 field_names
= ['vnf id', 'name', 'ns id', 'vnf member index',
567 'vnfd name', 'vim account id', 'ip address']
569 field_names
= ['vnf id', 'name', 'ns id', 'vnf member index',
570 'vnfd name', 'vim account id', 'ip address',
571 'date', 'last update']
572 table
= PrettyTable(field_names
)
574 name
= vnfr
['name'] if 'name' in vnfr
else '-'
575 new_row
= [vnfr
['_id'], name
, vnfr
['nsr-id-ref'],
576 vnfr
['member-vnf-index-ref'], vnfr
['vnfd-ref'],
577 vnfr
['vim-account-id'], vnfr
['ip-address']]
579 date
= datetime
.fromtimestamp(vnfr
['_admin']['created']).strftime("%Y-%m-%dT%H:%M:%S")
580 last_update
= datetime
.fromtimestamp(vnfr
['_admin']['modified']).strftime("%Y-%m-%dT%H:%M:%S")
581 new_row
.extend([date
, last_update
])
582 table
.add_row(new_row
)
587 'operational status',
590 if 'mgmt-interface' not in vnfr
:
591 vnfr
['mgmt-interface'] = {}
592 vnfr
['mgmt-interface']['ip-address'] = None
596 vnfr
['operational-status'],
597 vnfr
['config-status']])
602 @cli_osm.command(name
='vnf-list', short_help
='list all NF instances')
603 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
604 @click.option('--filter', default
=None,
605 help='restricts the list to the NF instances matching the filter.')
606 @click.option('--long', is_flag
=True, help='get more details')
608 def vnf_list1(ctx
, ns
, filter, long):
609 """list all NF instances"""
611 vnf_list(ctx
, ns
, filter, long)
614 @cli_osm.command(name
='nf-list', short_help
='list all NF instances')
615 @click.option('--ns', default
=None, help='NS instance id or name to restrict the NF list')
616 @click.option('--filter', default
=None,
617 help='restricts the list to the NF instances matching the filter.')
618 @click.option('--long', is_flag
=True, help='get more details')
620 def nf_list(ctx
, ns
, filter, long):
621 """list all NF instances
625 --ns TEXT NS instance id or name to restrict the VNF list
626 --filter filterExpr Restricts the list to the VNF instances matching the filter
629 filterExpr consists of one or more strings formatted according to "simpleFilterExpr",
630 concatenated using the "&" character:
633 filterExpr := <simpleFilterExpr>["&"<simpleFilterExpr>]*
634 simpleFilterExpr := <attrName>["."<attrName>]*["."<op>]"="<value>[","<value>]*
635 op := "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "cont" | "ncont"
637 value := scalar value
641 * zero or more occurrences
642 ? zero or one occurrence
643 [] grouping of expressions to be used with ? and *
644 "" quotation marks for marking string constants
648 "AttrName" is the name of one attribute in the data type that defines the representation
649 of the resource. The dot (".") character in "simpleFilterExpr" allows concatenation of
650 <attrName> entries to filter by attributes deeper in the hierarchy of a structured document.
651 "Op" stands for the comparison operator. If the expression has concatenated <attrName>
652 entries, it means that the operator "op" is applied to the attribute addressed by the last
653 <attrName> entry included in the concatenation. All simple filter expressions are combined
654 by the "AND" logical operator. In a concatenation of <attrName> entries in a <simpleFilterExpr>,
655 the rightmost "attrName" entry in a "simpleFilterExpr" is called "leaf attribute". The
656 concatenation of all "attrName" entries except the leaf attribute is called the "attribute
657 prefix". If an attribute referenced in an expression is an array, an object that contains a
658 corresponding array shall be considered to match the expression if any of the elements in the
659 array matches all expressions that have the same attribute prefix.
663 --filter vim-account-id=<VIM_ACCOUNT_ID>
664 --filter vnfd-ref=<VNFD_NAME>
665 --filter vdur.ip-address=<IP_ADDRESS>
666 --filter vnfd-ref=<VNFD_NAME>,vdur.ip-address=<IP_ADDRESS>
669 vnf_list(ctx
, ns
, filter)
672 @cli_osm.command(name
='ns-op-list', short_help
='shows the history of operations over a NS instance')
673 @click.argument('name')
674 @click.option('--long', is_flag
=True,
675 help='get more details of the NS operation (date, ).')
677 def ns_op_list(ctx
, name
, long):
678 """shows the history of operations over a NS instance
680 NAME: name or ID of the NS instance
682 def formatParams(params
):
683 if params
['lcmOperationType']=='instantiate':
684 params
.pop('nsDescription')
688 elif params
['lcmOperationType']=='action':
689 params
.pop('primitive')
690 params
.pop('lcmOperationType')
691 params
.pop('nsInstanceId')
696 check_client_version(ctx
.obj
, ctx
.command
.name
)
697 resp
= ctx
.obj
.ns
.list_op(name
)
698 # except ClientException as e:
703 table
= PrettyTable(['id', 'operation', 'action_name', 'operation_params', 'status', 'date', 'last update', 'detail'])
705 table
= PrettyTable(['id', 'operation', 'action_name', 'status', 'date', 'detail'])
707 #print(yaml.safe_dump(resp))
710 if op
['lcmOperationType']=='action':
711 action_name
= op
['operationParams']['primitive']
713 if op
['operationState']=='PROCESSING':
714 if op
['lcmOperationType'] in ('instantiate', 'terminate'):
718 detail
= "In queue. Current position: {}".format(op
['queuePosition'])
719 elif op
['operationState'] in ('FAILED', 'FAILED_TEMP'):
720 detail
= op
.get('errorMessage','-')
721 date
= datetime
.fromtimestamp(op
['startTime']).strftime("%Y-%m-%dT%H:%M:%S")
722 last_update
= datetime
.fromtimestamp(op
['statusEnteredTime']).strftime("%Y-%m-%dT%H:%M:%S")
724 table
.add_row([op
['id'],
725 op
['lcmOperationType'],
727 wrap_text(text
=json
.dumps(formatParams(op
['operationParams']),indent
=2),width
=50),
728 op
['operationState'],
731 wrap_text(text
=detail
,width
=50)])
733 table
.add_row([op
['id'], op
['lcmOperationType'], action_name
,
734 op
['operationState'], date
, wrap_text(text
=detail
or "",width
=50)])
739 def nsi_list(ctx
, filter):
740 """list all Network Slice Instances"""
743 check_client_version(ctx
.obj
, ctx
.command
.name
)
744 resp
= ctx
.obj
.nsi
.list(filter)
745 # except ClientException as e:
749 ['netslice instance name',
751 'operational status',
755 nsi_name
= nsi
['name']
757 opstatus
= nsi
['operational-status'] if 'operational-status' in nsi
else 'Not found'
758 configstatus
= nsi
['config-status'] if 'config-status' in nsi
else 'Not found'
759 detailed_status
= nsi
['detailed-status'] if 'detailed-status' in nsi
else 'Not found'
760 if configstatus
== "config_not_needed":
761 configstatus
= "configured (no charms)"
772 @cli_osm.command(name
='nsi-list', short_help
='list all Network Slice Instances (NSI)')
773 @click.option('--filter', default
=None,
774 help='restricts the list to the Network Slice Instances matching the filter')
776 def nsi_list1(ctx
, filter):
777 """list all Network Slice Instances (NSI)"""
779 nsi_list(ctx
, filter)
782 @cli_osm.command(name
='netslice-instance-list', short_help
='list all Network Slice Instances (NSI)')
783 @click.option('--filter', default
=None,
784 help='restricts the list to the Network Slice Instances matching the filter')
786 def nsi_list2(ctx
, filter):
787 """list all Network Slice Instances (NSI)"""
789 nsi_list(ctx
, filter)
792 def nst_list(ctx
, filter):
795 check_client_version(ctx
.obj
, ctx
.command
.name
)
796 resp
= ctx
.obj
.nst
.list(filter)
797 # except ClientException as e:
800 # print(yaml.safe_dump(resp))
801 table
= PrettyTable(['nst name', 'id'])
803 name
= nst
['name'] if 'name' in nst
else '-'
804 table
.add_row([name
, nst
['_id']])
809 @cli_osm.command(name
='nst-list', short_help
='list all Network Slice Templates (NST)')
810 @click.option('--filter', default
=None,
811 help='restricts the list to the NST matching the filter')
813 def nst_list1(ctx
, filter):
814 """list all Network Slice Templates (NST) in the system"""
816 nst_list(ctx
, filter)
819 @cli_osm.command(name
='netslice-template-list', short_help
='list all Network Slice Templates (NST)')
820 @click.option('--filter', default
=None,
821 help='restricts the list to the NST matching the filter')
823 def nst_list2(ctx
, filter):
824 """list all Network Slice Templates (NST) in the system"""
826 nst_list(ctx
, filter)
829 def nsi_op_list(ctx
, name
):
832 check_client_version(ctx
.obj
, ctx
.command
.name
)
833 resp
= ctx
.obj
.nsi
.list_op(name
)
834 # except ClientException as e:
837 table
= PrettyTable(['id', 'operation', 'status'])
839 table
.add_row([op
['id'], op
['lcmOperationType'],
840 op
['operationState']])
845 @cli_osm.command(name
='nsi-op-list', short_help
='shows the history of operations over a Network Slice Instance (NSI)')
846 @click.argument('name')
848 def nsi_op_list1(ctx
, name
):
849 """shows the history of operations over a Network Slice Instance (NSI)
851 NAME: name or ID of the Network Slice Instance
854 nsi_op_list(ctx
, name
)
857 @cli_osm.command(name
='netslice-instance-op-list', short_help
='shows the history of operations over a Network Slice Instance (NSI)')
858 @click.argument('name')
860 def nsi_op_list2(ctx
, name
):
861 """shows the history of operations over a Network Slice Instance (NSI)
863 NAME: name or ID of the Network Slice Instance
866 nsi_op_list(ctx
, name
)
869 @cli_osm.command(name
='pdu-list', short_help
='list all Physical Deployment Units (PDU)')
870 @click.option('--filter', default
=None,
871 help='restricts the list to the Physical Deployment Units matching the filter')
873 def pdu_list(ctx
, filter):
874 """list all Physical Deployment Units (PDU)"""
877 check_client_version(ctx
.obj
, ctx
.command
.name
)
878 resp
= ctx
.obj
.pdu
.list(filter)
879 # except ClientException as e:
888 pdu_name
= pdu
['name']
890 pdu_type
= pdu
['type']
891 pdu_ipaddress
= "None"
892 for iface
in pdu
['interfaces']:
894 pdu_ipaddress
= iface
['ip-address']
909 def nsd_show(ctx
, name
, literal
):
912 resp
= ctx
.obj
.nsd
.get(name
)
913 # resp = ctx.obj.nsd.get_individual(name)
914 # except ClientException as e:
919 print(yaml
.safe_dump(resp
))
922 table
= PrettyTable(['field', 'value'])
923 for k
, v
in list(resp
.items()):
924 table
.add_row([k
, wrap_text(text
=json
.dumps(v
, indent
=2),width
=100)])
929 @cli_osm.command(name
='nsd-show', short_help
='shows the content of a NSD')
930 @click.option('--literal', is_flag
=True,
931 help='print literally, no pretty table')
932 @click.argument('name')
934 def nsd_show1(ctx
, name
, literal
):
935 """shows the content of a NSD
937 NAME: name or ID of the NSD/NSpkg
940 nsd_show(ctx
, name
, literal
)
943 @cli_osm.command(name
='nspkg-show', short_help
='shows the content of a NSD')
944 @click.option('--literal', is_flag
=True,
945 help='print literally, no pretty table')
946 @click.argument('name')
948 def nsd_show2(ctx
, name
, literal
):
949 """shows the content of a NSD
951 NAME: name or ID of the NSD/NSpkg
954 nsd_show(ctx
, name
, literal
)
957 def vnfd_show(ctx
, name
, literal
):
960 resp
= ctx
.obj
.vnfd
.get(name
)
961 # resp = ctx.obj.vnfd.get_individual(name)
962 # except ClientException as e:
967 print(yaml
.safe_dump(resp
))
970 table
= PrettyTable(['field', 'value'])
971 for k
, v
in list(resp
.items()):
972 table
.add_row([k
, wrap_text(text
=json
.dumps(v
, indent
=2),width
=100)])
977 @cli_osm.command(name
='vnfd-show', short_help
='shows the content of a VNFD')
978 @click.option('--literal', is_flag
=True,
979 help='print literally, no pretty table')
980 @click.argument('name')
982 def vnfd_show1(ctx
, name
, literal
):
983 """shows the content of a VNFD
985 NAME: name or ID of the VNFD/VNFpkg
988 vnfd_show(ctx
, name
, literal
)
991 @cli_osm.command(name
='vnfpkg-show', short_help
='shows the content of a VNFD')
992 @click.option('--literal', is_flag
=True,
993 help='print literally, no pretty table')
994 @click.argument('name')
996 def vnfd_show2(ctx
, name
, literal
):
997 """shows the content of a VNFD
999 NAME: name or ID of the VNFD/VNFpkg
1002 vnfd_show(ctx
, name
, literal
)
1005 @cli_osm.command(name
='nfpkg-show', short_help
='shows the content of a NF Descriptor')
1006 @click.option('--literal', is_flag
=True,
1007 help='print literally, no pretty table')
1008 @click.argument('name')
1010 def nfpkg_show(ctx
, name
, literal
):
1011 """shows the content of a NF Descriptor
1013 NAME: name or ID of the NFpkg
1016 vnfd_show(ctx
, name
, literal
)
1019 @cli_osm.command(name
='ns-show', short_help
='shows the info of a NS instance')
1020 @click.argument('name')
1021 @click.option('--literal', is_flag
=True,
1022 help='print literally, no pretty table')
1023 @click.option('--filter', default
=None)
1025 def ns_show(ctx
, name
, literal
, filter):
1026 """shows the info of a NS instance
1028 NAME: name or ID of the NS instance
1032 ns
= ctx
.obj
.ns
.get(name
)
1033 # except ClientException as e:
1038 print(yaml
.safe_dump(ns
))
1041 table
= PrettyTable(['field', 'value'])
1043 for k
, v
in list(ns
.items()):
1044 if filter is None or filter in k
:
1045 table
.add_row([k
, wrap_text(text
=json
.dumps(v
, indent
=2),width
=100)])
1047 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
1048 if fullclassname
!= 'osmclient.sol005.client.Client':
1049 nsopdata
= ctx
.obj
.ns
.get_opdata(ns
['id'])
1050 nsr_optdata
= nsopdata
['nsr:nsr']
1051 for k
, v
in list(nsr_optdata
.items()):
1052 if filter is None or filter in k
:
1053 table
.add_row([k
, wrap_text(json
.dumps(v
, indent
=2),width
=100)])
1058 @cli_osm.command(name
='vnf-show', short_help
='shows the info of a VNF instance')
1059 @click.argument('name')
1060 @click.option('--literal', is_flag
=True,
1061 help='print literally, no pretty table')
1062 @click.option('--filter', default
=None, help='restricts the information to the fields in the filter')
1063 @click.option('--kdu', default
=None, help='KDU name (whose status will be shown)')
1065 def vnf_show(ctx
, name
, literal
, filter, kdu
):
1066 """shows the info of a VNF instance
1068 NAME: name or ID of the VNF instance
1070 def print_kdu_status(op_info_status
):
1071 """print KDU status properly formatted
1074 op_status
= yaml
.safe_load(op_info_status
)
1075 if "namespace" in op_status
and "info" in op_status
and \
1076 "last_deployed" in op_status
["info"] and "status" in op_status
["info"] and \
1077 "code" in op_status
["info"]["status"] and "resources" in op_status
["info"]["status"] and \
1078 "seconds" in op_status
["info"]["last_deployed"]:
1079 last_deployed_time
= datetime
.fromtimestamp(op_status
["info"]["last_deployed"]["seconds"]).strftime("%a %b %d %I:%M:%S %Y")
1080 print("LAST DEPLOYED: {}".format(last_deployed_time
))
1081 print("NAMESPACE: {}".format(op_status
["namespace"]))
1082 status_code
= "UNKNOWN"
1083 if op_status
["info"]["status"]["code"]==1:
1084 status_code
= "DEPLOYED"
1085 print("STATUS: {}".format(status_code
))
1088 print(op_status
["info"]["status"]["resources"])
1089 if "notes" in op_status
["info"]["status"]:
1091 print(op_status
["info"]["status"]["notes"])
1093 print(op_info_status
)
1095 print(op_info_status
)
1100 raise ClientException('"--literal" option is incompatible with "--kdu" option')
1102 raise ClientException('"--filter" option is incompatible with "--kdu" option')
1105 check_client_version(ctx
.obj
, ctx
.command
.name
)
1106 resp
= ctx
.obj
.vnf
.get(name
)
1109 ns_id
= resp
['nsr-id-ref']
1111 op_data
['member_vnf_index'] = resp
['member-vnf-index-ref']
1112 op_data
['kdu_name'] = kdu
1113 op_data
['primitive'] = 'status'
1114 op_data
['primitive_params'] = {}
1115 op_id
= ctx
.obj
.ns
.exec_op(ns_id
, op_name
='action', op_data
=op_data
, wait
=False)
1118 op_info
= ctx
.obj
.ns
.get_op(op_id
)
1119 if op_info
['operationState'] == 'COMPLETED':
1120 print_kdu_status(op_info
['detailed-status'])
1124 print ("Could not determine KDU status")
1127 print(yaml
.safe_dump(resp
))
1130 table
= PrettyTable(['field', 'value'])
1132 for k
, v
in list(resp
.items()):
1133 if filter is None or filter in k
:
1134 table
.add_row([k
, wrap_text(text
=json
.dumps(v
,indent
=2),width
=100)])
1137 # except ClientException as e:
1142 #@cli_osm.command(name='vnf-monitoring-show')
1143 #@click.argument('vnf_name')
1144 #@click.pass_context
1145 #def vnf_monitoring_show(ctx, vnf_name):
1147 # check_client_version(ctx.obj, ctx.command.name, 'v1')
1148 # resp = ctx.obj.vnf.get_monitoring(vnf_name)
1149 # except ClientException as e:
1153 # table = PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
1154 # if resp is not None:
1155 # for monitor in resp:
1159 # monitor['value-integer'],
1160 # monitor['units']])
1165 #@cli_osm.command(name='ns-monitoring-show')
1166 #@click.argument('ns_name')
1167 #@click.pass_context
1168 #def ns_monitoring_show(ctx, ns_name):
1170 # check_client_version(ctx.obj, ctx.command.name, 'v1')
1171 # resp = ctx.obj.ns.get_monitoring(ns_name)
1172 # except ClientException as e:
1176 # table = PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
1177 # for key, val in list(resp.items()):
1178 # for monitor in val:
1182 # monitor['value-integer'],
1183 # monitor['units']])
1188 @cli_osm.command(name
='ns-op-show', short_help
='shows the info of a NS operation')
1189 @click.argument('id')
1190 @click.option('--filter', default
=None)
1191 @click.option('--literal', is_flag
=True,
1192 help='print literally, no pretty table')
1194 def ns_op_show(ctx
, id, filter, literal
):
1195 """shows the detailed info of a NS operation
1197 ID: operation identifier
1201 check_client_version(ctx
.obj
, ctx
.command
.name
)
1202 op_info
= ctx
.obj
.ns
.get_op(id)
1203 # except ClientException as e:
1208 print(yaml
.safe_dump(op_info
))
1211 table
= PrettyTable(['field', 'value'])
1212 for k
, v
in list(op_info
.items()):
1213 if filter is None or filter in k
:
1214 table
.add_row([k
, wrap_text(json
.dumps(v
, indent
=2), 100)])
1219 def nst_show(ctx
, name
, literal
):
1222 check_client_version(ctx
.obj
, ctx
.command
.name
)
1223 resp
= ctx
.obj
.nst
.get(name
)
1224 #resp = ctx.obj.nst.get_individual(name)
1225 # except ClientException as e:
1230 print(yaml
.safe_dump(resp
))
1233 table
= PrettyTable(['field', 'value'])
1234 for k
, v
in list(resp
.items()):
1235 table
.add_row([k
, wrap_text(json
.dumps(v
, indent
=2), 100)])
1240 @cli_osm.command(name
='nst-show', short_help
='shows the content of a Network Slice Template (NST)')
1241 @click.option('--literal', is_flag
=True,
1242 help='print literally, no pretty table')
1243 @click.argument('name')
1245 def nst_show1(ctx
, name
, literal
):
1246 """shows the content of a Network Slice Template (NST)
1248 NAME: name or ID of the NST
1251 nst_show(ctx
, name
, literal
)
1254 @cli_osm.command(name
='netslice-template-show', short_help
='shows the content of a Network Slice Template (NST)')
1255 @click.option('--literal', is_flag
=True,
1256 help='print literally, no pretty table')
1257 @click.argument('name')
1259 def nst_show2(ctx
, name
, literal
):
1260 """shows the content of a Network Slice Template (NST)
1262 NAME: name or ID of the NST
1265 nst_show(ctx
, name
, literal
)
1268 def nsi_show(ctx
, name
, literal
, filter):
1271 check_client_version(ctx
.obj
, ctx
.command
.name
)
1272 nsi
= ctx
.obj
.nsi
.get(name
)
1273 # except ClientException as e:
1278 print(yaml
.safe_dump(nsi
))
1281 table
= PrettyTable(['field', 'value'])
1283 for k
, v
in list(nsi
.items()):
1284 if filter is None or filter in k
:
1285 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1291 @cli_osm.command(name
='nsi-show', short_help
='shows the content of a Network Slice Instance (NSI)')
1292 @click.argument('name')
1293 @click.option('--literal', is_flag
=True,
1294 help='print literally, no pretty table')
1295 @click.option('--filter', default
=None)
1297 def nsi_show1(ctx
, name
, literal
, filter):
1298 """shows the content of a Network Slice Instance (NSI)
1300 NAME: name or ID of the Network Slice Instance
1303 nsi_show(ctx
, name
, literal
, filter)
1306 @cli_osm.command(name
='netslice-instance-show', short_help
='shows the content of a Network Slice Instance (NSI)')
1307 @click.argument('name')
1308 @click.option('--literal', is_flag
=True,
1309 help='print literally, no pretty table')
1310 @click.option('--filter', default
=None)
1312 def nsi_show2(ctx
, name
, literal
, filter):
1313 """shows the content of a Network Slice Instance (NSI)
1315 NAME: name or ID of the Network Slice Instance
1318 nsi_show(ctx
, name
, literal
, filter)
1321 def nsi_op_show(ctx
, id, filter):
1324 check_client_version(ctx
.obj
, ctx
.command
.name
)
1325 op_info
= ctx
.obj
.nsi
.get_op(id)
1326 # except ClientException as e:
1330 table
= PrettyTable(['field', 'value'])
1331 for k
, v
in list(op_info
.items()):
1332 if filter is None or filter in k
:
1333 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1338 @cli_osm.command(name
='nsi-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
1339 @click.argument('id')
1340 @click.option('--filter', default
=None)
1342 def nsi_op_show1(ctx
, id, filter):
1343 """shows the info of an operation over a Network Slice Instance(NSI)
1345 ID: operation identifier
1348 nsi_op_show(ctx
, id, filter)
1351 @cli_osm.command(name
='netslice-instance-op-show', short_help
='shows the info of an operation over a Network Slice Instance(NSI)')
1352 @click.argument('id')
1353 @click.option('--filter', default
=None)
1355 def nsi_op_show2(ctx
, id, filter):
1356 """shows the info of an operation over a Network Slice Instance(NSI)
1358 ID: operation identifier
1361 nsi_op_show(ctx
, id, filter)
1364 @cli_osm.command(name
='pdu-show', short_help
='shows the content of a Physical Deployment Unit (PDU)')
1365 @click.argument('name')
1366 @click.option('--literal', is_flag
=True,
1367 help='print literally, no pretty table')
1368 @click.option('--filter', default
=None)
1370 def pdu_show(ctx
, name
, literal
, filter):
1371 """shows the content of a Physical Deployment Unit (PDU)
1373 NAME: name or ID of the PDU
1377 check_client_version(ctx
.obj
, ctx
.command
.name
)
1378 pdu
= ctx
.obj
.pdu
.get(name
)
1379 # except ClientException as e:
1384 print(yaml
.safe_dump(pdu
))
1387 table
= PrettyTable(['field', 'value'])
1389 for k
, v
in list(pdu
.items()):
1390 if filter is None or filter in k
:
1391 table
.add_row([k
, json
.dumps(v
, indent
=2)])
1397 ####################
1399 ####################
1401 def nsd_create(ctx
, filename
, overwrite
, skip_charm_build
):
1404 check_client_version(ctx
.obj
, ctx
.command
.name
)
1405 ctx
.obj
.nsd
.create(filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
)
1406 # except ClientException as e:
1411 @cli_osm.command(name
='nsd-create', short_help
='creates a new NSD/NSpkg')
1412 @click.argument('filename')
1413 @click.option('--overwrite', 'overwrite', default
=None, # hidden=True,
1414 help='Deprecated. Use override')
1415 @click.option('--override', 'overwrite', default
=None,
1416 help='overrides fields in descriptor, format: '
1417 '"key1.key2...=value[;key3...=value;...]"')
1418 @click.option('--skip-charm-build', default
=False, is_flag
=True,
1419 help='The charm will not be compiled, it is assumed to already exist')
1421 def nsd_create1(ctx
, filename
, overwrite
, skip_charm_build
):
1422 """creates a new NSD/NSpkg
1424 FILENAME: NSD yaml file or NSpkg tar.gz file
1427 nsd_create(ctx
, filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
)
1430 @cli_osm.command(name
='nspkg-create', short_help
='creates a new NSD/NSpkg')
1431 @click.argument('filename')
1432 @click.option('--overwrite', 'overwrite', default
=None, # hidden=True,
1433 help='Deprecated. Use override')
1434 @click.option('--override', 'overwrite', default
=None,
1435 help='overrides fields in descriptor, format: '
1436 '"key1.key2...=value[;key3...=value;...]"')
1437 @click.option('--skip-charm-build', default
=False, is_flag
=True,
1438 help='The charm will not be compiled, it is assumed to already exist')
1440 def nsd_create2(ctx
, filename
, overwrite
, skip_charm_build
):
1441 """creates a new NSD/NSpkg
1443 FILENAME: NSD folder, NSD yaml file or NSpkg tar.gz file
1446 nsd_create(ctx
, filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
)
1449 def vnfd_create(ctx
, filename
, overwrite
, skip_charm_build
, override_epa
, override_nonepa
, override_paravirt
):
1452 check_client_version(ctx
.obj
, ctx
.command
.name
)
1453 ctx
.obj
.vnfd
.create(filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
,
1454 override_epa
=override_epa
, override_nonepa
=override_nonepa
,
1455 override_paravirt
=override_paravirt
)
1456 # except ClientException as e:
1461 @cli_osm.command(name
='vnfd-create', short_help
='creates a new VNFD/VNFpkg')
1462 @click.argument('filename')
1463 @click.option('--overwrite', 'overwrite', default
=None,
1464 help='overwrite deprecated, use override')
1465 @click.option('--override', 'overwrite', default
=None,
1466 help='overrides fields in descriptor, format: '
1467 '"key1.key2...=value[;key3...=value;...]"')
1468 @click.option('--skip-charm-build', default
=False, is_flag
=True,
1469 help='The charm will not be compiled, it is assumed to already exist')
1470 @click.option('--override-epa', required
=False, default
=False, is_flag
=True,
1471 help='adds guest-epa parameters to all VDU')
1472 @click.option('--override-nonepa', required
=False, default
=False, is_flag
=True,
1473 help='removes all guest-epa parameters from all VDU')
1474 @click.option('--override-paravirt', required
=False, default
=False, is_flag
=True,
1475 help='overrides all VDU interfaces to PARAVIRT')
1477 def vnfd_create1(ctx
, filename
, overwrite
, skip_charm_build
, override_epa
, override_nonepa
, override_paravirt
):
1478 """creates a new VNFD/VNFpkg
1480 FILENAME: VNFD yaml file or VNFpkg tar.gz file
1483 vnfd_create(ctx
, filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
,
1484 override_epa
=override_epa
, override_nonepa
=override_nonepa
, override_paravirt
=override_paravirt
)
1487 @cli_osm.command(name
='vnfpkg-create', short_help
='creates a new VNFD/VNFpkg')
1488 @click.argument('filename')
1489 @click.option('--overwrite', 'overwrite', default
=None, # hidden=True,
1490 help='Deprecated. Use override')
1491 @click.option('--override', 'overwrite', default
=None,
1492 help='overrides fields in descriptor, format: '
1493 '"key1.key2...=value[;key3...=value;...]"')
1494 @click.option('--skip-charm-build', default
=False, is_flag
=True,
1495 help='The charm will not be compiled, it is assumed to already exist')
1496 @click.option('--override-epa', required
=False, default
=False, is_flag
=True,
1497 help='adds guest-epa parameters to all VDU')
1498 @click.option('--override-nonepa', required
=False, default
=False, is_flag
=True,
1499 help='removes all guest-epa parameters from all VDU')
1500 @click.option('--override-paravirt', required
=False, default
=False, is_flag
=True,
1501 help='overrides all VDU interfaces to PARAVIRT')
1503 def vnfd_create2(ctx
, filename
, overwrite
, skip_charm_build
, override_epa
, override_nonepa
, override_paravirt
):
1504 """creates a new VNFD/VNFpkg
1506 FILENAME: NF Package Folder, NF Descriptor yaml file or NFpkg tar.gz file
1509 vnfd_create(ctx
, filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
,
1510 override_epa
=override_epa
, override_nonepa
=override_nonepa
, override_paravirt
=override_paravirt
)
1513 @cli_osm.command(name
='nfpkg-create', short_help
='creates a new NFpkg')
1514 @click.argument('filename')
1515 @click.option('--overwrite', 'overwrite', default
=None, # hidden=True,
1516 help='Deprecated. Use override')
1517 @click.option('--override', 'overwrite', default
=None,
1518 help='overrides fields in descriptor, format: '
1519 '"key1.key2...=value[;key3...=value;...]"')
1520 @click.option('--skip-charm-build', default
=False, is_flag
=True,
1521 help='The charm will not be compiled, it is assumed to already exist')
1522 @click.option('--override-epa', required
=False, default
=False, is_flag
=True,
1523 help='adds guest-epa parameters to all VDU')
1524 @click.option('--override-nonepa', required
=False, default
=False, is_flag
=True,
1525 help='removes all guest-epa parameters from all VDU')
1526 @click.option('--override-paravirt', required
=False, default
=False, is_flag
=True,
1527 help='overrides all VDU interfaces to PARAVIRT')
1529 def nfpkg_create(ctx
, filename
, overwrite
, skip_charm_build
, override_epa
, override_nonepa
, override_paravirt
):
1530 """creates a new NFpkg
1532 FILENAME: NF Package Folder, NF Descriptor yaml file or NFpkg tar.gz filems to build
1535 vnfd_create(ctx
, filename
, overwrite
=overwrite
, skip_charm_build
=skip_charm_build
,
1536 override_epa
=override_epa
, override_nonepa
=override_nonepa
, override_paravirt
=override_paravirt
)
1539 @cli_osm.command(name
='ns-create', short_help
='creates a new Network Service instance')
1540 @click.option('--ns_name',
1541 prompt
=True, help='name of the NS instance')
1542 @click.option('--nsd_name',
1543 prompt
=True, help='name of the NS descriptor')
1544 @click.option('--vim_account',
1545 prompt
=True, help='default VIM account id or name for the deployment')
1546 @click.option('--admin_status',
1548 help='administration status')
1549 @click.option('--ssh_keys',
1551 help='comma separated list of public key files to inject to vnfs')
1552 @click.option('--config',
1554 help='ns specific yaml configuration')
1555 @click.option('--config_file',
1557 help='ns specific yaml configuration file')
1558 @click.option('--wait',
1562 help='do not return the control immediately, but keep it '
1563 'until the operation is completed, or timeout')
1574 """creates a new NS instance"""
1578 check_client_version(ctx
.obj
, '--config_file')
1580 raise ClientException('"--config" option is incompatible with "--config_file" option')
1581 with
open(config_file
, 'r') as cf
:
1588 account
=vim_account
,
1590 # except ClientException as e:
1595 def nst_create(ctx
, filename
, overwrite
):
1598 check_client_version(ctx
.obj
, ctx
.command
.name
)
1599 ctx
.obj
.nst
.create(filename
, overwrite
)
1600 # except ClientException as e:
1605 @cli_osm.command(name
='nst-create', short_help
='creates a new Network Slice Template (NST)')
1606 @click.argument('filename')
1607 @click.option('--overwrite', 'overwrite', default
=None, # hidden=True,
1608 help='Deprecated. Use override')
1609 @click.option('--override', 'overwrite', default
=None,
1610 help='overrides fields in descriptor, format: '
1611 '"key1.key2...=value[;key3...=value;...]"')
1613 def nst_create1(ctx
, charm_folder
, overwrite
):
1614 """creates a new Network Slice Template (NST)
1616 FILENAME: NST package folder, NST yaml file or NSTpkg tar.gz file
1619 nst_create(ctx
, charm_folder
, overwrite
)
1622 @cli_osm.command(name
='netslice-template-create', short_help
='creates a new Network Slice Template (NST)')
1623 @click.argument('filename')
1624 @click.option('--overwrite', 'overwrite', default
=None, # hidden=True,
1625 help='Deprecated. Use override')
1626 @click.option('--override', 'overwrite', default
=None,
1627 help='overrides fields in descriptor, format: '
1628 '"key1.key2...=value[;key3...=value;...]"')
1630 def nst_create2(ctx
, filename
, overwrite
):
1631 """creates a new Network Slice Template (NST)
1633 FILENAME: NST yaml file or NSTpkg tar.gz file
1636 nst_create(ctx
, filename
, overwrite
)
1639 def nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1640 """creates a new Network Slice Instance (NSI)"""
1643 check_client_version(ctx
.obj
, ctx
.command
.name
)
1646 raise ClientException('"--config" option is incompatible with "--config_file" option')
1647 with
open(config_file
, 'r') as cf
:
1649 ctx
.obj
.nsi
.create(nst_name
, nsi_name
, config
=config
, ssh_keys
=ssh_keys
,
1650 account
=vim_account
, wait
=wait
)
1651 # except ClientException as e:
1656 @cli_osm.command(name
='nsi-create', short_help
='creates a new Network Slice Instance')
1657 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1658 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1659 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1660 @click.option('--ssh_keys', default
=None,
1661 help='comma separated list of keys to inject to vnfs')
1662 @click.option('--config', default
=None,
1663 help='Netslice specific yaml configuration:\n'
1664 'netslice_subnet: [\n'
1665 'id: TEXT, vim_account: TEXT,\n'
1666 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1667 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
1668 'additionalParamsForNsi: {param: value, ...}\n'
1669 'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
1671 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1673 @click.option('--config_file',
1675 help='nsi specific yaml configuration file')
1676 @click.option('--wait',
1680 help='do not return the control immediately, but keep it '
1681 'until the operation is completed, or timeout')
1683 def nsi_create1(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1684 """creates a new Network Slice Instance (NSI)"""
1686 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
)
1689 @cli_osm.command(name
='netslice-instance-create', short_help
='creates a new Network Slice Instance')
1690 @click.option('--nsi_name', prompt
=True, help='name of the Network Slice Instance')
1691 @click.option('--nst_name', prompt
=True, help='name of the Network Slice Template')
1692 @click.option('--vim_account', prompt
=True, help='default VIM account id or name for the deployment')
1693 @click.option('--ssh_keys', default
=None,
1694 help='comma separated list of keys to inject to vnfs')
1695 @click.option('--config', default
=None,
1696 help='Netslice specific yaml configuration:\n'
1697 'netslice_subnet: [\n'
1698 'id: TEXT, vim_account: TEXT,\n'
1699 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
1700 'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1702 'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
1704 @click.option('--config_file',
1706 help='nsi specific yaml configuration file')
1707 @click.option('--wait',
1711 help='do not return the control immediately, but keep it '
1712 'until the operation is completed, or timeout')
1714 def nsi_create2(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
):
1715 """creates a new Network Slice Instance (NSI)"""
1717 nsi_create(ctx
, nst_name
, nsi_name
, vim_account
, ssh_keys
, config
, config_file
, wait
=wait
)
1720 @cli_osm.command(name
='pdu-create', short_help
='adds a new Physical Deployment Unit to the catalog')
1721 @click.option('--name', help='name of the Physical Deployment Unit')
1722 @click.option('--pdu_type', help='type of PDU (e.g. router, firewall, FW001)')
1723 @click.option('--interface',
1724 help='interface(s) of the PDU: name=<NAME>,mgmt=<true|false>,ip-address=<IP_ADDRESS>'+
1725 '[,type=<overlay|underlay>][,mac-address=<MAC_ADDRESS>][,vim-network-name=<VIM_NET_NAME>]',
1727 @click.option('--description', help='human readable description')
1728 @click.option('--vim_account', help='list of VIM accounts (in the same VIM) that can reach this PDU', multiple
=True)
1729 @click.option('--descriptor_file', default
=None,
1730 help='PDU descriptor file (as an alternative to using the other arguments')
1732 def pdu_create(ctx
, name
, pdu_type
, interface
, description
, vim_account
, descriptor_file
):
1733 """creates a new Physical Deployment Unit (PDU)"""
1736 check_client_version(ctx
.obj
, ctx
.command
.name
)
1738 if not descriptor_file
:
1740 raise ClientException('in absence of descriptor file, option "--name" is mandatory')
1742 raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
1744 raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
1746 raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
1748 with
open(descriptor_file
, 'r') as df
:
1749 pdu
= yaml
.safe_load(df
.read())
1750 if name
: pdu
["name"] = name
1751 if pdu_type
: pdu
["type"] = pdu_type
1752 if description
: pdu
["description"] = description
1753 if vim_account
: pdu
["vim_accounts"] = vim_account
1756 for iface
in interface
:
1757 new_iface
={k
:v
for k
,v
in [i
.split('=') for i
in iface
.split(',')]}
1758 new_iface
["mgmt"] = (new_iface
.get("mgmt","false").lower() == "true")
1759 ifaces_list
.append(new_iface
)
1760 pdu
["interfaces"] = ifaces_list
1761 ctx
.obj
.pdu
.create(pdu
)
1762 # except ClientException as e:
1767 ####################
1769 ####################
1771 def nsd_update(ctx
, name
, content
):
1774 check_client_version(ctx
.obj
, ctx
.command
.name
)
1775 ctx
.obj
.nsd
.update(name
, content
)
1776 # except ClientException as e:
1781 @cli_osm.command(name
='nsd-update', short_help
='updates a NSD/NSpkg')
1782 @click.argument('name')
1783 @click.option('--content', default
=None,
1784 help='filename with the NSD/NSpkg replacing the current one')
1786 def nsd_update1(ctx
, name
, content
):
1787 """updates a NSD/NSpkg
1789 NAME: name or ID of the NSD/NSpkg
1792 nsd_update(ctx
, name
, content
)
1795 @cli_osm.command(name
='nspkg-update', short_help
='updates a NSD/NSpkg')
1796 @click.argument('name')
1797 @click.option('--content', default
=None,
1798 help='filename with the NSD/NSpkg replacing the current one')
1800 def nsd_update2(ctx
, name
, content
):
1801 """updates a NSD/NSpkg
1803 NAME: name or ID of the NSD/NSpkg
1806 nsd_update(ctx
, name
, content
)
1809 def vnfd_update(ctx
, name
, content
):
1812 check_client_version(ctx
.obj
, ctx
.command
.name
)
1813 ctx
.obj
.vnfd
.update(name
, content
)
1814 # except ClientException as e:
1819 @cli_osm.command(name
='vnfd-update', short_help
='updates a new VNFD/VNFpkg')
1820 @click.argument('name')
1821 @click.option('--content', default
=None,
1822 help='filename with the VNFD/VNFpkg replacing the current one')
1824 def vnfd_update1(ctx
, name
, content
):
1825 """updates a VNFD/VNFpkg
1827 NAME: name or ID of the VNFD/VNFpkg
1830 vnfd_update(ctx
, name
, content
)
1833 @cli_osm.command(name
='vnfpkg-update', short_help
='updates a VNFD/VNFpkg')
1834 @click.argument('name')
1835 @click.option('--content', default
=None,
1836 help='filename with the VNFD/VNFpkg replacing the current one')
1838 def vnfd_update2(ctx
, name
, content
):
1839 """updates a VNFD/VNFpkg
1841 NAME: VNFD yaml file or VNFpkg tar.gz file
1844 vnfd_update(ctx
, name
, content
)
1847 @cli_osm.command(name
='nfpkg-update', short_help
='updates a NFpkg')
1848 @click.argument('name')
1849 @click.option('--content', default
=None,
1850 help='filename with the NFpkg replacing the current one')
1852 def nfpkg_update(ctx
, name
, content
):
1855 NAME: NF Descriptor yaml file or NFpkg tar.gz file
1858 vnfd_update(ctx
, name
, content
)
1861 def nst_update(ctx
, name
, content
):
1864 check_client_version(ctx
.obj
, ctx
.command
.name
)
1865 ctx
.obj
.nst
.update(name
, content
)
1866 # except ClientException as e:
1871 @cli_osm.command(name
='nst-update', short_help
='updates a Network Slice Template (NST)')
1872 @click.argument('name')
1873 @click.option('--content', default
=None,
1874 help='filename with the NST/NSTpkg replacing the current one')
1876 def nst_update1(ctx
, name
, content
):
1877 """updates a Network Slice Template (NST)
1879 NAME: name or ID of the NSD/NSpkg
1882 nst_update(ctx
, name
, content
)
1885 @cli_osm.command(name
='netslice-template-update', short_help
='updates a Network Slice Template (NST)')
1886 @click.argument('name')
1887 @click.option('--content', default
=None,
1888 help='filename with the NST/NSTpkg replacing the current one')
1890 def nst_update2(ctx
, name
, content
):
1891 """updates a Network Slice Template (NST)
1893 NAME: name or ID of the NSD/NSpkg
1896 nst_update(ctx
, name
, content
)
1899 ####################
1901 ####################
1903 def nsd_delete(ctx
, name
, force
):
1907 ctx
.obj
.nsd
.delete(name
)
1909 check_client_version(ctx
.obj
, '--force')
1910 ctx
.obj
.nsd
.delete(name
, force
)
1911 # except ClientException as e:
1916 @cli_osm.command(name
='nsd-delete', short_help
='deletes a NSD/NSpkg')
1917 @click.argument('name')
1918 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1920 def nsd_delete1(ctx
, name
, force
):
1921 """deletes a NSD/NSpkg
1923 NAME: name or ID of the NSD/NSpkg to be deleted
1926 nsd_delete(ctx
, name
, force
)
1929 @cli_osm.command(name
='nspkg-delete', short_help
='deletes a NSD/NSpkg')
1930 @click.argument('name')
1931 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1933 def nsd_delete2(ctx
, name
, force
):
1934 """deletes a NSD/NSpkg
1936 NAME: name or ID of the NSD/NSpkg to be deleted
1939 nsd_delete(ctx
, name
, force
)
1942 def vnfd_delete(ctx
, name
, force
):
1946 ctx
.obj
.vnfd
.delete(name
)
1948 check_client_version(ctx
.obj
, '--force')
1949 ctx
.obj
.vnfd
.delete(name
, force
)
1950 # except ClientException as e:
1955 @cli_osm.command(name
='vnfd-delete', short_help
='deletes a VNFD/VNFpkg')
1956 @click.argument('name')
1957 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1959 def vnfd_delete1(ctx
, name
, force
):
1960 """deletes a VNFD/VNFpkg
1962 NAME: name or ID of the VNFD/VNFpkg to be deleted
1965 vnfd_delete(ctx
, name
, force
)
1968 @cli_osm.command(name
='vnfpkg-delete', short_help
='deletes a VNFD/VNFpkg')
1969 @click.argument('name')
1970 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1972 def vnfd_delete2(ctx
, name
, force
):
1973 """deletes a VNFD/VNFpkg
1975 NAME: name or ID of the VNFD/VNFpkg to be deleted
1978 vnfd_delete(ctx
, name
, force
)
1981 @cli_osm.command(name
='nfpkg-delete', short_help
='deletes a NFpkg')
1982 @click.argument('name')
1983 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1985 def nfpkg_delete(ctx
, name
, force
):
1988 NAME: name or ID of the NFpkg to be deleted
1991 vnfd_delete(ctx
, name
, force
)
1994 @cli_osm.command(name
='ns-delete', short_help
='deletes a NS instance')
1995 @click.argument('name')
1996 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
1997 @click.option('--config', default
=None,
1998 help="specific yaml configuration for the termination, e.g. '{autoremove: False, timeout_ns_terminate: "
1999 "600, skip_terminate_primitives: True}'")
2000 @click.option('--wait',
2004 help='do not return the control immediately, but keep it '
2005 'until the operation is completed, or timeout')
2007 def ns_delete(ctx
, name
, force
, config
, wait
):
2008 """deletes a NS instance
2010 NAME: name or ID of the NS instance to be deleted
2015 ctx
.obj
.ns
.delete(name
, config
=config
, wait
=wait
)
2017 check_client_version(ctx
.obj
, '--force')
2018 ctx
.obj
.ns
.delete(name
, force
, config
=config
, wait
=wait
)
2019 # except ClientException as e:
2024 def nst_delete(ctx
, name
, force
):
2027 check_client_version(ctx
.obj
, ctx
.command
.name
)
2028 ctx
.obj
.nst
.delete(name
, force
)
2029 # except ClientException as e:
2034 @cli_osm.command(name
='nst-delete', short_help
='deletes a Network Slice Template (NST)')
2035 @click.argument('name')
2036 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2038 def nst_delete1(ctx
, name
, force
):
2039 """deletes a Network Slice Template (NST)
2041 NAME: name or ID of the NST/NSTpkg to be deleted
2044 nst_delete(ctx
, name
, force
)
2047 @cli_osm.command(name
='netslice-template-delete', short_help
='deletes a Network Slice Template (NST)')
2048 @click.argument('name')
2049 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2051 def nst_delete2(ctx
, name
, force
):
2052 """deletes a Network Slice Template (NST)
2054 NAME: name or ID of the NST/NSTpkg to be deleted
2057 nst_delete(ctx
, name
, force
)
2060 def nsi_delete(ctx
, name
, force
, wait
):
2063 check_client_version(ctx
.obj
, ctx
.command
.name
)
2064 ctx
.obj
.nsi
.delete(name
, force
, wait
=wait
)
2065 # except ClientException as e:
2070 @cli_osm.command(name
='nsi-delete', short_help
='deletes a Network Slice Instance (NSI)')
2071 @click.argument('name')
2072 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2073 @click.option('--wait',
2077 help='do not return the control immediately, but keep it '
2078 'until the operation is completed, or timeout')
2080 def nsi_delete1(ctx
, name
, force
, wait
):
2081 """deletes a Network Slice Instance (NSI)
2083 NAME: name or ID of the Network Slice instance to be deleted
2086 nsi_delete(ctx
, name
, force
, wait
=wait
)
2089 @cli_osm.command(name
='netslice-instance-delete', short_help
='deletes a Network Slice Instance (NSI)')
2090 @click.argument('name')
2091 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2093 def nsi_delete2(ctx
, name
, force
, wait
):
2094 """deletes a Network Slice Instance (NSI)
2096 NAME: name or ID of the Network Slice instance to be deleted
2099 nsi_delete(ctx
, name
, force
, wait
=wait
)
2102 @cli_osm.command(name
='pdu-delete', short_help
='deletes a Physical Deployment Unit (PDU)')
2103 @click.argument('name')
2104 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2106 def pdu_delete(ctx
, name
, force
):
2107 """deletes a Physical Deployment Unit (PDU)
2109 NAME: name or ID of the PDU to be deleted
2113 check_client_version(ctx
.obj
, ctx
.command
.name
)
2114 ctx
.obj
.pdu
.delete(name
, force
)
2115 # except ClientException as e:
2124 @cli_osm.command(name
='vim-create', short_help
='creates a new VIM account')
2125 @click.option('--name',
2127 help='Name to create datacenter')
2128 @click.option('--user',
2130 help='VIM username')
2131 @click.option('--password',
2134 confirmation_prompt
=True,
2135 help='VIM password')
2136 @click.option('--auth_url',
2139 @click.option('--tenant',
2141 help='VIM tenant name')
2142 @click.option('--config',
2144 help='VIM specific config parameters')
2145 @click.option('--account_type',
2146 default
='openstack',
2148 @click.option('--description',
2150 help='human readable description')
2151 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller associated to this VIM account')
2152 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
2153 @click.option('--wait',
2157 help='do not return the control immediately, but keep it '
2158 'until the operation is completed, or timeout')
2172 """creates a new VIM account"""
2176 check_client_version(ctx
.obj
, '--sdn_controller')
2177 if sdn_port_mapping
:
2178 check_client_version(ctx
.obj
, '--sdn_port_mapping')
2180 vim
['vim-username'] = user
2181 vim
['vim-password'] = password
2182 vim
['vim-url'] = auth_url
2183 vim
['vim-tenant-name'] = tenant
2184 vim
['vim-type'] = account_type
2185 vim
['description'] = description
2186 vim
['config'] = config
2187 if sdn_controller
or sdn_port_mapping
:
2188 ctx
.obj
.vim
.create(name
, vim
, sdn_controller
, sdn_port_mapping
, wait
=wait
)
2190 ctx
.obj
.vim
.create(name
, vim
, wait
=wait
)
2191 # except ClientException as e:
2196 @cli_osm.command(name
='vim-update', short_help
='updates a VIM account')
2197 @click.argument('name')
2198 @click.option('--newname', help='New name for the VIM account')
2199 @click.option('--user', help='VIM username')
2200 @click.option('--password', help='VIM password')
2201 @click.option('--auth_url', help='VIM url')
2202 @click.option('--tenant', help='VIM tenant name')
2203 @click.option('--config', help='VIM specific config parameters')
2204 @click.option('--account_type', help='VIM type')
2205 @click.option('--description', help='human readable description')
2206 @click.option('--sdn_controller', default
=None, help='Name or id of the SDN controller to be associated with this VIM'
2207 'account. Use empty string to disassociate')
2208 @click.option('--sdn_port_mapping', default
=None, help="File describing the port mapping between compute nodes' ports and switch ports")
2209 @click.option('--wait',
2213 help='do not return the control immediately, but keep it '
2214 'until the operation is completed, or timeout')
2229 """updates a VIM account
2231 NAME: name or ID of the VIM account
2235 check_client_version(ctx
.obj
, ctx
.command
.name
)
2237 if newname
: vim
['name'] = newname
2238 if user
: vim
['vim_user'] = user
2239 if password
: vim
['vim_password'] = password
2240 if auth_url
: vim
['vim_url'] = auth_url
2241 if tenant
: vim
['vim-tenant-name'] = tenant
2242 if account_type
: vim
['vim_type'] = account_type
2243 if description
: vim
['description'] = description
2244 if config
: vim
['config'] = config
2245 ctx
.obj
.vim
.update(name
, vim
, sdn_controller
, sdn_port_mapping
, wait
=wait
)
2246 # except ClientException as e:
2251 @cli_osm.command(name
='vim-delete', short_help
='deletes a VIM account')
2252 @click.argument('name')
2253 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2254 @click.option('--wait',
2258 help='do not return the control immediately, but keep it '
2259 'until the operation is completed, or timeout')
2261 def vim_delete(ctx
, name
, force
, wait
):
2262 """deletes a VIM account
2264 NAME: name or ID of the VIM account to be deleted
2269 ctx
.obj
.vim
.delete(name
, wait
=wait
)
2271 check_client_version(ctx
.obj
, '--force')
2272 ctx
.obj
.vim
.delete(name
, force
, wait
=wait
)
2273 # except ClientException as e:
2278 @cli_osm.command(name
='vim-list', short_help
='list all VIM accounts')
2279 #@click.option('--ro_update/--no_ro_update',
2281 # help='update list from RO')
2282 @click.option('--filter', default
=None,
2283 help='restricts the list to the VIM accounts matching the filter')
2284 @click.option('--long', is_flag
=True,
2285 help='get more details of the NS (project, vim, deployment status, configuration status.')
2287 def vim_list(ctx
, filter, long):
2288 """list all VIM accounts"""
2291 check_client_version(ctx
.obj
, '--filter')
2293 # check_client_version(ctx.obj, '--ro_update', 'v1')
2294 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
2295 if fullclassname
== 'osmclient.sol005.client.Client':
2296 resp
= ctx
.obj
.vim
.list(filter)
2298 # resp = ctx.obj.vim.list(ro_update)
2300 table
= PrettyTable(['vim name', 'uuid', 'operational state', 'error details'])
2302 table
= PrettyTable(['vim name', 'uuid'])
2305 vim_details
= ctx
.obj
.vim
.get(vim
['uuid'])
2306 if 'vim_password' in vim_details
:
2307 vim_details
['vim_password']='********'
2308 logger
.debug('VIM details: {}'.format(yaml
.safe_dump(vim_details
)))
2309 vim_state
= vim_details
['_admin'].get('operationalState', '-')
2310 error_details
= 'N/A'
2311 if vim_state
== 'ERROR':
2312 error_details
= vim_details
['_admin'].get('detailed-status', 'Not found')
2313 table
.add_row([vim
['name'], vim
['uuid'], vim_state
, wrap_text(text
=error_details
, width
=80)])
2315 table
.add_row([vim
['name'], vim
['uuid']])
2320 @cli_osm.command(name
='vim-show', short_help
='shows the details of a VIM account')
2321 @click.argument('name')
2323 def vim_show(ctx
, name
):
2324 """shows the details of a VIM account
2326 NAME: name or ID of the VIM account
2330 resp
= ctx
.obj
.vim
.get(name
)
2331 if 'vim_password' in resp
:
2332 resp
['vim_password']='********'
2333 # except ClientException as e:
2337 table
= PrettyTable(['key', 'attribute'])
2338 for k
, v
in list(resp
.items()):
2339 table
.add_row([k
, wrap_text(text
=json
.dumps(v
, indent
=2),width
=100)])
2344 ####################
2346 ####################
2348 @cli_osm.command(name
='wim-create', short_help
='creates a new WIM account')
2349 @click.option('--name',
2351 help='Name for the WIM account')
2352 @click.option('--user',
2353 help='WIM username')
2354 @click.option('--password',
2355 help='WIM password')
2356 @click.option('--url',
2359 # @click.option('--tenant',
2360 # help='wIM tenant name')
2361 @click.option('--config',
2363 help='WIM specific config parameters')
2364 @click.option('--wim_type',
2366 @click.option('--description',
2368 help='human readable description')
2369 @click.option('--wim_port_mapping', default
=None,
2370 help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge "
2371 "(WAN service endpoint id and info)")
2372 @click.option('--wait',
2376 help='do not return the control immediately, but keep it '
2377 'until the operation is completed, or timeout')
2390 """creates a new WIM account"""
2393 check_client_version(ctx
.obj
, ctx
.command
.name
)
2394 # if sdn_controller:
2395 # check_client_version(ctx.obj, '--sdn_controller')
2396 # if sdn_port_mapping:
2397 # check_client_version(ctx.obj, '--sdn_port_mapping')
2399 if user
: wim
['user'] = user
2400 if password
: wim
['password'] = password
2401 if url
: wim
['wim_url'] = url
2402 # if tenant: wim['tenant'] = tenant
2403 wim
['wim_type'] = wim_type
2404 if description
: wim
['description'] = description
2405 if config
: wim
['config'] = config
2406 ctx
.obj
.wim
.create(name
, wim
, wim_port_mapping
, wait
=wait
)
2407 # except ClientException as e:
2412 @cli_osm.command(name
='wim-update', short_help
='updates a WIM account')
2413 @click.argument('name')
2414 @click.option('--newname', help='New name for the WIM account')
2415 @click.option('--user', help='WIM username')
2416 @click.option('--password', help='WIM password')
2417 @click.option('--url', help='WIM url')
2418 @click.option('--config', help='WIM specific config parameters')
2419 @click.option('--wim_type', help='WIM type')
2420 @click.option('--description', help='human readable description')
2421 @click.option('--wim_port_mapping', default
=None,
2422 help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge "
2423 "(WAN service endpoint id and info)")
2424 @click.option('--wait',
2428 help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2441 """updates a WIM account
2443 NAME: name or ID of the WIM account
2447 check_client_version(ctx
.obj
, ctx
.command
.name
)
2449 if newname
: wim
['name'] = newname
2450 if user
: wim
['user'] = user
2451 if password
: wim
['password'] = password
2452 if url
: wim
['url'] = url
2453 # if tenant: wim['tenant'] = tenant
2454 if wim_type
: wim
['wim_type'] = wim_type
2455 if description
: wim
['description'] = description
2456 if config
: wim
['config'] = config
2457 ctx
.obj
.wim
.update(name
, wim
, wim_port_mapping
, wait
=wait
)
2458 # except ClientException as e:
2463 @cli_osm.command(name
='wim-delete', short_help
='deletes a WIM account')
2464 @click.argument('name')
2465 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2466 @click.option('--wait',
2470 help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2472 def wim_delete(ctx
, name
, force
, wait
):
2473 """deletes a WIM account
2475 NAME: name or ID of the WIM account to be deleted
2479 check_client_version(ctx
.obj
, ctx
.command
.name
)
2480 ctx
.obj
.wim
.delete(name
, force
, wait
=wait
)
2481 # except ClientException as e:
2486 @cli_osm.command(name
='wim-list', short_help
='list all WIM accounts')
2487 @click.option('--filter', default
=None,
2488 help='restricts the list to the WIM accounts matching the filter')
2490 def wim_list(ctx
, filter):
2491 """list all WIM accounts"""
2494 check_client_version(ctx
.obj
, ctx
.command
.name
)
2495 resp
= ctx
.obj
.wim
.list(filter)
2496 table
= PrettyTable(['wim name', 'uuid'])
2498 table
.add_row([wim
['name'], wim
['uuid']])
2501 # except ClientException as e:
2506 @cli_osm.command(name
='wim-show', short_help
='shows the details of a WIM account')
2507 @click.argument('name')
2509 def wim_show(ctx
, name
):
2510 """shows the details of a WIM account
2512 NAME: name or ID of the WIM account
2516 check_client_version(ctx
.obj
, ctx
.command
.name
)
2517 resp
= ctx
.obj
.wim
.get(name
)
2518 if 'password' in resp
:
2519 resp
['wim_password']='********'
2520 # except ClientException as e:
2524 table
= PrettyTable(['key', 'attribute'])
2525 for k
, v
in list(resp
.items()):
2526 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2531 ####################
2532 # SDN controller operations
2533 ####################
2535 @cli_osm.command(name
='sdnc-create', short_help
='creates a new SDN controller')
2536 @click.option('--name',
2538 help='Name to create sdn controller')
2539 @click.option('--type',
2541 help='SDN controller type')
2542 @click.option('--sdn_controller_version', # hidden=True,
2543 help='Deprecated. Use --config {version: sdn_controller_version}')
2544 @click.option('--url',
2545 help='URL in format http[s]://HOST:IP/')
2546 @click.option('--ip_address', # hidden=True,
2547 help='Deprecated. Use --url')
2548 @click.option('--port', # hidden=True,
2549 help='Deprecated. Use --url')
2550 @click.option('--switch_dpid', # hidden=True,
2551 help='Deprecated. Use --config {switch_id: DPID}')
2552 @click.option('--config',
2553 help='Extra information for SDN in yaml format, as {switch_id: identity used for the plugin (e.g. DPID: '
2554 'Openflow Datapath ID), version: version}')
2555 @click.option('--user',
2556 help='SDN controller username')
2557 @click.option('--password',
2559 confirmation_prompt
=True,
2560 help='SDN controller password')
2561 @click.option('--description', default
=None, help='human readable description')
2562 @click.option('--wait',
2566 help="do not return the control immediately, but keep it until the operation is completed, or timeout")
2568 def sdnc_create(ctx
, **kwargs
):
2569 """creates a new SDN controller"""
2571 sdncontroller
= {x
: kwargs
[x
] for x
in kwargs
if kwargs
[x
] and
2572 x
not in ("wait", "ip_address", "port", "switch_dpid")}
2573 if kwargs
.get("port"):
2574 print("option '--port' is deprecated, use '--url' instead")
2575 sdncontroller
["port"] = int(kwargs
["port"])
2576 if kwargs
.get("ip_address"):
2577 print("option '--ip_address' is deprecated, use '--url' instead")
2578 sdncontroller
["ip"] = kwargs
["ip_address"]
2579 if kwargs
.get("switch_dpid"):
2580 print("option '--switch_dpid' is deprecated, use '--config={switch_id: id|DPID}' instead")
2581 sdncontroller
["dpid"] = kwargs
["switch_dpid"]
2582 if kwargs
.get("sdn_controller_version"):
2583 print("option '--sdn_controller_version' is deprecated, use '--config={version: SDN_CONTROLLER_VERSION}'"
2586 check_client_version(ctx
.obj
, ctx
.command
.name
)
2587 ctx
.obj
.sdnc
.create(kwargs
["name"], sdncontroller
, wait
=kwargs
["wait"])
2588 # except ClientException as e:
2592 @cli_osm.command(name
='sdnc-update', short_help
='updates an SDN controller')
2593 @click.argument('name')
2594 @click.option('--newname', help='New name for the SDN controller')
2595 @click.option('--description', default
=None, help='human readable description')
2596 @click.option('--type', help='SDN controller type')
2597 @click.option('--url', help='URL in format http[s]://HOST:IP/')
2598 @click.option('--config', help='Extra information for SDN in yaml format, as '
2599 '{switch_id: identity used for the plugin (e.g. DPID: '
2600 'Openflow Datapath ID), version: version}')
2601 @click.option('--user', help='SDN controller username')
2602 @click.option('--password', help='SDN controller password')
2603 @click.option('--ip_address', help='Deprecated. Use --url') # hidden=True
2604 @click.option('--port', help='Deprecated. Use --url') # hidden=True
2605 @click.option('--switch_dpid', help='Deprecated. Use --config {switch_dpid: DPID}') # hidden=True
2606 @click.option('--sdn_controller_version', help='Deprecated. Use --config {version: VERSION}') # hidden=True
2607 @click.option('--wait', required
=False, default
=False, is_flag
=True,
2608 help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2610 def sdnc_update(ctx
, **kwargs
):
2611 """updates an SDN controller
2613 NAME: name or ID of the SDN controller
2616 sdncontroller
= {x
: kwargs
[x
] for x
in kwargs
if kwargs
[x
] and
2617 x
not in ("wait", "ip_address", "port", "switch_dpid", "new_name")}
2618 if kwargs
.get("newname"):
2619 sdncontroller
["name"] = kwargs
["newname"]
2620 if kwargs
.get("port"):
2621 print("option '--port' is deprecated, use '--url' instead")
2622 sdncontroller
["port"] = int(kwargs
["port"])
2623 if kwargs
.get("ip_address"):
2624 print("option '--ip_address' is deprecated, use '--url' instead")
2625 sdncontroller
["ip"] = kwargs
["ip_address"]
2626 if kwargs
.get("switch_dpid"):
2627 print("option '--switch_dpid' is deprecated, use '--config={switch_id: id|DPID}' instead")
2628 sdncontroller
["dpid"] = kwargs
["switch_dpid"]
2629 if kwargs
.get("sdn_controller_version"):
2630 print("option '--sdn_controller_version' is deprecated, use '---config={version: SDN_CONTROLLER_VERSION}'"
2634 check_client_version(ctx
.obj
, ctx
.command
.name
)
2635 ctx
.obj
.sdnc
.update(kwargs
["name"], sdncontroller
, wait
=kwargs
["wait"])
2636 # except ClientException as e:
2641 @cli_osm.command(name
='sdnc-delete', short_help
='deletes an SDN controller')
2642 @click.argument('name')
2643 @click.option('--force', is_flag
=True, help='forces the deletion bypassing pre-conditions')
2644 @click.option('--wait', required
=False, default
=False, is_flag
=True,
2645 help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2647 def sdnc_delete(ctx
, name
, force
, wait
):
2648 """deletes an SDN controller
2650 NAME: name or ID of the SDN controller to be deleted
2654 check_client_version(ctx
.obj
, ctx
.command
.name
)
2655 ctx
.obj
.sdnc
.delete(name
, force
, wait
=wait
)
2656 # except ClientException as e:
2661 @cli_osm.command(name
='sdnc-list', short_help
='list all SDN controllers')
2662 @click.option('--filter', default
=None,
2663 help="restricts the list to the SDN controllers matching the filter with format: 'k[.k..]=v[&k[.k]=v2]'")
2665 def sdnc_list(ctx
, filter):
2666 """list all SDN controllers"""
2669 check_client_version(ctx
.obj
, ctx
.command
.name
)
2670 resp
= ctx
.obj
.sdnc
.list(filter)
2671 # except ClientException as e:
2674 table
= PrettyTable(['sdnc name', 'id'])
2676 table
.add_row([sdnc
['name'], sdnc
['_id']])
2681 @cli_osm.command(name
='sdnc-show', short_help
='shows the details of an SDN controller')
2682 @click.argument('name')
2684 def sdnc_show(ctx
, name
):
2685 """shows the details of an SDN controller
2687 NAME: name or ID of the SDN controller
2691 check_client_version(ctx
.obj
, ctx
.command
.name
)
2692 resp
= ctx
.obj
.sdnc
.get(name
)
2693 # except ClientException as e:
2697 table
= PrettyTable(['key', 'attribute'])
2698 for k
, v
in list(resp
.items()):
2699 table
.add_row([k
, json
.dumps(v
, indent
=2)])
2704 ###########################
2705 # K8s cluster operations
2706 ###########################
2708 @cli_osm.command(name
='k8scluster-add', short_help
='adds a K8s cluster to OSM')
2709 @click.argument('name')
2710 @click.option('--creds',
2712 help='credentials file, i.e. a valid `.kube/config` file')
2713 @click.option('--version',
2715 help='Kubernetes version')
2716 @click.option('--vim',
2718 help='VIM target, the VIM where the cluster resides')
2719 @click.option('--k8s-nets',
2721 help='list of VIM networks, in JSON inline format, where the cluster is accessible via L3 routing, e.g. "{(k8s_net1:vim_network1) [,(k8s_net2:vim_network2) ...]}"')
2722 @click.option('--description',
2724 help='human readable description')
2725 @click.option('--namespace',
2726 default
='kube-system',
2727 help='namespace to be used for its operation, defaults to `kube-system`')
2728 @click.option('--cni',
2730 help='list of CNI plugins, in JSON inline format, used in the cluster')
2731 #@click.option('--skip-init',
2733 # help='If set, K8s cluster is assumed to be ready for its use with OSM')
2734 #@click.option('--wait',
2736 # help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2738 def k8scluster_add(ctx
,
2747 """adds a K8s cluster to OSM
2749 NAME: name of the K8s cluster
2752 check_client_version(ctx
.obj
, ctx
.command
.name
)
2754 cluster
['name'] = name
2755 with
open(creds
, 'r') as cf
:
2756 cluster
['credentials'] = yaml
.safe_load(cf
.read())
2757 cluster
['k8s_version'] = version
2758 cluster
['vim_account'] = vim
2759 cluster
['nets'] = yaml
.safe_load(k8s_nets
)
2761 cluster
['description'] = description
2762 if namespace
: cluster
['namespace'] = namespace
2763 if cni
: cluster
['cni'] = yaml
.safe_load(cni
)
2764 ctx
.obj
.k8scluster
.create(name
, cluster
)
2765 # except ClientException as e:
2770 @cli_osm.command(name
='k8scluster-update', short_help
='updates a K8s cluster')
2771 @click.argument('name')
2772 @click.option('--newname', help='New name for the K8s cluster')
2773 @click.option('--creds', help='credentials file, i.e. a valid `.kube/config` file')
2774 @click.option('--version', help='Kubernetes version')
2775 @click.option('--vim', help='VIM target, the VIM where the cluster resides')
2776 @click.option('--k8s-nets', help='list of VIM networks, in JSON inline format, where the cluster is accessible via L3 routing, e.g. "{(k8s_net1:vim_network1) [,(k8s_net2:vim_network2) ...]}"')
2777 @click.option('--description', help='human readable description')
2778 @click.option('--namespace', help='namespace to be used for its operation, defaults to `kube-system`')
2779 @click.option('--cni', help='list of CNI plugins, in JSON inline format, used in the cluster')
2781 def k8scluster_update(ctx
,
2791 """updates a K8s cluster
2793 NAME: name or ID of the K8s cluster
2796 check_client_version(ctx
.obj
, ctx
.command
.name
)
2798 if newname
: cluster
['name'] = newname
2800 with
open(creds
, 'r') as cf
:
2801 cluster
['credentials'] = yaml
.safe_load(cf
.read())
2802 if version
: cluster
['k8s_version'] = version
2803 if vim
: cluster
['vim_account'] = vim
2804 if k8s_nets
: cluster
['nets'] = yaml
.safe_load(k8s_nets
)
2805 if description
: cluster
['description'] = description
2806 if namespace
: cluster
['namespace'] = namespace
2807 if cni
: cluster
['cni'] = yaml
.safe_load(cni
)
2808 ctx
.obj
.k8scluster
.update(name
, cluster
)
2809 # except ClientException as e:
2814 @cli_osm.command(name
='k8scluster-delete', short_help
='deletes a K8s cluster')
2815 @click.argument('name')
2816 @click.option('--force', is_flag
=True, help='forces the deletion from the DB (not recommended)')
2817 #@click.option('--wait',
2819 # help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2821 def k8scluster_delete(ctx
, name
, force
):
2822 """deletes a K8s cluster
2824 NAME: name or ID of the K8s cluster to be deleted
2827 check_client_version(ctx
.obj
, ctx
.command
.name
)
2828 ctx
.obj
.k8scluster
.delete(name
, force
=force
)
2829 # except ClientException as e:
2834 @cli_osm.command(name
='k8scluster-list')
2835 @click.option('--filter', default
=None,
2836 help='restricts the list to the K8s clusters matching the filter')
2837 @click.option('--literal', is_flag
=True,
2838 help='print literally, no pretty table')
2840 def k8scluster_list(ctx
, filter, literal
):
2841 """list all K8s clusters"""
2843 check_client_version(ctx
.obj
, ctx
.command
.name
)
2844 resp
= ctx
.obj
.k8scluster
.list(filter)
2846 print(yaml
.safe_dump(resp
))
2848 table
= PrettyTable(['Name', 'Id', 'Version', 'VIM', 'K8s-nets', 'Operational State', 'Description'])
2849 for cluster
in resp
:
2850 table
.add_row([cluster
['name'], cluster
['_id'], cluster
['k8s_version'], cluster
['vim_account'],
2851 json
.dumps(cluster
['nets']), cluster
["_admin"]["operationalState"],
2852 trunc_text(cluster
.get('description',''),40)])
2855 # except ClientException as e:
2860 @cli_osm.command(name
='k8scluster-show', short_help
='shows the details of a K8s cluster')
2861 @click.argument('name')
2862 @click.option('--literal', is_flag
=True,
2863 help='print literally, no pretty table')
2865 def k8scluster_show(ctx
, name
, literal
):
2866 """shows the details of a K8s cluster
2868 NAME: name or ID of the K8s cluster
2871 resp
= ctx
.obj
.k8scluster
.get(name
)
2873 print(yaml
.safe_dump(resp
))
2875 table
= PrettyTable(['key', 'attribute'])
2876 for k
, v
in list(resp
.items()):
2877 table
.add_row([k
, wrap_text(text
=json
.dumps(v
, indent
=2),width
=100)])
2880 # except ClientException as e:
2886 ###########################
2888 ###########################
2890 @cli_osm.command(name
='repo-add', short_help
='adds a repo to OSM')
2891 @click.argument('name')
2892 @click.argument('uri')
2893 @click.option('--type',
2894 type=click
.Choice(['helm-chart', 'juju-bundle']),
2896 help='type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles)')
2897 @click.option('--description',
2899 help='human readable description')
2900 #@click.option('--wait',
2902 # help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2909 """adds a repo to OSM
2911 NAME: name of the repo
2912 URI: URI of the repo
2915 check_client_version(ctx
.obj
, ctx
.command
.name
)
2921 repo
['description'] = description
2922 ctx
.obj
.repo
.create(name
, repo
)
2923 # except ClientException as e:
2928 @cli_osm.command(name
='repo-update', short_help
='updates a repo in OSM')
2929 @click.argument('name')
2930 @click.option('--newname', help='New name for the repo')
2931 @click.option('--uri', help='URI of the repo')
2932 @click.option('--type', type=click
.Choice(['helm-chart', 'juju-bundle']),
2933 help='type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles)')
2934 @click.option('--description', help='human readable description')
2935 #@click.option('--wait',
2937 # help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2939 def repo_update(ctx
,
2945 """updates a repo in OSM
2947 NAME: name of the repo
2950 check_client_version(ctx
.obj
, ctx
.command
.name
)
2952 if newname
: repo
['name'] = newname
2953 if uri
: repo
['uri'] = uri
2954 if type: repo
['type'] = type
2955 if description
: repo
['description'] = description
2956 ctx
.obj
.repo
.update(name
, repo
)
2957 # except ClientException as e:
2962 @cli_osm.command(name
='repo-delete', short_help
='deletes a repo')
2963 @click.argument('name')
2964 @click.option('--force', is_flag
=True, help='forces the deletion from the DB (not recommended)')
2965 #@click.option('--wait',
2967 # help='do not return the control immediately, but keep it until the operation is completed, or timeout')
2969 def repo_delete(ctx
, name
, force
):
2972 NAME: name or ID of the repo to be deleted
2975 check_client_version(ctx
.obj
, ctx
.command
.name
)
2976 ctx
.obj
.repo
.delete(name
, force
=force
)
2977 # except ClientException as e:
2982 @cli_osm.command(name
='repo-list')
2983 @click.option('--filter', default
=None,
2984 help='restricts the list to the repos matching the filter')
2985 @click.option('--literal', is_flag
=True,
2986 help='print literally, no pretty table')
2988 def repo_list(ctx
, filter, literal
):
2989 """list all repos"""
2991 check_client_version(ctx
.obj
, ctx
.command
.name
)
2992 resp
= ctx
.obj
.repo
.list(filter)
2994 print(yaml
.safe_dump(resp
))
2996 table
= PrettyTable(['Name', 'Id', 'Type', 'URI', 'Description'])
2998 #cluster['k8s-nets'] = json.dumps(yaml.safe_load(cluster['k8s-nets']))
2999 table
.add_row([repo
['name'], repo
['_id'], repo
['type'], repo
['url'], trunc_text(repo
.get('description',''),40)])
3002 # except ClientException as e:
3007 @cli_osm.command(name
='repo-show', short_help
='shows the details of a repo')
3008 @click.argument('name')
3009 @click.option('--literal', is_flag
=True,
3010 help='print literally, no pretty table')
3012 def repo_show(ctx
, name
, literal
):
3013 """shows the details of a repo
3015 NAME: name or ID of the repo
3018 resp
= ctx
.obj
.repo
.get(name
)
3020 print(yaml
.safe_dump(resp
))
3022 table
= PrettyTable(['key', 'attribute'])
3023 for k
, v
in list(resp
.items()):
3024 table
.add_row([k
, json
.dumps(v
, indent
=2)])
3027 # except ClientException as e:
3033 ####################
3034 # Project mgmt operations
3035 ####################
3037 @cli_osm.command(name
='project-create', short_help
='creates a new project')
3038 @click.argument('name')
3039 #@click.option('--description',
3040 # default='no description',
3041 # help='human readable description')
3042 @click.option('--domain-name', 'domain_name',
3044 help='assign to a domain')
3046 def project_create(ctx
, name
, domain_name
):
3047 """Creates a new project
3049 NAME: name of the project
3050 DOMAIN_NAME: optional domain name for the project when keystone authentication is used
3054 project
['name'] = name
3056 project
['domain_name'] = domain_name
3058 check_client_version(ctx
.obj
, ctx
.command
.name
)
3059 ctx
.obj
.project
.create(name
, project
)
3060 # except ClientException as e:
3065 @cli_osm.command(name
='project-delete', short_help
='deletes a project')
3066 @click.argument('name')
3067 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
3069 def project_delete(ctx
, name
):
3070 """deletes a project
3072 NAME: name or ID of the project to be deleted
3076 check_client_version(ctx
.obj
, ctx
.command
.name
)
3077 ctx
.obj
.project
.delete(name
)
3078 # except ClientException as e:
3083 @cli_osm.command(name
='project-list', short_help
='list all projects')
3084 @click.option('--filter', default
=None,
3085 help='restricts the list to the projects matching the filter')
3087 def project_list(ctx
, filter):
3088 """list all projects"""
3091 check_client_version(ctx
.obj
, ctx
.command
.name
)
3092 resp
= ctx
.obj
.project
.list(filter)
3093 # except ClientException as e:
3096 table
= PrettyTable(['name', 'id'])
3098 table
.add_row([proj
['name'], proj
['_id']])
3103 @cli_osm.command(name
='project-show', short_help
='shows the details of a project')
3104 @click.argument('name')
3106 def project_show(ctx
, name
):
3107 """shows the details of a project
3109 NAME: name or ID of the project
3113 check_client_version(ctx
.obj
, ctx
.command
.name
)
3114 resp
= ctx
.obj
.project
.get(name
)
3115 # except ClientException as e:
3119 table
= PrettyTable(['key', 'attribute'])
3120 for k
, v
in resp
.items():
3121 table
.add_row([k
, json
.dumps(v
, indent
=2)])
3126 @cli_osm.command(name
='project-update', short_help
='updates a project (only the name can be updated)')
3127 @click.argument('project')
3128 @click.option('--name',
3130 help='new name for the project')
3133 def project_update(ctx
, project
, name
):
3135 Update a project name
3138 :param project: id or name of the project to modify
3139 :param name: new name for the project
3143 project_changes
= {}
3144 project_changes
['name'] = name
3147 check_client_version(ctx
.obj
, ctx
.command
.name
)
3148 ctx
.obj
.project
.update(project
, project_changes
)
3149 # except ClientException as e:
3153 ####################
3154 # User mgmt operations
3155 ####################
3157 @cli_osm.command(name
='user-create', short_help
='creates a new user')
3158 @click.argument('username')
3159 @click.option('--password',
3162 confirmation_prompt
=True,
3163 help='user password')
3164 @click.option('--projects',
3165 # prompt="Comma separate list of projects",
3167 callback
=lambda ctx
, param
, value
: ''.join(value
).split(',') if all(len(x
)==1 for x
in value
) else value
,
3168 help='list of project ids that the user belongs to')
3169 @click.option('--project-role-mappings', 'project_role_mappings',
3170 default
=None, multiple
=True,
3171 help="assign role(s) in a project. Can be used several times: 'project,role1[,role2,...]'")
3172 @click.option('--domain-name', 'domain_name',
3174 help='assign to a domain')
3176 def user_create(ctx
, username
, password
, projects
, project_role_mappings
, domain_name
):
3177 """Creates a new user
3180 USERNAME: name of the user
3181 PASSWORD: password of the user
3182 PROJECTS: projects assigned to user (internal only)
3183 PROJECT_ROLE_MAPPING: roles in projects assigned to user (keystone)
3184 DOMAIN_NAME: optional domain name for the user when keystone authentication is used
3188 user
['username'] = username
3189 user
['password'] = password
3190 user
['projects'] = projects
3191 user
['project_role_mappings'] = project_role_mappings
3193 user
['domain_name'] = domain_name
3196 check_client_version(ctx
.obj
, ctx
.command
.name
)
3197 ctx
.obj
.user
.create(username
, user
)
3198 # except ClientException as e:
3203 @cli_osm.command(name
='user-update', short_help
='updates user information')
3204 @click.argument('username')
3205 @click.option('--password',
3208 # confirmation_prompt=True,
3209 help='user password')
3210 @click.option('--set-username', 'set_username',
3212 help='change username')
3213 @click.option('--set-project', 'set_project',
3214 default
=None, multiple
=True,
3215 help="create/replace the roles for this project: 'project,role1[,role2,...]'")
3216 @click.option('--remove-project', 'remove_project',
3217 default
=None, multiple
=True,
3218 help="removes project from user: 'project'")
3219 @click.option('--add-project-role', 'add_project_role',
3220 default
=None, multiple
=True,
3221 help="assign role(s) in a project. Can be used several times: 'project,role1[,role2,...]'")
3222 @click.option('--remove-project-role', 'remove_project_role',
3223 default
=None, multiple
=True,
3224 help="remove role(s) in a project. Can be used several times: 'project,role1[,role2,...]'")
3226 def user_update(ctx
, username
, password
, set_username
, set_project
, remove_project
,
3227 add_project_role
, remove_project_role
):
3228 """Update a user information
3231 USERNAME: name of the user
3232 PASSWORD: new password
3233 SET_USERNAME: new username
3234 SET_PROJECT: creating mappings for project/role(s)
3235 REMOVE_PROJECT: deleting mappings for project/role(s)
3236 ADD_PROJECT_ROLE: adding mappings for project/role(s)
3237 REMOVE_PROJECT_ROLE: removing mappings for project/role(s)
3241 user
['password'] = password
3242 user
['username'] = set_username
3243 user
['set-project'] = set_project
3244 user
['remove-project'] = remove_project
3245 user
['add-project-role'] = add_project_role
3246 user
['remove-project-role'] = remove_project_role
3249 check_client_version(ctx
.obj
, ctx
.command
.name
)
3250 ctx
.obj
.user
.update(username
, user
)
3251 # except ClientException as e:
3256 @cli_osm.command(name
='user-delete', short_help
='deletes a user')
3257 @click.argument('name')
3258 #@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
3260 def user_delete(ctx
, name
):
3264 NAME: name or ID of the user to be deleted
3268 check_client_version(ctx
.obj
, ctx
.command
.name
)
3269 ctx
.obj
.user
.delete(name
)
3270 # except ClientException as e:
3275 @cli_osm.command(name
='user-list', short_help
='list all users')
3276 @click.option('--filter', default
=None,
3277 help='restricts the list to the users matching the filter')
3279 def user_list(ctx
, filter):
3280 """list all users"""
3282 check_client_version(ctx
.obj
, ctx
.command
.name
)
3283 resp
= ctx
.obj
.user
.list(filter)
3284 # except ClientException as e:
3287 table
= PrettyTable(['name', 'id'])
3289 table
.add_row([user
['username'], user
['_id']])
3294 @cli_osm.command(name
='user-show', short_help
='shows the details of a user')
3295 @click.argument('name')
3297 def user_show(ctx
, name
):
3298 """shows the details of a user
3300 NAME: name or ID of the user
3304 check_client_version(ctx
.obj
, ctx
.command
.name
)
3305 resp
= ctx
.obj
.user
.get(name
)
3306 if 'password' in resp
:
3307 resp
['password']='********'
3308 # except ClientException as e:
3312 table
= PrettyTable(['key', 'attribute'])
3313 for k
, v
in resp
.items():
3314 table
.add_row([k
, json
.dumps(v
, indent
=2)])
3319 ####################
3320 # Fault Management operations
3321 ####################
3323 @cli_osm.command(name
='ns-alarm-create')
3324 @click.argument('name')
3325 @click.option('--ns', prompt
=True, help='NS instance id or name')
3326 @click.option('--vnf', prompt
=True,
3327 help='VNF name (VNF member index as declared in the NSD)')
3328 @click.option('--vdu', prompt
=True,
3329 help='VDU name (VDU name as declared in the VNFD)')
3330 @click.option('--metric', prompt
=True,
3331 help='Name of the metric (e.g. cpu_utilization)')
3332 @click.option('--severity', default
='WARNING',
3333 help='severity of the alarm (WARNING, MINOR, MAJOR, CRITICAL, INDETERMINATE)')
3334 @click.option('--threshold_value', prompt
=True,
3335 help='threshold value that, when crossed, an alarm is triggered')
3336 @click.option('--threshold_operator', prompt
=True,
3337 help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)')
3338 @click.option('--statistic', default
='AVERAGE',
3339 help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)')
3341 def ns_alarm_create(ctx
, name
, ns
, vnf
, vdu
, metric
, severity
,
3342 threshold_value
, threshold_operator
, statistic
):
3343 """creates a new alarm for a NS instance"""
3344 # TODO: Check how to validate threshold_value.
3345 # Should it be an integer (1-100), percentage, or decimal (0.01-1.00)?
3348 ns_instance
= ctx
.obj
.ns
.get(ns
)
3350 alarm
['alarm_name'] = name
3351 alarm
['ns_id'] = ns_instance
['_id']
3352 alarm
['correlation_id'] = ns_instance
['_id']
3353 alarm
['vnf_member_index'] = vnf
3354 alarm
['vdu_name'] = vdu
3355 alarm
['metric_name'] = metric
3356 alarm
['severity'] = severity
3357 alarm
['threshold_value'] = int(threshold_value
)
3358 alarm
['operation'] = threshold_operator
3359 alarm
['statistic'] = statistic
3360 check_client_version(ctx
.obj
, ctx
.command
.name
)
3361 ctx
.obj
.ns
.create_alarm(alarm
)
3362 # except ClientException as e:
3367 #@cli_osm.command(name='ns-alarm-delete')
3368 #@click.argument('name')
3369 #@click.pass_context
3370 #def ns_alarm_delete(ctx, name):
3371 # """deletes an alarm
3373 # NAME: name of the alarm to be deleted
3376 # check_client_version(ctx.obj, ctx.command.name)
3377 # ctx.obj.ns.delete_alarm(name)
3378 # except ClientException as e:
3383 ####################
3384 # Performance Management operations
3385 ####################
3387 @cli_osm.command(name
='ns-metric-export', short_help
='exports a metric to the internal OSM bus, which can be read by other apps')
3388 @click.option('--ns', prompt
=True, help='NS instance id or name')
3389 @click.option('--vnf', prompt
=True,
3390 help='VNF name (VNF member index as declared in the NSD)')
3391 @click.option('--vdu', prompt
=True,
3392 help='VDU name (VDU name as declared in the VNFD)')
3393 @click.option('--metric', prompt
=True,
3394 help='name of the metric (e.g. cpu_utilization)')
3395 #@click.option('--period', default='1w',
3396 # help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
3397 @click.option('--interval', help='periodic interval (seconds) to export metrics continuously')
3399 def ns_metric_export(ctx
, ns
, vnf
, vdu
, metric
, interval
):
3400 """exports a metric to the internal OSM bus, which can be read by other apps"""
3401 # TODO: Check how to validate interval.
3402 # Should it be an integer (seconds), or should a suffix (s,m,h,d,w) also be permitted?
3405 ns_instance
= ctx
.obj
.ns
.get(ns
)
3407 metric_data
['ns_id'] = ns_instance
['_id']
3408 metric_data
['correlation_id'] = ns_instance
['_id']
3409 metric_data
['vnf_member_index'] = vnf
3410 metric_data
['vdu_name'] = vdu
3411 metric_data
['metric_name'] = metric
3412 metric_data
['collection_unit'] = 'WEEK'
3413 metric_data
['collection_period'] = 1
3414 check_client_version(ctx
.obj
, ctx
.command
.name
)
3416 print('{}'.format(ctx
.obj
.ns
.export_metric(metric_data
)))
3420 print('{} {}'.format(ctx
.obj
.ns
.export_metric(metric_data
),i
))
3421 time
.sleep(int(interval
))
3423 # except ClientException as e:
3428 ####################
3430 ####################
3432 @cli_osm.command(name
='version', short_help
='shows client and server versions')
3434 def get_version(ctx
):
3435 """shows client and server versions"""
3437 check_client_version(ctx
.obj
, "version")
3438 print ("Server version: {}".format(ctx
.obj
.get_version()))
3439 print ("Client version: {}".format(pkg_resources
.get_distribution("osmclient").version
))
3440 # except ClientException as e:
3444 @cli_osm.command(name
='upload-package', short_help
='uploads a VNF package or NS package')
3445 @click.argument('filename')
3446 @click.option('--skip-charm-build', default
=False, is_flag
=True,
3447 help='the charm will not be compiled, it is assumed to already exist')
3449 def upload_package(ctx
, filename
, skip_charm_build
):
3450 """uploads a vnf package or ns package
3452 filename: vnf or ns package folder, or vnf or ns package file (tar.gz)
3456 ctx
.obj
.package
.upload(filename
, skip_charm_build
=skip_charm_build
)
3457 fullclassname
= ctx
.obj
.__module
__ + "." + ctx
.obj
.__class
__.__name
__
3458 if fullclassname
!= 'osmclient.sol005.client.Client':
3459 ctx
.obj
.package
.wait_for_upload(filename
)
3460 # except ClientException as e:
3465 #@cli_osm.command(name='ns-scaling-show')
3466 #@click.argument('ns_name')
3467 #@click.pass_context
3468 #def show_ns_scaling(ctx, ns_name):
3469 # """shows the status of a NS scaling operation
3471 # NS_NAME: name of the NS instance being scaled
3474 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3475 # resp = ctx.obj.ns.list()
3476 # except ClientException as e:
3480 # table = PrettyTable(
3483 # 'operational status',
3488 # if ns_name == ns['name']:
3489 # nsopdata = ctx.obj.ns.get_opdata(ns['id'])
3490 # scaling_records = nsopdata['nsr:nsr']['scaling-group-record']
3491 # for record in scaling_records:
3492 # if 'instance' in record:
3493 # instances = record['instance']
3494 # for inst in instances:
3496 # [record['scaling-group-name-ref'],
3497 # inst['instance-id'],
3498 # inst['op-status'],
3499 # time.strftime('%Y-%m-%d %H:%M:%S',
3501 # inst['create-time'])),
3507 #@cli_osm.command(name='ns-scale')
3508 #@click.argument('ns_name')
3509 #@click.option('--ns_scale_group', prompt=True)
3510 #@click.option('--index', prompt=True)
3511 #@click.option('--wait',
3515 # help='do not return the control immediately, but keep it \
3516 # until the operation is completed, or timeout')
3517 #@click.pass_context
3518 #def ns_scale(ctx, ns_name, ns_scale_group, index, wait):
3521 # NS_NAME: name of the NS instance to be scaled
3524 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3525 # ctx.obj.ns.scale(ns_name, ns_scale_group, index, wait=wait)
3526 # except ClientException as e:
3531 #@cli_osm.command(name='config-agent-list')
3532 #@click.pass_context
3533 #def config_agent_list(ctx):
3534 # """list config agents"""
3536 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3537 # except ClientException as e:
3540 # table = PrettyTable(['name', 'account-type', 'details'])
3541 # for account in ctx.obj.vca.list():
3544 # account['account-type'],
3550 #@cli_osm.command(name='config-agent-delete')
3551 #@click.argument('name')
3552 #@click.pass_context
3553 #def config_agent_delete(ctx, name):
3554 # """deletes a config agent
3556 # NAME: name of the config agent to be deleted
3559 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3560 # ctx.obj.vca.delete(name)
3561 # except ClientException as e:
3566 #@cli_osm.command(name='config-agent-add')
3567 #@click.option('--name',
3569 #@click.option('--account_type',
3571 #@click.option('--server',
3573 #@click.option('--user',
3575 #@click.option('--secret',
3578 # confirmation_prompt=True)
3579 #@click.pass_context
3580 #def config_agent_add(ctx, name, account_type, server, user, secret):
3581 # """adds a config agent"""
3583 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3584 # ctx.obj.vca.create(name, account_type, server, user, secret)
3585 # except ClientException as e:
3590 #@cli_osm.command(name='ro-dump')
3591 #@click.pass_context
3593 # """shows RO agent information"""
3594 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3595 # resp = ctx.obj.vim.get_resource_orchestrator()
3596 # table = PrettyTable(['key', 'attribute'])
3597 # for k, v in list(resp.items()):
3598 # table.add_row([k, json.dumps(v, indent=2)])
3603 #@cli_osm.command(name='vcs-list')
3604 #@click.pass_context
3606 # check_client_version(ctx.obj, ctx.command.name, 'v1')
3607 # resp = ctx.obj.utils.get_vcs_info()
3608 # table = PrettyTable(['component name', 'state'])
3609 # for component in resp:
3610 # table.add_row([component['component_name'], component['state']])
3615 @cli_osm.command(name
='ns-action', short_help
='executes an action/primitive over a NS instance')
3616 @click.argument('ns_name')
3617 @click.option('--vnf_name', default
=None, help='member-vnf-index if the target is a vnf instead of a ns)')
3618 @click.option('--kdu_name', default
=None, help='kdu-name if the target is a kdu)')
3619 @click.option('--vdu_id', default
=None, help='vdu-id if the target is a vdu')
3620 @click.option('--vdu_count', default
=None, help='number of vdu instance of this vdu_id')
3621 @click.option('--action_name', prompt
=True, help='action name')
3622 @click.option('--params', default
=None, help='action params in YAML/JSON inline string')
3623 @click.option('--params_file', default
=None, help='YAML/JSON file with action params')
3624 @click.option('--timeout', required
=False, default
=None, type=int, help='timeout in seconds')
3625 @click.option('--wait',
3629 help='do not return the control immediately, but keep it until the operation is completed, or timeout')
3642 """executes an action/primitive over a NS instance
3644 NS_NAME: name or ID of the NS instance
3648 check_client_version(ctx
.obj
, ctx
.command
.name
)
3651 op_data
['member_vnf_index'] = vnf_name
3653 op_data
['kdu_name'] = kdu_name
3655 op_data
['vdu_id'] = vdu_id
3657 op_data
['vdu_count_index'] = vdu_count
3659 op_data
['timeout_ns_action'] = timeout
3660 op_data
['primitive'] = action_name
3662 with
open(params_file
, 'r') as pf
:
3665 op_data
['primitive_params'] = yaml
.safe_load(params
)
3667 op_data
['primitive_params'] = {}
3668 print(ctx
.obj
.ns
.exec_op(ns_name
, op_name
='action', op_data
=op_data
, wait
=wait
))
3670 # except ClientException as e:
3675 @cli_osm.command(name
='vnf-scale', short_help
='executes a VNF scale (adding/removing VDUs)')
3676 @click.argument('ns_name')
3677 @click.argument('vnf_name')
3678 @click.option('--scaling-group', prompt
=True, help="scaling-group-descriptor name to use")
3679 @click.option('--scale-in', default
=False, is_flag
=True, help="performs a scale in operation")
3680 @click.option('--scale-out', default
=False, is_flag
=True, help="performs a scale out operation (by default)")
3681 @click.option('--timeout', required
=False, default
=None, type=int, help='timeout in seconds')
3682 @click.option('--wait', required
=False, default
=False, is_flag
=True,
3683 help='do not return the control immediately, but keep it until the operation is completed, or timeout')
3694 Executes a VNF scale (adding/removing VDUs)
3697 NS_NAME: name or ID of the NS instance.
3698 VNF_NAME: member-vnf-index in the NS to be scaled.
3702 check_client_version(ctx
.obj
, ctx
.command
.name
)
3703 if not scale_in
and not scale_out
:
3705 ctx
.obj
.ns
.scale_vnf(ns_name
, vnf_name
, scaling_group
, scale_in
, scale_out
, wait
, timeout
)
3706 # except ClientException as e:
3711 ##############################
3712 # Role Management Operations #
3713 ##############################
3715 @cli_osm.command(name
='role-create', short_help
='creates a new role')
3716 @click.argument('name')
3717 @click.option('--permissions',
3719 help='role permissions using a dictionary')
3721 def role_create(ctx
, name
, permissions
):
3726 NAME: Name or ID of the role.
3727 DEFINITION: Definition of grant/denial of access to resources.
3731 check_client_version(ctx
.obj
, ctx
.command
.name
)
3732 ctx
.obj
.role
.create(name
, permissions
)
3733 # except ClientException as e:
3738 @cli_osm.command(name
='role-update', short_help
='updates a role')
3739 @click.argument('name')
3740 @click.option('--set-name',
3742 help='change name of rle')
3743 # @click.option('--permissions',
3745 # help='provide a yaml format dictionary with incremental changes. Values can be bool or None to delete')
3746 @click.option('--add',
3748 help='yaml format dictionary with permission: True/False to access grant/denial')
3749 @click.option('--remove',
3751 help='yaml format list to remove a permission')
3753 def role_update(ctx
, name
, set_name
, add
, remove
):
3758 NAME: Name or ID of the role.
3759 DEFINITION: Definition overwrites the old definition.
3760 ADD: Grant/denial of access to resource to add.
3761 REMOVE: Grant/denial of access to resource to remove.
3765 check_client_version(ctx
.obj
, ctx
.command
.name
)
3766 ctx
.obj
.role
.update(name
, set_name
, None, add
, remove
)
3767 # except ClientException as e:
3772 @cli_osm.command(name
='role-delete', short_help
='deletes a role')
3773 @click.argument('name')
3774 # @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
3776 def role_delete(ctx
, name
):
3781 NAME: Name or ID of the role.
3785 check_client_version(ctx
.obj
, ctx
.command
.name
)
3786 ctx
.obj
.role
.delete(name
)
3787 # except ClientException as e:
3792 @cli_osm.command(name
='role-list', short_help
='list all roles')
3793 @click.option('--filter', default
=None,
3794 help='restricts the list to the projects matching the filter')
3796 def role_list(ctx
, filter):
3802 check_client_version(ctx
.obj
, ctx
.command
.name
)
3803 resp
= ctx
.obj
.role
.list(filter)
3804 # except ClientException as e:
3807 table
= PrettyTable(['name', 'id'])
3809 table
.add_row([role
['name'], role
['_id']])
3814 @cli_osm.command(name
='role-show', short_help
='show specific role')
3815 @click.argument('name')
3817 def role_show(ctx
, name
):
3819 Shows the details of a role.
3822 NAME: Name or ID of the role.
3826 check_client_version(ctx
.obj
, ctx
.command
.name
)
3827 resp
= ctx
.obj
.role
.get(name
)
3828 # except ClientException as e:
3832 table
= PrettyTable(['key', 'attribute'])
3833 for k
, v
in resp
.items():
3834 table
.add_row([k
, json
.dumps(v
, indent
=2)])
3839 @cli_osm.command(name
='package-create',
3840 short_help
='Create a package descriptor')
3841 @click.argument('package-type')
3842 @click.argument('package-name')
3843 @click.option('--base-directory',
3845 help=('(NS/VNF/NST) Set the location for package creation. Default: "."'))
3846 @click.option('--image',
3847 default
="image-name",
3848 help='(VNF) Set the name of the vdu image. Default "image-name"')
3849 @click.option('--vdus',
3851 help='(VNF) Set the number of vdus in a VNF. Default 1')
3852 @click.option('--vcpu',
3854 help='(VNF) Set the number of virtual CPUs in a vdu. Default 1')
3855 @click.option('--memory',
3857 help='(VNF) Set the memory size (MB) of the vdu. Default 1024')
3858 @click.option('--storage',
3860 help='(VNF) Set the disk size (GB) of the vdu. Default 10')
3861 @click.option('--interfaces',
3863 help='(VNF) Set the number of additional interfaces apart from the management interface. Default 0')
3864 @click.option('--vendor',
3866 help='(NS/VNF) Set the descriptor vendor. Default "OSM"')
3867 @click.option('--override',
3870 help='(NS/VNF/NST) Flag for overriding the package if exists.')
3871 @click.option('--detailed',
3874 help='(NS/VNF/NST) Flag for generating descriptor .yaml with all possible commented options')
3875 @click.option('--netslice-subnets',
3877 help='(NST) Number of netslice subnets. Default 1')
3878 @click.option('--netslice-vlds',
3880 help='(NST) Number of netslice vlds. Default 1')
3882 def package_create(ctx
,
3898 Creates an OSM NS, VNF, NST package
3901 PACKAGE_TYPE: Package to be created: NS, VNF or NST.
3902 PACKAGE_NAME: Name of the package to create the folder with the content.
3906 check_client_version(ctx
.obj
, ctx
.command
.name
)
3907 print("Creating the {} structure: {}/{}".format(package_type
.upper(), base_directory
, package_name
))
3908 resp
= ctx
.obj
.package_tool
.create(package_type
,
3917 interfaces
=interfaces
,
3920 netslice_subnets
=netslice_subnets
,
3921 netslice_vlds
=netslice_vlds
)
3923 # except ClientException as inst:
3924 # print("ERROR: {}".format(inst))
3927 @cli_osm.command(name
='package-validate',
3928 short_help
='Validate a package descriptor')
3929 @click.argument('base-directory',
3932 @click.option('--recursive/--no-recursive',
3934 help='The activated recursive option will validate the yaml files'
3935 ' within the indicated directory and in its subdirectories')
3937 def package_validate(ctx
,
3941 Validate descriptors given a base directory.
3944 BASE_DIRECTORY: Stub folder for NS, VNF or NST package.
3947 check_client_version(ctx
.obj
, ctx
.command
.name
)
3948 results
= ctx
.obj
.package_tool
.validate(base_directory
, recursive
)
3949 table
= PrettyTable()
3950 table
.field_names
= ["TYPE", "PATH", "VALID", "ERROR"]
3951 # Print the dictionary generated by the validation function
3952 for result
in results
:
3953 table
.add_row([result
["type"], result
["path"], result
["valid"], result
["error"]])
3954 table
.sortby
= "VALID"
3955 table
.align
["PATH"] = "l"
3956 table
.align
["TYPE"] = "l"
3957 table
.align
["ERROR"] = "l"
3959 # except ClientException as inst:
3960 # print("ERROR: {}".format(inst))
3963 @cli_osm.command(name
='package-build',
3964 short_help
='Build the tar.gz of the package')
3965 @click.argument('package-folder')
3966 @click.option('--skip-validation',
3969 help='skip package validation')
3970 @click.option('--skip-charm-build', default
=False, is_flag
=True,
3971 help='the charm will not be compiled, it is assumed to already exist')
3973 def package_build(ctx
,
3978 Build the package NS, VNF given the package_folder.
3981 PACKAGE_FOLDER: Folder of the NS, VNF or NST to be packaged
3984 check_client_version(ctx
.obj
, ctx
.command
.name
)
3985 results
= ctx
.obj
.package_tool
.build(package_folder
,
3986 skip_validation
=skip_validation
,
3987 skip_charm_build
=skip_charm_build
)
3989 # except ClientException as inst:
3990 # print("ERROR: {}".format(inst))
3998 except pycurl
.error
as exc
:
4000 print('Maybe "--hostname" option or OSM_HOSTNAME environment variable needs to be specified')
4001 except ClientException
as exc
:
4002 print("ERROR: {}".format(exc
))
4003 except (FileNotFoundError
, PermissionError
) as exc
:
4004 print("Cannot open file: {}".format(exc
))
4005 except yaml
.YAMLError
as exc
:
4006 print("Invalid YAML format: {}".format(exc
))
4008 # TODO capture other controlled exceptions here
4009 # TODO remove the ClientException captures from all places, unless they do something different
4012 if __name__
== '__main__':