From 62c9ec9297bffb3e9054cdf665ad8e24a3a4d796 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 6 Oct 2008 15:58:26 +0000 Subject: [PATCH] backend.py change to get cluster name from master Currently there are three function in backend that need the cluster name in order to instantiate an SshRunner. The patch changes these to get the cluster name from the master in the rpc call; once the multi-hypervisor change is implemented, then very few places in which we need the SCR remain in the backend. Reviewed-by: killerfoxi, imsnah --- daemons/ganeti-noded | 9 +++++---- lib/backend.py | 23 +++++++++++++---------- lib/cmdlib.py | 13 +++++++++---- lib/rpc.py | 13 +++++++------ 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index a4811f99c..495b65c21 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -236,7 +236,8 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): disk = objects.Disk.FromDict(params[0]) dest_node = params[1] instance = objects.Instance.FromDict(params[2]) - return backend.ExportSnapshot(disk, dest_node, instance) + cluster_name = params[3] + return backend.ExportSnapshot(disk, dest_node, instance, cluster_name) @staticmethod def perspective_finalize_export(params): @@ -333,10 +334,10 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): """Run the import function of an OS onto a given instance. """ - inst_s, os_disk, swap_disk, src_node, src_image = params + inst_s, os_disk, swap_disk, src_node, src_image, cluster_name = params inst = objects.Instance.FromDict(inst_s) return backend.ImportOSIntoInstance(inst, os_disk, swap_disk, - src_node, src_image) + src_node, src_image, cluster_name) @staticmethod def perspective_instance_shutdown(params): @@ -425,7 +426,7 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): """Run a verify sequence on this node. """ - return backend.VerifyNode(params[0]) + return backend.VerifyNode(params[0], params[1]) @staticmethod def perspective_node_start_master(params): diff --git a/lib/backend.py b/lib/backend.py index 474fc815a..7dbce0c6c 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -48,8 +48,8 @@ def _GetConfig(): return ssconf.SimpleConfigReader() -def _GetSshRunner(): - return ssh.SshRunner(_GetConfig().GetClusterName()) +def _GetSshRunner(cluster_name): + return ssh.SshRunner(cluster_name) def _CleanDirectory(path, exclude=[]): @@ -264,7 +264,7 @@ def GetNodeInfo(vgname): return outputarray -def VerifyNode(what): +def VerifyNode(what, cluster_name): """Verify the status of the local node. Args: @@ -294,7 +294,7 @@ def VerifyNode(what): result['nodelist'] = {} random.shuffle(what['nodelist']) for node in what['nodelist']: - success, message = _GetSshRunner().VerifyNodeHostname(node) + success, message = _GetSshRunner(cluster_name).VerifyNodeHostname(node) if not success: result['nodelist'][node] = message if 'node-net-test' in what: @@ -1295,7 +1295,7 @@ def SnapshotBlockDevice(disk): (disk.unique_id, disk.dev_type)) -def ExportSnapshot(disk, dest_node, instance): +def ExportSnapshot(disk, dest_node, instance, cluster_name): """Export a block device snapshot to a remote node. Args: @@ -1336,8 +1336,9 @@ def ExportSnapshot(disk, dest_node, instance): destcmd = utils.BuildShellCmd("mkdir -p %s && cat > %s/%s", destdir, destdir, destfile) - remotecmd = _GetSshRunner().BuildCmd(dest_node, constants.GANETI_RUNAS, - destcmd) + remotecmd = _GetSshRunner(cluster_name).BuildCmd(dest_node, + constants.GANETI_RUNAS, + destcmd) # all commands have been checked, so we're safe to combine them command = '|'.join([expcmd, comprcmd, utils.ShellQuoteArgs(remotecmd)]) @@ -1436,7 +1437,8 @@ def ExportInfo(dest): return config -def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image): +def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image, + cluster_name): """Import an os image into an instance. Args: @@ -1482,8 +1484,9 @@ def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image): os.mkdir(constants.LOG_OS_DIR, 0750) destcmd = utils.BuildShellCmd('cat %s', src_image) - remotecmd = _GetSshRunner().BuildCmd(src_node, constants.GANETI_RUNAS, - destcmd) + remotecmd = _GetSshRunner(cluster_name).BuildCmd(src_node, + constants.GANETI_RUNAS, + destcmd) comprcmd = "gunzip" impcmd = utils.BuildShellCmd("(cd %s; %s -i %s -b %s -s %s &>%s)", diff --git a/lib/cmdlib.py b/lib/cmdlib.py index a91ca23d1..9dd65554a 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -748,7 +748,8 @@ class LUVerifyCluster(LogicalUnit): 'node-net-test': [(node.name, node.primary_ip, node.secondary_ip) for node in nodeinfo] } - all_nvinfo = rpc.call_node_verify(nodelist, node_verify_param) + all_nvinfo = rpc.call_node_verify(nodelist, node_verify_param, + self.cfg.GetClusterName()) all_rversion = rpc.call_version(nodelist) all_ninfo = rpc.call_node_info(nodelist, self.cfg.GetVGName()) @@ -1777,7 +1778,8 @@ class LUAddNode(LogicalUnit): # TODO: do a node-net-test as well? } - result = rpc.call_node_verify(node_verify_list, node_verify_param) + result = rpc.call_node_verify(node_verify_list, node_verify_param, + self.cfg.GetClusterName()) for verifier in node_verify_list: if not result[verifier]: raise errors.OpExecError("Cannot communicate with %s's node daemon" @@ -3581,8 +3583,9 @@ class LUCreateInstance(LogicalUnit): feedback_fn("* running the instance OS import scripts...") src_node = self.op.src_node src_image = self.src_image + cluster_name = self.cfg.GetClusterName() if not rpc.call_instance_os_import(pnode_name, iobj, "sda", "sdb", - src_node, src_image): + src_node, src_image, cluster_name): raise errors.OpExecError("Could not import os for instance" " %s on node %s" % (instance, pnode_name)) @@ -4830,8 +4833,10 @@ class LUExportInstance(LogicalUnit): # TODO: check for size + cluster_name = self.cfg.GetClusterName() for dev in snap_disks: - if not rpc.call_snapshot_export(src_node, dev, dst_node.name, instance): + if not rpc.call_snapshot_export(src_node, dev, dst_node.name, + instance, cluster_name): logger.Error("could not export block device %s from node %s to node %s" % (dev.logical_id[1], src_node, dst_node.name)) if not rpc.call_blockdev_remove(src_node, dev): diff --git a/lib/rpc.py b/lib/rpc.py index 7bf0fce40..14a618580 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -346,13 +346,13 @@ def call_node_add(node, dsa, dsapub, rsa, rsapub, ssh, sshpub): return c.getresult().get(node, False) -def call_node_verify(node_list, checkdict): +def call_node_verify(node_list, checkdict, cluster_name): """Request verification of given parameters. This is a multi-node call. """ - c = Client("node_verify", [checkdict]) + c = Client("node_verify", [checkdict, cluster_name]) c.connect_list(node_list) c.run() return c.getresult() @@ -652,13 +652,13 @@ def call_blockdev_snapshot(node, cf_bdev): return c.getresult().get(node, False) -def call_snapshot_export(node, snap_bdev, dest_node, instance): +def call_snapshot_export(node, snap_bdev, dest_node, instance, cluster_name): """Request the export of a given snapshot. This is a single-node call. """ - params = [snap_bdev.ToDict(), dest_node, instance.ToDict()] + params = [snap_bdev.ToDict(), dest_node, instance.ToDict(), cluster_name] c = Client("snapshot_export", params) c.connect(node) c.run() @@ -698,13 +698,14 @@ def call_export_info(node, path): return objects.SerializableConfigParser.Loads(str(result)) -def call_instance_os_import(node, inst, osdev, swapdev, src_node, src_image): +def call_instance_os_import(node, inst, osdev, swapdev, + src_node, src_image, cluster_name): """Request the import of a backup into an instance. This is a single-node call. """ - params = [inst.ToDict(), osdev, swapdev, src_node, src_image] + params = [inst.ToDict(), osdev, swapdev, src_node, src_image, cluster_name] c = Client("instance_os_import", params) c.connect(node) c.run() -- GitLab