Fix multi-allocation RAPI method
authorHrvoje Ribicic <riba@google.com>
Tue, 28 Jan 2014 15:26:32 +0000 (15:26 +0000)
committerHrvoje Ribicic <riba@google.com>
Wed, 29 Jan 2014 15:26:42 +0000 (16:26 +0100)
The OpInstanceMultiAlloc that the instances-multi-alloc RAPI method
uses accepts a list of OpInstanceCreate opcodes rather than a list of
dictionaries as provided by the method. This patch correctly constructs
the opcodes, allowing the RAPI call to work as expected.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/rapi/rlib2.py

index 4c902a8..ac230e0 100644 (file)
@@ -980,12 +980,18 @@ class R_2_instances_multi_alloc(baserlib.OpcodeResource):
       raise http.HttpBadRequest("Request is missing required 'instances' field"
                                 " in body")
 
-    op_id = {
-      "OP_ID": self.POST_OPCODE.OP_ID, # pylint: disable=E1101
-      }
+    # Unlike most other RAPI calls, this one is composed of individual opcodes,
+    # and we have to do the filling ourselves
+    OPCODE_RENAME = {
+      "os": "os_type",
+      "name": "instance_name",
+    }
+
     body = objects.FillDict(self.request_body, {
-      "instances": [objects.FillDict(inst, op_id)
-                    for inst in self.request_body["instances"]],
+      "instances": [
+        baserlib.FillOpcode(opcodes.OpInstanceCreate, inst, {}, OPCODE_RENAME)
+        for inst in self.request_body["instances"]
+        ],
       })
 
     return (body, {