Revision 4331f6cd lib/rpc.py

b/lib/rpc.py
41 41
from ganeti import serializer
42 42

  
43 43

  
44
# Module level variable
45
_http_manager = None
46

  
47

  
48
def Init():
49
  """Initializes the module-global HTTP client manager.
50

  
51
  Must be called before using any RPC function.
52

  
53
  """
54
  global _http_manager
55

  
56
  assert not _http_manager, "RPC module initialized more than once"
57

  
58
  _http_manager = http.HttpClientManager()
59

  
60

  
61
def Shutdown():
62
  """Stops the module-global HTTP client manager.
63

  
64
  Must be called before quitting the program.
65

  
66
  """
67
  global _http_manager
68

  
69
  if _http_manager:
70
    _http_manager.Shutdown()
71
    _http_manager = None
72

  
73

  
44 74
class Client:
45 75
  """RPC Client class.
46 76

  
......
103 133
    @returns: List of RPC results
104 134

  
105 135
    """
106
    # TODO: Shared and reused manager
107
    mgr = http.HttpClientManager()
108
    try:
109
      mgr.ExecRequests(self.nc.values())
110
    finally:
111
      mgr.Shutdown()
136
    assert _http_manager, "RPC module not intialized"
137

  
138
    _http_manager.ExecRequests(self.nc.values())
112 139

  
113 140
    results = {}
114 141

  

Also available in: Unified diff