class Client:
"""RPC Client class.
- This class, given a (remote) ethod name, a list of parameters and a
+ This class, given a (remote) method name, a list of parameters and a
list of nodes, will contact (in parallel) all nodes, and return a
dict of results (key: node name, value: result).
def call_instance_start(node, instance, extra_args):
- """Stars an instance.
+ """Starts an instance.
This is a single-node call.
return c.getresult().get(node, False)
+def call_instance_reboot(node, instance, reboot_type, extra_args):
+ """Reboots an instance.
+
+ This is a single-node call.
+
+ """
+ c = Client("instance_reboot", [instance.ToDict(), reboot_type, extra_args])
+ c.connect(node)
+ c.run()
+ return c.getresult().get(node, False)
+
+
def call_instance_os_add(node, inst, osdev, swapdev):
"""Installs an OS on the given instance.
return c.getresult()
-def call_blockdev_create(node, bdev, size, on_primary, info):
+def call_blockdev_create(node, bdev, size, owner, on_primary, info):
"""Request creation of a given block device.
This is a single-node call.
"""
- params = [bdev.ToDict(), size, on_primary, info]
+ params = [bdev.ToDict(), size, owner, on_primary, info]
c = Client("blockdev_create", params)
c.connect(node)
c.run()
return c.getresult().get(node, False)
-def call_blockdev_assemble(node, disk, on_primary):
+def call_blockdev_rename(node, devlist):
+ """Request rename of the given block devices.
+
+ This is a single-node call.
+
+ """
+ params = [(d.ToDict(), uid) for d, uid in devlist]
+ c = Client("blockdev_rename", params)
+ c.connect(node)
+ c.run()
+ return c.getresult().get(node, False)
+
+
+def call_blockdev_assemble(node, disk, owner, on_primary):
"""Request assembling of a given block device.
This is a single-node call.
"""
- params = [disk.ToDict(), on_primary]
+ params = [disk.ToDict(), owner, on_primary]
c = Client("blockdev_assemble", params)
c.connect(node)
c.run()
return c.getresult().get(node, False)
-def call_blockdev_addchild(node, bdev, ndev):
- """Request adding a new child to a (mirroring) device.
+def call_blockdev_addchildren(node, bdev, ndevs):
+ """Request adding a list of children to a (mirroring) device.
This is a single-node call.
"""
- params = [bdev.ToDict(), ndev.ToDict()]
- c = Client("blockdev_addchild", params)
+ params = [bdev.ToDict(), [disk.ToDict() for disk in ndevs]]
+ c = Client("blockdev_addchildren", params)
c.connect(node)
c.run()
return c.getresult().get(node, False)
-def call_blockdev_removechild(node, bdev, ndev):
- """Request removing a new child from a (mirroring) device.
+def call_blockdev_removechildren(node, bdev, ndevs):
+ """Request removing a list of children from a (mirroring) device.
This is a single-node call.
"""
- params = [bdev.ToDict(), ndev.ToDict()]
- c = Client("blockdev_removechild", params)
+ params = [bdev.ToDict(), [disk.ToDict() for disk in ndevs]]
+ c = Client("blockdev_removechildren", params)
c.connect(node)
c.run()
return c.getresult().get(node, False)
result = c.getresult()
new_result = {}
for node_name in result:
- nr = []
if result[node_name]:
- for data in result[node_name]:
- if data:
- if isinstance(data, dict):
- nr.append(objects.OS.FromDict(data))
- elif isinstance(data, tuple) and len(data) == 3:
- nr.append(errors.InvalidOS(data[0], data[1], data[2]))
- else:
- raise errors.ProgrammerError("Invalid data from"
- " xcserver.os_diagnose")
+ nr = [objects.OS.FromDict(oss) for oss in result[node_name]]
+ else:
+ nr = []
new_result[node_name] = nr
return new_result
-def call_os_get(node_list, name):
+def call_os_get(node, name):
"""Returns an OS definition.
- This is a multi-node call.
+ This is a single-node call.
"""
c = Client("os_get", [name])
- c.connect_list(node_list)
+ c.connect(node)
c.run()
- result = c.getresult()
- new_result = {}
- for node_name in result:
- data = result[node_name]
- if isinstance(data, dict):
- new_result[node_name] = objects.OS.FromDict(data)
- elif isinstance(data, tuple) and len(data) == 3:
- new_result[node_name] = errors.InvalidOS(data[0], data[1], data[2])
- else:
- new_result[node_name] = data
- return new_result
+ result = c.getresult().get(node, False)
+ if isinstance(result, dict):
+ return objects.OS.FromDict(result)
+ else:
+ return result
def call_hooks_runner(node_list, hpath, phase, env):
c.connect_list(node_list)
c.run()
return c.getresult()
+
+
+def call_test_delay(node_list, duration):
+ """Sleep for a fixed time on given node(s).
+
+ This is a multi-node call.
+
+ """
+ c = Client("test_delay", [duration])
+ c.connect_list(node_list)
+ c.run()
+ return c.getresult()