Commit 62c9ec92 authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent 3d3a04bc
...@@ -236,7 +236,8 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): ...@@ -236,7 +236,8 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler):
disk = objects.Disk.FromDict(params[0]) disk = objects.Disk.FromDict(params[0])
dest_node = params[1] dest_node = params[1]
instance = objects.Instance.FromDict(params[2]) 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 @staticmethod
def perspective_finalize_export(params): def perspective_finalize_export(params):
...@@ -333,10 +334,10 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): ...@@ -333,10 +334,10 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler):
"""Run the import function of an OS onto a given instance. """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) inst = objects.Instance.FromDict(inst_s)
return backend.ImportOSIntoInstance(inst, os_disk, swap_disk, return backend.ImportOSIntoInstance(inst, os_disk, swap_disk,
src_node, src_image) src_node, src_image, cluster_name)
@staticmethod @staticmethod
def perspective_instance_shutdown(params): def perspective_instance_shutdown(params):
...@@ -425,7 +426,7 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): ...@@ -425,7 +426,7 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler):
"""Run a verify sequence on this node. """Run a verify sequence on this node.
""" """
return backend.VerifyNode(params[0]) return backend.VerifyNode(params[0], params[1])
@staticmethod @staticmethod
def perspective_node_start_master(params): def perspective_node_start_master(params):
......
...@@ -48,8 +48,8 @@ def _GetConfig(): ...@@ -48,8 +48,8 @@ def _GetConfig():
return ssconf.SimpleConfigReader() return ssconf.SimpleConfigReader()
def _GetSshRunner(): def _GetSshRunner(cluster_name):
return ssh.SshRunner(_GetConfig().GetClusterName()) return ssh.SshRunner(cluster_name)
def _CleanDirectory(path, exclude=[]): def _CleanDirectory(path, exclude=[]):
...@@ -264,7 +264,7 @@ def GetNodeInfo(vgname): ...@@ -264,7 +264,7 @@ def GetNodeInfo(vgname):
return outputarray return outputarray
def VerifyNode(what): def VerifyNode(what, cluster_name):
"""Verify the status of the local node. """Verify the status of the local node.
Args: Args:
...@@ -294,7 +294,7 @@ def VerifyNode(what): ...@@ -294,7 +294,7 @@ def VerifyNode(what):
result['nodelist'] = {} result['nodelist'] = {}
random.shuffle(what['nodelist']) random.shuffle(what['nodelist'])
for node in what['nodelist']: for node in what['nodelist']:
success, message = _GetSshRunner().VerifyNodeHostname(node) success, message = _GetSshRunner(cluster_name).VerifyNodeHostname(node)
if not success: if not success:
result['nodelist'][node] = message result['nodelist'][node] = message
if 'node-net-test' in what: if 'node-net-test' in what:
...@@ -1295,7 +1295,7 @@ def SnapshotBlockDevice(disk): ...@@ -1295,7 +1295,7 @@ def SnapshotBlockDevice(disk):
(disk.unique_id, disk.dev_type)) (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. """Export a block device snapshot to a remote node.
Args: Args:
...@@ -1336,7 +1336,8 @@ def ExportSnapshot(disk, dest_node, instance): ...@@ -1336,7 +1336,8 @@ def ExportSnapshot(disk, dest_node, instance):
destcmd = utils.BuildShellCmd("mkdir -p %s && cat > %s/%s", destcmd = utils.BuildShellCmd("mkdir -p %s && cat > %s/%s",
destdir, destdir, destfile) destdir, destdir, destfile)
remotecmd = _GetSshRunner().BuildCmd(dest_node, constants.GANETI_RUNAS, remotecmd = _GetSshRunner(cluster_name).BuildCmd(dest_node,
constants.GANETI_RUNAS,
destcmd) destcmd)
# all commands have been checked, so we're safe to combine them # all commands have been checked, so we're safe to combine them
...@@ -1436,7 +1437,8 @@ def ExportInfo(dest): ...@@ -1436,7 +1437,8 @@ def ExportInfo(dest):
return config 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. """Import an os image into an instance.
Args: Args:
...@@ -1482,7 +1484,8 @@ def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image): ...@@ -1482,7 +1484,8 @@ def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image):
os.mkdir(constants.LOG_OS_DIR, 0750) os.mkdir(constants.LOG_OS_DIR, 0750)
destcmd = utils.BuildShellCmd('cat %s', src_image) destcmd = utils.BuildShellCmd('cat %s', src_image)
remotecmd = _GetSshRunner().BuildCmd(src_node, constants.GANETI_RUNAS, remotecmd = _GetSshRunner(cluster_name).BuildCmd(src_node,
constants.GANETI_RUNAS,
destcmd) destcmd)
comprcmd = "gunzip" comprcmd = "gunzip"
......
...@@ -748,7 +748,8 @@ class LUVerifyCluster(LogicalUnit): ...@@ -748,7 +748,8 @@ class LUVerifyCluster(LogicalUnit):
'node-net-test': [(node.name, node.primary_ip, node.secondary_ip) 'node-net-test': [(node.name, node.primary_ip, node.secondary_ip)
for node in nodeinfo] 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_rversion = rpc.call_version(nodelist)
all_ninfo = rpc.call_node_info(nodelist, self.cfg.GetVGName()) all_ninfo = rpc.call_node_info(nodelist, self.cfg.GetVGName())
...@@ -1777,7 +1778,8 @@ class LUAddNode(LogicalUnit): ...@@ -1777,7 +1778,8 @@ class LUAddNode(LogicalUnit):
# TODO: do a node-net-test as well? # 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: for verifier in node_verify_list:
if not result[verifier]: if not result[verifier]:
raise errors.OpExecError("Cannot communicate with %s's node daemon" raise errors.OpExecError("Cannot communicate with %s's node daemon"
...@@ -3581,8 +3583,9 @@ class LUCreateInstance(LogicalUnit): ...@@ -3581,8 +3583,9 @@ class LUCreateInstance(LogicalUnit):
feedback_fn("* running the instance OS import scripts...") feedback_fn("* running the instance OS import scripts...")
src_node = self.op.src_node src_node = self.op.src_node
src_image = self.src_image src_image = self.src_image
cluster_name = self.cfg.GetClusterName()
if not rpc.call_instance_os_import(pnode_name, iobj, "sda", "sdb", 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" raise errors.OpExecError("Could not import os for instance"
" %s on node %s" % " %s on node %s" %
(instance, pnode_name)) (instance, pnode_name))
...@@ -4830,8 +4833,10 @@ class LUExportInstance(LogicalUnit): ...@@ -4830,8 +4833,10 @@ class LUExportInstance(LogicalUnit):
# TODO: check for size # TODO: check for size
cluster_name = self.cfg.GetClusterName()
for dev in snap_disks: 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" logger.Error("could not export block device %s from node %s to node %s"
% (dev.logical_id[1], src_node, dst_node.name)) % (dev.logical_id[1], src_node, dst_node.name))
if not rpc.call_blockdev_remove(src_node, dev): if not rpc.call_blockdev_remove(src_node, dev):
......
...@@ -346,13 +346,13 @@ def call_node_add(node, dsa, dsapub, rsa, rsapub, ssh, sshpub): ...@@ -346,13 +346,13 @@ def call_node_add(node, dsa, dsapub, rsa, rsapub, ssh, sshpub):
return c.getresult().get(node, False) 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. """Request verification of given parameters.
This is a multi-node call. This is a multi-node call.
""" """
c = Client("node_verify", [checkdict]) c = Client("node_verify", [checkdict, cluster_name])
c.connect_list(node_list) c.connect_list(node_list)
c.run() c.run()
return c.getresult() return c.getresult()
...@@ -652,13 +652,13 @@ def call_blockdev_snapshot(node, cf_bdev): ...@@ -652,13 +652,13 @@ def call_blockdev_snapshot(node, cf_bdev):
return c.getresult().get(node, False) 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. """Request the export of a given snapshot.
This is a single-node call. 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 = Client("snapshot_export", params)
c.connect(node) c.connect(node)
c.run() c.run()
...@@ -698,13 +698,14 @@ def call_export_info(node, path): ...@@ -698,13 +698,14 @@ def call_export_info(node, path):
return objects.SerializableConfigParser.Loads(str(result)) 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. """Request the import of a backup into an instance.
This is a single-node call. 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 = Client("instance_os_import", params)
c.connect(node) c.connect(node)
c.run() c.run()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment