Skip to content

Commit

Permalink
Added Node tagging support (Issue #8) (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbens authored Oct 15, 2020
1 parent b5a7655 commit 40e9e32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
22 changes: 20 additions & 2 deletions rundeck-oci-nodes-plugin/contents/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
config_file = environ.get('RD_CONFIG_OCI_CONFIG', None)
node_user = environ.get('RD_CONFIG_NODE_USER', 'opc')
vnic_tag = environ.get('RD_CONFIG_VNIC_TAG', None)
defined_list = environ.get('RD_CONFIG_DEFINED_TAGS', None)
freeform_enabled = environ.get('RD_CONFIG_FREEFORM_TAGS', None)

# oci config

Expand Down Expand Up @@ -48,11 +50,12 @@
node = {}
node["nodename"] = instance.display_name
node["username"] = node_user

# hostname
vnic_attachments = compute.list_vnic_attachments(
compartment_id=compartment_id,
instance_id=instance.id
).data

).data
for vnic_attachment in vnic_attachments:
vnic = network.get_vnic(vnic_attachment.vnic_id).data

Expand All @@ -65,6 +68,21 @@
node["hostname"] = vnic.private_ip
break

# tags
if freeform_enabled == "true":
# convert all freeform tag values to comma seperated string
node["tags"] = ', '.join(filter(None, instance.freeform_tags))

if defined_list:
for namespace in defined_list.split(','):
namespace_tags = instance.defined_tags.get(namespace)
if namespace_tags:
# convert all defined tag values to comma seperated string
if node["tags"]:
node["tags"] = node["tags"] + ", " + ', '.join(filter(None, namespace_tags.values()))
else:
node["tags"] = ', '.join(filter(None, namespace_tags.values()))

nodes[instance.display_name] = node

# print nodes
Expand Down
9 changes: 9 additions & 0 deletions rundeck-oci-nodes-plugin/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ providers:
name: vnic_tag
title: VNIC Override Tag
description: Enter a freeform Tag Key that will specify which VNIC Rundeck should connect to. If not specified or a VNIC is not found with this Tag, the primary VNIC will be used. (optional)
- type: String
name: defined_tags
title: OCI Defined Tag Namespaces
description: Enter a comma seperated list of OCI Defined Tag Namespaces to be included in Tag Value mapping to Rundeck Nodes. (optional)
- type: Boolean
name: freeform_tags
title: OCI Freeform Tag Values
description: Enable OCI Freeform Tag Value mapping to Rundeck Nodes. (optional)

0 comments on commit 40e9e32

Please sign in to comment.