from ganeti import masterd
from ganeti import netutils
from ganeti import objects
-from ganeti import opcodes
from ganeti import pathutils
from ganeti import rpc
from ganeti import utils
net = nic.get(constants.INIC_NETWORK, None)
link = nic.get(constants.NIC_LINK, None)
ip = nic.get(constants.INIC_IP, None)
+ vlan = nic.get(constants.INIC_VLAN, None)
if net is None or net.lower() == constants.VALUE_NONE:
net = None
" is allowed to be passed",
errors.ECODE_INVAL)
+ if vlan is not None and nic_mode != constants.NIC_MODE_OVS:
+ raise errors.OpPrereqError("VLAN is given, but network mode is not"
+ " openvswitch", errors.ECODE_INVAL)
+
# ip validity checks
if ip is None or ip.lower() == constants.VALUE_NONE:
nic_ip = None
nicparams[constants.NIC_MODE] = nic_mode
if link:
nicparams[constants.NIC_LINK] = link
+ if vlan:
+ nicparams[constants.NIC_VLAN] = vlan
check_params = cluster.SimpleFillNIC(nicparams)
objects.NIC.CheckParameterSyntax(check_params)
self.adopt_disks = has_adopt
+ def _CheckVLANArguments(self):
+ """ Check validity of VLANs if given
+
+ """
+ for nic in self.op.nics:
+ vlan = nic.get(constants.INIC_VLAN, None)
+ if vlan:
+ if vlan[0] == ".":
+ # vlan starting with dot means single untagged vlan,
+ # might be followed by trunk (:)
+ if not vlan[1:].isdigit():
+ vlanlist = vlan[1:].split(':')
+ for vl in vlanlist:
+ if not vl.isdigit():
+ raise errors.OpPrereqError("Specified VLAN parameter is "
+ "invalid : %s" % vlan,
+ errors.ECODE_INVAL)
+ elif vlan[0] == ":":
+ # Trunk - tagged only
+ vlanlist = vlan[1:].split(':')
+ for vl in vlanlist:
+ if not vl.isdigit():
+ raise errors.OpPrereqError("Specified VLAN parameter is invalid"
+ " : %s" % vlan, errors.ECODE_INVAL)
+ elif vlan.isdigit():
+ # This is the simplest case. No dots, only single digit
+ # -> Create untagged access port, dot needs to be added
+ nic[constants.INIC_VLAN] = "." + vlan
+ else:
+ raise errors.OpPrereqError("Specified VLAN parameter is invalid"
+ " : %s" % vlan, errors.ECODE_INVAL)
+
def CheckArguments(self):
"""Check arguments.
# check that NIC's parameters names are unique and valid
utils.ValidateDeviceNames("NIC", self.op.nics)
+ self._CheckVLANArguments()
+
self._CheckDiskArguments()
+ assert self.op.disk_template is not None
# instance name verification
if self.op.name_check:
raise errors.OpPrereqError("Invalid file driver name '%s'" %
self.op.file_driver, errors.ECODE_INVAL)
+ # set default file_driver if unset and required
+ if (not self.op.file_driver and
+ self.op.disk_template in [constants.DT_FILE,
+ constants.DT_SHARED_FILE]):
+ self.op.file_driver = constants.FD_LOOP
+
### Node/iallocator related checks
CheckIAllocatorOrNode(self, "iallocator", "pnode")
_CheckOpportunisticLocking(self.op)
- self._cds = GetClusterDomainSecret()
-
if self.op.mode == constants.INSTANCE_IMPORT:
# On import force_variant must be True, because if we forced it at
# initial install, our only chance when importing it back is that it
raise errors.OpPrereqError("Guest OS '%s' is not allowed for"
" installation" % self.op.os_type,
errors.ECODE_STATE)
- if self.op.disk_template is None:
- raise errors.OpPrereqError("No disk template specified",
- errors.ECODE_INVAL)
-
elif self.op.mode == constants.INSTANCE_REMOTE_IMPORT:
+ self._cds = GetClusterDomainSecret()
+
# Check handshake to ensure both clusters have the same domain secret
src_handshake = self.op.source_handshake
if not src_handshake:
else:
node_name_whitelist = None
- #TODO Export network to iallocator so that it chooses a pnode
- # in a nodegroup that has the desired network connected to
req = _CreateInstanceAllocRequest(self.op, self.disks,
self.nics, self.be_full,
node_name_whitelist)
netparams = self.cfg.GetGroupNetParams(net_uuid, self.pnode.uuid)
if netparams is None:
raise errors.OpPrereqError("No netparams found for network"
- " %s. Propably not connected to"
+ " %s. Probably not connected to"
" node's %s nodegroup" %
(nobj.name, self.pnode.name),
errors.ECODE_INVAL)
for t_dsk, a_dsk in zip(tmp_disks, self.disks):
rename_to.append(t_dsk.logical_id)
t_dsk.logical_id = (t_dsk.logical_id[0], a_dsk[constants.IDISK_ADOPT])
- self.cfg.SetDiskID(t_dsk, self.pnode.uuid)
result = self.rpc.call_blockdev_rename(self.pnode.uuid,
zip(tmp_disks, rename_to))
result.Raise("Failed to rename adoped LVs")
ReleaseLocks(self, locking.LEVEL_NODE_RES)
if iobj.disk_template != constants.DT_DISKLESS and not self.adopt_disks:
- # we need to set the disks ID to the primary node, since the
- # preceding code might or might have not done it, depending on
- # disk template and other options
- for disk in iobj.disks:
- self.cfg.SetDiskID(disk, self.pnode.uuid)
if self.op.mode == constants.INSTANCE_CREATE:
if not self.op.no_install:
pause_sync = (iobj.disk_template in constants.DTS_INT_MIRROR and
dt = masterd.instance.DiskTransfer("disk/%s" % idx,
constants.IEIO_FILE, (image, ),
constants.IEIO_SCRIPT,
- (iobj.disks[idx], idx),
+ ((iobj.disks[idx], iobj), idx),
None)
transfers.append(dt)
info = GetInstanceInfoText(renamed_inst)
for (idx, disk) in enumerate(renamed_inst.disks):
for node_uuid in renamed_inst.all_nodes:
- self.cfg.SetDiskID(disk, node_uuid)
- result = self.rpc.call_blockdev_setinfo(node_uuid, disk, info)
+ result = self.rpc.call_blockdev_setinfo(node_uuid,
+ (disk, renamed_inst), info)
result.Warn("Error setting info on node %s for disk %s" %
(self.cfg.GetNodeName(node_uuid), idx), self.LogWarning)
try:
bep = self.cfg.GetClusterInfo().FillBE(self.instance)
for idx, dsk in enumerate(self.instance.disks):
- if dsk.dev_type not in (constants.LD_LV, constants.LD_FILE):
+ if dsk.dev_type not in (constants.DT_PLAIN, constants.DT_FILE,
+ constants.DT_SHARED_FILE):
raise errors.OpPrereqError("Instance disk %d has a complex layout,"
" cannot copy" % idx, errors.ECODE_STATE)
for inst in self.op.instances:
(inst.pnode_uuid, inst.pnode) = \
ExpandNodeUuidAndName(self.cfg, inst.pnode_uuid, inst.pnode)
- nodeslist.append(inst.pnode)
+ nodeslist.append(inst.pnode_uuid)
if inst.snode is not None:
(inst.snode_uuid, inst.snode) = \
ExpandNodeUuidAndName(self.cfg, inst.snode_uuid, inst.snode)
- nodeslist.append(inst.snode)
+ nodeslist.append(inst.snode_uuid)
self.needed_locks[locking.LEVEL_NODE] = nodeslist
# Lock resources of instance's primary and secondary nodes (copy to
failed_insts = []
return {
- opcodes.OpInstanceMultiAlloc.ALLOCATABLE_KEY: allocatable_insts,
- opcodes.OpInstanceMultiAlloc.FAILED_KEY: failed_insts,
+ constants.ALLOCATABLE_KEY: allocatable_insts,
+ constants.FAILED_KEY: failed_insts,
}
def Exec(self, feedback_fn):
def _ApplyContainerMods(kind, container, chgdesc, mods,
- create_fn, modify_fn, remove_fn):
+ create_fn, modify_fn, remove_fn,
+ post_add_fn=None):
"""Applies descriptions in C{mods} to C{container}.
@type kind: string
@type remove_fn: callable
@param remove_fn: Callback on removing item; receives absolute item index,
item and private data object as added by L{_PrepareContainerMods}
+ @type post_add_fn: callable
+ @param post_add_fn: Callable for post-processing a newly created item after
+ it has been put into the container. It receives the index of the new item
+ and the new item as parameters.
"""
for (op, identifier, params, private) in mods:
assert idx <= len(container)
# list.insert does so before the specified index
container.insert(idx, item)
+
+ if post_add_fn is not None:
+ post_add_fn(addidx, item)
+
else:
# Retrieve existing item
(absidx, item) = GetItemFromContainer(identifier, kind, container)
if size is None:
raise errors.OpPrereqError("Required disk parameter '%s' missing" %
constants.IDISK_SIZE, errors.ECODE_INVAL)
-
- try:
- size = int(size)
- except (TypeError, ValueError), err:
- raise errors.OpPrereqError("Invalid disk size parameter: %s" % err,
- errors.ECODE_INVAL)
+ size = int(size)
params[constants.IDISK_SIZE] = size
name = params.get(constants.IDISK_NAME, None)
def CheckArguments(self):
if not (self.op.nics or self.op.disks or self.op.disk_template or
self.op.hvparams or self.op.beparams or self.op.os_name or
- self.op.offline is not None or self.op.runtime_mem or
- self.op.pnode):
+ self.op.osparams or self.op.offline is not None or
+ self.op.runtime_mem or self.op.pnode):
raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
if self.op.hvparams:
"hypervisor", "instance", "cluster")
self.op.disks = self._UpgradeDiskNicMods(
- "disk", self.op.disks, opcodes.OpInstanceSetParams.TestDiskModifications)
+ "disk", self.op.disks, ht.TSetParamsMods(ht.TIDiskParams))
self.op.nics = self._UpgradeDiskNicMods(
- "NIC", self.op.nics, opcodes.OpInstanceSetParams.TestNicModifications)
+ "NIC", self.op.nics, ht.TSetParamsMods(ht.TINicParams))
if self.op.disks and self.op.disk_template is not None:
raise errors.OpPrereqError("Disk template conversion and other disk"
self.instance.disk_template,
errors.ECODE_INVAL)
- if not self.cluster.IsDiskTemplateEnabled(self.instance.disk_template):
+ if not self.cluster.IsDiskTemplateEnabled(self.op.disk_template):
raise errors.OpPrereqError("Disk template '%s' is not enabled for this"
- " cluster." % self.instance.disk_template)
+ " cluster." % self.op.disk_template)
if (self.instance.disk_template,
self.op.disk_template) not in self._DISK_CONVERSIONS:
constants.DT_EXT),
errors.ECODE_INVAL)
+ if not self.op.wait_for_sync and self.instance.disks_active:
+ for mod in self.diskmod:
+ if mod[0] == constants.DDM_ADD:
+ raise errors.OpPrereqError("Can't add a disk to an instance with"
+ " activated disks and"
+ " --no-wait-for-sync given.",
+ errors.ECODE_INVAL)
+
if self.op.disks and self.instance.disk_template == constants.DT_DISKLESS:
raise errors.OpPrereqError("Disk operations not supported for"
" diskless instances", errors.ECODE_INVAL)
self.instance.uuid, pnode_uuid,
[snode_uuid], disk_info, None, None, 0,
feedback_fn, self.diskparams)
- anno_disks = rpc.AnnotateDiskParams(constants.DT_DRBD8, new_disks,
- self.diskparams)
+ anno_disks = rpc.AnnotateDiskParams(new_disks, self.diskparams)
p_excl_stor = IsExclusiveStorageEnabledNodeUuid(self.cfg, pnode_uuid)
s_excl_stor = IsExclusiveStorageEnabledNodeUuid(self.cfg, snode_uuid)
info = GetInstanceInfoText(self.instance)
except errors.GenericError, e:
feedback_fn("Initializing of DRBD devices failed;"
" renaming back original volumes...")
- for disk in new_disks:
- self.cfg.SetDiskID(disk, pnode_uuid)
rename_back_list = [(n.children[0], o.logical_id)
for (n, o) in zip(new_disks, self.instance.disks)]
result = self.rpc.call_blockdev_rename(pnode_uuid, rename_back_list)
feedback_fn("Removing volumes on the secondary node...")
for disk in old_disks:
- self.cfg.SetDiskID(disk, snode_uuid)
- msg = self.rpc.call_blockdev_remove(snode_uuid, disk).fail_msg
- if msg:
- self.LogWarning("Could not remove block device %s on node %s,"
- " continuing anyway: %s", disk.iv_name,
- self.cfg.GetNodeName(snode_uuid), msg)
+ result = self.rpc.call_blockdev_remove(snode_uuid, (disk, self.instance))
+ result.Warn("Could not remove block device %s on node %s,"
+ " continuing anyway" %
+ (disk.iv_name, self.cfg.GetNodeName(snode_uuid)),
+ self.LogWarning)
feedback_fn("Removing unneeded volumes on the primary node...")
for idx, disk in enumerate(old_disks):
meta = disk.children[1]
- self.cfg.SetDiskID(meta, pnode_uuid)
- msg = self.rpc.call_blockdev_remove(pnode_uuid, meta).fail_msg
- if msg:
- self.LogWarning("Could not remove metadata for disk %d on node %s,"
- " continuing anyway: %s", idx,
- self.cfg.GetNodeName(pnode_uuid), msg)
+ result = self.rpc.call_blockdev_remove(pnode_uuid, (meta, self.instance))
+ result.Warn("Could not remove metadata for disk %d on node %s,"
+ " continuing anyway" %
+ (idx, self.cfg.GetNodeName(pnode_uuid)),
+ self.LogWarning)
def _CreateNewDisk(self, idx, params, _):
"""Creates a new disk.
("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)),
])
+ def _PostAddDisk(self, _, disk):
+ if not WaitForSync(self, self.instance, disks=[disk],
+ oneshot=not self.op.wait_for_sync):
+ raise errors.OpExecError("Failed to sync disks of %s" %
+ self.instance.name)
+
+ # the disk is active at this point, so deactivate it if the instance disks
+ # are supposed to be inactive
+ if not self.instance.disks_active:
+ ShutdownInstanceDisks(self, self.instance, disks=[disk])
+
@staticmethod
def _ModifyDisk(idx, disk, params, _):
"""Modifies a disk.
(anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg)
for node_uuid, disk in anno_disk.ComputeNodeTree(
self.instance.primary_node):
- self.cfg.SetDiskID(disk, node_uuid)
- msg = self.rpc.call_blockdev_remove(node_uuid, disk).fail_msg
+ msg = self.rpc.call_blockdev_remove(node_uuid, (disk, self.instance)) \
+ .fail_msg
if msg:
self.LogWarning("Could not remove disk/%d on node '%s': %s,"
" continuing anyway", idx,
# Apply disk changes
_ApplyContainerMods("disk", self.instance.disks, result, self.diskmod,
self._CreateNewDisk, self._ModifyDisk,
- self._RemoveDisk)
+ self._RemoveDisk, post_add_fn=self._PostAddDisk)
_UpdateIvNames(0, self.instance.disks)
if self.op.disk_template: