source: OpenRLabs-Git/web2py/applications/rlabs/modules/ognsys_globals.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100644
File size: 2.0 KB
Line 
1# -*- coding: utf-8 -*-
2#################################################################################
3# @file    ognsys_servers.py
4# @brief   Module that store global info to access Rest API opengnsys.
5#          Suply global access using import vs singleton pattern.
6#          With threading.local() ensure one var per threading/Http Requests
7# @warning None
8# @note Use: None     
9# @license GNU GPLv3+
10# @author  David Fuertes, EUPT, University of Zaragoza.
11#          Opengnsys Api Rest support provided by Juan Carlos García, EUPT, University of Zaragoza.
12# @version 1.1.0 - First version
13# @date    2019-15-11
14#################################################################################
15
16
17import threading
18import urllib3
19
20urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
21
22from ados import adoDB_openRlabs_setup
23
24
25local = threading.local()
26
27
28       
29def init(db):
30    # Don't do 'local' var inittialization in module import beacause module is
31    # imported only first time server thread is launch.
32     
33    global local
34    local.__OPENGNSYS_SERVER__ = adoDB_openRlabs_setup.get_openGnsys_server(db)
35   
36    local.__RLABS_SERVER__ = adoDB_openRlabs_setup.get_openRLabs_server(db)
37   
38    # Global Request/Thread  PoolManager
39   
40    local.__POOL_MANAGER__ = urllib3.PoolManager(num_pools=10, maxsize=10,
41                                           cert_reqs='CERT_NONE',
42                                           assert_hostname=False)
43   
44    # Do init __APIKEY__ because import do only first time
45    # and var local is new each request.
46   
47    local.__APIKEY__ = ""
48           
49
50
51def set_servers(db):               
52    global local
53    local.__OPENGNSYS_SERVER__ = adoDB_openRlabs_setup.get_openGnsys_server(db)
54   
55    local.__RLABS_SERVER__ = adoDB_openRlabs_setup.get_openRLabs_server(db)
56   
57    # Do init __APIKEY__ because import do only first time
58    # and var local is new each request.
59   
60    local.__APIKEY__ = ""
61   
62def set_apikey(apikey):
63    global local
64    local.__APIKEY__ = apikey
65
Note: See TracBrowser for help on using the repository browser.