1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 """Master daemon program.
32
33 Some classes deviates from the standard style guide since the
34 inheritance from parent classes requires it.
35
36 """
37
38
39
40
41 import logging
42
43 from ganeti import config
44 from ganeti import constants
45 from ganeti import jqueue
46 from ganeti import utils
47 import ganeti.rpc.node as rpc
48
49
50 CLIENT_REQUEST_WORKERS = 16
51
52 EXIT_NOTMASTER = constants.EXIT_NOTMASTER
53 EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR
54
55
56 -class GanetiContext(object):
57 """Context common to all ganeti threads.
58
59 This class creates and holds common objects shared by all threads.
60
61 """
62
63
64 _instance = None
65
66 - def __init__(self, livelock=None):
67 """Constructs a new GanetiContext object.
68
69 There should be only a GanetiContext object at any time, so this
70 function raises an error if this is not the case.
71
72 """
73 assert self.__class__._instance is None, "double GanetiContext instance"
74
75
76 if livelock is None:
77 self.livelock = utils.livelock.LiveLock("masterd")
78 else:
79 self.livelock = livelock
80
81
82 cfg = self.GetConfig(None)
83 logging.debug("Creating the job queue")
84 self.jobqueue = jqueue.JobQueue(self, cfg)
85
86
87 self.__class__._instance = self
88
89 - def __setattr__(self, name, value):
90 """Setting GanetiContext attributes is forbidden after initialization.
91
92 """
93 assert self.__class__._instance is None, "Attempt to modify Ganeti Context"
94 object.__setattr__(self, name, value)
95
96 - def GetWConfdContext(self, ec_id):
98
99 - def GetConfig(self, ec_id):
100 return config.GetConfig(ec_id, self.livelock)
101
102
103
104 - def GetRpc(self, cfg):
105 return rpc.RpcRunner(cfg, lambda _: None)
106
107 - def AddNode(self, cfg, node, ec_id):
108 """Adds a node to the configuration.
109
110 """
111
112 cfg.AddNode(node, ec_id)
113
114 - def RemoveNode(self, cfg, node):
115 """Removes a node from the configuration and lock manager.
116
117 """
118
119 cfg.RemoveNode(node.uuid)
120