14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
+ import threading
17
18
import os
18
19
import re
19
20
import yaml
@@ -36,6 +37,8 @@ class LambdaCloudConnector(CloudConnector):
36
37
Cloud Launcher to create Lambda functions.
37
38
"""
38
39
40
+ _lock = threading .Lock ()
41
+ """Threading Lock to avoid concurrency problems."""
39
42
type = "Lambda"
40
43
"""str with the name of the provider."""
41
44
@@ -173,9 +176,10 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
173
176
inf .add_vm (vm )
174
177
175
178
try :
176
- self ._set_scar_env (radl .systems [0 ], auth_data )
177
- AWS ("init" )
178
- self ._free_scar_env ()
179
+ with LambdaCloudConnector ._lock :
180
+ self ._set_scar_env (radl .systems [0 ], auth_data )
181
+ AWS ("init" )
182
+ self ._free_scar_env ()
179
183
vm .destroy = False
180
184
vm .state = VirtualMachine .RUNNING
181
185
res .append ((True , vm ))
@@ -191,10 +195,11 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
191
195
192
196
def finalize (self , vm , last , auth_data ):
193
197
try :
194
- aws_resources = self ._set_scar_env (vm .info .systems [0 ], auth_data )
195
- Lambda (aws_resources ["functions" ]["aws" ][0 ]).get_function_configuration (vm .id )
196
- AWS ("rm" )
197
- self ._free_scar_env ()
198
+ with LambdaCloudConnector ._lock :
199
+ aws_resources = self ._set_scar_env (vm .info .systems [0 ], auth_data )
200
+ Lambda (aws_resources ["functions" ]["aws" ][0 ]).get_function_configuration (vm .id )
201
+ AWS ("rm" )
202
+ self ._free_scar_env ()
198
203
except ClientError as ce :
199
204
# Function not found
200
205
if ce .response ['Error' ]['Code' ] == 'ResourceNotFoundException' :
@@ -224,10 +229,11 @@ def update_system_info_from_function_conf(system, func_conf):
224
229
225
230
def updateVMInfo (self , vm , auth_data ):
226
231
try :
227
- aws_resources = self ._set_scar_env (vm .info .systems [0 ], auth_data )
228
- func_conf = Lambda (aws_resources ["functions" ]["aws" ][0 ]).get_function_configuration (vm .id )
229
- self .update_system_info_from_function_conf (vm .info .systems [0 ], func_conf )
230
- self ._free_scar_env ()
232
+ with LambdaCloudConnector ._lock :
233
+ aws_resources = self ._set_scar_env (vm .info .systems [0 ], auth_data )
234
+ func_conf = Lambda (aws_resources ["functions" ]["aws" ][0 ]).get_function_configuration (vm .id )
235
+ self .update_system_info_from_function_conf (vm .info .systems [0 ], func_conf )
236
+ self ._free_scar_env ()
231
237
return True , vm
232
238
except ClientError as ce :
233
239
# Function not found
@@ -250,11 +256,12 @@ def alterVM(self, vm, radl, auth_data):
250
256
251
257
if new_memory and new_memory != memory :
252
258
try :
253
- aws_resources = self ._set_scar_env (vm .info .systems [0 ], auth_data )
254
- Lambda (aws_resources ["functions" ]["aws" ][0 ]).client .update_function_configuration (
255
- MemorySize = new_memory , FunctionName = vm .id )
256
- self .update_system_info_from_function_conf (vm .info .systems [0 ], {"MemorySize" : new_memory })
257
- self ._free_scar_env ()
259
+ with LambdaCloudConnector ._lock :
260
+ aws_resources = self ._set_scar_env (vm .info .systems [0 ], auth_data )
261
+ Lambda (aws_resources ["functions" ]["aws" ][0 ]).client .update_function_configuration (
262
+ MemorySize = new_memory , FunctionName = vm .id )
263
+ self .update_system_info_from_function_conf (vm .info .systems [0 ], {"MemorySize" : new_memory })
264
+ self ._free_scar_env ()
258
265
return True , vm
259
266
except ClientError as ce :
260
267
# Function not found
0 commit comments