diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 93ab08db51bb812f11ad368a350cac9748d5bb45..bd5e77f9efbeae1333963092c9f530e87de930af 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -545,11 +545,7 @@ class LUInitCluster(LogicalUnit): ourselves in the post-run node list. """ - env = { - "CLUSTER": self.op.cluster_name, - "MASTER": self.hostname.name, - } - return env, [], [self.hostname.name] + return {}, [], [self.hostname.name] def CheckPrereq(self): """Verify that the passed name is a valid one. @@ -615,7 +611,7 @@ class LUInitCluster(LogicalUnit): hostname = self.hostname # set up the simple store - ss = ssconf.SimpleStore() + self.sstore = ss = ssconf.SimpleStore() ss.SetKey(ss.SS_HYPERVISOR, self.op.hypervisor_type) ss.SetKey(ss.SS_MASTER_NODE, hostname.name) ss.SetKey(ss.SS_MASTER_IP, clustername.ip) @@ -643,7 +639,7 @@ class LUInitCluster(LogicalUnit): _InitSSHSetup(hostname.name) # init of cluster config file - cfgw = config.ConfigWriter() + self.cfg = cfgw = config.ConfigWriter() cfgw.InitConfig(hostname.name, hostname.ip, self.secondary_ip, sshkey, self.op.mac_prefix, self.op.vg_name, self.op.def_bridge) diff --git a/lib/mcpu.py b/lib/mcpu.py index 874658a8e94cdbe7b47b59d09ce2b401d69398ca..9673ce7186ec6507a2887e3c1c22af62fb85c656 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -170,9 +170,7 @@ class HooksMaster(object): self.callfn = callfn self.lu = lu self.op = lu.op - self.hpath = self.lu.HPATH self.env, node_list_pre, node_list_post = self._BuildEnv() - self.node_list = {constants.HOOKS_PHASE_PRE: node_list_pre, constants.HOOKS_PHASE_POST: node_list_post} @@ -198,15 +196,24 @@ class HooksMaster(object): else: lu_nodes_pre = lu_nodes_post = [] + return env, frozenset(lu_nodes_pre), frozenset(lu_nodes_post) + + def _RunWrapper(self, node_list, hpath, phase): + """Simple wrapper over self.callfn. + + This method fixes the environment before doing the rpc call. + + """ + env = self.env.copy() + env["GANETI_HOOKS_PHASE"] = phase + env["GANETI_HOOKS_PATH"] = hpath if self.lu.sstore is not None: env["GANETI_CLUSTER"] = self.lu.sstore.GetClusterName() env["GANETI_MASTER"] = self.lu.sstore.GetMasterNode() - for key in env: - if not isinstance(env[key], str): - env[key] = str(env[key]) + env = dict([(str(key), str(val)) for key, val in env.iteritems()]) - return env, frozenset(lu_nodes_pre), frozenset(lu_nodes_post) + return self.callfn(node_list, hpath, phase, env) def RunPhase(self, phase): """Run all the scripts for a phase. @@ -219,8 +226,8 @@ class HooksMaster(object): # we're in the cluster init phase and the rpc client part can't # even attempt to run, or this LU doesn't do hooks at all return - self.env["GANETI_HOOKS_PHASE"] = str(phase) - results = self.callfn(self.node_list[phase], self.hpath, phase, self.env) + hpath = self.lu.HPATH + results = self._RunWrapper(self.node_list[phase], hpath, phase) if phase == constants.HOOKS_PHASE_PRE: errs = [] if not results: