| 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 | """ |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 28 | __author__="Alfonso Tierno" |
| 29 | __date__ ="$16-oct-2015 11:09:29$" |
| 30 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 31 | import logging |
| 32 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 33 | #Error variables |
| 34 | HTTP_Bad_Request = 400 |
| 35 | HTTP_Unauthorized = 401 |
| 36 | HTTP_Not_Found = 404 |
| 37 | HTTP_Method_Not_Allowed = 405 |
| 38 | HTTP_Request_Timeout = 408 |
| 39 | HTTP_Conflict = 409 |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 40 | HTTP_Not_Implemented = 501 |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 41 | HTTP_Service_Unavailable = 503 |
| 42 | HTTP_Internal_Server_Error = 500 |
| 43 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 44 | class vimconnException(Exception): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 45 | """Common and base class Exception for all vimconnector exceptions""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 46 | def __init__(self, message, http_code=HTTP_Bad_Request): |
| 47 | Exception.__init__(self, message) |
| 48 | self.http_code = http_code |
| 49 | |
| 50 | class vimconnConnectionException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 51 | """Connectivity error with the VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 52 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| 53 | vimconnException.__init__(self, message, http_code) |
| 54 | |
| 55 | class vimconnUnexpectedResponse(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 56 | """Get an wrong response from VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 57 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| 58 | vimconnException.__init__(self, message, http_code) |
| 59 | |
| 60 | class vimconnAuthException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 61 | """Invalid credentials or authorization to perform this action over the VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 62 | def __init__(self, message, http_code=HTTP_Unauthorized): |
| 63 | vimconnException.__init__(self, message, http_code) |
| 64 | |
| 65 | class vimconnNotFoundException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 66 | """The item is not found at VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 67 | def __init__(self, message, http_code=HTTP_Not_Found): |
| 68 | vimconnException.__init__(self, message, http_code) |
| 69 | |
| 70 | class vimconnConflictException(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 71 | """There is a conflict, e.g. more item found than one""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 72 | def __init__(self, message, http_code=HTTP_Conflict): |
| 73 | vimconnException.__init__(self, message, http_code) |
| 74 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 75 | class vimconnNotSupportedException(vimconnException): |
| 76 | """The request is not supported by connector""" |
| 77 | def __init__(self, message, http_code=HTTP_Service_Unavailable): |
| 78 | vimconnException.__init__(self, message, http_code) |
| 79 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 80 | class vimconnNotImplemented(vimconnException): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 81 | """The method is not implemented by the connected""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 82 | def __init__(self, message, http_code=HTTP_Not_Implemented): |
| 83 | vimconnException.__init__(self, message, http_code) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 84 | |
| 85 | class vimconnector(): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 86 | """Abstract base class for all the VIM connector plugins |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 87 | These plugins must implement a vimconnector class derived from this |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 88 | and all these privated methods |
| 89 | """ |
| 90 | def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None, |
| 91 | config={}, persitent_info={}): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 92 | """Constructor of VIM |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 93 | Params: |
| 94 | 'uuid': id asigned to this VIM |
| 95 | 'name': name assigned to this VIM, can be used for logging |
| 96 | 'tenant_id', 'tenant_name': (only one of them is mandatory) VIM tenant to be used |
| 97 | 'url_admin': (optional), url used for administrative tasks |
| 98 | 'user', 'passwd': credentials of the VIM user |
| 99 | 'log_level': provider if it should use a different log_level than the general one |
| 100 | 'config': dictionary with extra VIM information. This contains a consolidate version of general VIM config |
| 101 | at creation and particular VIM config at teh attachment |
| 102 | 'persistent_info': dict where the class can store information that will be available among class |
| 103 | destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an |
| 104 | empty dict. Useful to store login/tokens information for speed up communication |
| 105 | |
| 106 | Returns: Raise an exception is some needed parameter is missing, but it must not do any connectivity |
| 107 | check against the VIM |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 108 | """ |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 109 | self.id = uuid |
| 110 | self.name = name |
| 111 | self.url = url |
| 112 | self.url_admin = url_admin |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 113 | self.tenant_id = tenant_id |
| 114 | self.tenant_name = tenant_name |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 115 | self.user = user |
| 116 | self.passwd = passwd |
| 117 | self.config = config |
| tierno | 73ad9e4 | 2016-09-12 18:11:11 +0200 | [diff] [blame] | 118 | self.logger = logging.getLogger('openmano.vim') |
| tierno | fe78990 | 2016-09-29 14:20:44 +0000 | [diff] [blame] | 119 | if log_level: |
| 120 | self.logger.setLevel( getattr(logging, log_level) ) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 121 | if not self.url_admin: #try to use normal url |
| 122 | self.url_admin = self.url |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 123 | |
| 124 | def __getitem__(self,index): |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 125 | if index=='tenant_id': |
| 126 | return self.tenant_id |
| 127 | if index=='tenant_name': |
| 128 | return self.tenant_name |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 129 | elif index=='id': |
| 130 | return self.id |
| 131 | elif index=='name': |
| 132 | return self.name |
| 133 | elif index=='user': |
| 134 | return self.user |
| 135 | elif index=='passwd': |
| 136 | return self.passwd |
| 137 | elif index=='url': |
| 138 | return self.url |
| 139 | elif index=='url_admin': |
| 140 | return self.url_admin |
| 141 | elif index=="config": |
| 142 | return self.config |
| 143 | else: |
| 144 | raise KeyError("Invalid key '%s'" %str(index)) |
| 145 | |
| 146 | def __setitem__(self,index, value): |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 147 | if index=='tenant_id': |
| 148 | self.tenant_id = value |
| 149 | if index=='tenant_name': |
| 150 | self.tenant_name = value |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 151 | elif index=='id': |
| 152 | self.id = value |
| 153 | elif index=='name': |
| 154 | self.name = value |
| 155 | elif index=='user': |
| 156 | self.user = value |
| 157 | elif index=='passwd': |
| 158 | self.passwd = value |
| 159 | elif index=='url': |
| 160 | self.url = value |
| 161 | elif index=='url_admin': |
| 162 | self.url_admin = value |
| 163 | else: |
| 164 | raise KeyError("Invalid key '%s'" %str(index)) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 165 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 166 | def check_vim_connectivity(self): |
| 167 | """Checks VIM can be reached and user credentials are ok. |
| 168 | Returns None if success or raised vimconnConnectionException, vimconnAuthException, ... |
| 169 | """ |
| 170 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 171 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 172 | def new_tenant(self,tenant_name,tenant_description): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 173 | """Adds a new tenant to VIM with this name and description, this is done using admin_url if provided |
| 174 | "tenant_name": string max lenght 64 |
| 175 | "tenant_description": string max length 256 |
| 176 | returns the tenant identifier or raise exception |
| 177 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 178 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 179 | |
| 180 | def delete_tenant(self,tenant_id,): |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 181 | """Delete a tenant from VIM |
| 182 | tenant_id: returned VIM tenant_id on "new_tenant" |
| 183 | Returns None on success. Raises and exception of failure. If tenant is not found raises vimconnNotFoundException |
| 184 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 185 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 186 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 187 | def get_tenant_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 188 | """Obtain tenants of VIM |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 189 | filter_dict dictionary that can contain the following keys: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 190 | name: filter by tenant name |
| 191 | id: filter by tenant uuid/id |
| 192 | <other VIM specific> |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 193 | 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] | 194 | [{'name':'<name>, 'id':'<id>, ...}, ...] |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 195 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 196 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 197 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 198 | 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] | 199 | """Adds a tenant network to VIM |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 200 | Params: |
| 201 | 'net_name': name of the network |
| 202 | 'net_type': one of: |
| 203 | 'bridge': overlay isolated network |
| 204 | 'data': underlay E-LAN network for Passthrough and SRIOV interfaces |
| 205 | 'ptp': underlay E-LINE network for Passthrough and SRIOV interfaces. |
| 206 | 'ip_profile': is a dict containing the IP parameters of the network (Currently only IPv4 is implemented) |
| 207 | 'ip-version': can be one of ["IPv4","IPv6"] |
| 208 | 'subnet-address': ip_prefix_schema, that is X.X.X.X/Y |
| 209 | 'gateway-address': (Optional) ip_schema, that is X.X.X.X |
| 210 | 'dns-address': (Optional) ip_schema, |
| 211 | 'dhcp': (Optional) dict containing |
| 212 | 'enabled': {"type": "boolean"}, |
| 213 | 'start-address': ip_schema, first IP to grant |
| 214 | 'count': number of IPs to grant. |
| 215 | 'shared': if this network can be seen/use by other tenants/organization |
| 216 | 'vlan': in case of a data or ptp net_type, the intended vlan tag to be used for the network |
| 217 | Returns the network identifier on success or raises and exception on failure |
| tierno | fb1987b | 2016-11-15 17:35:06 +0000 | [diff] [blame] | 218 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 219 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 220 | |
| 221 | def get_network_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 222 | """Obtain tenant networks of VIM |
| 223 | Params: |
| 224 | 'filter_dict' (optional) contains entries to return only networks that matches ALL entries: |
| 225 | name: string => returns only networks with this name |
| 226 | id: string => returns networks with this VIM id, this imply returns one network at most |
| 227 | shared: boolean >= returns only networks that are (or are not) shared |
| 228 | tenant_id: sting => returns only networks that belong to this tenant/project |
| 229 | ,#(not used yet) admin_state_up: boolean => returns only networks that are (or are not) in admin state active |
| 230 | #(not used yet) status: 'ACTIVE','ERROR',... => filter networks that are on this status |
| 231 | Returns the network list of dictionaries. each dictionary contains: |
| 232 | 'id': (mandatory) VIM network id |
| 233 | 'name': (mandatory) VIM network name |
| 234 | 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 235 | 'error_msg': (optional) text that explains the ERROR status |
| 236 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 237 | List can be empty if no network map the filter_dict. Raise an exception only upon VIM connectivity, |
| 238 | authorization, or some other unspecific error |
| 239 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 240 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 241 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 242 | def get_network(self, net_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 243 | """Obtain network details from the 'net_id' VIM network |
| 244 | Return a dict that contains: |
| 245 | 'id': (mandatory) VIM network id, that is, net_id |
| 246 | 'name': (mandatory) VIM network name |
| 247 | 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER' |
| 248 | 'error_msg': (optional) text that explains the ERROR status |
| 249 | other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param |
| 250 | Raises an exception upon error or when network is not found |
| 251 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 252 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 253 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 254 | def delete_network(self, net_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 255 | """Deletes a tenant network from VIM |
| 256 | Returns the network identifier or raises an exception upon error or when network is not found |
| 257 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 258 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 259 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 260 | def refresh_nets_status(self, net_list): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 261 | """Get the status of the networks |
| 262 | Params: |
| 263 | 'net_list': a list with the VIM network id to be get the status |
| 264 | Returns a dictionary with: |
| 265 | 'net_id': #VIM id of this network |
| 266 | status: #Mandatory. Text with one of: |
| 267 | # DELETED (not found at vim) |
| 268 | # VIM_ERROR (Cannot connect to VIM, authentication problems, VIM response error, ...) |
| 269 | # OTHER (Vim reported other status not understood) |
| 270 | # ERROR (VIM indicates an ERROR status) |
| 271 | # ACTIVE, INACTIVE, DOWN (admin down), |
| 272 | # BUILD (on building process) |
| 273 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 274 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| 275 | 'net_id2': ... |
| 276 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 277 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 278 | |
| 279 | def get_flavor(self, flavor_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 280 | """Obtain flavor details from the VIM |
| 281 | Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } |
| 282 | Raises an exception upon error or if not found |
| 283 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 284 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 285 | |
| 286 | def get_flavor_id_from_data(self, flavor_dict): |
| 287 | """Obtain flavor id that match the flavor description |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 288 | Params: |
| 289 | 'flavor_dict': dictionary that contains: |
| 290 | 'disk': main hard disk in GB |
| 291 | 'ram': meomry in MB |
| 292 | 'vcpus': number of virtual cpus |
| 293 | #TODO: complete parameters for EPA |
| 294 | Returns the flavor_id or raises a vimconnNotFoundException |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 295 | """ |
| 296 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 297 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 298 | def new_flavor(self, flavor_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 299 | """Adds a tenant flavor to VIM |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 300 | flavor_data contains a dictionary with information, keys: |
| 301 | name: flavor name |
| 302 | ram: memory (cloud type) in MBytes |
| 303 | vpcus: cpus (cloud type) |
| 304 | extended: EPA parameters |
| 305 | - numas: #items requested in same NUMA |
| 306 | memory: number of 1G huge pages memory |
| 307 | paired-threads|cores|threads: number of paired hyperthreads, complete cores OR individual threads |
| 308 | interfaces: # passthrough(PT) or SRIOV interfaces attached to this numa |
| 309 | - name: interface name |
| 310 | dedicated: yes|no|yes:sriov; for PT, SRIOV or only one SRIOV for the physical NIC |
| 311 | bandwidth: X Gbps; requested guarantee bandwidth |
| 312 | vpci: requested virtual PCI address |
| 313 | disk: disk size |
| 314 | is_public: |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 315 | #TODO to concrete |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 316 | Returns the flavor identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 317 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 318 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 319 | def delete_flavor(self, flavor_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 320 | """Deletes a tenant flavor from VIM identify by its id |
| 321 | Returns the used id or raise an exception""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 322 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 323 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 324 | def new_image(self, image_dict): |
| 325 | """ Adds a tenant image to VIM |
| 326 | Returns the image id or raises an exception if failed |
| 327 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 328 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 329 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 330 | def delete_image(self, image_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 331 | """Deletes a tenant image from VIM |
| 332 | 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] | 333 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 334 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 335 | def get_image_id_from_path(self, path): |
| tierno | cf157a8 | 2017-01-30 14:07:06 +0100 | [diff] [blame] | 336 | """Get the image id from image path in the VIM database. |
| 337 | Returns the image_id or raises a vimconnNotFoundException |
| 338 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 339 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 340 | |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 341 | def get_image_list(self, filter_dict={}): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 342 | """Obtain tenant images from VIM |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 343 | Filter_dict can be: |
| 344 | name: image name |
| 345 | id: image uuid |
| 346 | checksum: image checksum |
| 347 | location: image path |
| 348 | Returns the image list of dictionaries: |
| 349 | [{<the fields at Filter_dict plus some VIM specific>}, ...] |
| 350 | List can be empty |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 351 | """ |
| garciadeblas | b69fa9f | 2016-09-28 12:04:10 +0200 | [diff] [blame] | 352 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 353 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 354 | def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, |
| 355 | disk_list=None): |
| 356 | """Adds a VM instance to VIM |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 357 | Params: |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 358 | 'start': (boolean) indicates if VM must start or created in pause mode. |
| 359 | 'image_id','flavor_id': image and flavor VIM id to use for the VM |
| 360 | 'net_list': list of interfaces, each one is a dictionary with: |
| 361 | 'name': (optional) name for the interface. |
| 362 | 'net_id': VIM network id where this interface must be connect to. Mandatory for type==virtual |
| 363 | 'vpci': (optional) virtual vPCI address to assign at the VM. Can be ignored depending on VIM capabilities |
| 364 | 'model': (optional and only have sense for type==virtual) interface model: virtio, e2000, ... |
| 365 | 'mac_address': (optional) mac address to assign to this interface |
| 366 | #TODO: CHECK if an optional 'vlan' parameter is needed for VIMs when type if VF and net_id is not provided, |
| 367 | the VLAN tag to be used. In case net_id is provided, the internal network vlan is used for tagging VF |
| 368 | 'type': (mandatory) can be one of: |
| 369 | 'virtual', in this case always connected to a network of type 'net_type=bridge' |
| 370 | 'PF' (passthrough): depending on VIM capabilities it can be connected to a data/ptp network ot it |
| 371 | can created unconnected |
| 372 | 'VF' (SRIOV with VLAN tag): same as PF for network connectivity. |
| 373 | 'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs |
| 374 | are allocated on the same physical NIC |
| 375 | '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] | 376 | 'port_security': (optional) If False it must avoid any traffic filtering at this interface. If missing |
| 377 | or True, it must apply the default VIM behaviour |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 378 | After execution the method will add the key: |
| 379 | 'vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this |
| 380 | interface. 'net_list' is modified |
| 381 | 'cloud_config': (optional) dictionary with: |
| 382 | 'key-pairs': (optional) list of strings with the public key to be inserted to the default user |
| 383 | 'users': (optional) list of users to be inserted, each item is a dict with: |
| 384 | 'name': (mandatory) user name, |
| 385 | 'key-pairs': (optional) list of strings with the public key to be inserted to the user |
| 386 | 'user-data': (optional) string is a text script to be passed directly to cloud-init |
| 387 | 'config-files': (optional). List of files to be transferred. Each item is a dict with: |
| 388 | 'dest': (mandatory) string with the destination absolute path |
| 389 | 'encoding': (optional, by default text). Can be one of: |
| 390 | 'b64', 'base64', 'gz', 'gz+b64', 'gz+base64', 'gzip+b64', 'gzip+base64' |
| 391 | 'content' (mandatory): string with the content of the file |
| 392 | 'permissions': (optional) string with file permissions, typically octal notation '0644' |
| 393 | 'owner': (optional) file owner, string with the format 'owner:group' |
| 394 | 'boot-data-drive': boolean to indicate if user-data must be passed using a boot drive (hard disk) |
| 395 | 'disk_list': (optional) list with additional disks to the VM. Each item is a dict with: |
| 396 | 'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted |
| 397 | 'size': (mandatory) string with the size of the disk in GB |
| 398 | Returns the instance identifier or raises an exception on error |
| 399 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 400 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 401 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 402 | def get_vminstance(self,vm_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 403 | """Returns the VM instance information from VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 404 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 405 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 406 | def delete_vminstance(self, vm_id): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 407 | """Removes a VM instance from VIM |
| 408 | Returns the instance identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 409 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 410 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 411 | def refresh_vms_status(self, vm_list): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 412 | """Get the status of the virtual machines and their interfaces/ports |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 413 | Params: the list of VM identifiers |
| 414 | Returns a dictionary with: |
| 415 | vm_id: #VIM id of this Virtual Machine |
| 416 | status: #Mandatory. Text with one of: |
| 417 | # DELETED (not found at vim) |
| 418 | # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) |
| 419 | # OTHER (Vim reported other status not understood) |
| 420 | # ERROR (VIM indicates an ERROR status) |
| 421 | # ACTIVE, PAUSED, SUSPENDED, INACTIVE (not running), |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 422 | # BUILD (on building process), ERROR |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 423 | # ACTIVE:NoMgmtIP (Active but any of its interface has an IP address |
| 424 | # |
| 425 | error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR |
| 426 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 427 | interfaces: list with interface info. Each item a dictionary with: |
| 428 | vim_info: #Text with plain information obtained from vim (yaml.safe_dump) |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 429 | mac_address: #Text format XX:XX:XX:XX:XX:XX |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 430 | 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] | 431 | vim_interface_id: #interface/port VIM id |
| 432 | ip_address: #null, or text with IPv4, IPv6 address |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 433 | physical_compute: #identification of compute node where PF,VF interface is allocated |
| 434 | physical_pci: #PCI address of the NIC that hosts the PF,VF |
| 435 | physical_vlan: #physical VLAN used for VF |
| 436 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 437 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 438 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 439 | def action_vminstance(self, vm_id, action_dict): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 440 | """Send and action over a VM instance from VIM |
| 441 | Returns the vm_id if the action was successfully sent to the VIM""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 442 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 443 | |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 444 | def get_vminstance_console(self, vm_id, console_type="vnc"): |
| 445 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 446 | Get a console for the virtual machine |
| 447 | Params: |
| 448 | vm_id: uuid of the VM |
| 449 | console_type, can be: |
| 450 | "novnc" (by default), "xvpvnc" for VNC types, |
| 451 | "rdp-html5" for RDP types, "spice-html5" for SPICE types |
| 452 | Returns dict with the console parameters: |
| 453 | protocol: ssh, ftp, http, https, ... |
| 454 | server: usually ip address |
| 455 | port: the http, ssh, ... port |
| 456 | suffix: extra text, e.g. the http path and query string |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 457 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 458 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 459 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 460 | #NOT USED METHODS in current version |
| 461 | |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 462 | def host_vim2gui(self, host, server_dict): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 463 | """Transform host dictionary from VIM format to GUI format, |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 464 | and append to the server_dict |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 465 | """ |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 466 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 467 | |
| 468 | def get_hosts_info(self): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 469 | """Get the information of deployed hosts |
| 470 | Returns the hosts content""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 471 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 472 | |
| 473 | def get_hosts(self, vim_tenant): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 474 | """Get the hosts and deployed instances |
| 475 | Returns the hosts content""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 476 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 477 | |
| 478 | def get_processor_rankings(self): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 479 | """Get the processor rankings in the VIM database""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 480 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 481 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 482 | def new_host(self, host_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 483 | """Adds a new host to VIM""" |
| 484 | """Returns status code of the VIM response""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 485 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 486 | |
| 487 | def new_external_port(self, port_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 488 | """Adds a external port to VIM""" |
| 489 | """Returns the port identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 490 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 491 | |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 492 | def new_external_network(self,net_name,net_type): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 493 | """Adds a external network to VIM (shared)""" |
| 494 | """Returns the network identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 495 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 496 | |
| 497 | def connect_port_network(self, port_id, network_id, admin=False): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 498 | """Connects a external port to a network""" |
| 499 | """Returns status code of the VIM response""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 500 | raise vimconnNotImplemented( "Should have implemented this" ) |
| 501 | |
| 502 | def new_vminstancefromJSON(self, vm_data): |
| tierno | a7d34d0 | 2017-02-23 14:42:07 +0100 | [diff] [blame] | 503 | """Adds a VM instance to VIM""" |
| 504 | """Returns the instance identifier""" |
| tierno | ae4a8d1 | 2016-07-08 12:30:39 +0200 | [diff] [blame] | 505 | raise vimconnNotImplemented( "Should have implemented this" ) |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 506 | |