Revision 703fa9ab lib/cli.py
b/lib/cli.py | ||
---|---|---|
43 | 43 |
from ganeti import compat |
44 | 44 |
from ganeti import netutils |
45 | 45 |
from ganeti import qlang |
46 |
from ganeti import objects |
|
46 | 47 |
|
47 | 48 |
from optparse import (OptionParser, TitledHelpFormatter, |
48 | 49 |
Option, OptionValueError) |
... | ... | |
201 | 202 |
"INSTANCE_POLICY_OPTS", |
202 | 203 |
# Generic functions for CLI programs |
203 | 204 |
"ConfirmOperation", |
205 |
"CreateIPolicyFromOpts", |
|
204 | 206 |
"GenericMain", |
205 | 207 |
"GenericInstanceCreate", |
206 | 208 |
"GenericList", |
... | ... | |
285 | 287 |
_CHOOSE_BATCH = 25 |
286 | 288 |
|
287 | 289 |
|
290 |
# constants used to create InstancePolicy dictionary |
|
291 |
TISPECS_GROUP_TYPES = { |
|
292 |
constants.ISPECS_MIN: constants.VTYPE_INT, |
|
293 |
constants.ISPECS_MAX: constants.VTYPE_INT, |
|
294 |
} |
|
295 |
|
|
296 |
TISPECS_CLUSTER_TYPES = { |
|
297 |
constants.ISPECS_MIN: constants.VTYPE_INT, |
|
298 |
constants.ISPECS_MAX: constants.VTYPE_INT, |
|
299 |
constants.ISPECS_STD: constants.VTYPE_INT, |
|
300 |
} |
|
301 |
|
|
302 |
|
|
288 | 303 |
class _Argument: |
289 | 304 |
def __init__(self, min=0, max=None): # pylint: disable=W0622 |
290 | 305 |
self.min = min |
... | ... | |
3393 | 3408 |
choices.pop(1) |
3394 | 3409 |
choice = AskUser(msg + affected, choices) |
3395 | 3410 |
return choice |
3411 |
|
|
3412 |
|
|
3413 |
def CreateIPolicyFromOpts(ispecs_mem_size=None, |
|
3414 |
ispecs_cpu_count=None, |
|
3415 |
ispecs_disk_count=None, |
|
3416 |
ispecs_disk_size=None, |
|
3417 |
ispecs_nic_count=None, |
|
3418 |
ipolicy_disk_templates=None, |
|
3419 |
ipolicy_vcpu_ratio=None, |
|
3420 |
group_ipolicy=False, |
|
3421 |
allowed_values=None, |
|
3422 |
fill_all=False): |
|
3423 |
"""Creation of instance policy based on command line options. |
|
3424 |
|
|
3425 |
@param fill_all: whether for cluster policies we should ensure that |
|
3426 |
all values are filled |
|
3427 |
|
|
3428 |
|
|
3429 |
""" |
|
3430 |
# prepare ipolicy dict |
|
3431 |
ipolicy_transposed = { |
|
3432 |
constants.ISPEC_MEM_SIZE: ispecs_mem_size, |
|
3433 |
constants.ISPEC_CPU_COUNT: ispecs_cpu_count, |
|
3434 |
constants.ISPEC_DISK_COUNT: ispecs_disk_count, |
|
3435 |
constants.ISPEC_DISK_SIZE: ispecs_disk_size, |
|
3436 |
constants.ISPEC_NIC_COUNT: ispecs_nic_count, |
|
3437 |
} |
|
3438 |
|
|
3439 |
# first, check that the values given are correct |
|
3440 |
if group_ipolicy: |
|
3441 |
forced_type = TISPECS_GROUP_TYPES |
|
3442 |
else: |
|
3443 |
forced_type = TISPECS_CLUSTER_TYPES |
|
3444 |
|
|
3445 |
for specs in ipolicy_transposed.values(): |
|
3446 |
utils.ForceDictType(specs, forced_type, allowed_values=allowed_values) |
|
3447 |
|
|
3448 |
# then transpose |
|
3449 |
ipolicy_out = objects.MakeEmptyIPolicy() |
|
3450 |
for name, specs in ipolicy_transposed.iteritems(): |
|
3451 |
assert name in constants.ISPECS_PARAMETERS |
|
3452 |
for key, val in specs.items(): # {min: .. ,max: .., std: ..} |
|
3453 |
ipolicy_out[key][name] = val |
|
3454 |
|
|
3455 |
# no filldict for non-dicts |
|
3456 |
if not group_ipolicy and fill_all: |
|
3457 |
if ipolicy_disk_templates is None: |
|
3458 |
ipolicy_disk_templates = constants.DISK_TEMPLATES |
|
3459 |
if ipolicy_vcpu_ratio is None: |
|
3460 |
ipolicy_vcpu_ratio = \ |
|
3461 |
constants.IPOLICY_DEFAULTS[constants.IPOLICY_VCPU_RATIO] |
|
3462 |
if ipolicy_disk_templates is not None: |
|
3463 |
ipolicy_out[constants.IPOLICY_DTS] = list(ipolicy_disk_templates) |
|
3464 |
if ipolicy_vcpu_ratio is not None: |
|
3465 |
ipolicy_out[constants.IPOLICY_VCPU_RATIO] = ipolicy_vcpu_ratio |
|
3466 |
|
|
3467 |
assert not (frozenset(ipolicy_out.keys()) - constants.IPOLICY_ALL_KEYS) |
|
3468 |
|
|
3469 |
return ipolicy_out |
Also available in: Unified diff