Commit bf44a602 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

gtools: Make eventd send instance's disks

Extend snf-ganeti-eventd to send the disks of the instance when needed,
exactly like it is doing for the NICs of the instance.
parent 82476a1e
......@@ -99,41 +99,55 @@ def get_time_from_status(op, job):
raise InvalidBackendStatus(status, job)
def get_instance_nics(instance, logger):
"""Query Ganeti to a get the instance's NICs.
def get_instance_attachments(instance, logger):
"""Query Ganeti to a get the instance's attachments (NICs and Disks)
Get instance's NICs from Ganeti configuration data. If running on master,
query Ganeti via Ganeti CLI client. Otherwise, get the nics from Ganeti
configuration file.
Get instance's attachments from Ganeti configuration data. If running on
master, query Ganeti via Ganeti CLI client. Otherwise, get attachments
straight from Ganeti's configuration file.
@type instance: string
@param instance: the name of the instance
@rtype: List of dicts
@return: Dictionary containing the instance's NICs. Each dictionary
contains the following keys: 'network', 'ip', 'mac', 'mode',
'link' and 'firewall'
@rtype: instance's NICs and Disks
@return: Dictionary containing the 'nics' and 'disks' of the instance.
"""
try:
client = cli.GetClient()
fields = ["nic.names", "nic.networks.names", "nic.ips", "nic.macs",
"nic.modes", "nic.links", "tags"]
info = client.QueryInstances([instance], fields, use_locking=False)
names, networks, ips, macs, modes, links, tags = info[0]
nic_keys = ["name", "network", "ip", "mac", "mode", "link"]
nics = zip(names, networks, ips, macs, modes, links)
q_fields = ["nic.names", "nic.networks.names", "nic.ips", "nic.macs",
"nic.modes", "nic.links", "nic.uuids", "tags",
"disk.names", "disk.sizes", "disk.uuids"]
info = client.QueryInstances([instance], q_fields, use_locking=False)
# Parse NICs
names, networks, ips, macs, modes, links, uuids, tags = info[0][:-3]
nic_keys = ["name", "network", "ip", "mac", "mode", "link", "uuid"]
nics = zip(names, networks, ips, macs, modes, links, uuids)
nics = map(lambda x: dict(zip(nic_keys, x)), nics)
# Parse Disks
names, sizes, uuids = info[0][-3:]
disk_keys = ["name", "size", "uuid"]
disks = zip(names, sizes, uuids)
disks = map(lambda x: dict(zip(disk_keys, x)), disks)
except ganeti_errors.OpPrereqError:
# Not running on master! Load the conf file
raw_data = utils.ReadFile(pathutils.CLUSTER_CONF_FILE)
config = serializer.LoadJson(raw_data)
i = config["instances"][instance]
# Parse NICs
nics = []
for nic in i["nics"]:
for index, nic in enumerate(i["nics"]):
params = nic.pop("nicparams")
nic["mode"] = params["mode"]
nic["link"] = params["link"]
nic["index"] = index
nics.append(nic)
# Parse Disks
disks = []
for index, disk in enumerate(i["disks"]):
disks.append({"name": disk.pop("name"),
"size": disk["size"],
"uuid": disk["uuid"],
"index": index})
tags = i.get("tags", [])
# Get firewall from instance Tags
# Tags are of the form synnefo:network:N:firewall_mode
......@@ -147,7 +161,9 @@ def get_instance_nics(instance, logger):
firewall = t[3]
[nic.setdefault("firewall", firewall)
for nic in nics if nic["name"] == nic_name]
return nics
attachments = {"nics": nics,
"disks": disks}
return attachments
class InvalidBackendStatus(Exception):
......@@ -299,8 +315,10 @@ class JobFileHandler(pyinotify.ProcessEvent):
op.status == "success") or
(op_id == "OP_INSTANCE_SET_PARAMS" and
op.status in ["success", "error", "cancelled"])):
nics = get_instance_nics(msg["instance"], self.logger)
msg["instance_nics"] = nics
attachments = get_instance_attachments(msg["instance"],
self.logger)
msg["instance_nics"] = attachments["nics"]
msg["instance_disks"] = attachments["disks"]
routekey = "ganeti.%s.event.op" % prefix_from_name(instances)
......
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