commit e6fbada10cb3616447d402c433cfefda563a8405
Author: Christos Stavrakakis <cstavr@grnet.gr>
Date:   Wed Jul 3 17:54:53 2013 +0300

    gtools: Make eventd send job fields
    
    Make snf-ganeti-eventd send 'job_fields' for instance and network
    opcodes, and modify the corresponding backend functions and
    snf-dispatcher callbacks.

diff --git a/snf-cyclades-app/synnefo/logic/backend.py b/snf-cyclades-app/synnefo/logic/backend.py
index 87865ca..5fb6167 100644
--- a/snf-cyclades-app/synnefo/logic/backend.py
+++ b/snf-cyclades-app/synnefo/logic/backend.py
@@ -115,7 +115,7 @@ def handle_vm_quotas(vm, job_id, job_opcode, job_status, job_fields):
 
 @transaction.commit_on_success
 def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
-                      beparams=None):
+                      job_fields=None):
     """Process a job progress notification from the backend
 
     Process an incoming message from the backend (currently Ganeti).
@@ -137,12 +137,15 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
         vm.save()
         return
 
+    if job_fields is None:
+        job_fields = {}
     state_for_success = VirtualMachine.OPER_STATE_FROM_OPCODE.get(opcode)
 
     # Notifications of success change the operating state
     if status == "success":
         if state_for_success is not None:
             vm.operstate = state_for_success
+        beparams = job_fields.get("beparams", None)
         if beparams:
             # Change the flavor of the VM
             _process_resize(vm, beparams)
@@ -180,9 +183,9 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
 
     if status in ["success", "error", "canceled"]:
         # Job is finalized: Handle quotas/commissioning
-        job_fields = {"nics": nics, "beparams": beparams}
+        fields = {"nics": nics, "beparams": beparams}
         vm = handle_vm_quotas(vm, job_id=jobid, job_opcode=opcode,
-                              job_status=status, job_fields=job_fields)
+                              job_status=status, job_fields=fields)
         # and clear task fields
         if vm.task_job_id == jobid:
             vm.task = None
@@ -424,7 +427,7 @@ def update_network_state(network):
 
 @transaction.commit_on_success
 def process_network_modify(back_network, etime, jobid, opcode, status,
-                           add_reserved_ips):
+                           job_fields):
     assert (opcode == "OP_NETWORK_SET_PARAMS")
     if status not in [x[0] for x in BACKEND_STATUSES]:
         raise Network.InvalidBackendMsgError(opcode, status)
@@ -433,6 +436,7 @@ def process_network_modify(back_network, etime, jobid, opcode, status,
     back_network.backendjobstatus = status
     back_network.opcode = opcode
 
+    add_reserved_ips = job_fields.get("add_reserved_ips")
     if add_reserved_ips:
         net = back_network.network
         pool = net.get_pool()
diff --git a/snf-cyclades-app/synnefo/logic/callbacks.py b/snf-cyclades-app/synnefo/logic/callbacks.py
index cd566f2..2faee7f 100644
--- a/snf-cyclades-app/synnefo/logic/callbacks.py
+++ b/snf-cyclades-app/synnefo/logic/callbacks.py
@@ -171,12 +171,12 @@ def update_db(vm, msg, event_time):
         log.error("Message is of unknown type %s.", msg['type'])
         return
 
-    nics = msg.get("nics", None)
-    beparams = msg.get("beparams", None)
+    nics = msg.get("instance_nics", None)
+    job_fields = msg.get("job_fields", {})
     backend_mod.process_op_status(vm, event_time, msg['jobId'],
                                   msg['operation'], msg['status'],
                                   msg['logmsg'], nics=nics,
-                                  beparams=beparams)
+                                  job_fields=job_fields)
 
     log.debug("Done processing ganeti-op-status msg for vm %s.",
               msg['instance'])
@@ -195,10 +195,11 @@ def update_network(network, msg, event_time):
     opcode = msg['operation']
     status = msg['status']
     jobid = msg['jobId']
+    job_fields = msg.get('job_fields', {})
 
     if opcode == "OP_NETWORK_SET_PARAMS":
         backend_mod.process_network_modify(network, event_time, jobid, opcode,
-                                           status, msg['add_reserved_ips'])
+                                           status, job_fields)
     else:
         backend_mod.process_network_status(network, event_time, jobid, opcode,
                                            status, msg['logmsg'])
diff --git a/snf-cyclades-app/synnefo/logic/reconciliation.py b/snf-cyclades-app/synnefo/logic/reconciliation.py
index a22709f..85b5e00 100644
--- a/snf-cyclades-app/synnefo/logic/reconciliation.py
+++ b/snf-cyclades-app/synnefo/logic/reconciliation.py
@@ -274,7 +274,7 @@ class BackendReconciler(object):
                 backend_mod.process_op_status(
                     vm=db_server, etime=self.event_time, jobid=-0,
                     opcode=opcode, status='success',
-                    beparams=beparams,
+                    job_fields={"beparams": beparams},
                     logmsg='Reconciliation: simulated Ganeti event')
                 # process_op_status with beparams will set the vmstate to
                 # shutdown. Fix this be returning it to old state
diff --git a/snf-cyclades-gtools/synnefo/ganeti/eventd.py b/snf-cyclades-gtools/synnefo/ganeti/eventd.py
index de4cac3..122cf49 100644
--- a/snf-cyclades-gtools/synnefo/ganeti/eventd.py
+++ b/snf-cyclades-gtools/synnefo/ganeti/eventd.py
@@ -282,14 +282,22 @@ class JobFileHandler(pyinotify.ProcessEvent):
         self.logger.debug("Job: %d: %s(%s) %s", job_id, op_id,
                           instances, op.status)
 
+        job_fields = {}
+        if op_id in ["OP_INSTANCE_SET_PARAMS", "OP_INSTANCE_CREATE"]:
+            job_fields = {"nics": get_field(input, "nics"),
+                          "disks": get_field(input, "disks"),
+                          "beparams": get_field(input, "beparams")}
+
         msg = {"type": "ganeti-op-status",
                "instance": instances,
-               "operation": op_id}
+               "operation": op_id,
+               "job_fields": job_fields}
 
-        if op_id == "OP_INSTANCE_SET_PARAMS":
-            beparams = get_field(input, "beparams")
-            if beparams:
-                msg["beparams"] = beparams
+        if op_id in ["OP_INSTANCE_CREATE", "OP_INSTANCE_SET_PARAMS",
+                     "OP_INSTANCE_STARTUP"]:
+            if op.status == "success":
+                nics = get_instance_nics(msg["instance"], self.logger)
+                msg["instance_nics"] = nics
 
         routekey = "ganeti.%s.event.op" % prefix_from_name(instances)
 
@@ -310,19 +318,20 @@ class JobFileHandler(pyinotify.ProcessEvent):
         self.logger.debug("Job: %d: %s(%s) %s", job_id, op_id,
                           network_name, op.status)
 
+        job_fields = {
+            'subnet': get_field(input, 'network'),
+            'gateway': get_field(input, 'gateway'),
+            "add_reserved_ips": get_field(input, "add_reserved_ips"),
+            "remove_reserved_ips": get_field(input, "remove_reserved_ips"),
+            # 'network_mode': get_field(input, 'network_mode'),
+            # 'network_link': get_field(input, 'network_link'),
+            'group_name': get_field(input, 'group_name')}
+
         msg = {'operation':    op_id,
                'type':         "ganeti-network-status",
                'network':      network_name,
-               'subnet':       get_field(input, 'network'),
-               # 'network_mode': get_field(input, 'network_mode'),
-               # 'network_link': get_field(input, 'network_link'),
-               'gateway':      get_field(input, 'gateway'),
-               'group_name':   get_field(input, 'group_name')}
-
-        if op_id == "OP_NETWORK_SET_PARAMS":
-            msg["add_reserved_ips"] = get_field(input, "add_reserved_ips")
-            msg["remove_reserved_ips"] = get_field(input,
-                                                   "remove_reserved_ips")
+               'job_fields':   job_fields}
+
         routekey = "ganeti.%s.event.network" % prefix_from_name(network_name)
 
         return msg, routekey
