Revision 8c9ee749 lib/opcodes.py
b/lib/opcodes.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
import logging |
37 | 37 |
import re |
38 |
import operator |
|
38 | 39 |
|
39 | 40 |
from ganeti import constants |
40 | 41 |
from ganeti import errors |
... | ... | |
81 | 82 |
#: OP_ID conversion regular expression |
82 | 83 |
_OPID_RE = re.compile("([a-z])([A-Z])") |
83 | 84 |
|
85 |
#: Utility function for L{OpClusterSetParams} |
|
86 |
_TestClusterOsList = ht.TOr(ht.TNone, |
|
87 |
ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2), |
|
88 |
ht.TMap(ht.WithDesc("GetFirstItem")(operator.itemgetter(0)), |
|
89 |
ht.TElemOf(constants.DDMS_VALUES))))) |
|
90 |
|
|
84 | 91 |
|
85 | 92 |
def _NameToId(name): |
86 | 93 |
"""Convert an opcode class name to an OP_ID. |
... | ... | |
117 | 124 |
errors.ECODE_INVAL) |
118 | 125 |
|
119 | 126 |
|
120 |
def _CheckDiskTemplate(template): |
|
121 |
"""Ensure a given disk template is valid. |
|
127 |
@ht.WithDesc("CheckFileStorage") |
|
128 |
def _CheckFileStorage(value): |
|
129 |
"""Ensures file storage is enabled if used. |
|
122 | 130 |
|
123 | 131 |
""" |
124 |
if template not in constants.DISK_TEMPLATES: |
|
125 |
# Using str.join directly to avoid importing utils for CommaJoin |
|
126 |
msg = ("Invalid disk template name '%s', valid templates are: %s" % |
|
127 |
(template, ", ".join(constants.DISK_TEMPLATES))) |
|
128 |
raise errors.OpPrereqError(msg, errors.ECODE_INVAL) |
|
129 |
if template == constants.DT_FILE: |
|
132 |
if value == constants.DT_FILE: |
|
130 | 133 |
RequireFileStorage() |
131 | 134 |
return True |
132 | 135 |
|
133 | 136 |
|
137 |
_CheckDiskTemplate = ht.TAnd(ht.TElemOf(constants.DISK_TEMPLATES), |
|
138 |
_CheckFileStorage) |
|
139 |
|
|
140 |
|
|
134 | 141 |
def _CheckStorageType(storage_type): |
135 | 142 |
"""Ensure a given storage type is valid. |
136 | 143 |
|
... | ... | |
539 | 546 |
("default_iallocator", None, ht.TOr(ht.TString, ht.TNone)), |
540 | 547 |
("master_netdev", None, ht.TOr(ht.TString, ht.TNone)), |
541 | 548 |
("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone)), |
542 |
("hidden_os", None, ht.TOr(ht.TListOf( |
|
543 |
ht.TAnd(ht.TList, |
|
544 |
ht.TIsLength(2), |
|
545 |
ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))), |
|
546 |
ht.TNone)), |
|
547 |
("blacklisted_os", None, ht.TOr(ht.TListOf( |
|
548 |
ht.TAnd(ht.TList, |
|
549 |
ht.TIsLength(2), |
|
550 |
ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))), |
|
551 |
ht.TNone)), |
|
549 |
("hidden_os", None, _TestClusterOsList), |
|
550 |
("blacklisted_os", None, _TestClusterOsList), |
|
552 | 551 |
] |
553 | 552 |
|
554 | 553 |
|
Also available in: Unified diff