openmano first code upload
[osm/RO.git] / vimconn.py
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
41
42 class vimconnector():
43 '''Abstract base class for all the VIM connector plugins
44 These plugins must implement a vimconnector class deribed from this
45 and all these methods
46 '''
47 def __init__(self, uuid, name, tenant, url, url_admin=None, user=None, passwd=None,debug=True,config={}):
48 self.id = uuid
49 self.name = name
50 self.url = url
51 self.url_admin = url_admin
52 self.tenant = tenant
53 self.user = user
54 self.passwd = passwd
55 self.config = config
56 self.debug = debug
57
58 def __getitem__(self,index):
59 if index=='tenant':
60 return self.tenant
61 elif index=='id':
62 return self.id
63 elif index=='name':
64 return self.name
65 elif index=='user':
66 return self.user
67 elif index=='passwd':
68 return self.passwd
69 elif index=='url':
70 return self.url
71 elif index=='url_admin':
72 return self.url_admin
73 elif index=="config":
74 return self.config
75 else:
76 raise KeyError("Invalid key '%s'" %str(index))
77
78 def __setitem__(self,index, value):
79 if index=='tenant':
80 self.tenant = value
81 elif index=='id':
82 self.id = value
83 elif index=='name':
84 self.name = value
85 elif index=='user':
86 self.user = value
87 elif index=='passwd':
88 self.passwd = value
89 elif index=='url':
90 self.url = value
91 elif index=='url_admin':
92 self.url_admin = value
93 else:
94 raise KeyError("Invalid key '%s'" %str(index))
95
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" )
100
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" )
105
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" )
110
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" )
115
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" )
120
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" )
125
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" )
130
131 def get_network_list(self, filter_dict={}):
132 '''Obtain tenant networks of VIM
133 Filter_dict can be:
134 name: network name
135 id: network uuid
136 shared: boolean
137 tenant_id: tenant
138 admin_state_up: boolean
139 status: 'ACTIVE'
140 Returns the network list of dictionaries
141 '''
142 raise NotImplementedError( "Should have implemented this" )
143
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" )
148
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" )
153
154 def refresh_tenant_network(self, net_id):
155 '''Refreshes the status of the tenant network'''
156 '''Returns: 0 if no error,
157 <0 if error'''
158 raise NotImplementedError( "Should have implemented this" )
159
160 def get_tenant_flavor(self, flavor_id):
161 '''Obtain flavor details from the VIM
162 Returns the flavor dict details
163 '''
164 raise NotImplementedError( "Should have implemented this" )
165
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" )
170
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" )
175
176 def new_tenant_image(self,image_dict):
177 '''
178 Adds a tenant image to VIM
179 Returns:
180 200, image-id if the image is created
181 <0, message if there is an error
182 '''
183 raise NotImplementedError( "Should have implemented this" )
184
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" )
189
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" )
194
195 def new_tenant_vminstance(self,name,description,start,image_id,flavor_id,net_list):
196 '''Adds a VM instance to VIM
197 Params:
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:
201 name:
202 net_id: network uuid to connect
203 vpci: virtual vcpi to assign
204 model: interface model, virtio, e2000, ...
205 mac_address:
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
211 <0, error_text
212 '''
213 raise NotImplementedError( "Should have implemented this" )
214
215 def get_tenant_vminstance(self,vm_id):
216 '''Returns the VM instance information from VIM'''
217 raise NotImplementedError( "Should have implemented this" )
218
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" )
223
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'''
226 '''Returns:
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
231 '''
232 raise NotImplementedError( "Should have implemented this" )
233
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" )
238
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
242 '''
243 raise NotImplementedError( "Should have implemented this" )
244
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" )
249
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" )
254
255 def get_processor_rankings(self):
256 '''Get the processor rankings in the VIM database'''
257 raise NotImplementedError( "Should have implemented this" )
258
259 def get_image_id_from_path(self, path):
260 '''Get the image id from image path in the VIM database'''
261 '''Returns:
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.)
265 '''
266 raise NotImplementedError( "Should have implemented this" )
267
268
269