コード例 #1
0
    def setUp(self):
        super(TestLUTestAllocator, self).setUp()

        self.base_op = opcodes.OpTestAllocator(
            name="new-instance.example.com",
            nics=[],
            disks=[],
            disk_template=constants.DT_DISKLESS,
            direction=constants.IALLOCATOR_DIR_OUT,
            iallocator="test")

        self.valid_alloc_op = \
          self.CopyOpCode(self.base_op,
                          mode=constants.IALLOCATOR_MODE_ALLOC,
                          memory=0,
                          disk_template=constants.DT_DISKLESS,
                          os="mock_os",
                          group_name="default",
                          vcpus=1)
        self.valid_multi_alloc_op = \
          self.CopyOpCode(self.base_op,
                          mode=constants.IALLOCATOR_MODE_MULTI_ALLOC,
                          instances=["new-instance.example.com"],
                          memory=0,
                          disk_template=constants.DT_DISKLESS,
                          os="mock_os",
                          group_name="default",
                          vcpus=1)
        self.valid_reloc_op = \
          self.CopyOpCode(self.base_op,
                          mode=constants.IALLOCATOR_MODE_RELOC)
        self.valid_chg_group_op = \
          self.CopyOpCode(self.base_op,
                          mode=constants.IALLOCATOR_MODE_CHG_GROUP,
                          instances=["new-instance.example.com"],
                          target_groups=["default"])
        self.valid_node_evac_op = \
          self.CopyOpCode(self.base_op,
                          mode=constants.IALLOCATOR_MODE_NODE_EVAC,
                          instances=["new-instance.example.com"],
                          evac_mode=constants.NODE_EVAC_PRI)

        self.iallocator_cls.return_value.in_text = "mock in text"
        self.iallocator_cls.return_value.out_text = "mock out text"
コード例 #2
0
ファイル: gnt_debug.py プロジェクト: vladimir-ipatov/ganeti-1
    opts.tags = []
  else:
    opts.tags = opts.tags.split(",")
  if opts.target_groups is None:
    target_groups = []
  else:
    target_groups = opts.target_groups

  op = opcodes.OpTestAllocator(mode=opts.mode,
                               name=args[0],
                               instances=args,
                               memory=opts.memory,
                               disks=disks,
                               disk_template=opts.disk_template,
                               nics=nic_dict,
                               os=opts.os,
                               vcpus=opts.vcpus,
                               tags=opts.tags,
                               direction=opts.direction,
                               iallocator=opts.iallocator,
                               evac_mode=opts.evac_mode,
                               target_groups=target_groups,
                               spindle_use=opts.spindle_use,
                               count=opts.count)
  result = SubmitOpCode(op, opts=opts)
  ToStdout("%s" % result)
  return 0


def _TestJobDependency(opts):
  """Tests job dependencies.
コード例 #3
0
def TestAllocator(opts, args):
    """Runs the test allocator opcode.

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

  """
    try:
        disks = [{
            constants.IDISK_SIZE: utils.ParseUnit(val),
            constants.IDISK_MODE: constants.DISK_RDWR,
        } for val in opts.disks.split(",")]
    except errors.UnitParseError as err:
        ToStderr("Invalid disks parameter '%s': %s", opts.disks, err)
        return 1

    nics = [val.split("/") for val in opts.nics.split(",")]
    for row in nics:
        while len(row) < 3:
            row.append(None)
        for i in range(3):
            if row[i] == "":
                row[i] = None
    nic_dict = [
        {
            constants.INIC_MAC: v[0],
            constants.INIC_IP: v[1],
            # The iallocator interface defines a "bridge" item
            "bridge": v[2],
        } for v in nics
    ]

    if opts.tags is None:
        opts.tags = []
    else:
        opts.tags = opts.tags.split(",")
    if opts.target_groups is None:
        target_groups = []
    else:
        target_groups = opts.target_groups

    op = opcodes.OpTestAllocator(mode=opts.mode,
                                 name=args[0],
                                 instances=args,
                                 memory=opts.memory,
                                 disks=disks,
                                 disk_template=opts.disk_template,
                                 nics=nic_dict,
                                 os=opts.os,
                                 vcpus=opts.vcpus,
                                 tags=opts.tags,
                                 direction=opts.direction,
                                 iallocator=opts.iallocator,
                                 evac_mode=opts.evac_mode,
                                 target_groups=target_groups,
                                 spindle_use=opts.spindle_use,
                                 count=opts.count)
    result = SubmitOpCode(op, opts=opts)
    ToStdout("%s" % result)
    return 0