Azure-plugin not sending REST calls to Azure cloud
[multicloud/azure.git] / azure / aria / aria-rest-server / src / main / python / aria-rest / aria_rest / util.py
1 #
2 # ============LICENSE_START===================================================
3 # Copyright (c) 2018 Amdocs.  All rights reserved.
4 # ===================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 # use this file except in compliance with the License. You may obtain a copy
7 # of the License at
8 #
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations under
15 # the License.
16 # ============LICENSE_END====================================================
17 #
18
19
20 import threading
21
22
23 def make_template_name(user, template_name):
24     return "{}.{}".format(user, template_name)
25
26
27 class SafeDict(dict):
28     def __init__(self, *args):
29         self._lockobj = threading.Lock()
30         dict.__init__(self, args)
31
32     def __getitem__(self, key):
33         try:
34             self._lockobj.acquire()
35             val = dict.__getitem__(self, key)
36         except:
37             raise
38         finally:
39             self._lockobj.release()
40
41     def __setitem__(self, key, value):
42         try:
43             self._lockobj.acquire()
44             dict.__setitem__(self, key, value)
45         except:
46             raise
47         finally:
48             self._lockobj.release()