Example #1
0
 def BurnRemove(self):
     """Remove the instances."""
     Log("Removing instances")
     for instance in self.to_rem:
         Log("instance %s", instance, indent=1)
         op = opcodes.OpInstanceRemove(instance_name=instance,
                                       ignore_failures=True)
         self.ExecOrQueue(instance, [op])
Example #2
0
    def BurnImportExport(self):
        """Export the instance, delete it, and import it back.

    """
        Log("Exporting and re-importing instances")
        mytor = izip(cycle(self.nodes), islice(cycle(self.nodes), 1, None),
                     islice(cycle(self.nodes), 2, None), self.instances)

        qcl = GetClient(query=True)
        for pnode, snode, enode, instance in mytor:
            Log("instance %s", instance, indent=1)
            # read the full name of the instance
            ((full_name, ), ) = qcl.QueryInstances([instance], ["name"], False)

            if self.opts.iallocator:
                pnode = snode = None
                import_log_msg = ("import from %s"
                                  " with iallocator %s" %
                                  (enode, self.opts.iallocator))
            elif self.opts.disk_template not in constants.DTS_INT_MIRROR:
                snode = None
                import_log_msg = ("import from %s to %s" % (enode, pnode))
            else:
                import_log_msg = ("import from %s to %s, %s" %
                                  (enode, pnode, snode))

            exp_op = opcodes.OpBackupExport(instance_name=instance,
                                            target_node=enode,
                                            mode=constants.EXPORT_MODE_LOCAL,
                                            shutdown=True)
            rem_op = opcodes.OpInstanceRemove(instance_name=instance,
                                              ignore_failures=True)
            imp_dir = utils.PathJoin(pathutils.EXPORT_DIR, full_name)
            imp_op = opcodes.OpInstanceCreate(
                instance_name=instance,
                disks=[{
                    "size": size
                } for size in self.disk_size],
                disk_template=self.opts.disk_template,
                nics=self.opts.nics,
                mode=constants.INSTANCE_IMPORT,
                src_node=enode,
                src_path=imp_dir,
                pnode=pnode,
                snode=snode,
                start=True,
                ip_check=self.opts.ip_check,
                name_check=self.opts.name_check,
                wait_for_sync=True,
                file_storage_dir=None,
                file_driver="loop",
                iallocator=self.opts.iallocator,
                beparams=self.bep,
                hvparams=self.hvp,
                osparams=self.opts.osparams,
            )

            erem_op = opcodes.OpBackupRemove(instance_name=instance)

            Log("export to node %s", enode, indent=2)
            Log("remove instance", indent=2)
            Log(import_log_msg, indent=2)
            Log("remove export", indent=2)
            self.ExecOrQueue(instance, [exp_op, rem_op, imp_op, erem_op])
        qcl.Close()