コード例 #1
0
 def testStrictDict(self):
   fn = ht.TStrictDict(False, False, { "a": ht.TInt, })
   self.assertTrue(fn({}))
   self.assertFalse(fn({"a": ""}))
   self.assertTrue(fn({"a": 11}))
   self.assertTrue(fn({"other": 11}))
   self.assertTrue(fn({"other": object()}))
コード例 #2
0
  def testStrictDictRequireAllExclusive(self):
    fn = ht.TStrictDict(True, True, { "a": ht.TInt, })
    self.assertFalse(fn(1))
    self.assertFalse(fn(None))
    self.assertFalse(fn({}))
    self.assertFalse(fn({"a": "Hello", }))
    self.assertFalse(fn({"unknown": 999,}))
    self.assertFalse(fn({"unknown": None,}))

    self.assertTrue(fn({"a": 123, }))
    self.assertTrue(fn({"a": -5, }))

    fn = ht.TStrictDict(True, True, { "a": ht.TInt, "x": ht.TString, })
    self.assertFalse(fn({}))
    self.assertFalse(fn({"a": -5, }))
    self.assertTrue(fn({"a": 123, "x": "", }))
    self.assertFalse(fn({"a": 123, "x": None, }))
コード例 #3
0
  def testStrictDictExclusive(self):
    fn = ht.TStrictDict(False, True, { "a": ht.TInt, "b": ht.TList, })
    self.assertTrue(fn({}))
    self.assertTrue(fn({"a": 123, }))
    self.assertTrue(fn({"b": range(4), }))
    self.assertFalse(fn({"b": 123, }))

    self.assertFalse(fn({"foo": {}, }))
    self.assertFalse(fn({"bar": object(), }))
コード例 #4
0
 def testStrictDictRequireAll(self):
     fn = ht.TStrictDict(True, False, {
         "a": ht.TInt,
         "m": ht.TInt,
     })
     self.assertTrue(fn({
         "a": 1,
         "m": 2,
         "bar": object(),
     }))
     self.assertFalse(fn({}))
     self.assertFalse(fn({
         "a": 1,
         "bar": object(),
     }))
     self.assertFalse(fn({
         "a": 1,
         "m": [],
         "bar": object(),
     }))
コード例 #5
0
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.

  """
コード例 #6
0
            ht.TSshKeyType,
            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:
        _SSH_KEY_LIST,
        constants.SSHS_SSH_AUTHORIZED_KEYS:
        ht.TDictOf(ht.TNonEmptyString, ht.TListOf(ht.TNonEmptyString)),
        constants.SSHS_SSH_KEY_TYPE:
        ht.TSshKeyType,
        constants.SSHS_SSH_KEY_BITS:
        ht.TPositive,
    })


class JoinError(errors.GenericError):
    """Local class for reporting errors.

  """
コード例 #7
0
_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.TItems([
            ht.TSshKeyType,  # The type of key to generate
            ht.TPositive,  # The number of bits in the key
            ht.TString
        ]),  # The suffix
        constants.SSHS_SSH_KEY_TYPE:
        ht.TSshKeyType,
        constants.SSHS_SSH_KEY_BITS:
        ht.TPositive,
    })
コード例 #8
0
ファイル: iallocator.py プロジェクト: sajalcody/ganeti
from ganeti import serializer
from ganeti import utils

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),
コード例 #9
0
from cStringIO import StringIO

from ganeti import cli
from ganeti import constants
from ganeti import errors
from ganeti import pathutils
from ganeti import utils
from ganeti import serializer
from ganeti import runtime
from ganeti import ht
from ganeti import ssconf

_DATA_CHECK = ht.TStrictDict(
    False, True, {
        constants.NDS_CLUSTER_NAME: ht.TNonEmptyString,
        constants.NDS_NODE_DAEMON_CERTIFICATE: ht.TNonEmptyString,
        constants.NDS_SSCONF: ht.TDictOf(ht.TNonEmptyString, ht.TString),
        constants.NDS_START_NODE_DAEMON: ht.TBool,
    })


class SetupError(errors.GenericError):
    """Local class for reporting errors.

  """


def ParseOptions():
    """Parses the options passed to the program.

  @return: Options and arguments
コード例 #10
0
import optparse
import sys
import logging

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

_DATA_CHECK = ht.TStrictDict(
    False, True, {
        constants.NDS_CLUSTER_NAME: ht.TNonEmptyString,
        constants.NDS_NODE_DAEMON_CERTIFICATE: ht.TNonEmptyString,
        constants.NDS_NODE_NAME: ht.TNonEmptyString,
        constants.NDS_ACTION: ht.TNonEmptyString,
    })


class SslSetupError(errors.GenericError):
    """Local class for reporting errors.

  """


def ParseOptions():
    """Parses the options passed to the program.

  @return: Options and arguments
コード例 #11
0

_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: _SSH_KEY_LIST,
    })


class JoinError(errors.GenericError):
    """Local class for reporting errors.

  """


def ParseOptions():
    """Parses the options passed to the program.

  @return: Options and arguments