Exemple #1
0
def ExportInstance(opts, args):
    """Export an instance to an image in the cluster.

  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the name
      of the instance to be exported
  @rtype: int
  @return: the desired exit code

  """
    ignore_remove_failures = opts.ignore_remove_failures

    if not opts.node:
        raise errors.OpPrereqError("Target node must be specified",
                                   errors.ECODE_INVAL)

    op = opcodes.OpBackupExport(
        instance_name=args[0],
        target_node=opts.node,
        compress=opts.transport_compression,
        shutdown=opts.shutdown,
        shutdown_timeout=opts.shutdown_timeout,
        remove_instance=opts.remove_instance,
        ignore_remove_failures=ignore_remove_failures,
        zero_free_space=opts.zero_free_space,
        zeroing_timeout_fixed=opts.zeroing_timeout_fixed,
        zeroing_timeout_per_mib=opts.zeroing_timeout_per_mib,
        long_sleep=opts.long_sleep)

    SubmitOrSend(op, opts)
    return 0
Exemple #2
0
 def testRemoveRunningInstanceWithoutShutdown(self):
     inst = self.cfg.AddNewInstance(admin_state=constants.ADMINST_UP)
     op = opcodes.OpBackupExport(instance_name=inst.name,
                                 target_node=self.master.name,
                                 shutdown=False,
                                 remove_instance=True)
     self.ExecOpCodeExpectOpPrereqError(
         op, "Can not remove instance without shutting it down before")
Exemple #3
0
    def setUp(self):
        super(TestLUBackupExportRemoteExport, self).setUp()

        self.inst = self.cfg.AddNewInstance()
        self.op = opcodes.OpBackupExport(mode=constants.EXPORT_MODE_REMOTE,
                                         instance_name=self.inst.name,
                                         target_node=[],
                                         x509_key_name=["mock_key_name"],
                                         destination_x509_ca="mock_dest_ca")
Exemple #4
0
    def setUp(self):
        # The initial instance prep
        super(TestLUBackupExportLocalExport, self).setUp()

        self.target_node = self.cfg.AddNewNode()
        self.op = opcodes.OpBackupExport(mode=constants.EXPORT_MODE_LOCAL,
                                         target_node=self.target_node.name)
        self._PrepareInstance()

        self.rpc.call_import_start.return_value = \
          self.RpcResultsBuilder() \
            .CreateSuccessfulNodeResult(self.target_node, "import_daemon")
Exemple #5
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()
Exemple #6
0
 def testUnsupportedDiskTemplate(self):
     inst = self.cfg.AddNewInstance(disk_template=constants.DT_FILE)
     op = opcodes.OpBackupExport(instance_name=inst.name,
                                 target_node=self.master.name)
     self.ExecOpCodeExpectOpPrereqError(
         op, "Export not supported for instances with file-based disks")