vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / multicloud_azure / pub / aria / util.py
1 # Copyright (c) 2018 Amdocs
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
13 import threading
14
15
16 def make_template_name(user, template_name):
17     return "{}.{}".format(user, template_name)
18
19
20 class SafeDict(dict):
21     def __init__(self, *args):
22         self._lockobj = threading.Lock()
23         dict.__init__(self, args)
24
25     def __getitem__(self, key):
26         try:
27             self._lockobj.acquire()
28         except Exception as ex:
29             raise ex
30         finally:
31             self._lockobj.release()
32
33     def __setitem__(self, key, value):
34         try:
35             self._lockobj.acquire()
36             dict.__setitem__(self, key, value)
37         except Exception as ex:
38             raise ex
39         finally:
40             self._lockobj.release()