| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 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 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 24 | """ |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 25 | vimconn implement an Abstract class for the vim connector plugins |
| 26 | with the definition of the method to be implemented. |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 27 | """ |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 28 | __author__="Alfonso Tierno, Igor D.C." |
| 29 | __date__ ="$14-aug-2017 23:59:59$" |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 30 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 31 | import logging |
| gcalvino | e580c7d | 2017-09-22 14:09:51 +0200 | [diff] [blame^] | 32 | import paramiko |
| 33 | import socket |
| 34 | import StringIO |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 35 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 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 |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 43 | HTTP_Not_Implemented = 501 |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 44 | HTTP_Service_Unavailable = 503 |
| 45 | HTTP_Internal_Server_Error = 500 |
| 46 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 47 | class vimconnException(Exception): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 48 | """Common and base class Exception for all vimconnector exceptions""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 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): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 54 | """Connectivity error with the VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 55 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| 56 | vimconnException.__init__(self, message, http_code) |
| 57 | |
| 58 | class vimconnUnexpectedResponse(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 59 | """Get an wrong response from VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 60 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| 61 | vimconnException.__init__(self, message, http_code) |
| 62 | |
| 63 | class vimconnAuthException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 64 | """Invalid credentials or authorization to perform this action over the VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 65 | def __init__(self, message, http_code=HTTP_Unauthorized): |
| 66 | vimconnException.__init__(self, message, http_code) |
| 67 | |
| 68 | class vimconnNotFoundException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 69 | """The item is not found at VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 70 | def __init__(self, message, http_code=HTTP_Not_Found): |
| 71 | vimconnException.__init__(self, message, http_code) |
| 72 | |
| 73 | class vimconnConflictException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 74 | """There is a conflict, e.g. more item found than one""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 75 | def __init__(self, message, http_code=HTTP_Conflict): |
| 76 | vimconnException.__init__(self, message, http_code) |
| 77 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 83 | class vimconnNotImplemented(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 84 | """The method is not implemented by the connected""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 85 | def __init__(self, message, http_code=HTTP_Not_Implemented): |
| 86 | vimconnException.__init__(self, message, http_code) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 87 | |
| mirabal | 2935631 | 2017-07-27 12:21:22 +0200 | [diff] [blame] | 88 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 89 | class vimconnector(): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 90 | """Abstract base class for all the VIM connector plugins |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 91 | These plugins must implement a vimconnector class derived from this |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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={}): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 96 | """Constructor of VIM |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 112 | """ |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 113 | self.id = uuid |
| 114 | self.name = name |
| 115 | self.url = url |
| 116 | self.url_admin = url_admin |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 117 | self.tenant_id = tenant_id |
| 118 | self.tenant_name = tenant_name |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 119 | self.user = user |
| 120 | self.passwd = passwd |
| 121 | self.config = config |
| mirabal | 2935631 | 2017-07-27 12:21:22 +0200 | [diff] [blame] | 122 | self.availability_zone = None |
| tierno | 73ad9e4 | 2016-09-12 18:11:11 +0200 | [diff] [blame] | 123 | self.logger = logging.getLogger('openmano.vim') |
| tierno | fe78990 | 2016-09-29 14:20:44 +0000 | [diff] [blame] | 124 | if log_level: |
| 125 | self.logger.setLevel( getattr(logging, log_level) ) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 126 | if not self.url_admin: #try to use normal url |
| 127 | self.url_admin = self.url |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 128 | |
| 129 | def __getitem__(self,index): |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 130 | if index=='tenant_id': |
| 131 | return self.tenant_id |
| 132 | if index=='tenant_name': |
| 133 | return self.tenant_name |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 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): |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 152 | if index=='tenant_id': |
| 153 | self.tenant_id = value |
| 154 | if index=='tenant_name': |
| 155 | self.tenant_name = value |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 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)) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 170 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 177 | def new_tenant(self,tenant_name,tenant_description): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 183 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 184 | |
| 185 | def delete_tenant(self,tenant_id,): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 190 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 191 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 192 | def get_tenant_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 193 | """Obtain tenants of VIM |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 194 | filter_dict dictionary that can contain the following keys: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 195 | name: filter by tenant name |
| 196 | id: filter by tenant uuid/id |
| 197 | <other VIM specific> |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 198 | Returns the tenant list of dictionaries, and empty list if no tenant match all the filers: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 199 | [{'name':'<name>, 'id':'<id>, ...}, ...] |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 200 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 201 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 202 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 203 | def new_network(self, net_name, net_type, ip_profile=None, shared=False, vlan=None): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 204 | """Adds a tenant network to VIM |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 223 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 224 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 225 | |
| 226 | def get_network_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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' |
| Pablo Montes Moreno | 3fbff9b | 2017-03-08 11:28:15 +0100 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 247 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 248 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 249 | def get_network(self, net_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 259 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 260 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 261 | def delete_network(self, net_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 265 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 266 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 267 | def refresh_nets_status(self, net_list): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 284 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 285 | |
| 286 | def get_flavor(self, flavor_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 291 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 292 | |
| 293 | def get_flavor_id_from_data(self, flavor_dict): |
| 294 | """Obtain flavor id that match the flavor description |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 302 | """ |
| 303 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 304 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 305 | def new_flavor(self, flavor_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 306 | """Adds a tenant flavor to VIM |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 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: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 322 | #TODO to concrete |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 323 | Returns the flavor identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 324 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 325 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 326 | def delete_flavor(self, flavor_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 327 | """Deletes a tenant flavor from VIM identify by its id |
| 328 | Returns the used id or raise an exception""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 329 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 330 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 335 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 336 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 337 | def delete_image(self, image_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 338 | """Deletes a tenant image from VIM |
| 339 | Returns the image_id if image is deleted or raises an exception on error""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 340 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 341 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 342 | def get_image_id_from_path(self, path): |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 343 | """Get the image id from image path in the VIM database. |
| 344 | Returns the image_id or raises a vimconnNotFoundException |
| 345 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 346 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 347 | |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 348 | def get_image_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 349 | """Obtain tenant images from VIM |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 358 | """ |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 359 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 360 | |
| mirabal | 2935631 | 2017-07-27 12:21:22 +0200 | [diff] [blame] | 361 | def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None, |
| tierno | 5a3273c | 2017-08-29 11:43:46 +0200 | [diff] [blame] | 362 | availability_zone_index=None, availability_zone_list=None): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 363 | """Adds a VM instance to VIM |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 364 | Params: |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 |
| tierno | b3d3674 | 2017-03-03 23:51:05 +0100 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 |
| tierno | 40e1bce | 2017-08-09 09:12:04 +0200 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 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 |
| tierno | 5a3273c | 2017-08-29 11:43:46 +0200 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 409 | Returns the instance identifier or raises an exception on error |
| 410 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 411 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 412 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 413 | def get_vminstance(self,vm_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 414 | """Returns the VM instance information from VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 415 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 416 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 417 | def delete_vminstance(self, vm_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 418 | """Removes a VM instance from VIM |
| 419 | Returns the instance identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 420 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 421 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 422 | def refresh_vms_status(self, vm_list): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 423 | """Get the status of the virtual machines and their interfaces/ports |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 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), |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 433 | # BUILD (on building process), ERROR |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 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) |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 438 | interfaces: list with interface info. Each item a dictionary with: |
| 439 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 440 | mac_address: #Text format XX:XX:XX:XX:XX:XX |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 441 | vim_net_id: #network id where this interface is connected, if provided at creation |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 442 | vim_interface_id: #interface/port VIM id |
| 443 | ip_address: #null, or text with IPv4, IPv6 address |
| tierno | 867ffe9 | 2017-03-27 12:50:34 +0200 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 447 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 448 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 449 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 450 | def action_vminstance(self, vm_id, action_dict): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 451 | """Send and action over a VM instance from VIM |
| 452 | Returns the vm_id if the action was successfully sent to the VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 453 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 454 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 455 | def get_vminstance_console(self, vm_id, console_type="vnc"): |
| 456 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 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 |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 468 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 469 | raise vimconnNotImplemented( "Should have implemented this" ) |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 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 | |
| gcalvino | e580c7d | 2017-09-22 14:09:51 +0200 | [diff] [blame^] | 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 | |
| Igor Duarte Cardoso | 862a60a | 2017-08-09 16:07:46 +0000 | [diff] [blame] | 709 | #NOT USED METHODS in current version |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 710 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 711 | def host_vim2gui(self, host, server_dict): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 712 | """Transform host dictionary from VIM format to GUI format, |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 713 | and append to the server_dict |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 714 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 715 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 716 | |
| 717 | def get_hosts_info(self): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 718 | """Get the information of deployed hosts |
| 719 | Returns the hosts content""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 720 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 721 | |
| 722 | def get_hosts(self, vim_tenant): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 723 | """Get the hosts and deployed instances |
| 724 | Returns the hosts content""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 725 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 726 | |
| 727 | def get_processor_rankings(self): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 728 | """Get the processor rankings in the VIM database""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 729 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 730 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 731 | def new_host(self, host_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 732 | """Adds a new host to VIM""" |
| 733 | """Returns status code of the VIM response""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 734 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 735 | |
| 736 | def new_external_port(self, port_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 737 | """Adds a external port to VIM""" |
| 738 | """Returns the port identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 739 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 740 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 741 | def new_external_network(self,net_name,net_type): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 742 | """Adds a external network to VIM (shared)""" |
| 743 | """Returns the network identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 744 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 745 | |
| 746 | def connect_port_network(self, port_id, network_id, admin=False): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 747 | """Connects a external port to a network""" |
| 748 | """Returns status code of the VIM response""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 749 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 750 | |
| 751 | def new_vminstancefromJSON(self, vm_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 752 | """Adds a VM instance to VIM""" |
| 753 | """Returns the instance identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 754 | raise vimconnNotImplemented( "Should have implemented this" ) |
| gcalvino | e580c7d | 2017-09-22 14:09:51 +0200 | [diff] [blame^] | 755 | |