From e36e3ad8c17a674309337cfcd3b72d0698921225 Mon Sep 17 00:00:00 2001 From: Rob Hirschfeld Date: Sun, 25 Feb 2018 16:07:19 -0600 Subject: [PATCH 1/2] add description at top --- content/templates/setup.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/templates/setup.tmpl b/content/templates/setup.tmpl index 72e0aa18..8b82cd51 100644 --- a/content/templates/setup.tmpl +++ b/content/templates/setup.tmpl @@ -1,4 +1,6 @@ #!/usr/local/bin/env bash +# Helper to setup DRP tasks for other templates +# ### # This is a BASH script snippet intended to be run inside other BASH templates. # From 00b722bcbd1b1e4b7e9f89c0273fa78d6222b7ed Mon Sep 17 00:00:00 2001 From: Rob Hirschfeld Date: Sun, 25 Feb 2018 16:08:17 -0600 Subject: [PATCH 2/2] make color setting icon available in base package --- content/params/machine-meta.color.yaml | 8 +++++ content/params/machine-meta.icon.yaml | 8 +++++ content/stages/machine-meta.yaml | 10 +++++++ content/tasks/machine-meta-setter.yaml | 14 +++++++++ content/templates/machine-meta-setter.sh.tmpl | 29 +++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 content/params/machine-meta.color.yaml create mode 100644 content/params/machine-meta.icon.yaml create mode 100644 content/stages/machine-meta.yaml create mode 100644 content/tasks/machine-meta-setter.yaml create mode 100644 content/templates/machine-meta-setter.sh.tmpl diff --git a/content/params/machine-meta.color.yaml b/content/params/machine-meta.color.yaml new file mode 100644 index 00000000..1905f170 --- /dev/null +++ b/content/params/machine-meta.color.yaml @@ -0,0 +1,8 @@ +Description: The color for machines icon +Meta: + color: blue + icon: info + title: RackN Content +Name: machine-meta/color +Schema: + type: string diff --git a/content/params/machine-meta.icon.yaml b/content/params/machine-meta.icon.yaml new file mode 100644 index 00000000..3af592ea --- /dev/null +++ b/content/params/machine-meta.icon.yaml @@ -0,0 +1,8 @@ +Description: The icon for machines icon +Meta: + color: blue + icon: info + title: RackN Content +Name: machine-meta/icon +Schema: + type: string diff --git a/content/stages/machine-meta.yaml b/content/stages/machine-meta.yaml new file mode 100644 index 00000000..a492ce4e --- /dev/null +++ b/content/stages/machine-meta.yaml @@ -0,0 +1,10 @@ +Description: Stage to assign the machine icon and color +Meta: + color: yellow + icon: info +Name: machine-meta +Reboot: false +RunnerWait: true +Tasks: +- machine-meta-setter + diff --git a/content/tasks/machine-meta-setter.yaml b/content/tasks/machine-meta-setter.yaml new file mode 100644 index 00000000..fbd3823e --- /dev/null +++ b/content/tasks/machine-meta-setter.yaml @@ -0,0 +1,14 @@ +Description: A task to set the color and icon for a machine +Meta: + color: blue + icon: info +Name: machine-meta-setter +OptionalParams: + - "machine-meta/color" + - "machine-meta/icon" +Templates: +- Contents: "" + ID: machine-meta-setter.sh.tmpl + Name: "Set Icons" + Path: "" + diff --git a/content/templates/machine-meta-setter.sh.tmpl b/content/templates/machine-meta-setter.sh.tmpl new file mode 100644 index 00000000..24f2be49 --- /dev/null +++ b/content/templates/machine-meta-setter.sh.tmpl @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Set the Machine Meta: Icon and Color + +set -e + +export RS_UUID="{{.Machine.UUID}}" + +{{template "setup.tmpl" .}} + +{{if .ParamExists "machine-meta/color" -}} +COLOR={{.Param "machine-meta/color"}} +{{else -}} +COLOR="black" +{{end -}} + +{{if .ParamExists "machine-meta/icon" -}} +ICON={{.Param "machine-meta/icon"}} +{{else -}} +ICON="server" +{{end -}} + +echo "Setting the Color to $COLOR and Icon to $ICON" + +# do work! +drpcli machines update $RS_UUID "{\"Meta\":{\"color\":\"$COLOR\", \"icon\": \"$ICON\"}}" | jq .Meta + +echo "Finished successfully" +exit 0 +