Export device UUIDs to hooks and OS scripts
authorChristos Stavrakakis <cstavr@grnet.gr>
Mon, 3 Jun 2013 16:31:26 +0000 (19:31 +0300)
committerKlaus Aehlig <aehlig@google.com>
Tue, 4 Jun 2013 09:59:40 +0000 (11:59 +0200)
Export UUIDs and names of instance NICs and disks to the environment
of OS scripts and instance related hooks.

Signed-off-by: Christos Stavrakakis <cstavr@grnet.gr>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/backend.py
lib/cmdlib/instance.py
lib/cmdlib/instance_utils.py
man/ganeti-os-interface.rst

index bc833e9..a75432b 100644 (file)
@@ -2523,6 +2523,9 @@ def OSEnvironment(instance, inst_os, debug=0):
     real_disk = _OpenRealBD(disk)
     result["DISK_%d_PATH" % idx] = real_disk.dev_path
     result["DISK_%d_ACCESS" % idx] = disk.mode
+    result["DISK_%d_UUID" % idx] = disk.uuid
+    if disk.name:
+      result["DISK_%d_NAME" % idx] = disk.name
     if constants.HV_DISK_TYPE in instance.hvparams:
       result["DISK_%d_FRONTEND_TYPE" % idx] = \
         instance.hvparams[constants.HV_DISK_TYPE]
@@ -2535,6 +2538,9 @@ def OSEnvironment(instance, inst_os, debug=0):
   # NICs
   for idx, nic in enumerate(instance.nics):
     result["NIC_%d_MAC" % idx] = nic.mac
+    result["NIC_%d_UUID" % idx] = nic.uuid
+    if nic.name:
+      result["NIC_%d_NAME" % idx] = nic.name
     if nic.ip:
       result["NIC_%d_IP" % idx] = nic.ip
     result["NIC_%d_MODE" % idx] = nic.nicparams[constants.NIC_MODE]
index f7d3bb9..1739d8d 100644 (file)
@@ -620,8 +620,9 @@ class LUInstanceCreate(LogicalUnit):
       vcpus=self.be_full[constants.BE_VCPUS],
       nics=NICListToTuple(self, self.nics),
       disk_template=self.op.disk_template,
-      disks=[(d[constants.IDISK_NAME], d[constants.IDISK_SIZE],
-              d[constants.IDISK_MODE]) for d in self.disks],
+      disks=[(d[constants.IDISK_NAME], d.get("uuid", ""),
+              d[constants.IDISK_SIZE], d[constants.IDISK_MODE])
+             for d in self.disks],
       bep=self.be_full,
       hvp=self.hv_full,
       hypervisor_name=self.op.hypervisor,
index f6efa92..cd126a4 100644 (file)
@@ -94,10 +94,12 @@ def BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
     }
   if nics:
     nic_count = len(nics)
-    for idx, (name, _, ip, mac, mode, link, net, netinfo) in enumerate(nics):
+    for idx, (name, uuid, ip, mac, mode, link, net, netinfo) in enumerate(nics):
       if ip is None:
         ip = ""
-      env["INSTANCE_NIC%d_NAME" % idx] = name
+      if name:
+        env["INSTANCE_NIC%d_NAME" % idx] = name
+      env["INSTANCE_NIC%d_UUID" % idx] = uuid
       env["INSTANCE_NIC%d_IP" % idx] = ip
       env["INSTANCE_NIC%d_MAC" % idx] = mac
       env["INSTANCE_NIC%d_MODE" % idx] = mode
@@ -119,8 +121,10 @@ def BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
 
   if disks:
     disk_count = len(disks)
-    for idx, (name, size, mode) in enumerate(disks):
-      env["INSTANCE_DISK%d_NAME" % idx] = name
+    for idx, (name, uuid, size, mode) in enumerate(disks):
+      if name:
+        env["INSTANCE_DISK%d_NAME" % idx] = name
+      env["INSTANCE_DISK%d_UUID" % idx] = uuid
       env["INSTANCE_DISK%d_SIZE" % idx] = size
       env["INSTANCE_DISK%d_MODE" % idx] = mode
   else:
@@ -169,7 +173,7 @@ def BuildInstanceHookEnvByObject(lu, instance, override=None):
     "vcpus": bep[constants.BE_VCPUS],
     "nics": NICListToTuple(lu, instance.nics),
     "disk_template": instance.disk_template,
-    "disks": [(disk.name, disk.size, disk.mode)
+    "disks": [(disk.name, disk.uuid, disk.size, disk.mode)
               for disk in instance.disks],
     "bep": bep,
     "hvp": hvp,
index ec8ec86..52e5153 100644 (file)
@@ -76,6 +76,12 @@ DISK_%N_ACCESS
     This is how the hypervisor will export the instance disks: either
     read-write (``rw``) or read-only (``ro``).
 
+DISK_%N_UUID
+    The uuid associated with the N-th disk of the instance.
+
+DISK_%N_NAME
+    (Optional) The name, if any, associated with the N-th disk of the instance.
+
 DISK_%N_FRONTEND_TYPE
     (Optional) If applicable to the current hypervisor type: the type
     of the device exported by the hypervisor. For example, the Xen HVM
@@ -96,6 +102,12 @@ NIC_COUNT
 NIC_%N_MAC
     The MAC address associated with this interface.
 
+NIC_%N_UUID
+    The uuid associated with the N-th NIC of the instance.
+
+NIC_%N_NAME
+    (Optional) The name, if any, associated with the N-th NIC of the instance.
+
 NIC_%N_IP
     The IP address, if any, associated with the N-th NIC of the
     instance.