- def _Compress(data):
- """Compresses a string for transport over RPC.
-
- Small amounts of data are not compressed.
-
- @type data: str
- @param data: Data
- @rtype: tuple
- @return: Encoded data to send
-
- """
- # Small amounts of data are not compressed
- if len(data) < 512:
- return (constants.RPC_ENCODING_NONE, data)
-
- # Compress with zlib and encode in base64
- return (constants.RPC_ENCODING_ZLIB_BASE64,
- base64.b64encode(zlib.compress(data, 3)))
-
- #
- # Begin RPC calls
- #
-
- def call_volume_list(self, node_list, vg_name):
- """Gets the logical volumes present in a given volume group.
-
- This is a multi-node call.
-
- """
- return self._MultiNodeCall(node_list, "volume_list", [vg_name])
-
- def call_vg_list(self, node_list):
- """Gets the volume group list.
-
- This is a multi-node call.
-
- """
- return self._MultiNodeCall(node_list, "vg_list", [])
-
- def call_bridges_exist(self, node, bridges_list):
- """Checks if a node has all the bridges given.
-
- This method checks if all bridges given in the bridges_list are
- present on the remote node, so that an instance that uses interfaces
- on those bridges can be started.
-
- This is a single-node call.
-
- """
- return self._SingleNodeCall(node, "bridges_exist", [bridges_list])
-
- def call_instance_start(self, node, instance, hvp, bep):
- """Starts an instance.
-
- This is a single-node call.
-
- """
- idict = self._InstDict(instance, hvp=hvp, bep=bep)
- return self._SingleNodeCall(node, "instance_start", [idict])
-
- def call_instance_shutdown(self, node, instance):
- """Stops an instance.
-
- This is a single-node call.
-
- """
- return self._SingleNodeCall(node, "instance_shutdown",
- [self._InstDict(instance)])
-
- def call_migration_info(self, node, instance):
- """Gather the information necessary to prepare an instance migration.
-
- This is a single-node call.
-
- @type node: string
- @param node: the node on which the instance is currently running
- @type instance: C{objects.Instance}
- @param instance: the instance definition
-
- """
- return self._SingleNodeCall(node, "migration_info",
- [self._InstDict(instance)])
-
- def call_accept_instance(self, node, instance, info, target):
- """Prepare a node to accept an instance.
-
- This is a single-node call.
-
- @type node: string
- @param node: the target node for the migration
- @type instance: C{objects.Instance}
- @param instance: the instance definition
- @type info: opaque/hypervisor specific (string/data)
- @param info: result for the call_migration_info call
- @type target: string
- @param target: target hostname (usually ip address) (on the node itself)
-
- """
- return self._SingleNodeCall(node, "accept_instance",
- [self._InstDict(instance), info, target])
-
- def call_finalize_migration(self, node, instance, info, success):
- """Finalize any target-node migration specific operation.
-
- This is called both in case of a successful migration and in case of error
- (in which case it should abort the migration).
-
- This is a single-node call.
-
- @type node: string
- @param node: the target node for the migration
- @type instance: C{objects.Instance}
- @param instance: the instance definition
- @type info: opaque/hypervisor specific (string/data)
- @param info: result for the call_migration_info call
- @type success: boolean
- @param success: whether the migration was a success or a failure
-
- """
- return self._SingleNodeCall(node, "finalize_migration",
- [self._InstDict(instance), info, success])
-
- def call_instance_migrate(self, node, instance, target, live):
- """Migrate an instance.
-
- This is a single-node call.
-
- @type node: string
- @param node: the node on which the instance is currently running
- @type instance: C{objects.Instance}
- @param instance: the instance definition
- @type target: string
- @param target: the target node name
- @type live: boolean
- @param live: whether the migration should be done live or not (the
- interpretation of this parameter is left to the hypervisor)
-
- """
- return self._SingleNodeCall(node, "instance_migrate",
- [self._InstDict(instance), target, live])
-
- def call_instance_reboot(self, node, instance, reboot_type):
- """Reboots an instance.
-
- This is a single-node call.
-
- """
- return self._SingleNodeCall(node, "instance_reboot",
- [self._InstDict(instance), reboot_type])
-
- def call_instance_os_add(self, node, inst, reinstall):
- """Installs an OS on the given instance.
-
- This is a single-node call.
-
- """
- return self._SingleNodeCall(node, "instance_os_add",
- [self._InstDict(inst), reinstall])
-
- def call_instance_run_rename(self, node, inst, old_name):
- """Run the OS rename script for an instance.
-
- This is a single-node call.
-
- """
- return self._SingleNodeCall(node, "instance_run_rename",
- [self._InstDict(inst), old_name])
-
- def call_instance_info(self, node, instance, hname):
- """Returns information about a single instance.
-
- This is a single-node call.
-
- @type node: list
- @param node: the list of nodes to query
- @type instance: string
- @param instance: the instance name
- @type hname: string
- @param hname: the hypervisor type of the instance
-
- """
- return self._SingleNodeCall(node, "instance_info", [instance, hname])
-
- def call_instance_migratable(self, node, instance):
- """Checks whether the given instance can be migrated.
-
- This is a single-node call.
-
- @param node: the node to query
- @type instance: L{objects.Instance}
- @param instance: the instance to check
-