| 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 | |
| 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" |
| 29 | __date__ ="$16-oct-2015 11:09:29$" |
| 30 | |
| 31 | #Error variables |
| 32 | HTTP_Bad_Request = 400 |
| 33 | HTTP_Unauthorized = 401 |
| 34 | HTTP_Not_Found = 404 |
| 35 | HTTP_Method_Not_Allowed = 405 |
| 36 | HTTP_Request_Timeout = 408 |
| 37 | HTTP_Conflict = 409 |
| 38 | HTTP_Service_Unavailable = 503 |
| 39 | HTTP_Internal_Server_Error = 500 |
| 40 | |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 41 | class vimconnectorException(Exception): |
| 42 | pass |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 43 | |
| 44 | class vimconnector(): |
| 45 | '''Abstract base class for all the VIM connector plugins |
| 46 | These plugins must implement a vimconnector class deribed from this |
| 47 | and all these methods |
| 48 | ''' |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 49 | def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None,debug=True,config={}): |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 50 | self.id = uuid |
| 51 | self.name = name |
| 52 | self.url = url |
| 53 | self.url_admin = url_admin |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 54 | self.tenant_id = tenant_id |
| 55 | self.tenant_name = tenant_name |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 56 | self.user = user |
| 57 | self.passwd = passwd |
| 58 | self.config = config |
| 59 | self.debug = debug |
| 60 | |
| 61 | def __getitem__(self,index): |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 62 | if index=='tenant_id': |
| 63 | return self.tenant_id |
| 64 | if index=='tenant_name': |
| 65 | return self.tenant_name |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 66 | elif index=='id': |
| 67 | return self.id |
| 68 | elif index=='name': |
| 69 | return self.name |
| 70 | elif index=='user': |
| 71 | return self.user |
| 72 | elif index=='passwd': |
| 73 | return self.passwd |
| 74 | elif index=='url': |
| 75 | return self.url |
| 76 | elif index=='url_admin': |
| 77 | return self.url_admin |
| 78 | elif index=="config": |
| 79 | return self.config |
| 80 | else: |
| 81 | raise KeyError("Invalid key '%s'" %str(index)) |
| 82 | |
| 83 | def __setitem__(self,index, value): |
| tierno | 392f285 | 2016-05-13 12:28:55 +0200 | [diff] [blame] | 84 | if index=='tenant_id': |
| 85 | self.tenant_id = value |
| 86 | if index=='tenant_name': |
| 87 | self.tenant_name = value |
| tierno | 7edb675 | 2016-03-21 17:37:52 +0100 | [diff] [blame] | 88 | elif index=='id': |
| 89 | self.id = value |
| 90 | elif index=='name': |
| 91 | self.name = value |
| 92 | elif index=='user': |
| 93 | self.user = value |
| 94 | elif index=='passwd': |
| 95 | self.passwd = value |
| 96 | elif index=='url': |
| 97 | self.url = value |
| 98 | elif index=='url_admin': |
| 99 | self.url_admin = value |
| 100 | else: |
| 101 | raise KeyError("Invalid key '%s'" %str(index)) |
| 102 | |
| 103 | def new_host(self, host_data): |
| 104 | '''Adds a new host to VIM''' |
| 105 | '''Returns status code of the VIM response''' |
| 106 | raise NotImplementedError( "Should have implemented this" ) |
| 107 | |
| 108 | def new_external_port(self, port_data): |
| 109 | '''Adds a external port to VIM''' |
| 110 | '''Returns the port identifier''' |
| 111 | raise NotImplementedError( "Should have implemented this" ) |
| 112 | |
| 113 | def new_external_network(self,net_name,net_type): |
| 114 | '''Adds a external network to VIM (shared)''' |
| 115 | '''Returns the network identifier''' |
| 116 | raise NotImplementedError( "Should have implemented this" ) |
| 117 | |
| 118 | def connect_port_network(self, port_id, network_id, admin=False): |
| 119 | '''Connects a external port to a network''' |
| 120 | '''Returns status code of the VIM response''' |
| 121 | raise NotImplementedError( "Should have implemented this" ) |
| 122 | |
| 123 | def new_tenant(self,tenant_name,tenant_description): |
| 124 | '''Adds a new tenant to VIM''' |
| 125 | '''Returns the tenant identifier''' |
| 126 | raise NotImplementedError( "Should have implemented this" ) |
| 127 | |
| 128 | def delete_tenant(self,tenant_id,): |
| 129 | '''Delete a tenant from VIM''' |
| 130 | '''Returns the tenant identifier''' |
| 131 | raise NotImplementedError( "Should have implemented this" ) |
| 132 | |
| 133 | def new_tenant_network(self,net_name,net_type): |
| 134 | '''Adds a tenant network to VIM''' |
| 135 | '''Returns the network identifier''' |
| 136 | raise NotImplementedError( "Should have implemented this" ) |
| 137 | |
| 138 | def get_network_list(self, filter_dict={}): |
| 139 | '''Obtain tenant networks of VIM |
| 140 | Filter_dict can be: |
| 141 | name: network name |
| 142 | id: network uuid |
| 143 | shared: boolean |
| 144 | tenant_id: tenant |
| 145 | admin_state_up: boolean |
| 146 | status: 'ACTIVE' |
| 147 | Returns the network list of dictionaries |
| 148 | ''' |
| 149 | raise NotImplementedError( "Should have implemented this" ) |
| 150 | |
| 151 | def get_tenant_network(self, net_id, tenant_id=None): |
| 152 | '''Obtain tenant networks of VIM''' |
| 153 | '''Returns the network information from a network id''' |
| 154 | raise NotImplementedError( "Should have implemented this" ) |
| 155 | |
| 156 | def delete_tenant_network(self, net_id): |
| 157 | '''Deletes a tenant network from VIM''' |
| 158 | '''Returns the network identifier''' |
| 159 | raise NotImplementedError( "Should have implemented this" ) |
| 160 | |
| 161 | def refresh_tenant_network(self, net_id): |
| 162 | '''Refreshes the status of the tenant network''' |
| 163 | '''Returns: 0 if no error, |
| 164 | <0 if error''' |
| 165 | raise NotImplementedError( "Should have implemented this" ) |
| 166 | |
| 167 | def get_tenant_flavor(self, flavor_id): |
| 168 | '''Obtain flavor details from the VIM |
| 169 | Returns the flavor dict details |
| 170 | ''' |
| 171 | raise NotImplementedError( "Should have implemented this" ) |
| 172 | |
| 173 | def new_tenant_flavor(self, flavor_data): |
| 174 | '''Adds a tenant flavor to VIM''' |
| 175 | '''Returns the flavor identifier''' |
| 176 | raise NotImplementedError( "Should have implemented this" ) |
| 177 | |
| 178 | def delete_tenant_flavor(self,flavor_id): |
| 179 | '''Deletes a tenant flavor from VIM''' |
| 180 | '''Returns the HTTP response code and a message indicating details of the success or fail''' |
| 181 | raise NotImplementedError( "Should have implemented this" ) |
| 182 | |
| 183 | def new_tenant_image(self,image_dict): |
| 184 | ''' |
| 185 | Adds a tenant image to VIM |
| 186 | Returns: |
| 187 | 200, image-id if the image is created |
| 188 | <0, message if there is an error |
| 189 | ''' |
| 190 | raise NotImplementedError( "Should have implemented this" ) |
| 191 | |
| 192 | def delete_tenant_image(self, image_id): |
| 193 | '''Deletes a tenant image from VIM''' |
| 194 | '''Returns the HTTP response code and a message indicating details of the success or fail''' |
| 195 | raise NotImplementedError( "Should have implemented this" ) |
| 196 | |
| 197 | def new_tenant_vminstancefromJSON(self, vm_data): |
| 198 | '''Adds a VM instance to VIM''' |
| 199 | '''Returns the instance identifier''' |
| 200 | raise NotImplementedError( "Should have implemented this" ) |
| 201 | |
| 202 | def new_tenant_vminstance(self,name,description,start,image_id,flavor_id,net_list): |
| 203 | '''Adds a VM instance to VIM |
| 204 | Params: |
| 205 | start: indicates if VM must start or boot in pause mode. Ignored |
| 206 | image_id,flavor_id: image and flavor uuid |
| 207 | net_list: list of interfaces, each one is a dictionary with: |
| 208 | name: |
| 209 | net_id: network uuid to connect |
| 210 | vpci: virtual vcpi to assign |
| 211 | model: interface model, virtio, e2000, ... |
| 212 | mac_address: |
| 213 | use: 'data', 'bridge', 'mgmt' |
| 214 | type: 'virtual', 'PF', 'VF', 'VFnotShared' |
| 215 | vim_id: filled/added by this function |
| 216 | #TODO ip, security groups |
| 217 | Returns >=0, the instance identifier |
| 218 | <0, error_text |
| 219 | ''' |
| 220 | raise NotImplementedError( "Should have implemented this" ) |
| 221 | |
| 222 | def get_tenant_vminstance(self,vm_id): |
| 223 | '''Returns the VM instance information from VIM''' |
| 224 | raise NotImplementedError( "Should have implemented this" ) |
| 225 | |
| 226 | def delete_tenant_vminstance(self, vm_id): |
| 227 | '''Removes a VM instance from VIM''' |
| 228 | '''Returns the instance identifier''' |
| 229 | raise NotImplementedError( "Should have implemented this" ) |
| 230 | |
| 231 | def refresh_tenant_vms_and_nets(self, vmDict, netDict): |
| 232 | '''Refreshes the status of the dictionaries of VM instances and nets passed as arguments. It modifies the dictionaries''' |
| 233 | '''Returns: |
| 234 | - result: 0 if all elements could be refreshed (even if its status didn't change) |
| 235 | n>0, the number of elements that couldn't be refreshed, |
| 236 | <0 if error (foreseen) |
| 237 | - error_msg: text with reference to possible errors |
| 238 | ''' |
| 239 | raise NotImplementedError( "Should have implemented this" ) |
| 240 | |
| 241 | def action_tenant_vminstance(self, vm_id, action_dict): |
| 242 | '''Send and action over a VM instance from VIM''' |
| 243 | '''Returns the status''' |
| 244 | raise NotImplementedError( "Should have implemented this" ) |
| 245 | |
| 246 | def host_vim2gui(self, host, server_dict): |
| 247 | '''Transform host dictionary from VIM format to GUI format, |
| 248 | and append to the server_dict |
| 249 | ''' |
| 250 | raise NotImplementedError( "Should have implemented this" ) |
| 251 | |
| 252 | def get_hosts_info(self): |
| 253 | '''Get the information of deployed hosts |
| 254 | Returns the hosts content''' |
| 255 | raise NotImplementedError( "Should have implemented this" ) |
| 256 | |
| 257 | def get_hosts(self, vim_tenant): |
| 258 | '''Get the hosts and deployed instances |
| 259 | Returns the hosts content''' |
| 260 | raise NotImplementedError( "Should have implemented this" ) |
| 261 | |
| 262 | def get_processor_rankings(self): |
| 263 | '''Get the processor rankings in the VIM database''' |
| 264 | raise NotImplementedError( "Should have implemented this" ) |
| 265 | |
| 266 | def get_image_id_from_path(self, path): |
| 267 | '''Get the image id from image path in the VIM database''' |
| 268 | '''Returns: |
| 269 | 0,"Image not found" if there are no images with that path |
| 270 | 1,image-id if there is one image with that path |
| 271 | <0,message if there was an error (Image not found, error contacting VIM, more than 1 image with that path, etc.) |
| 272 | ''' |
| 273 | raise NotImplementedError( "Should have implemented this" ) |
| 274 | |
| 275 | |
| 276 | |