Skip to content

Commit 6cdb3d4

Browse files
committed
Fix #1512
1 parent 75631f6 commit 6cdb3d4

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

IM/connectors/Lambda.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
import threading
1718
import os
1819
import re
1920
import yaml
@@ -36,6 +37,8 @@ class LambdaCloudConnector(CloudConnector):
3637
Cloud Launcher to create Lambda functions.
3738
"""
3839

40+
_lock = threading.Lock()
41+
"""Threading Lock to avoid concurrency problems."""
3942
type = "Lambda"
4043
"""str with the name of the provider."""
4144

@@ -173,9 +176,10 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
173176
inf.add_vm(vm)
174177

175178
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()
179183
vm.destroy = False
180184
vm.state = VirtualMachine.RUNNING
181185
res.append((True, vm))
@@ -191,10 +195,11 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
191195

192196
def finalize(self, vm, last, auth_data):
193197
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()
198203
except ClientError as ce:
199204
# Function not found
200205
if ce.response['Error']['Code'] == 'ResourceNotFoundException':
@@ -224,10 +229,11 @@ def update_system_info_from_function_conf(system, func_conf):
224229

225230
def updateVMInfo(self, vm, auth_data):
226231
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()
231237
return True, vm
232238
except ClientError as ce:
233239
# Function not found
@@ -250,11 +256,12 @@ def alterVM(self, vm, radl, auth_data):
250256

251257
if new_memory and new_memory != memory:
252258
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()
258265
return True, vm
259266
except ClientError as ce:
260267
# Function not found

0 commit comments

Comments
 (0)