Commit 9dfa16fc authored by Apollon Oikonomopoulos's avatar Apollon Oikonomopoulos Committed by Iustin Pop
Browse files

Export instance tags to instance hooks



Instance hooks now get an INSTANCE_TAGS environment variable, which contains a
space-delimited list of the affected instance's tags.

Also update the documentation to reflect the change.
Signed-off-by: default avatarApollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a57981c5
...@@ -581,6 +581,9 @@ MASTER_CAPABLE ...@@ -581,6 +581,9 @@ MASTER_CAPABLE
VM_CAPABLE VM_CAPABLE
Whether the node can host instances. Whether the node can host instances.
INSTANCE_TAGS
A space-delimited list of the instance's tags.
NODE_NAME NODE_NAME
The target node of this operation (not the node on which the hook The target node of this operation (not the node on which the hook
runs). runs).
......
...@@ -861,7 +861,7 @@ def _ExpandInstanceName(cfg, name): ...@@ -861,7 +861,7 @@ def _ExpandInstanceName(cfg, name):
def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
memory, vcpus, nics, disk_template, disks, memory, vcpus, nics, disk_template, disks,
bep, hvp, hypervisor_name): bep, hvp, hypervisor_name, tags):
"""Builds instance related env variables for hooks """Builds instance related env variables for hooks
This builds the hook environment from individual variables. This builds the hook environment from individual variables.
...@@ -893,6 +893,8 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, ...@@ -893,6 +893,8 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
@param hvp: the hypervisor parameters for the instance @param hvp: the hypervisor parameters for the instance
@type hypervisor_name: string @type hypervisor_name: string
@param hypervisor_name: the hypervisor for the instance @param hypervisor_name: the hypervisor for the instance
@type tags: list
@param tags: list of instance tags as strings
@rtype: dict @rtype: dict
@return: the hook environment for this instance @return: the hook environment for this instance
...@@ -940,6 +942,11 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, ...@@ -940,6 +942,11 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
env["INSTANCE_DISK_COUNT"] = disk_count env["INSTANCE_DISK_COUNT"] = disk_count
if not tags:
tags = []
env["INSTANCE_TAGS"] = " ".join(tags)
for source, kind in [(bep, "BE"), (hvp, "HV")]: for source, kind in [(bep, "BE"), (hvp, "HV")]:
for key, value in source.items(): for key, value in source.items():
env["INSTANCE_%s_%s" % (kind, key)] = value env["INSTANCE_%s_%s" % (kind, key)] = value
...@@ -1003,6 +1010,7 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None): ...@@ -1003,6 +1010,7 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None):
'bep': bep, 'bep': bep,
'hvp': hvp, 'hvp': hvp,
'hypervisor_name': instance.hypervisor, 'hypervisor_name': instance.hypervisor,
'tags': instance.tags,
} }
if override: if override:
args.update(override) args.update(override)
...@@ -8057,6 +8065,7 @@ class LUInstanceCreate(LogicalUnit): ...@@ -8057,6 +8065,7 @@ class LUInstanceCreate(LogicalUnit):
bep=self.be_full, bep=self.be_full,
hvp=self.hv_full, hvp=self.hv_full,
hypervisor_name=self.op.hypervisor, hypervisor_name=self.op.hypervisor,
tags=self.op.tags,
)) ))
return env return env
......
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