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

cyclades: Fix small issues with snapshots

* fix IndexError in snf-ganeti-event when processing an
  OP_INSTANCE_SNAPSHOT operation without defining --disk option.
* fix TypeError in snf-dispatcher when processing an
  OP_INSTANCE_SNAPSHOT without snapshot information.

Both issues are caused by using directly the 'gnt-instance snaspshot'
command.
parent cb12d703
......@@ -117,16 +117,18 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
"""
# See #1492, #1031, #1111 why this line has been removed
#if (opcode not in [x[0] for x in VirtualMachine.BACKEND_OPCODES] or
# if (opcode not in [x[0] for x in VirtualMachine.BACKEND_OPCODES] or
if status not in [x[0] for x in BACKEND_STATUSES]:
raise VirtualMachine.InvalidBackendMsgError(opcode, status)
if opcode == "OP_INSTANCE_SNAPSHOT":
for disk_id, disk_info in job_fields.get("disks", []):
snap_info = json.loads(disk_info["snapshot_info"])
snap_id = snap_info["snapshot_id"]
update_snapshot(snap_id, user_id=vm.userid, job_id=jobid,
job_status=status, etime=etime)
snap_info = disk_info.get("snasphot_info", None)
if snap_info is not None:
snap_info = json.loads(snap_info)
snap_id = snap_info["snapshot_id"]
update_snapshot(snap_id, user_id=vm.userid, job_id=jobid,
job_status=status, etime=etime)
return
vm.backendjobid = jobid
......
......@@ -306,14 +306,16 @@ class JobFileHandler(pyinotify.ProcessEvent):
"disks": get_field(input, "disks"),
"beparams": get_field(input, "beparams")}
elif op_id == "OP_INSTANCE_SNAPSHOT":
job_fields = {"disks": get_field(input, "disks")}
reason = get_field(input, "reason")
snapshot_info = None
if isinstance(reason, list) and len(reason) > 0:
reason = reason[0]
if reason[0] == "gnt:user":
snapshot_info = reason[1]
job_fields["disks"][0][1]["snapshot_info"] = snapshot_info
disks = get_field(input, "disks")
if disks:
reason = get_field(input, "reason")
snapshot_info = None
if isinstance(reason, list) and len(reason) > 0:
reason = reason[0]
if reason[0] == "gnt:user":
snapshot_info = reason[1]
disks[0][1]["snapshot_info"] = snapshot_info
job_fields = {"disks": disks}
msg = {"type": "ganeti-op-status",
"instance": 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