예제 #1
0
    def testElemOf(self):
        fn = ht.TElemOf(range(10))
        self.assertTrue(fn(0))
        self.assertTrue(fn(3))
        self.assertTrue(fn(9))
        self.assertFalse(fn(-1))
        self.assertFalse(fn(100))

        fn = ht.TElemOf([])
        self.assertFalse(fn(0))
        self.assertFalse(fn(100))
        self.assertFalse(fn(True))

        fn = ht.TElemOf(["Hello", "World"])
        self.assertTrue(fn("Hello"))
        self.assertTrue(fn("World"))
        self.assertFalse(fn("e"))
예제 #2
0
class _OpTestVerifyErrors(opcodes.OpCode):
  OP_PARAMS = [
    ("debug_simulate_errors", False, ht.TBool, ""),
    ("error_codes", False, ht.TBool, ""),
    ("ignore_errors",
     [],
     ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
     "")
    ]
예제 #3
0
def BuildJobDepCheck(relative):
    """Builds check for job dependencies (L{DEPEND_ATTR}).

  @type relative: bool
  @param relative: Whether to accept relative job IDs (negative)
  @rtype: callable

  """
    if relative:
        job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
    else:
        job_id = ht.TJobId

    job_dep = \
      ht.TAnd(ht.TOr(ht.TListOf(ht.TAny), ht.TTuple),
              ht.TIsLength(2),
              ht.TItems([job_id,
                         ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))

    return ht.TMaybe(ht.TListOf(job_dep))
예제 #4
0
from ganeti import errors
from ganeti import utils
from ganeti import ht
from ganeti import ssh
from ganeti import pathutils
from ganeti.tools import common

_DATA_CHECK = ht.TStrictDict(
    False, True, {
        constants.SSHS_CLUSTER_NAME:
        ht.TNonEmptyString,
        constants.SSHS_NODE_DAEMON_CERTIFICATE:
        ht.TNonEmptyString,
        constants.SSHS_SSH_PUBLIC_KEYS:
        ht.TItems([
            ht.TElemOf(constants.SSHS_ACTIONS),
            ht.TDictOf(ht.TNonEmptyString, ht.TListOf(ht.TNonEmptyString))
        ]),
        constants.SSHS_SSH_AUTHORIZED_KEYS:
        ht.TItems([
            ht.TElemOf(constants.SSHS_ACTIONS),
            ht.TDictOf(ht.TNonEmptyString, ht.TListOf(ht.TNonEmptyString))
        ]),
        constants.SSHS_GENERATE:
        ht.TDictOf(ht.TNonEmptyString, ht.TString),
    })


class SshUpdateError(errors.GenericError):
    """Local class for reporting errors.
예제 #5
0
import ganeti.rpc.node as rpc
import ganeti.masterd.instance as gmi

_STRING_LIST = ht.TListOf(ht.TString)
_JOB_LIST = ht.TListOf(
    ht.TListOf(
        ht.TStrictDict(
            True,
            False,
            {
                # pylint: disable=E1101
                # Class '...' has no 'OP_ID' member
                "OP_ID":
                ht.TElemOf([
                    opcodes.OpInstanceFailover.OP_ID,
                    opcodes.OpInstanceMigrate.OP_ID,
                    opcodes.OpInstanceReplaceDisks.OP_ID
                ]),
            })))

_NEVAC_MOVED = \
  ht.TListOf(ht.TAnd(ht.TIsLength(3),
                     ht.TItems([ht.TNonEmptyString,
                                ht.TNonEmptyString,
                                ht.TListOf(ht.TNonEmptyString),
                                ])))
_NEVAC_FAILED = \
  ht.TListOf(ht.TAnd(ht.TIsLength(2),
                     ht.TItems([ht.TNonEmptyString,
                                ht.TMaybeString,
                                ])))
예제 #6
0
import logging

from ganeti import cli
from ganeti import constants
from ganeti import errors
from ganeti import pathutils
from ganeti import utils
from ganeti import ht
from ganeti import ssh
from ganeti.tools import common


_SSH_KEY_LIST_ITEM = \
  ht.TAnd(ht.TIsLength(3),
          ht.TItems([
            ht.TElemOf(constants.SSHK_ALL),
            ht.Comment("public")(ht.TNonEmptyString),
            ht.Comment("private")(ht.TNonEmptyString),
          ]))

_SSH_KEY_LIST = ht.TListOf(_SSH_KEY_LIST_ITEM)

_DATA_CHECK = ht.TStrictDict(
    False, True, {
        constants.SSHS_CLUSTER_NAME:
        ht.TNonEmptyString,
        constants.SSHS_NODE_DAEMON_CERTIFICATE:
        ht.TNonEmptyString,
        constants.SSHS_SSH_HOST_KEY:
        _SSH_KEY_LIST,
        constants.SSHS_SSH_ROOT_KEY: