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
43 '''Abstract base class for all the VIM connector plugins
44 These plugins must implement a vimconnector class deribed from this
47 def __init__(self
, uuid
, name
, tenant
, url
, url_admin
=None, user
=None, passwd
=None,debug
=True,config
={}):
51 self
.url_admin
= url_admin
58 def __getitem__(self
,index
):
71 elif index
=='url_admin':
76 raise KeyError("Invalid key '%s'" %str
(index
))
78 def __setitem__(self
,index
, value
):
91 elif index
=='url_admin':
92 self
.url_admin
= value
94 raise KeyError("Invalid key '%s'" %str
(index
))
96 def new_host(self
, host_data
):
97 '''Adds a new host to VIM'''
98 '''Returns status code of the VIM response'''
99 raise NotImplementedError( "Should have implemented this" )
101 def new_external_port(self
, port_data
):
102 '''Adds a external port to VIM'''
103 '''Returns the port identifier'''
104 raise NotImplementedError( "Should have implemented this" )
106 def new_external_network(self
,net_name
,net_type
):
107 '''Adds a external network to VIM (shared)'''
108 '''Returns the network identifier'''
109 raise NotImplementedError( "Should have implemented this" )
111 def connect_port_network(self
, port_id
, network_id
, admin
=False):
112 '''Connects a external port to a network'''
113 '''Returns status code of the VIM response'''
114 raise NotImplementedError( "Should have implemented this" )
116 def new_tenant(self
,tenant_name
,tenant_description
):
117 '''Adds a new tenant to VIM'''
118 '''Returns the tenant identifier'''
119 raise NotImplementedError( "Should have implemented this" )
121 def delete_tenant(self
,tenant_id
,):
122 '''Delete a tenant from VIM'''
123 '''Returns the tenant identifier'''
124 raise NotImplementedError( "Should have implemented this" )
126 def new_tenant_network(self
,net_name
,net_type
):
127 '''Adds a tenant network to VIM'''
128 '''Returns the network identifier'''
129 raise NotImplementedError( "Should have implemented this" )
131 def get_network_list(self
, filter_dict
={}):
132 '''Obtain tenant networks of VIM
138 admin_state_up: boolean
140 Returns the network list of dictionaries
142 raise NotImplementedError( "Should have implemented this" )
144 def get_tenant_network(self
, net_id
, tenant_id
=None):
145 '''Obtain tenant networks of VIM'''
146 '''Returns the network information from a network id'''
147 raise NotImplementedError( "Should have implemented this" )
149 def delete_tenant_network(self
, net_id
):
150 '''Deletes a tenant network from VIM'''
151 '''Returns the network identifier'''
152 raise NotImplementedError( "Should have implemented this" )
154 def refresh_tenant_network(self
, net_id
):
155 '''Refreshes the status of the tenant network'''
156 '''Returns: 0 if no error,
158 raise NotImplementedError( "Should have implemented this" )
160 def get_tenant_flavor(self
, flavor_id
):
161 '''Obtain flavor details from the VIM
162 Returns the flavor dict details
164 raise NotImplementedError( "Should have implemented this" )
166 def new_tenant_flavor(self
, flavor_data
):
167 '''Adds a tenant flavor to VIM'''
168 '''Returns the flavor identifier'''
169 raise NotImplementedError( "Should have implemented this" )
171 def delete_tenant_flavor(self
,flavor_id
):
172 '''Deletes a tenant flavor from VIM'''
173 '''Returns the HTTP response code and a message indicating details of the success or fail'''
174 raise NotImplementedError( "Should have implemented this" )
176 def new_tenant_image(self
,image_dict
):
178 Adds a tenant image to VIM
180 200, image-id if the image is created
181 <0, message if there is an error
183 raise NotImplementedError( "Should have implemented this" )
185 def delete_tenant_image(self
, image_id
):
186 '''Deletes a tenant image from VIM'''
187 '''Returns the HTTP response code and a message indicating details of the success or fail'''
188 raise NotImplementedError( "Should have implemented this" )
190 def new_tenant_vminstancefromJSON(self
, vm_data
):
191 '''Adds a VM instance to VIM'''
192 '''Returns the instance identifier'''
193 raise NotImplementedError( "Should have implemented this" )
195 def new_tenant_vminstance(self
,name
,description
,start
,image_id
,flavor_id
,net_list
):
196 '''Adds a VM instance to VIM
198 start: indicates if VM must start or boot in pause mode. Ignored
199 image_id,flavor_id: image and flavor uuid
200 net_list: list of interfaces, each one is a dictionary with:
202 net_id: network uuid to connect
203 vpci: virtual vcpi to assign
204 model: interface model, virtio, e2000, ...
206 use: 'data', 'bridge', 'mgmt'
207 type: 'virtual', 'PF', 'VF', 'VFnotShared'
208 vim_id: filled/added by this function
209 #TODO ip, security groups
210 Returns >=0, the instance identifier
213 raise NotImplementedError( "Should have implemented this" )
215 def get_tenant_vminstance(self
,vm_id
):
216 '''Returns the VM instance information from VIM'''
217 raise NotImplementedError( "Should have implemented this" )
219 def delete_tenant_vminstance(self
, vm_id
):
220 '''Removes a VM instance from VIM'''
221 '''Returns the instance identifier'''
222 raise NotImplementedError( "Should have implemented this" )
224 def refresh_tenant_vms_and_nets(self
, vmDict
, netDict
):
225 '''Refreshes the status of the dictionaries of VM instances and nets passed as arguments. It modifies the dictionaries'''
227 - result: 0 if all elements could be refreshed (even if its status didn't change)
228 n>0, the number of elements that couldn't be refreshed,
229 <0 if error (foreseen)
230 - error_msg: text with reference to possible errors
232 raise NotImplementedError( "Should have implemented this" )
234 def action_tenant_vminstance(self
, vm_id
, action_dict
):
235 '''Send and action over a VM instance from VIM'''
236 '''Returns the status'''
237 raise NotImplementedError( "Should have implemented this" )
239 def host_vim2gui(self
, host
, server_dict
):
240 '''Transform host dictionary from VIM format to GUI format,
241 and append to the server_dict
243 raise NotImplementedError( "Should have implemented this" )
245 def get_hosts_info(self
):
246 '''Get the information of deployed hosts
247 Returns the hosts content'''
248 raise NotImplementedError( "Should have implemented this" )
250 def get_hosts(self
, vim_tenant
):
251 '''Get the hosts and deployed instances
252 Returns the hosts content'''
253 raise NotImplementedError( "Should have implemented this" )
255 def get_processor_rankings(self
):
256 '''Get the processor rankings in the VIM database'''
257 raise NotImplementedError( "Should have implemented this" )
259 def get_image_id_from_path(self
, path
):
260 '''Get the image id from image path in the VIM database'''
262 0,"Image not found" if there are no images with that path
263 1,image-id if there is one image with that path
264 <0,message if there was an error (Image not found, error contacting VIM, more than 1 image with that path, etc.)
266 raise NotImplementedError( "Should have implemented this" )