Commit 2dd5390e authored by Christos Stavrakakis's avatar Christos Stavrakakis Committed by Helga Velroyen
Browse files

Support UUIDs and names when handling NICs/Disks



Handle UUID and name fields when creating/managing NICs and Disks. Also,
export NICs and Disks names to instance hooks environment.
Signed-off-by: default avatarChristos Stavrakakis <cstavr@grnet.gr>
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent ae860154
...@@ -1502,12 +1502,12 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, ...@@ -1502,12 +1502,12 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
@type vcpus: string @type vcpus: string
@param vcpus: the count of VCPUs the instance has @param vcpus: the count of VCPUs the instance has
@type nics: list @type nics: list
@param nics: list of tuples (ip, mac, mode, link, net, netinfo) representing @param nics: list of tuples (name, uuid, ip, mac, mode, link, net, netinfo)
the NICs the instance has representing the NICs the instance has
@type disk_template: string @type disk_template: string
@param disk_template: the disk template of the instance @param disk_template: the disk template of the instance
@type disks: list @type disks: list
@param disks: the list of (size, mode) pairs @param disks: list of tuples (name, uuid, size, mode)
@type bep: dict @type bep: dict
@param bep: the backend parameters for the instance @param bep: the backend parameters for the instance
@type hvp: dict @type hvp: dict
...@@ -1537,9 +1537,10 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, ...@@ -1537,9 +1537,10 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
} }
if nics: if nics:
nic_count = len(nics) nic_count = len(nics)
for idx, (ip, mac, mode, link, net, netinfo) in enumerate(nics): for idx, (name, _, ip, mac, mode, link, net, netinfo) in enumerate(nics):
if ip is None: if ip is None:
ip = "" ip = ""
env["INSTANCE_NIC%d_NAME" % idx] = name
env["INSTANCE_NIC%d_IP" % idx] = ip env["INSTANCE_NIC%d_IP" % idx] = ip
env["INSTANCE_NIC%d_MAC" % idx] = mac env["INSTANCE_NIC%d_MAC" % idx] = mac
env["INSTANCE_NIC%d_MODE" % idx] = mode env["INSTANCE_NIC%d_MODE" % idx] = mode
...@@ -1561,7 +1562,8 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, ...@@ -1561,7 +1562,8 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
   
if disks: if disks:
disk_count = len(disks) disk_count = len(disks)
for idx, (size, mode) in enumerate(disks): for idx, (name, size, mode) in enumerate(disks):
env["INSTANCE_DISK%d_NAME" % idx] = name
env["INSTANCE_DISK%d_SIZE" % idx] = size env["INSTANCE_DISK%d_SIZE" % idx] = size
env["INSTANCE_DISK%d_MODE" % idx] = mode env["INSTANCE_DISK%d_MODE" % idx] = mode
else: else:
...@@ -1598,7 +1600,7 @@ def _NICToTuple(lu, nic): ...@@ -1598,7 +1600,7 @@ def _NICToTuple(lu, nic):
if nic.network: if nic.network:
nobj = lu.cfg.GetNetwork(nic.network) nobj = lu.cfg.GetNetwork(nic.network)
netinfo = objects.Network.ToDict(nobj) netinfo = objects.Network.ToDict(nobj)
return (nic.ip, nic.mac, mode, link, nic.network, netinfo) return (nic.name, nic.uuid, nic.ip, nic.mac, mode, link, nic.network, netinfo)
   
   
def _NICListToTuple(lu, nics): def _NICListToTuple(lu, nics):
...@@ -1648,7 +1650,8 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None): ...@@ -1648,7 +1650,8 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None):
"vcpus": bep[constants.BE_VCPUS], "vcpus": bep[constants.BE_VCPUS],
"nics": _NICListToTuple(lu, instance.nics), "nics": _NICListToTuple(lu, instance.nics),
"disk_template": instance.disk_template, "disk_template": instance.disk_template,
"disks": [(disk.size, disk.mode) for disk in instance.disks], "disks": [(disk.name, disk.size, disk.mode)
for disk in instance.disks],
"bep": bep, "bep": bep,
"hvp": hvp, "hvp": hvp,
"hypervisor_name": instance.hypervisor, "hypervisor_name": instance.hypervisor,
...@@ -9456,16 +9459,19 @@ def _GenerateDRBD8Branch(lu, primary, secondary, size, vgnames, names, ...@@ -9456,16 +9459,19 @@ def _GenerateDRBD8Branch(lu, primary, secondary, size, vgnames, names,
dev_data = objects.Disk(dev_type=constants.LD_LV, size=size, dev_data = objects.Disk(dev_type=constants.LD_LV, size=size,
logical_id=(vgnames[0], names[0]), logical_id=(vgnames[0], names[0]),
params={}) params={})
dev_data.uuid = lu.cfg.GenerateUniqueID(lu.proc.GetECId())
dev_meta = objects.Disk(dev_type=constants.LD_LV, dev_meta = objects.Disk(dev_type=constants.LD_LV,
size=constants.DRBD_META_SIZE, size=constants.DRBD_META_SIZE,
logical_id=(vgnames[1], names[1]), logical_id=(vgnames[1], names[1]),
params={}) params={})
dev_meta.uuid = lu.cfg.GenerateUniqueID(lu.proc.GetECId())
drbd_dev = objects.Disk(dev_type=constants.LD_DRBD8, size=size, drbd_dev = objects.Disk(dev_type=constants.LD_DRBD8, size=size,
logical_id=(primary, secondary, port, logical_id=(primary, secondary, port,
p_minor, s_minor, p_minor, s_minor,
shared_secret), shared_secret),
children=[dev_data, dev_meta], children=[dev_data, dev_meta],
iv_name=iv_name, params={}) iv_name=iv_name, params={})
drbd_dev.uuid = lu.cfg.GenerateUniqueID(lu.proc.GetECId())
return drbd_dev return drbd_dev
   
   
...@@ -9527,6 +9533,7 @@ def _GenerateDiskTemplate( ...@@ -9527,6 +9533,7 @@ def _GenerateDiskTemplate(
"disk/%d" % disk_index, "disk/%d" % disk_index,
minors[idx * 2], minors[idx * 2 + 1]) minors[idx * 2], minors[idx * 2 + 1])
disk_dev.mode = disk[constants.IDISK_MODE] disk_dev.mode = disk[constants.IDISK_MODE]
disk_dev.name = disk.get(constants.IDISK_NAME, None)
disks.append(disk_dev) disks.append(disk_dev)
else: else:
if secondary_nodes: if secondary_nodes:
...@@ -9587,11 +9594,14 @@ def _GenerateDiskTemplate( ...@@ -9587,11 +9594,14 @@ def _GenerateDiskTemplate(
size = disk[constants.IDISK_SIZE] size = disk[constants.IDISK_SIZE]
feedback_fn("* disk %s, size %s" % feedback_fn("* disk %s, size %s" %
(disk_index, utils.FormatUnit(size, "h"))) (disk_index, utils.FormatUnit(size, "h")))
disks.append(objects.Disk(dev_type=dev_type, size=size, disk_dev = objects.Disk(dev_type=dev_type, size=size,
logical_id=logical_id_fn(idx, disk_index, disk), logical_id=logical_id_fn(idx, disk_index, disk),
iv_name="disk/%d" % disk_index, iv_name="disk/%d" % disk_index,
mode=disk[constants.IDISK_MODE], mode=disk[constants.IDISK_MODE],
params=params)) params=params)
disk_dev.name = disk.get(constants.IDISK_NAME, None)
disk_dev.uuid = lu.cfg.GenerateUniqueID(lu.proc.GetECId())
disks.append(disk_dev)
   
return disks return disks
   
...@@ -10044,8 +10054,11 @@ def _ComputeNics(op, cluster, default_ip, cfg, ec_id): ...@@ -10044,8 +10054,11 @@ def _ComputeNics(op, cluster, default_ip, cfg, ec_id):
check_params = cluster.SimpleFillNIC(nicparams) check_params = cluster.SimpleFillNIC(nicparams)
objects.NIC.CheckParameterSyntax(check_params) objects.NIC.CheckParameterSyntax(check_params)
net_uuid = cfg.LookupNetwork(net) net_uuid = cfg.LookupNetwork(net)
nics.append(objects.NIC(mac=mac, ip=nic_ip, name = nic.get(constants.INIC_NAME, None)
network=net_uuid, nicparams=nicparams)) nic_obj = objects.NIC(mac=mac, ip=nic_ip, name=name,
network=net_uuid, nicparams=nicparams)
nic_obj.uuid = cfg.GenerateUniqueID(ec_id)
nics.append(nic_obj)
   
return nics return nics
   
...@@ -10082,10 +10095,12 @@ def _ComputeDisks(op, default_vg): ...@@ -10082,10 +10095,12 @@ def _ComputeDisks(op, default_vg):
op.disk_template), errors.ECODE_INVAL) op.disk_template), errors.ECODE_INVAL)
   
data_vg = disk.get(constants.IDISK_VG, default_vg) data_vg = disk.get(constants.IDISK_VG, default_vg)
name = disk.get(constants.IDISK_NAME, None)
new_disk = { new_disk = {
constants.IDISK_SIZE: size, constants.IDISK_SIZE: size,
constants.IDISK_MODE: mode, constants.IDISK_MODE: mode,
constants.IDISK_VG: data_vg, constants.IDISK_VG: data_vg,
constants.IDISK_NAME: name,
} }
   
if constants.IDISK_METAVG in disk: if constants.IDISK_METAVG in disk:
...@@ -10440,8 +10455,8 @@ class LUInstanceCreate(LogicalUnit): ...@@ -10440,8 +10455,8 @@ class LUInstanceCreate(LogicalUnit):
vcpus=self.be_full[constants.BE_VCPUS], vcpus=self.be_full[constants.BE_VCPUS],
nics=_NICListToTuple(self, self.nics), nics=_NICListToTuple(self, self.nics),
disk_template=self.op.disk_template, disk_template=self.op.disk_template,
disks=[(d[constants.IDISK_SIZE], d[constants.IDISK_MODE]) disks=[(d[constants.IDISK_NAME], d[constants.IDISK_SIZE],
for d in self.disks], d[constants.IDISK_MODE]) for d in self.disks],
bep=self.be_full, bep=self.be_full,
hvp=self.hv_full, hvp=self.hv_full,
hypervisor_name=self.op.hypervisor, hypervisor_name=self.op.hypervisor,
...@@ -14028,7 +14043,8 @@ class LUInstanceSetParams(LogicalUnit): ...@@ -14028,7 +14043,8 @@ class LUInstanceSetParams(LogicalUnit):
   
# create a fake disk info for _GenerateDiskTemplate # create a fake disk info for _GenerateDiskTemplate
disk_info = [{constants.IDISK_SIZE: d.size, constants.IDISK_MODE: d.mode, disk_info = [{constants.IDISK_SIZE: d.size, constants.IDISK_MODE: d.mode,
constants.IDISK_VG: d.logical_id[0]} constants.IDISK_VG: d.logical_id[0],
constants.IDISK_NAME: d.name}
for d in instance.disks] for d in instance.disks]
new_disks = _GenerateDiskTemplate(self, self.op.disk_template, new_disks = _GenerateDiskTemplate(self, self.op.disk_template,
instance.name, pnode, [snode], instance.name, pnode, [snode],
...@@ -14097,10 +14113,11 @@ class LUInstanceSetParams(LogicalUnit): ...@@ -14097,10 +14113,11 @@ class LUInstanceSetParams(LogicalUnit):
old_disks = _AnnotateDiskParams(instance, instance.disks, self.cfg) old_disks = _AnnotateDiskParams(instance, instance.disks, self.cfg)
new_disks = [d.children[0] for d in instance.disks] new_disks = [d.children[0] for d in instance.disks]
   
# copy over size and mode # copy over size, mode and name
for parent, child in zip(old_disks, new_disks): for parent, child in zip(old_disks, new_disks):
child.size = parent.size child.size = parent.size
child.mode = parent.mode child.mode = parent.mode
child.name = parent.name
   
# this is a DRBD disk, return its port to the pool # this is a DRBD disk, return its port to the pool
# NOTE: this must be done right before the call to cfg.Update! # NOTE: this must be done right before the call to cfg.Update!
...@@ -14210,10 +14227,13 @@ class LUInstanceSetParams(LogicalUnit): ...@@ -14210,10 +14227,13 @@ class LUInstanceSetParams(LogicalUnit):
mac = params[constants.INIC_MAC] mac = params[constants.INIC_MAC]
ip = params.get(constants.INIC_IP, None) ip = params.get(constants.INIC_IP, None)
net = params.get(constants.INIC_NETWORK, None) net = params.get(constants.INIC_NETWORK, None)
name = params.get(constants.INIC_NAME, None)
net_uuid = self.cfg.LookupNetwork(net) net_uuid = self.cfg.LookupNetwork(net)
#TODO: not private.filled?? can a nic have no nicparams?? #TODO: not private.filled?? can a nic have no nicparams??
nicparams = private.filled nicparams = private.filled
nobj = objects.NIC(mac=mac, ip=ip, network=net_uuid, nicparams=nicparams) nobj = objects.NIC(mac=mac, ip=ip, network=net_uuid, name=name,
nicparams=nicparams)
nobj.uuid = self.cfg.GenerateUniqueID(self.proc.GetECId())
   
return (nobj, [ return (nobj, [
("nic.%d" % idx, ("nic.%d" % idx,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment