|
2 | 2 | set -euo pipefail
|
3 | 3 |
|
4 | 4 | source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/config.bash"
|
5 |
| -source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libaws.bash" |
6 |
| -source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libmageops.bash" |
7 |
| -source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libfeatures.bash" |
| 5 | +if [ "${config__aws_enabled}" = "yes" ];then |
| 6 | + source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libaws.bash" |
| 7 | + source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libmageops.bash" |
| 8 | + source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libfeatures.bash" |
| 9 | +fi |
| 10 | +source "$(dirname "${BASH_SOURCE[0]}")/../lib/mageops/libdynamicnode.bash" |
8 | 11 |
|
9 | 12 | main::main() {
|
10 | 13 | local cmd=${1:-}
|
11 | 14 |
|
12 | 15 | case $cmd in
|
13 | 16 | is_cron_node)
|
| 17 | + main::aws_only |
14 | 18 | if [ $# != 1 ];then main::help; fi
|
15 | 19 | main::is_cron_node || exit 1
|
16 | 20 | ;;
|
17 | 21 | is_tag_present)
|
| 22 | + main::aws_only |
18 | 23 | if [ $# != 2 ];then main::help; fi
|
19 | 24 | local tag=$2
|
20 | 25 | main::is_tag_present "$tag" || exit 1
|
21 | 26 | ;;
|
22 | 27 | get_tag_value)
|
| 28 | + main::aws_only |
23 | 29 | if [ $# != 2 ];then main::help; fi
|
24 | 30 | local tag=$2
|
25 | 31 | main::get_tag_value "$tag" || exit 1
|
26 | 32 | ;;
|
27 | 33 | current_instance_id)
|
| 34 | + main::aws_only |
28 | 35 | if [ $# != 1 ];then main::help; fi
|
29 | 36 | main::current_instance_id || exit 1
|
30 | 37 | ;;
|
31 | 38 | current_region)
|
| 39 | + main::aws_only |
32 | 40 | if [ $# != 1 ];then main::help; fi
|
33 | 41 | main::current_region || exit 1
|
34 | 42 | ;;
|
35 | 43 | set_feature_flag)
|
| 44 | + main::aws_only |
36 | 45 | if [ $# != 3 ];then main::help; fi
|
37 | 46 | local feature=$2
|
38 | 47 | local value=$3
|
39 | 48 | main::set_feature_flag "$feature" "$value"
|
40 | 49 | ;;
|
41 | 50 | read_feature_flag)
|
| 51 | + main::aws_only |
42 | 52 | if [ $# != 2 ];then main::help; fi
|
43 | 53 | local feature=$2
|
44 | 54 | main::read_feature_flag "$feature"
|
45 | 55 | ;;
|
46 | 56 | is_feature_flag_set)
|
| 57 | + main::aws_only |
47 | 58 | if [ $# != 2 ];then main::help; fi
|
48 | 59 | local feature=$2
|
49 | 60 | main::is_feature_flag_set "$feature" || exit 1
|
50 | 61 | ;;
|
51 | 62 | apply_features)
|
52 |
| - if [ $# != 1 ];then main::help; fi |
| 63 | + main::aws_only |
| 64 | + if [ $# != 1 ];then main::help; fi |
53 | 65 | main::apply_features
|
54 | 66 | ;;
|
| 67 | + register_dynamic_bakcend) |
| 68 | + if [ $# != 2 ];then main::help; fi |
| 69 | + local backend_name=$2 |
| 70 | + main::register_dynamic_backend "$backend_name" || exit 1 |
| 71 | + ;; |
55 | 72 | *) main::help ;;
|
56 | 73 | esac
|
57 | 74 | }
|
@@ -125,27 +142,58 @@ main::apply_features() {
|
125 | 142 | features::update_host_state
|
126 | 143 | }
|
127 | 144 |
|
| 145 | +main::register_dynamic_backend() { |
| 146 | + local backend_name=$1 |
| 147 | + |
| 148 | + dynamicnode::register_node "$backend_name" || main::panic "Failed to register this node as dynamic backend" |
| 149 | +} |
| 150 | + |
| 151 | +main::aws_only() { |
| 152 | + if [ "${config__aws_enabled}" != "yes" ];then |
| 153 | + main::panic "This command is only available on aws environment" |
| 154 | + fi |
| 155 | +} |
| 156 | + |
| 157 | +main::dynamic_node_only() { |
| 158 | + if [ "${config__dynamicnode_enabled}" != "yes" ];then |
| 159 | + main::panic "This command is only available on nodes with dynamic node feature configured" |
| 160 | + fi |
| 161 | +} |
| 162 | + |
128 | 163 | main::help() {
|
| 164 | + local contains_commands=0 |
129 | 165 | main::eprintln " $0 <cmd>"
|
130 | 166 | main::eprintln ""
|
131 | 167 | main::eprintln "Where cmd is one of:"
|
132 |
| - main::eprintln " is_cron_node Checks if there is tag 'Cron' with value 'yes'" |
133 |
| - main::eprintln " status code 0 means tag present, 1 means missing tag or" |
134 |
| - main::eprintln " other error" |
135 |
| - main::eprintln " is_tag_present <tag_name> Checks if specified tag name is set" |
136 |
| - main::eprintln " status code 0 means tag present, 1 means missing tag or" |
137 |
| - main::eprintln " other error" |
138 |
| - main::eprintln " get_tag_value <tag_name> Reads value assigned to tag" |
139 |
| - main::eprintln " current_instance_id Reads current ec2 instance id" |
140 |
| - main::eprintln " current_region Reads current ec2 region name" |
141 |
| - main::eprintln " set_feature_flag <feature> <value> Update feature flag value" |
142 |
| - main::eprintln " read_feature_flag <feature> Reads current feature flag value" |
143 |
| - main::eprintln " is_feature_flag_set <feature> Checks if there is any value set for feature flag" |
144 |
| - main::eprintln " status code 0 means flag is set, 1 otherwise" |
145 |
| - main::eprintln " apply_features Apply feature updates to this host" |
| 168 | + if [ "${config__aws_enabled}" = "yes" ];then |
| 169 | + contains_commands=1 |
| 170 | + main::eprintln " is_cron_node Checks if there is tag 'Cron' with value 'yes'" |
| 171 | + main::eprintln " status code 0 means tag present, 1 means missing tag or" |
| 172 | + main::eprintln " other error" |
| 173 | + main::eprintln " is_tag_present <tag_name> Checks if specified tag name is set" |
| 174 | + main::eprintln " status code 0 means tag present, 1 means missing tag or" |
| 175 | + main::eprintln " other error" |
| 176 | + main::eprintln " get_tag_value <tag_name> Reads value assigned to tag" |
| 177 | + main::eprintln " current_instance_id Reads current ec2 instance id" |
| 178 | + main::eprintln " current_region Reads current ec2 region name" |
| 179 | + main::eprintln " set_feature_flag <feature> <value> Update feature flag value" |
| 180 | + main::eprintln " read_feature_flag <feature> Reads current feature flag value" |
| 181 | + main::eprintln " is_feature_flag_set <feature> Checks if there is any value set for feature flag" |
| 182 | + main::eprintln " status code 0 means flag is set, 1 otherwise" |
| 183 | + main::eprintln " apply_features Apply feature updates to this host" |
| 184 | + fi |
| 185 | + if [ "${config__dynamicnode_enabled}" = "yes" ];then |
| 186 | + contains_commands=1 |
| 187 | + main::eprintln " register_dynamic_bakcend <name> Register this node as dynamic backend with <name>." |
| 188 | + main::eprintln " This command need to be repeated constandly to keep" |
| 189 | + main::eprintln " this node in list." |
| 190 | + fi |
| 191 | + if [ "${contains_commands}" = "0" ];then |
| 192 | + main::eprintln " Sorry but this node does not contain any usable commands" |
| 193 | + fi |
146 | 194 | main::eprintln ""
|
147 | 195 | main::eprintln " Mageops cli tools"
|
148 |
| - main::eprintln " (c) Creativestyle 2020" |
| 196 | + main::eprintln " (c) Creativestyle 2020-2021" |
149 | 197 | exit 1
|
150 | 198 | }
|
151 | 199 |
|
|
0 commit comments