+ Log("reboot with type '%s'" % reboot_type, indent=2)
+ ops.append(op)
+ self.ExecOrQueue(instance, *ops)
+
+ @_DoCheckInstances
+ @_DoBatch(True)
+ 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)
+
+ @_DoCheckInstances
+ @_DoBatch(False)
+ 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)
+
+ @_DoBatch(False)
+ 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)
+
+ 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)))