Revision 47aaeaff lib/opcodes.py
b/lib/opcodes.py | ||
---|---|---|
1548 | 1548 |
""" |
1549 | 1549 |
TestNicModifications = _TestInstSetParamsModList(_TestNicDef) |
1550 | 1550 |
TestDiskModifications = _TestInstSetParamsModList(_TDiskParams) |
1551 |
TestExtDiskModifications = _TestInstSetParamsModList(_TExtDiskParams) |
|
1551 | 1552 |
|
1552 | 1553 |
OP_DSC_FIELD = "instance_name" |
1553 | 1554 |
OP_PARAMS = [ |
... | ... | |
1581 | 1582 |
("wait_for_sync", True, ht.TBool, |
1582 | 1583 |
"Whether to wait for the disk to synchronize, when changing template"), |
1583 | 1584 |
("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"), |
1585 |
("allow_arbit_params", None, ht.TMaybeBool, |
|
1586 |
"Whether to allow the passing of arbitrary parameters to --disk(s)"), |
|
1584 | 1587 |
] |
1585 | 1588 |
OP_RESULT = _TSetParamsResult |
1586 | 1589 |
|
1590 |
def Validate(self, set_defaults): |
|
1591 |
"""Validate opcode parameters, optionally setting default values. |
|
1592 |
|
|
1593 |
@type set_defaults: bool |
|
1594 |
@param set_defaults: Whether to set default values |
|
1595 |
@raise errors.OpPrereqError: When a parameter value doesn't match |
|
1596 |
requirements |
|
1597 |
|
|
1598 |
""" |
|
1599 |
# Check if the template is DT_EXT |
|
1600 |
allow_arbitrary_params = False |
|
1601 |
for (attr_name, _, _, _) in self.GetAllParams(): |
|
1602 |
if hasattr(self, attr_name): |
|
1603 |
if attr_name == "allow_arbit_params" and \ |
|
1604 |
getattr(self, attr_name) == True: |
|
1605 |
allow_arbitrary_params = True |
|
1606 |
|
|
1607 |
for (attr_name, default, test, _) in self.GetAllParams(): |
|
1608 |
assert test == ht.NoType or callable(test) |
|
1609 |
|
|
1610 |
if not hasattr(self, attr_name): |
|
1611 |
if default == ht.NoDefault: |
|
1612 |
raise errors.OpPrereqError("Required parameter '%s.%s' missing" % |
|
1613 |
(self.OP_ID, attr_name), |
|
1614 |
errors.ECODE_INVAL) |
|
1615 |
elif set_defaults: |
|
1616 |
if callable(default): |
|
1617 |
dval = default() |
|
1618 |
else: |
|
1619 |
dval = default |
|
1620 |
setattr(self, attr_name, dval) |
|
1621 |
|
|
1622 |
# If `allow_arbit_params' is set, use the ExtStorage's test method for disks |
|
1623 |
if allow_arbitrary_params and attr_name == "disks": |
|
1624 |
test = OpInstanceSetParams.TestExtDiskModifications |
|
1625 |
|
|
1626 |
if test == ht.NoType: |
|
1627 |
# no tests here |
|
1628 |
continue |
|
1629 |
|
|
1630 |
if set_defaults or hasattr(self, attr_name): |
|
1631 |
attr_val = getattr(self, attr_name) |
|
1632 |
if not test(attr_val): |
|
1633 |
logging.error("OpCode %s, parameter %s, has invalid type %s/value %s", |
|
1634 |
self.OP_ID, attr_name, type(attr_val), attr_val) |
|
1635 |
raise errors.OpPrereqError("Parameter '%s.%s' fails validation" % |
|
1636 |
(self.OP_ID, attr_name), |
|
1637 |
errors.ECODE_INVAL) |
|
1638 |
|
|
1587 | 1639 |
|
1588 | 1640 |
class OpInstanceGrowDisk(OpCode): |
1589 | 1641 |
"""Grow a disk of an instance.""" |
Also available in: Unified diff