+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def Reinstall(self):
+ """Reinstall the instances."""
+ Log("Reinstalling instances")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ self.StopInstance(instance)
+ op = opcodes.OpReinstallInstance(instance_name=instance)
+ Log("reinstall without passing the OS", indent=2)
+ self.ExecOp(op)
+ op = opcodes.OpReinstallInstance(instance_name=instance,
+ os_type=self.opts.os)
+ Log("reinstall specifying the OS", indent=2)
+ self.ExecOp(op)
+ self.StartInstance(instance)
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def Reboot(self):
+ """Reboot the instances."""
+ Log("Rebooting instances")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ 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)
+ self.ExecOp(op)
+ self._CheckInstanceAlive(instance)
+
+ def ActivateDisks(self):
+ """Activate and deactivate disks of the instances."""
+ Log("Activating/deactivating disks")
+ for instance in self.instances:
+ Log("instance %s" % instance, indent=1)
+ op_act = opcodes.OpActivateInstanceDisks(instance_name=instance)
+ op_deact = opcodes.OpDeactivateInstanceDisks(instance_name=instance)
+ Log("activate disks when online", indent=2)
+ self.ExecOp(op_act)
+ self.StopInstance(instance)
+ Log("activate disks when offline", indent=2)
+ self.ExecOp(op_act)
+ Log("deactivate disks (when offline)", indent=2)
+ self.ExecOp(op_deact)
+ self.StartInstance(instance)
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def AddRemoveDisks(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, {})])
+ Log("adding a disk", indent=2)
+ self.ExecOp(op_add)
+ self.StopInstance(instance)
+ Log("removing last disk", indent=2)
+ self.ExecOp(op_rem)
+ self.StartInstance(instance)
+ for instance in self.instances:
+ self._CheckInstanceAlive(instance)
+
+ def AddRemoveNICs(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)
+ self.ExecOp(op_add)
+ Log("removing last NIC", indent=2)
+ self.ExecOp(op_rem)
+
+ 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
+ try:
+ for retries in range(self.opts.net_timeout):
+ try:
+ url = urllib2.urlopen("http://%s/hostname.txt" % instance)
+ except urllib2.URLError, err:
+ if err.args[0][0] == errno.ECONNREFUSED:
+ time.sleep(1)
+ continue
+ raise
+ except urllib2.URLError, err:
+ raise InstanceDown(instance, str(err))
+ hostname = url.read().strip()
+ if hostname != instance:
+ raise InstanceDown(instance, ("Hostname mismatch, expected %s, got %s" %
+ (instance, hostname)))
+