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