Revision 697f49d5

b/lib/ht.py
178 178
#: a strictly positive integer
179 179
TStrictPositiveInt = TAnd(TInt, lambda v: v > 0)
180 180

  
181
#: Number
182
TNumber = TOr(TInt, TFloat)
183

  
181 184

  
182 185
def TListOf(my_type):
183 186
  """Checks if a given value is a list with all elements of the same type.
b/lib/opcodes.py
1206 1206
  """
1207 1207
  OP_DSC_FIELD = "duration"
1208 1208
  OP_PARAMS = [
1209
    ("duration", ht.NoDefault, ht.TFloat),
1209
    ("duration", ht.NoDefault, ht.TNumber),
1210 1210
    ("on_master", True, ht.TBool),
1211 1211
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1212 1212
    ("repeat", 0, ht.TPositiveInt)
b/lib/query.py
101 101
  QFT_BOOL: ht.TBool,
102 102
  QFT_NUMBER: ht.TInt,
103 103
  QFT_UNIT: ht.TInt,
104
  QFT_TIMESTAMP: ht.TOr(ht.TInt, ht.TFloat),
104
  QFT_TIMESTAMP: ht.TNumber,
105 105
  QFT_OTHER: lambda _: True,
106 106
  }
107 107

  
b/test/ganeti.ht_unittest.py
53 53
  def testInt(self):
54 54
    for val in [-100, -3, 0, 16, 128, 923874]:
55 55
      self.assertTrue(ht.TInt(val))
56
      self.assertTrue(ht.TNumber(val))
56 57

  
57 58
    for val in [False, True, None, "", [], "Hello", 0.0, 0.23, -3818.163]:
58 59
      self.assertFalse(ht.TInt(val))
......
76 77
  def testFloat(self):
77 78
    for val in [-100.21, -3.0, 0.0, 16.12, 128.3433, 923874.928]:
78 79
      self.assertTrue(ht.TFloat(val))
80
      self.assertTrue(ht.TNumber(val))
79 81

  
80 82
    for val in [False, True, None, "", [], "Hello", 0, 28, -1, -3281]:
81 83
      self.assertFalse(ht.TFloat(val))
82 84

  
85
  def testNumber(self):
86
    for val in [-100, -3, 0, 16, 128, 923874,
87
                -100.21, -3.0, 0.0, 16.12, 128.3433, 923874.928]:
88
      self.assertTrue(ht.TNumber(val))
89

  
90
    for val in [False, True, None, "", [], "Hello", "1"]:
91
      self.assertFalse(ht.TNumber(val))
92

  
83 93
  def testString(self):
84 94
    for val in ["", "abc", "Hello World", "123",
85 95
                u"", u"\u272C", u"abc"]:

Also available in: Unified diff