1 # -*- coding: utf-8 -*-
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
25 vimconn implement an Abstract class for the vim connector plugins
26 with the definition of the method to be implemented.
28 __author__
="Alfonso Tierno"
29 __date__
="$16-oct-2015 11:09:29$"
32 HTTP_Bad_Request
= 400
33 HTTP_Unauthorized
= 401
35 HTTP_Method_Not_Allowed
= 405
36 HTTP_Request_Timeout
= 408
38 HTTP_Service_Unavailable
= 503
39 HTTP_Internal_Server_Error
= 500
41 class vimconnectorException(Exception):
45 '''Abstract base class for all the VIM connector plugins
46 These plugins must implement a vimconnector class deribed from this
49 def __init__(self
, uuid
, name
, tenant_id
, tenant_name
, url
, url_admin
=None, user
=None, passwd
=None,debug
=True,config
={}):
53 self
.url_admin
= url_admin
54 self
.tenant_id
= tenant_id
55 self
.tenant_name
= tenant_name
61 def __getitem__(self
,index
):
62 if index
=='tenant_id':
64 if index
=='tenant_name':
65 return self
.tenant_name
76 elif index
=='url_admin':
81 raise KeyError("Invalid key '%s'" %str
(index
))
83 def __setitem__(self
,index
, value
):
84 if index
=='tenant_id':
85 self
.tenant_id
= value
86 if index
=='tenant_name':
87 self
.tenant_name
= value
98 elif index
=='url_admin':
99 self
.url_admin
= value
101 raise KeyError("Invalid key '%s'" %str
(index
))
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" )
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" )
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" )
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" )
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" )
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" )
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" )
138 def get_network_list(self
, filter_dict
={}):
139 '''Obtain tenant networks of VIM
145 admin_state_up: boolean
147 Returns the network list of dictionaries
149 raise NotImplementedError( "Should have implemented this" )
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" )
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" )
161 def refresh_tenant_network(self
, net_id
):
162 '''Refreshes the status of the tenant network'''
163 '''Returns: 0 if no error,
165 raise NotImplementedError( "Should have implemented this" )
167 def get_tenant_flavor(self
, flavor_id
):
168 '''Obtain flavor details from the VIM
169 Returns the flavor dict details
171 raise NotImplementedError( "Should have implemented this" )
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" )
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" )
183 def new_tenant_image(self
,image_dict
):
185 Adds a tenant image to VIM
187 200, image-id if the image is created
188 <0, message if there is an error
190 raise NotImplementedError( "Should have implemented this" )
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" )
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" )
202 def new_tenant_vminstance(self
,name
,description
,start
,image_id
,flavor_id
,net_list
):
203 '''Adds a VM instance to VIM
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:
209 net_id: network uuid to connect
210 vpci: virtual vcpi to assign
211 model: interface model, virtio, e2000, ...
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
220 raise NotImplementedError( "Should have implemented this" )
222 def get_tenant_vminstance(self
,vm_id
):
223 '''Returns the VM instance information from VIM'''
224 raise NotImplementedError( "Should have implemented this" )
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" )
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'''
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
239 raise NotImplementedError( "Should have implemented this" )
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" )
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
250 raise NotImplementedError( "Should have implemented this" )
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" )
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" )
262 def get_processor_rankings(self
):
263 '''Get the processor rankings in the VIM database'''
264 raise NotImplementedError( "Should have implemented this" )
266 def get_image_id_from_path(self
, path
):
267 '''Get the image id from image path in the VIM database'''
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.)
273 raise NotImplementedError( "Should have implemented this" )