+ Log("instance %s" % instance, indent=1)
+ op_stop1 = self.StopInstanceOp(instance)
+ op_stop2 = self.StopInstanceOp(rename)
+ op_rename1 = self.RenameInstanceOp(instance, rename)
+ op_rename2 = self.RenameInstanceOp(rename, instance)
+ op_start1 = self.StartInstanceOp(rename)
+ op_start2 = self.StartInstanceOp(instance)
+ self.ExecOp(op_stop1, op_rename1, op_start1)
+ self._CheckInstanceAlive(rename)
+ self.ExecOp(op_stop2, op_rename2, op_start2)
+ self._CheckInstanceAlive(instance)
+
+ def BurnReinstall(self):
+ """Reinstall the instances."""
+ Log("Reinstalling instances")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ op1 = self.StopInstanceOp(instance)
+ op2 = opcodes.OpReinstallInstance(instance_name=instance)
+ Log("reinstall without passing the OS", indent=2)
+ op3 = opcodes.OpReinstallInstance(instance_name=instance,
+ os_type=self.opts.os)
+ Log("reinstall specifying the OS", indent=2)
+ op4 = self.StartInstanceOp(instance)
+ self.ExecOrQueue(instance, op1, op2, op3, op4)
+
+ self.CommitQueue()
+
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def BurnReboot(self):
+ """Reboot the instances."""
+ Log("Rebooting instances")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ ops = []
+ for reboot_type in constants.REBOOT_TYPES:
+ op = opcodes.OpRebootInstance(instance_name=instance,
+ reboot_type=reboot_type,
+ ignore_secondaries=False)
+ Log("reboot with type '%s'" % reboot_type, indent=2)
+ ops.append(op)
+ self.ExecOrQueue(instance, *ops)
+
+ self.CommitQueue()
+
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def BurnActivateDisks(self):
+ """Activate and deactivate disks of the instances."""
+ Log("Activating/deactivating disks")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ op_start = self.StartInstanceOp(instance)
+ op_act = opcodes.OpActivateInstanceDisks(instance_name=instance)
+ op_deact = opcodes.OpDeactivateInstanceDisks(instance_name=instance)
+ op_stop = self.StopInstanceOp(instance)
+ Log("activate disks when online", indent=2)
+ Log("activate disks when offline", indent=2)
+ Log("deactivate disks (when offline)", indent=2)
+ self.ExecOrQueue(instance, op_act, op_stop, op_act, op_deact, op_start)
+ self.CommitQueue()
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def BurnAddRemoveDisks(self):
+ """Add and remove an extra disk for the instances."""
+ Log("Adding and removing disks")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ op_add = opcodes.OpSetInstanceParams(\
+ instance_name=instance,
+ disks=[(constants.DDM_ADD, {"size": self.disk_size[0]})])
+ op_rem = opcodes.OpSetInstanceParams(\
+ instance_name=instance, disks=[(constants.DDM_REMOVE, {})])
+ op_stop = self.StopInstanceOp(instance)
+ op_start = self.StartInstanceOp(instance)
+ Log("adding a disk", indent=2)
+ Log("removing last disk", indent=2)
+ self.ExecOrQueue(instance, op_add, op_stop, op_rem, op_start)
+ self.CommitQueue()
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def BurnAddRemoveNICs(self):
+ """Add and remove an extra NIC for the instances."""
+ Log("Adding and removing NICs")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ op_add = opcodes.OpSetInstanceParams(\
+ instance_name=instance, nics=[(constants.DDM_ADD, {})])
+ op_rem = opcodes.OpSetInstanceParams(\
+ instance_name=instance, nics=[(constants.DDM_REMOVE, {})])
+ Log("adding a NIC", indent=2)
+ Log("removing last NIC", indent=2)
+ self.ExecOrQueue(instance, op_add, op_rem)
+ self.CommitQueue()
+
+ def _CheckInstanceAlive(self, instance):
+ """Check if an instance is alive by doing http checks.
+
+ This will try to retrieve the url on the instance /hostname.txt
+ and check that it contains the hostname of the instance. In case
+ we get ECONNREFUSED, we retry up to the net timeout seconds, for
+ any other error we abort.
+
+ """
+ if not self.opts.http_check:
+ return
+ end_time = time.time() + self.opts.net_timeout
+ url = None
+ while time.time() < end_time and url is None:
+ try:
+ url = self.url_opener.open("http://%s/hostname.txt" % instance)
+ except IOError:
+ # here we can have connection refused, no route to host, etc.
+ time.sleep(1)
+ if url is None:
+ raise InstanceDown(instance, "Cannot contact instance")
+ hostname = url.read().strip()
+ url.close()
+ if hostname != instance:
+ raise InstanceDown(instance, ("Hostname mismatch, expected %s, got %s" %
+ (instance, hostname)))