Merge lp:~mpontillo/maas/maas-enlist-wget-and-curl into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Superseded
Proposed branch: lp:~mpontillo/maas/maas-enlist-wget-and-curl
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~cyphermox/maas/maas-enlist-wget-not-curl
Diff against target: 123 lines (+60/-15) (has conflicts)
1 file modified
bin/maas-enlist (+60/-15)
Conflict adding file man.  Moved existing file to man.moved.
To merge this branch: bzr merge lp:~mpontillo/maas/maas-enlist-wget-and-curl
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Pending
Review via email: mp+270893@code.launchpad.net

This proposal has been superseded by a proposal from 2015-09-13.

Commit message

Support wget and curl in maas-enlist.

Description of the change

Support both wget and curl in maas-enlist.

Based on a branch proposed by Mathieu Trudel-Lapierre on 2015-09-03.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/maas-enlist'
2--- bin/maas-enlist 2015-09-13 07:29:24 +0000
3+++ bin/maas-enlist 2015-09-13 07:29:24 +0000
4@@ -37,13 +37,22 @@
5 echo "$mac"
6 }
7
8-get_mac_address_parms() {
9+get_mac_address_curl_parms() {
10+ local args="" input_string="$1"
11+ OIFS=$IFS; IFS=","; set -- $input_string; IFS=$OIFS
12+ for i in "$@";
13+ do
14+ args="${args} --data-urlencode mac_addresses=${i}"
15+ done
16+ echo "${args# }"
17+}
18+
19+get_mac_address_wget_parms() {
20 local args="" input_string="$1"
21 OIFS=$IFS; IFS=","; set -- $input_string; IFS=$OIFS
22 for i in "$@";
23 do
24 args="${args}&mac_addresses=${i}"
25- #mac_address="$mac_address""&mac_addresses=""${i}";
26 done
27 echo "${args# }"
28 }
29@@ -79,17 +88,41 @@
30 echo "$_RET";
31 }
32
33-enlist_node() {
34- serverurl="${1}"
35- mac="${2}"
36- arch="${3}"
37- subarch="${4}"
38- hostname="${5}"
39- power_type="${6}"
40- power_params="${7}"
41-
42- local macparms=""
43- macparms=$(get_mac_address_parms "$mac")
44+enlist_node_curl() {
45+ serverurl="${1}"
46+ mac="${2}"
47+ arch="${3}"
48+ subarch="${4}"
49+ hostname="${5}"
50+ power_type="${6}"
51+ power_params="${7}"
52+
53+ local macparms=""
54+ macparms=$(get_mac_address_curl_parms "$mac")
55+
56+ curl \
57+ --data-urlencode "op=new" \
58+ --data-urlencode "autodetect_nodegroup=1" \
59+ --data-urlencode "hostname=${hostname}" \
60+ --data-urlencode "architecture=${arch}" \
61+ --data-urlencode "subarchitecture=${subarch}" \
62+ --data-urlencode "power_type=${power_type}" \
63+ --data-urlencode "power_parameters=${power_params}" \
64+ ${macparms} \
65+ "${serverurl}"
66+}
67+
68+enlist_node_wget() {
69+ serverurl="${1}"
70+ mac="${2}"
71+ arch="${3}"
72+ subarch="${4}"
73+ hostname="${5}"
74+ power_type="${6}"
75+ power_params="${7}"
76+
77+ local macparms=""
78+ macparms=$(get_mac_address_wget_parms "$mac")
79
80 local params="op=new"
81 params="${params}&autodetect_nodegroup=1"
82@@ -134,8 +167,11 @@
83
84 bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || Error "$@"; exit 1; }
85
86+CURL=$(which curl)
87+WGET=$(which wget)
88+
89 short_opts="hs:n:i:a:t:p:"
90-long_opts="help,serverurl:,hostname:,interface:,arch:,subarch:,power-type:,power-params:"
91+long_opts="help,serverurl:,hostname:,interface:,arch:,subarch:,power-type:,power-params:,wget,curl"
92 getopt_out=$(getopt --name "${0##*/}" \
93 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
94 eval set -- "${getopt_out}" ||
95@@ -152,6 +188,8 @@
96 --subarch) subarch=${2}; shift;;
97 -t|--power-type) power_type=${2}; shift;;
98 -p|--power-params) power_parameters=${2}; shift;;
99+ --wget) CURL=""; shift;;
100+ --curl) WGET=""; shift;;
101 --) shift; break;;
102 esac
103 shift;
104@@ -160,6 +198,7 @@
105 ## check arguments here
106 #[ $# -eq 0 ] && bad_Usage
107
108+
109 # If no interface is specified. obtain the MAC from all interfaces
110 if [ -z "$iface" ]; then
111 mac_addrs=$(get_mac_addresses)
112@@ -213,4 +252,10 @@
113 esac
114 fi
115
116-enlist_node "$protocol://$servername/$api_url" "${mac_addrs}" "$arch" "$subarch" "$hostname" "$power_type" "$power_parameters"
117+if [ "$CURL" != "" ]; then
118+ enlist_node_curl "$protocol://$servername/$api_url" "${mac_addrs}" "$arch" "$subarch" "$hostname" "$power_type" "$power_parameters"
119+elif [ "$WGET" != "" ]; then
120+ enlist_node_wget "$protocol://$servername/$api_url" "${mac_addrs}" "$arch" "$subarch" "$hostname" "$power_type" "$power_parameters"
121+else
122+ echo "Must install 'curl' or 'wget' to use this script."
123+fi