Revision 6785674e lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
3153 | 3153 |
HTYPE = constants.HTYPE_INSTANCE |
3154 | 3154 |
_OP_REQP = ["instance_name", "mem_size", "disk_size", |
3155 | 3155 |
"disk_template", "swap_size", "mode", "start", "vcpus", |
3156 |
"wait_for_sync", "ip_check", "mac"] |
|
3156 |
"wait_for_sync", "ip_check", "mac", "hvparams"]
|
|
3157 | 3157 |
REQ_BGL = False |
3158 | 3158 |
|
3159 | 3159 |
def _ExpandNode(self, node): |
... | ... | |
3174 | 3174 |
self.needed_locks = {} |
3175 | 3175 |
|
3176 | 3176 |
# set optional parameters to none if they don't exist |
3177 |
for attr in ["kernel_path", "initrd_path", "pnode", "snode", |
|
3178 |
"iallocator", "hvm_boot_order", "hvm_acpi", "hvm_pae", |
|
3179 |
"hvm_cdrom_image_path", "hvm_nic_type", "hvm_disk_type", |
|
3180 |
"vnc_bind_address", "hypervisor"]: |
|
3177 |
for attr in ["pnode", "snode", "iallocator", "hypervisor"]: |
|
3181 | 3178 |
if not hasattr(self.op, attr): |
3182 | 3179 |
setattr(self.op, attr, None) |
3183 | 3180 |
|
... | ... | |
3202 | 3199 |
" cluster (%s)" % (self.op.hypervisor, |
3203 | 3200 |
",".join(enabled_hvs))) |
3204 | 3201 |
|
3202 |
# check hypervisor parameter syntax (locally) |
|
3203 |
|
|
3204 |
hv_type = hypervisor.GetHypervisor(self.op.hypervisor) |
|
3205 |
hv_type.CheckParameterSyntax(self.op.hvparams) |
|
3206 |
|
|
3205 | 3207 |
#### instance parameters check |
3206 | 3208 |
|
3207 | 3209 |
# instance name verification |
... | ... | |
3237 | 3239 |
raise errors.OpPrereqError("invalid MAC address specified: %s" % |
3238 | 3240 |
self.op.mac) |
3239 | 3241 |
|
3240 |
# boot order verification |
|
3241 |
if self.op.hvm_boot_order is not None: |
|
3242 |
if len(self.op.hvm_boot_order.strip("acdn")) != 0: |
|
3243 |
raise errors.OpPrereqError("invalid boot order specified," |
|
3244 |
" must be one or more of [acdn]") |
|
3245 | 3242 |
# file storage checks |
3246 | 3243 |
if (self.op.file_driver and |
3247 | 3244 |
not self.op.file_driver in constants.FILE_DRIVER): |
... | ... | |
3435 | 3432 |
" the primary node.") |
3436 | 3433 |
self.secondaries.append(self.op.snode) |
3437 | 3434 |
|
3435 |
nodenames = [pnode.name] + self.secondaries |
|
3436 |
|
|
3438 | 3437 |
req_size = _ComputeDiskSize(self.op.disk_template, |
3439 | 3438 |
self.op.disk_size, self.op.swap_size) |
3440 | 3439 |
|
3441 | 3440 |
# Check lv size requirements |
3442 | 3441 |
if req_size is not None: |
3443 |
nodenames = [pnode.name] + self.secondaries |
|
3444 | 3442 |
nodeinfo = self.rpc.call_node_info(nodenames, self.cfg.GetVGName(), |
3445 | 3443 |
self.op.hypervisor) |
3446 | 3444 |
for node in nodenames: |
... | ... | |
3457 | 3455 |
" %d MB available, %d MB required" % |
3458 | 3456 |
(node, info['vg_free'], req_size)) |
3459 | 3457 |
|
3458 |
# hypervisor parameter validation |
|
3459 |
hvinfo = self.rpc.call_hypervisor_validate_params(nodenames, |
|
3460 |
self.op.hypervisor, |
|
3461 |
self.op.hvparams) |
|
3462 |
for node in nodenames: |
|
3463 |
info = hvinfo.get(node, None) |
|
3464 |
if not info or not isinstance(info, (tuple, list)): |
|
3465 |
raise errors.OpPrereqError("Cannot get current information" |
|
3466 |
" from node '%s' (%s)" % (node, info)) |
|
3467 |
if not info[0]: |
|
3468 |
raise errors.OpPrereqError("Hypervisor parameter validation failed:" |
|
3469 |
" %s" % info[1]) |
|
3470 |
|
|
3460 | 3471 |
# os verification |
3461 | 3472 |
os_obj = self.rpc.call_os_get(pnode.name, self.op.os_type) |
3462 | 3473 |
if not os_obj: |
3463 | 3474 |
raise errors.OpPrereqError("OS '%s' not in supported os list for" |
3464 | 3475 |
" primary node" % self.op.os_type) |
3465 | 3476 |
|
3466 |
if self.op.kernel_path == constants.VALUE_NONE: |
|
3467 |
raise errors.OpPrereqError("Can't set instance kernel to none") |
|
3468 |
|
|
3469 | 3477 |
# bridge check on primary node |
3470 | 3478 |
if not self.rpc.call_bridges_exist(self.pnode.name, [self.op.bridge]): |
3471 | 3479 |
raise errors.OpPrereqError("target bridge '%s' does not exist on" |
... | ... | |
3478 | 3486 |
"creating instance %s" % self.op.instance_name, |
3479 | 3487 |
self.op.mem_size, self.op.hypervisor) |
3480 | 3488 |
|
3481 |
# hvm_cdrom_image_path verification |
|
3482 |
if self.op.hvm_cdrom_image_path is not None: |
|
3483 |
# FIXME (als): shouldn't these checks happen on the destination node? |
|
3484 |
if not os.path.isabs(self.op.hvm_cdrom_image_path): |
|
3485 |
raise errors.OpPrereqError("The path to the HVM CDROM image must" |
|
3486 |
" be an absolute path or None, not %s" % |
|
3487 |
self.op.hvm_cdrom_image_path) |
|
3488 |
if not os.path.isfile(self.op.hvm_cdrom_image_path): |
|
3489 |
raise errors.OpPrereqError("The HVM CDROM image must either be a" |
|
3490 |
" regular file or a symlink pointing to" |
|
3491 |
" an existing regular file, not %s" % |
|
3492 |
self.op.hvm_cdrom_image_path) |
|
3493 |
|
|
3494 |
# vnc_bind_address verification |
|
3495 |
if self.op.vnc_bind_address is not None: |
|
3496 |
if not utils.IsValidIP(self.op.vnc_bind_address): |
|
3497 |
raise errors.OpPrereqError("given VNC bind address '%s' doesn't look" |
|
3498 |
" like a valid IP address" % |
|
3499 |
self.op.vnc_bind_address) |
|
3500 |
|
|
3501 |
# Xen HVM device type checks |
|
3502 |
if self.op.hypervisor == constants.HT_XEN_HVM: |
|
3503 |
if self.op.hvm_nic_type not in constants.HT_HVM_VALID_NIC_TYPES: |
|
3504 |
raise errors.OpPrereqError("Invalid NIC type %s specified for Xen HVM" |
|
3505 |
" hypervisor" % self.op.hvm_nic_type) |
|
3506 |
if self.op.hvm_disk_type not in constants.HT_HVM_VALID_DISK_TYPES: |
|
3507 |
raise errors.OpPrereqError("Invalid disk type %s specified for Xen HVM" |
|
3508 |
" hypervisor" % self.op.hvm_disk_type) |
|
3509 |
|
|
3510 | 3489 |
if self.op.start: |
3511 | 3490 |
self.instance_status = 'up' |
3512 | 3491 |
else: |
... | ... | |
3534 | 3513 |
else: |
3535 | 3514 |
network_port = None |
3536 | 3515 |
|
3537 |
if self.op.vnc_bind_address is None: |
|
3538 |
self.op.vnc_bind_address = constants.VNC_DEFAULT_BIND_ADDRESS |
|
3516 |
##if self.op.vnc_bind_address is None:
|
|
3517 |
## self.op.vnc_bind_address = constants.VNC_DEFAULT_BIND_ADDRESS
|
|
3539 | 3518 |
|
3540 | 3519 |
# this is needed because os.path.join does not accept None arguments |
3541 | 3520 |
if self.op.file_storage_dir is None: |
... | ... | |
3565 | 3544 |
disk_template=self.op.disk_template, |
3566 | 3545 |
status=self.instance_status, |
3567 | 3546 |
network_port=network_port, |
3568 |
kernel_path=self.op.kernel_path, |
|
3569 |
initrd_path=self.op.initrd_path, |
|
3570 |
hvm_boot_order=self.op.hvm_boot_order, |
|
3571 |
hvm_acpi=self.op.hvm_acpi, |
|
3572 |
hvm_pae=self.op.hvm_pae, |
|
3573 |
hvm_cdrom_image_path=self.op.hvm_cdrom_image_path, |
|
3574 |
vnc_bind_address=self.op.vnc_bind_address, |
|
3575 |
hvm_nic_type=self.op.hvm_nic_type, |
|
3576 |
hvm_disk_type=self.op.hvm_disk_type, |
|
3547 |
hvparams=self.op.hvparams, |
|
3577 | 3548 |
hypervisor=self.op.hypervisor, |
3578 | 3549 |
) |
3579 | 3550 |
|
Also available in: Unified diff