Feature 1429 - secure key management feature
[osm/RO.git] / osm_ro / vimconn.py
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 #
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
22 ##
23
24 """
25 vimconn implement an Abstract class for the vim connector plugins
26 with the definition of the method to be implemented.
27 """
28 __author__="Alfonso Tierno, Igor D.C."
29 __date__ ="$14-aug-2017 23:59:59$"
30
31 import logging
32 import paramiko
33 import socket
34 import StringIO
35
36 #Error variables
37 HTTP_Bad_Request = 400
38 HTTP_Unauthorized = 401
39 HTTP_Not_Found = 404
40 HTTP_Method_Not_Allowed = 405
41 HTTP_Request_Timeout = 408
42 HTTP_Conflict = 409
43 HTTP_Not_Implemented = 501
44 HTTP_Service_Unavailable = 503
45 HTTP_Internal_Server_Error = 500
46
47 class vimconnException(Exception):
48 """Common and base class Exception for all vimconnector exceptions"""
49 def __init__(self, message, http_code=HTTP_Bad_Request):
50 Exception.__init__(self, message)
51 self.http_code = http_code
52
53 class vimconnConnectionException(vimconnException):
54 """Connectivity error with the VIM"""
55 def __init__(self, message, http_code=HTTP_Service_Unavailable):
56 vimconnException.__init__(self, message, http_code)
57
58 class vimconnUnexpectedResponse(vimconnException):
59 """Get an wrong response from VIM"""
60 def __init__(self, message, http_code=HTTP_Service_Unavailable):
61 vimconnException.__init__(self, message, http_code)
62
63 class vimconnAuthException(vimconnException):
64 """Invalid credentials or authorization to perform this action over the VIM"""
65 def __init__(self, message, http_code=HTTP_Unauthorized):
66 vimconnException.__init__(self, message, http_code)
67
68 class vimconnNotFoundException(vimconnException):
69 """The item is not found at VIM"""
70 def __init__(self, message, http_code=HTTP_Not_Found):
71 vimconnException.__init__(self, message, http_code)
72
73 class vimconnConflictException(vimconnException):
74 """There is a conflict, e.g. more item found than one"""
75 def __init__(self, message, http_code=HTTP_Conflict):
76 vimconnException.__init__(self, message, http_code)
77
78 class vimconnNotSupportedException(vimconnException):
79 """The request is not supported by connector"""
80 def __init__(self, message, http_code=HTTP_Service_Unavailable):
81 vimconnException.__init__(self, message, http_code)
82
83 class vimconnNotImplemented(vimconnException):
84 """The method is not implemented by the connected"""
85 def __init__(self, message, http_code=HTTP_Not_Implemented):
86 vimconnException.__init__(self, message, http_code)
87
88
89 class vimconnector():
90 """Abstract base class for all the VIM connector plugins
91 These plugins must implement a vimconnector class derived from this
92 and all these privated methods
93 """
94 def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None,
95 config={}, persitent_info={}):
96 """Constructor of VIM
97 Params:
98 'uuid': id asigned to this VIM
99 'name': name assigned to this VIM, can be used for logging
100 'tenant_id', 'tenant_name': (only one of them is mandatory) VIM tenant to be used
101 'url_admin': (optional), url used for administrative tasks
102 'user', 'passwd': credentials of the VIM user
103 'log_level': provider if it should use a different log_level than the general one
104 'config': dictionary with extra VIM information. This contains a consolidate version of general VIM config
105 at creation and particular VIM config at teh attachment
106 'persistent_info': dict where the class can store information that will be available among class
107 destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an
108 empty dict. Useful to store login/tokens information for speed up communication
109
110 Returns: Raise an exception is some needed parameter is missing, but it must not do any connectivity
111 check against the VIM
112 """
113 self.id = uuid
114 self.name = name
115 self.url = url
116 self.url_admin = url_admin
117 self.tenant_id = tenant_id
118 self.tenant_name = tenant_name
119 self.user = user
120 self.passwd = passwd
121 self.config = config
122 self.availability_zone = None
123 self.logger = logging.getLogger('openmano.vim')
124 if log_level:
125 self.logger.setLevel( getattr(logging, log_level) )
126 if not self.url_admin: #try to use normal url
127 self.url_admin = self.url
128
129 def __getitem__(self,index):
130 if index=='tenant_id':
131 return self.tenant_id
132 if index=='tenant_name':
133 return self.tenant_name
134 elif index=='id':
135 return self.id
136 elif index=='name':
137 return self.name
138 elif index=='user':
139 return self.user
140 elif index=='passwd':
141 return self.passwd
142 elif index=='url':
143 return self.url
144 elif index=='url_admin':
145 return self.url_admin
146 elif index=="config":
147 return self.config
148 else:
149 raise KeyError("Invalid key '%s'" %str(index))
150
151 def __setitem__(self,index, value):
152 if index=='tenant_id':
153 self.tenant_id = value
154 if index=='tenant_name':
155 self.tenant_name = value
156 elif index=='id':
157 self.id = value
158 elif index=='name':
159 self.name = value
160 elif index=='user':
161 self.user = value
162 elif index=='passwd':
163 self.passwd = value
164 elif index=='url':
165 self.url = value
166 elif index=='url_admin':
167 self.url_admin = value
168 else:
169 raise KeyError("Invalid key '%s'" %str(index))
170
171 def check_vim_connectivity(self):
172 """Checks VIM can be reached and user credentials are ok.
173 Returns None if success or raised vimconnConnectionException, vimconnAuthException, ...
174 """
175 raise vimconnNotImplemented( "Should have implemented this" )
176
177 def new_tenant(self,tenant_name,tenant_description):
178 """Adds a new tenant to VIM with this name and description, this is done using admin_url if provided
179 "tenant_name": string max lenght 64
180 "tenant_description": string max length 256
181 returns the tenant identifier or raise exception
182 """
183 raise vimconnNotImplemented( "Should have implemented this" )
184
185 def delete_tenant(self,tenant_id,):
186 """Delete a tenant from VIM
187 tenant_id: returned VIM tenant_id on "new_tenant"
188 Returns None on success. Raises and exception of failure. If tenant is not found raises vimconnNotFoundException
189 """
190 raise vimconnNotImplemented( "Should have implemented this" )
191
192 def get_tenant_list(self, filter_dict={}):
193 """Obtain tenants of VIM
194 filter_dict dictionary that can contain the following keys:
195 name: filter by tenant name
196 id: filter by tenant uuid/id
197 <other VIM specific>
198 Returns the tenant list of dictionaries, and empty list if no tenant match all the filers:
199 [{'name':'<name>, 'id':'<id>, ...}, ...]
200 """
201 raise vimconnNotImplemented( "Should have implemented this" )
202
203 def new_network(self, net_name, net_type, ip_profile=None, shared=False, vlan=None):
204 """Adds a tenant network to VIM
205 Params:
206 'net_name': name of the network
207 'net_type': one of:
208 'bridge': overlay isolated network
209 'data': underlay E-LAN network for Passthrough and SRIOV interfaces
210 'ptp': underlay E-LINE network for Passthrough and SRIOV interfaces.
211 'ip_profile': is a dict containing the IP parameters of the network (Currently only IPv4 is implemented)
212 'ip-version': can be one of ["IPv4","IPv6"]
213 'subnet-address': ip_prefix_schema, that is X.X.X.X/Y
214 'gateway-address': (Optional) ip_schema, that is X.X.X.X
215 'dns-address': (Optional) ip_schema,
216 'dhcp': (Optional) dict containing
217 'enabled': {"type": "boolean"},
218 'start-address': ip_schema, first IP to grant
219 'count': number of IPs to grant.
220 'shared': if this network can be seen/use by other tenants/organization
221 'vlan': in case of a data or ptp net_type, the intended vlan tag to be used for the network
222 Returns the network identifier on success or raises and exception on failure
223 """
224 raise vimconnNotImplemented( "Should have implemented this" )
225
226 def get_network_list(self, filter_dict={}):
227 """Obtain tenant networks of VIM
228 Params:
229 'filter_dict' (optional) contains entries to return only networks that matches ALL entries:
230 name: string => returns only networks with this name
231 id: string => returns networks with this VIM id, this imply returns one network at most
232 shared: boolean >= returns only networks that are (or are not) shared
233 tenant_id: sting => returns only networks that belong to this tenant/project
234 ,#(not used yet) admin_state_up: boolean => returns only networks that are (or are not) in admin state active
235 #(not used yet) status: 'ACTIVE','ERROR',... => filter networks that are on this status
236 Returns the network list of dictionaries. each dictionary contains:
237 'id': (mandatory) VIM network id
238 'name': (mandatory) VIM network name
239 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
240 'network_type': (optional) can be 'vxlan', 'vlan' or 'flat'
241 'segmentation_id': (optional) in case network_type is vlan or vxlan this field contains the segmentation id
242 'error_msg': (optional) text that explains the ERROR status
243 other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
244 List can be empty if no network map the filter_dict. Raise an exception only upon VIM connectivity,
245 authorization, or some other unspecific error
246 """
247 raise vimconnNotImplemented( "Should have implemented this" )
248
249 def get_network(self, net_id):
250 """Obtain network details from the 'net_id' VIM network
251 Return a dict that contains:
252 'id': (mandatory) VIM network id, that is, net_id
253 'name': (mandatory) VIM network name
254 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
255 'error_msg': (optional) text that explains the ERROR status
256 other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
257 Raises an exception upon error or when network is not found
258 """
259 raise vimconnNotImplemented( "Should have implemented this" )
260
261 def delete_network(self, net_id):
262 """Deletes a tenant network from VIM
263 Returns the network identifier or raises an exception upon error or when network is not found
264 """
265 raise vimconnNotImplemented( "Should have implemented this" )
266
267 def refresh_nets_status(self, net_list):
268 """Get the status of the networks
269 Params:
270 'net_list': a list with the VIM network id to be get the status
271 Returns a dictionary with:
272 'net_id': #VIM id of this network
273 status: #Mandatory. Text with one of:
274 # DELETED (not found at vim)
275 # VIM_ERROR (Cannot connect to VIM, authentication problems, VIM response error, ...)
276 # OTHER (Vim reported other status not understood)
277 # ERROR (VIM indicates an ERROR status)
278 # ACTIVE, INACTIVE, DOWN (admin down),
279 # BUILD (on building process)
280 error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR
281 vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
282 'net_id2': ...
283 """
284 raise vimconnNotImplemented( "Should have implemented this" )
285
286 def get_flavor(self, flavor_id):
287 """Obtain flavor details from the VIM
288 Returns the flavor dict details {'id':<>, 'name':<>, other vim specific }
289 Raises an exception upon error or if not found
290 """
291 raise vimconnNotImplemented( "Should have implemented this" )
292
293 def get_flavor_id_from_data(self, flavor_dict):
294 """Obtain flavor id that match the flavor description
295 Params:
296 'flavor_dict': dictionary that contains:
297 'disk': main hard disk in GB
298 'ram': meomry in MB
299 'vcpus': number of virtual cpus
300 #TODO: complete parameters for EPA
301 Returns the flavor_id or raises a vimconnNotFoundException
302 """
303 raise vimconnNotImplemented( "Should have implemented this" )
304
305 def new_flavor(self, flavor_data):
306 """Adds a tenant flavor to VIM
307 flavor_data contains a dictionary with information, keys:
308 name: flavor name
309 ram: memory (cloud type) in MBytes
310 vpcus: cpus (cloud type)
311 extended: EPA parameters
312 - numas: #items requested in same NUMA
313 memory: number of 1G huge pages memory
314 paired-threads|cores|threads: number of paired hyperthreads, complete cores OR individual threads
315 interfaces: # passthrough(PT) or SRIOV interfaces attached to this numa
316 - name: interface name
317 dedicated: yes|no|yes:sriov; for PT, SRIOV or only one SRIOV for the physical NIC
318 bandwidth: X Gbps; requested guarantee bandwidth
319 vpci: requested virtual PCI address
320 disk: disk size
321 is_public:
322 #TODO to concrete
323 Returns the flavor identifier"""
324 raise vimconnNotImplemented( "Should have implemented this" )
325
326 def delete_flavor(self, flavor_id):
327 """Deletes a tenant flavor from VIM identify by its id
328 Returns the used id or raise an exception"""
329 raise vimconnNotImplemented( "Should have implemented this" )
330
331 def new_image(self, image_dict):
332 """ Adds a tenant image to VIM
333 Returns the image id or raises an exception if failed
334 """
335 raise vimconnNotImplemented( "Should have implemented this" )
336
337 def delete_image(self, image_id):
338 """Deletes a tenant image from VIM
339 Returns the image_id if image is deleted or raises an exception on error"""
340 raise vimconnNotImplemented( "Should have implemented this" )
341
342 def get_image_id_from_path(self, path):
343 """Get the image id from image path in the VIM database.
344 Returns the image_id or raises a vimconnNotFoundException
345 """
346 raise vimconnNotImplemented( "Should have implemented this" )
347
348 def get_image_list(self, filter_dict={}):
349 """Obtain tenant images from VIM
350 Filter_dict can be:
351 name: image name
352 id: image uuid
353 checksum: image checksum
354 location: image path
355 Returns the image list of dictionaries:
356 [{<the fields at Filter_dict plus some VIM specific>}, ...]
357 List can be empty
358 """
359 raise vimconnNotImplemented( "Should have implemented this" )
360
361 def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None,
362 availability_zone_index=None, availability_zone_list=None):
363 """Adds a VM instance to VIM
364 Params:
365 'start': (boolean) indicates if VM must start or created in pause mode.
366 'image_id','flavor_id': image and flavor VIM id to use for the VM
367 'net_list': list of interfaces, each one is a dictionary with:
368 'name': (optional) name for the interface.
369 'net_id': VIM network id where this interface must be connect to. Mandatory for type==virtual
370 'vpci': (optional) virtual vPCI address to assign at the VM. Can be ignored depending on VIM capabilities
371 'model': (optional and only have sense for type==virtual) interface model: virtio, e2000, ...
372 'mac_address': (optional) mac address to assign to this interface
373 #TODO: CHECK if an optional 'vlan' parameter is needed for VIMs when type if VF and net_id is not provided,
374 the VLAN tag to be used. In case net_id is provided, the internal network vlan is used for tagging VF
375 'type': (mandatory) can be one of:
376 'virtual', in this case always connected to a network of type 'net_type=bridge'
377 'PF' (passthrough): depending on VIM capabilities it can be connected to a data/ptp network ot it
378 can created unconnected
379 'VF' (SRIOV with VLAN tag): same as PF for network connectivity.
380 'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs
381 are allocated on the same physical NIC
382 'bw': (optional) only for PF/VF/VFnotShared. Minimal Bandwidth required for the interface in GBPS
383 'port_security': (optional) If False it must avoid any traffic filtering at this interface. If missing
384 or True, it must apply the default VIM behaviour
385 After execution the method will add the key:
386 'vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this
387 interface. 'net_list' is modified
388 'cloud_config': (optional) dictionary with:
389 'key-pairs': (optional) list of strings with the public key to be inserted to the default user
390 'users': (optional) list of users to be inserted, each item is a dict with:
391 'name': (mandatory) user name,
392 'key-pairs': (optional) list of strings with the public key to be inserted to the user
393 'user-data': (optional) can be a string with the text script to be passed directly to cloud-init,
394 or a list of strings, each one contains a script to be passed, usually with a MIMEmultipart file
395 'config-files': (optional). List of files to be transferred. Each item is a dict with:
396 'dest': (mandatory) string with the destination absolute path
397 'encoding': (optional, by default text). Can be one of:
398 'b64', 'base64', 'gz', 'gz+b64', 'gz+base64', 'gzip+b64', 'gzip+base64'
399 'content' (mandatory): string with the content of the file
400 'permissions': (optional) string with file permissions, typically octal notation '0644'
401 'owner': (optional) file owner, string with the format 'owner:group'
402 'boot-data-drive': boolean to indicate if user-data must be passed using a boot drive (hard disk)
403 'disk_list': (optional) list with additional disks to the VM. Each item is a dict with:
404 'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted
405 'size': (mandatory) string with the size of the disk in GB
406 availability_zone_index: Index of availability_zone_list to use for this this VM. None if not AV required
407 availability_zone_list: list of availability zones given by user in the VNFD descriptor. Ignore if
408 availability_zone_index is None
409 Returns the instance identifier or raises an exception on error
410 """
411 raise vimconnNotImplemented( "Should have implemented this" )
412
413 def get_vminstance(self,vm_id):
414 """Returns the VM instance information from VIM"""
415 raise vimconnNotImplemented( "Should have implemented this" )
416
417 def delete_vminstance(self, vm_id):
418 """Removes a VM instance from VIM
419 Returns the instance identifier"""
420 raise vimconnNotImplemented( "Should have implemented this" )
421
422 def refresh_vms_status(self, vm_list):
423 """Get the status of the virtual machines and their interfaces/ports
424 Params: the list of VM identifiers
425 Returns a dictionary with:
426 vm_id: #VIM id of this Virtual Machine
427 status: #Mandatory. Text with one of:
428 # DELETED (not found at vim)
429 # VIM_ERROR (Cannot connect to VIM, VIM response error, ...)
430 # OTHER (Vim reported other status not understood)
431 # ERROR (VIM indicates an ERROR status)
432 # ACTIVE, PAUSED, SUSPENDED, INACTIVE (not running),
433 # BUILD (on building process), ERROR
434 # ACTIVE:NoMgmtIP (Active but any of its interface has an IP address
435 #
436 error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR
437 vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
438 interfaces: list with interface info. Each item a dictionary with:
439 vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
440 mac_address: #Text format XX:XX:XX:XX:XX:XX
441 vim_net_id: #network id where this interface is connected, if provided at creation
442 vim_interface_id: #interface/port VIM id
443 ip_address: #null, or text with IPv4, IPv6 address
444 compute_node: #identification of compute node where PF,VF interface is allocated
445 pci: #PCI address of the NIC that hosts the PF,VF
446 vlan: #physical VLAN used for VF
447 """
448 raise vimconnNotImplemented( "Should have implemented this" )
449
450 def action_vminstance(self, vm_id, action_dict):
451 """Send and action over a VM instance from VIM
452 Returns the vm_id if the action was successfully sent to the VIM"""
453 raise vimconnNotImplemented( "Should have implemented this" )
454
455 def get_vminstance_console(self, vm_id, console_type="vnc"):
456 """
457 Get a console for the virtual machine
458 Params:
459 vm_id: uuid of the VM
460 console_type, can be:
461 "novnc" (by default), "xvpvnc" for VNC types,
462 "rdp-html5" for RDP types, "spice-html5" for SPICE types
463 Returns dict with the console parameters:
464 protocol: ssh, ftp, http, https, ...
465 server: usually ip address
466 port: the http, ssh, ... port
467 suffix: extra text, e.g. the http path and query string
468 """
469 raise vimconnNotImplemented( "Should have implemented this" )
470
471 def new_classification(self, name, ctype, definition):
472 """Creates a traffic classification in the VIM
473 Params:
474 'name': name of this classification
475 'ctype': type of this classification
476 'definition': definition of this classification (type-dependent free-form text)
477 Returns the VIM's classification ID on success or raises an exception on failure
478 """
479 raise vimconnNotImplemented( "SFC support not implemented" )
480
481 def get_classification(self, classification_id):
482 """Obtain classification details of the VIM's classification with ID='classification_id'
483 Return a dict that contains:
484 'id': VIM's classification ID (same as classification_id)
485 'name': VIM's classification name
486 'type': type of this classification
487 'definition': definition of the classification
488 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
489 'error_msg': (optional) text that explains the ERROR status
490 other VIM specific fields: (optional) whenever possible
491 Raises an exception upon error or when classification is not found
492 """
493 raise vimconnNotImplemented( "SFC support not implemented" )
494
495 def get_classification_list(self, filter_dict={}):
496 """Obtain classifications from the VIM
497 Params:
498 'filter_dict' (optional): contains the entries to filter the classifications on and only return those that match ALL:
499 id: string => returns classifications with this VIM's classification ID, which implies a return of one classification at most
500 name: string => returns only classifications with this name
501 type: string => returns classifications of this type
502 definition: string => returns classifications that have this definition
503 tenant_id: string => returns only classifications that belong to this tenant/project
504 Returns a list of classification dictionaries, each dictionary contains:
505 'id': (mandatory) VIM's classification ID
506 'name': (mandatory) VIM's classification name
507 'type': type of this classification
508 'definition': definition of the classification
509 other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
510 List can be empty if no classification matches the filter_dict. Raise an exception only upon VIM connectivity,
511 authorization, or some other unspecific error
512 """
513 raise vimconnNotImplemented( "SFC support not implemented" )
514
515 def delete_classification(self, classification_id):
516 """Deletes a classification from the VIM
517 Returns the classification ID (classification_id) or raises an exception upon error or when classification is not found
518 """
519 raise vimconnNotImplemented( "SFC support not implemented" )
520
521 def new_sfi(self, name, ingress_ports, egress_ports, sfc_encap=True):
522 """Creates a service function instance in the VIM
523 Params:
524 'name': name of this service function instance
525 'ingress_ports': set of ingress ports (VIM's port IDs)
526 'egress_ports': set of egress ports (VIM's port IDs)
527 'sfc_encap': boolean stating whether this specific instance supports IETF SFC Encapsulation
528 Returns the VIM's service function instance ID on success or raises an exception on failure
529 """
530 raise vimconnNotImplemented( "SFC support not implemented" )
531
532 def get_sfi(self, sfi_id):
533 """Obtain service function instance details of the VIM's service function instance with ID='sfi_id'
534 Return a dict that contains:
535 'id': VIM's sfi ID (same as sfi_id)
536 'name': VIM's sfi name
537 'ingress_ports': set of ingress ports (VIM's port IDs)
538 'egress_ports': set of egress ports (VIM's port IDs)
539 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
540 'error_msg': (optional) text that explains the ERROR status
541 other VIM specific fields: (optional) whenever possible
542 Raises an exception upon error or when service function instance is not found
543 """
544 raise vimconnNotImplemented( "SFC support not implemented" )
545
546 def get_sfi_list(self, filter_dict={}):
547 """Obtain service function instances from the VIM
548 Params:
549 'filter_dict' (optional): contains the entries to filter the sfis on and only return those that match ALL:
550 id: string => returns sfis with this VIM's sfi ID, which implies a return of one sfi at most
551 name: string => returns only service function instances with this name
552 tenant_id: string => returns only service function instances that belong to this tenant/project
553 Returns a list of service function instance dictionaries, each dictionary contains:
554 'id': (mandatory) VIM's sfi ID
555 'name': (mandatory) VIM's sfi name
556 'ingress_ports': set of ingress ports (VIM's port IDs)
557 'egress_ports': set of egress ports (VIM's port IDs)
558 other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
559 List can be empty if no sfi matches the filter_dict. Raise an exception only upon VIM connectivity,
560 authorization, or some other unspecific error
561 """
562 raise vimconnNotImplemented( "SFC support not implemented" )
563
564 def delete_sfi(self, sfi_id):
565 """Deletes a service function instance from the VIM
566 Returns the service function instance ID (sfi_id) or raises an exception upon error or when sfi is not found
567 """
568 raise vimconnNotImplemented( "SFC support not implemented" )
569
570 def new_sf(self, name, sfis, sfc_encap=True):
571 """Creates (an abstract) service function in the VIM
572 Params:
573 'name': name of this service function
574 'sfis': set of service function instances of this (abstract) service function
575 'sfc_encap': boolean stating whether this service function supports IETF SFC Encapsulation
576 Returns the VIM's service function ID on success or raises an exception on failure
577 """
578 raise vimconnNotImplemented( "SFC support not implemented" )
579
580 def get_sf(self, sf_id):
581 """Obtain service function details of the VIM's service function with ID='sf_id'
582 Return a dict that contains:
583 'id': VIM's sf ID (same as sf_id)
584 'name': VIM's sf name
585 'sfis': VIM's sf's set of VIM's service function instance IDs
586 'sfc_encap': boolean stating whether this service function supports IETF SFC Encapsulation
587 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
588 'error_msg': (optional) text that explains the ERROR status
589 other VIM specific fields: (optional) whenever possible
590 Raises an exception upon error or when sf is not found
591 """
592
593 def get_sf_list(self, filter_dict={}):
594 """Obtain service functions from the VIM
595 Params:
596 'filter_dict' (optional): contains the entries to filter the sfs on and only return those that match ALL:
597 id: string => returns sfs with this VIM's sf ID, which implies a return of one sf at most
598 name: string => returns only service functions with this name
599 tenant_id: string => returns only service functions that belong to this tenant/project
600 Returns a list of service function dictionaries, each dictionary contains:
601 'id': (mandatory) VIM's sf ID
602 'name': (mandatory) VIM's sf name
603 'sfis': VIM's sf's set of VIM's service function instance IDs
604 'sfc_encap': boolean stating whether this service function supports IETF SFC Encapsulation
605 other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
606 List can be empty if no sf matches the filter_dict. Raise an exception only upon VIM connectivity,
607 authorization, or some other unspecific error
608 """
609 raise vimconnNotImplemented( "SFC support not implemented" )
610
611 def delete_sf(self, sf_id):
612 """Deletes (an abstract) service function from the VIM
613 Returns the service function ID (sf_id) or raises an exception upon error or when sf is not found
614 """
615 raise vimconnNotImplemented( "SFC support not implemented" )
616
617
618 def new_sfp(self, name, classifications, sfs, sfc_encap=True, spi=None):
619 """Creates a service function path
620 Params:
621 'name': name of this service function path
622 'classifications': set of traffic classifications that should be matched on to get into this sfp
623 'sfs': list of every service function that constitutes this path , from first to last
624 'sfc_encap': whether this is an SFC-Encapsulated chain (i.e using NSH), True by default
625 'spi': (optional) the Service Function Path identifier (SPI: Service Path Identifier) for this path
626 Returns the VIM's sfp ID on success or raises an exception on failure
627 """
628 raise vimconnNotImplemented( "SFC support not implemented" )
629
630 def get_sfp(self, sfp_id):
631 """Obtain service function path details of the VIM's sfp with ID='sfp_id'
632 Return a dict that contains:
633 'id': VIM's sfp ID (same as sfp_id)
634 'name': VIM's sfp name
635 'classifications': VIM's sfp's list of VIM's classification IDs
636 'sfs': VIM's sfp's list of VIM's service function IDs
637 'status': 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
638 'error_msg': (optional) text that explains the ERROR status
639 other VIM specific fields: (optional) whenever possible
640 Raises an exception upon error or when sfp is not found
641 """
642 raise vimconnNotImplemented( "SFC support not implemented" )
643
644 def get_sfp_list(self, filter_dict={}):
645 """Obtain service function paths from VIM
646 Params:
647 'filter_dict' (optional): contains the entries to filter the sfps on, and only return those that match ALL:
648 id: string => returns sfps with this VIM's sfp ID , which implies a return of one sfp at most
649 name: string => returns only sfps with this name
650 tenant_id: string => returns only sfps that belong to this tenant/project
651 Returns a list of service function path dictionaries, each dictionary contains:
652 'id': (mandatory) VIM's sfp ID
653 'name': (mandatory) VIM's sfp name
654 'classifications': VIM's sfp's list of VIM's classification IDs
655 'sfs': VIM's sfp's list of VIM's service function IDs
656 other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
657 List can be empty if no sfp matches the filter_dict. Raise an exception only upon VIM connectivity,
658 authorization, or some other unspecific error
659 """
660 raise vimconnNotImplemented( "SFC support not implemented" )
661
662 def delete_sfp(self, sfp_id):
663 """Deletes a service function path from the VIM
664 Returns the sfp ID (sfp_id) or raises an exception upon error or when sf is not found
665 """
666 raise vimconnNotImplemented( "SFC support not implemented" )
667
668 def inject_user_key(self, ip_addr=None, user=None, key=None, ro_key=None, password=None):
669 """
670 Inject a ssh public key in a VM
671 Params:
672 ip_addr: ip address of the VM
673 user: username (default-user) to enter in the VM
674 key: public key to be injected in the VM
675 ro_key: private key of the RO, used to enter in the VM if the password is not provided
676 password: password of the user to enter in the VM
677 The function doesn't return a value:
678 """
679 if not ip_addr or not user:
680 raise vimconnNotSupportedException("All parameters should be different from 'None'")
681 elif not ro_key and not password:
682 raise vimconnNotSupportedException("All parameters should be different from 'None'")
683 else:
684 commands = {'mkdir -p ~/.ssh/', 'echo "%s" >> ~/.ssh/authorized_keys' % key,
685 'chmod 644 ~/.ssh/authorized_keys', 'chmod 700 ~/.ssh/'}
686 client = paramiko.SSHClient()
687 try:
688 if ro_key:
689 pkey = paramiko.RSAKey.from_private_key(StringIO.StringIO(ro_key))
690 else:
691 pkey = None
692 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
693 client.connect(ip_addr, username=user, password=password, pkey=pkey, timeout=10)
694 for command in commands:
695 (i, o, e) = client.exec_command(command, timeout=10)
696 returncode = o.channel.recv_exit_status()
697 output = o.read()
698 outerror = e.read()
699 if returncode != 0:
700 text = "run_command='{}' Error='{}'".format(command, outerror)
701 raise vimconnUnexpectedResponse("Cannot inject ssh key in VM: '{}'".format(text))
702 return
703 except (socket.error, paramiko.AuthenticationException, paramiko.SSHException) as message:
704 raise vimconnUnexpectedResponse(
705 "Cannot inject ssh key in VM: '{}' - {}".format(ip_addr, str(message)))
706 return
707
708
709 #NOT USED METHODS in current version
710
711 def host_vim2gui(self, host, server_dict):
712 """Transform host dictionary from VIM format to GUI format,
713 and append to the server_dict
714 """
715 raise vimconnNotImplemented( "Should have implemented this" )
716
717 def get_hosts_info(self):
718 """Get the information of deployed hosts
719 Returns the hosts content"""
720 raise vimconnNotImplemented( "Should have implemented this" )
721
722 def get_hosts(self, vim_tenant):
723 """Get the hosts and deployed instances
724 Returns the hosts content"""
725 raise vimconnNotImplemented( "Should have implemented this" )
726
727 def get_processor_rankings(self):
728 """Get the processor rankings in the VIM database"""
729 raise vimconnNotImplemented( "Should have implemented this" )
730
731 def new_host(self, host_data):
732 """Adds a new host to VIM"""
733 """Returns status code of the VIM response"""
734 raise vimconnNotImplemented( "Should have implemented this" )
735
736 def new_external_port(self, port_data):
737 """Adds a external port to VIM"""
738 """Returns the port identifier"""
739 raise vimconnNotImplemented( "Should have implemented this" )
740
741 def new_external_network(self,net_name,net_type):
742 """Adds a external network to VIM (shared)"""
743 """Returns the network identifier"""
744 raise vimconnNotImplemented( "Should have implemented this" )
745
746 def connect_port_network(self, port_id, network_id, admin=False):
747 """Connects a external port to a network"""
748 """Returns status code of the VIM response"""
749 raise vimconnNotImplemented( "Should have implemented this" )
750
751 def new_vminstancefromJSON(self, vm_data):
752 """Adds a VM instance to VIM"""
753 """Returns the instance identifier"""
754 raise vimconnNotImplemented( "Should have implemented this" )
755