diff --git a/doc/hooks.rst b/doc/hooks.rst index f19e8b24c6560000b8529968d13ef414ba597255..95089938b484c32f06ac9fb3d7455f96c8e6f961 100644 --- a/doc/hooks.rst +++ b/doc/hooks.rst @@ -587,6 +587,9 @@ MASTER_CAPABLE VM_CAPABLE Whether the node can host instances. +INSTANCE_TAGS + A space-delimited list of the instance's tags. + NODE_NAME The target node of this operation (not the node on which the hook runs). diff --git a/lib/cmdlib.py b/lib/cmdlib.py index d8220f78d7fd83bf5f647b896fcdf6cf71d865fe..f693f7a8ba019b41f94d091bff59abca7048b604 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -783,7 +783,7 @@ def _ExpandInstanceName(cfg, name): def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, memory, vcpus, nics, disk_template, disks, - bep, hvp, hypervisor_name): + bep, hvp, hypervisor_name, tags): """Builds instance related env variables for hooks This builds the hook environment from individual variables. @@ -815,6 +815,8 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, @param hvp: the hypervisor parameters for the instance @type hypervisor_name: string @param hypervisor_name: the hypervisor for the instance + @type tags: list + @param tags: list of instance tags as strings @rtype: dict @return: the hook environment for this instance @@ -862,6 +864,11 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, env["INSTANCE_DISK_COUNT"] = disk_count + if not tags: + tags = [] + + env["INSTANCE_TAGS"] = " ".join(tags) + for source, kind in [(bep, "BE"), (hvp, "HV")]: for key, value in source.items(): env["INSTANCE_%s_%s" % (kind, key)] = value @@ -925,6 +932,7 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None): 'bep': bep, 'hvp': hvp, 'hypervisor_name': instance.hypervisor, + 'tags': instance.tags, } if override: args.update(override) @@ -7517,6 +7525,7 @@ class LUInstanceCreate(LogicalUnit): bep=self.be_full, hvp=self.hv_full, hypervisor_name=self.op.hypervisor, + tags=self.op.tags, )) nl = ([self.cfg.GetMasterNode(), self.op.pnode] +