-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathengine_network_assignment
182 lines (148 loc) · 4.79 KB
/
engine_network_assignment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/expect -f
#Adam Bowen - 2015
#engine_network_assignment
#Many thanks for the examples given at https://www.pantz.org/software/expect/expect_examples_and_tips.html
#####################################################################
set version 2.3.005
set DESCRIPTION "This script sets the static IP address and dns information for the Delphix Engine"
set timeout 20
set BOLD "\033\[01m"
set NORM "\033\[0m"
set enginename [lindex $argv 0]
set engineip [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
set network [lindex $argv 4]
set gateway [lindex $argv 5]
set dnsserver [lindex $argv 6]
set reboot [lindex $argv 7]
set change false
#log_user 0
if {[llength $argv] < 7} {
send_user "Usage: $argv0 enginename engineip username \'password\' network_cidr gateway dnsserver reboot(Y or N)\n"
exit 1
}
send_user "\n#####\n#${BOLD}Welcome to $argv0, v.$version${NORM}"
send_user "\n#$DESCRIPTION"
send_user "\n#This script will update the network settings to the following:"
send_user "\n#dhcp=false"
send_user "\n#ip address = $engineip/$network"
send_user "\n#default gateway = $gateway"
send_user "\n#dnsserver = $dnsserver"
send_user "\n#####\n"
send_user "\nConnecting to $engineip\n"
#spawn ssh -q -o ConnectTimeout=30 -o "StrictHostKeyChecking no" $username@$engineip
spawn ssh -o "StrictHostKeyChecking no" $username@$engineip
expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
eof { send_user "\nSSH failure for $engineip\n"; exit 1 }
"Password: " {
send "$password\r"
expect {
timeout { send_user "\nLogin failed. Password incorrect.\ngot '$expect_out(buffer)'\n"; exit 1}
"*network setup update*" {}
"*>*" {
send "/network/setup/update\r"
expect {
default { send_user "\nFailed to get the network update prompt. Ensure you are logged in as a user with sysadmin privileges\n"; exit 1}
"*network setup update *> "
}
}
}
}
"${enginename}> "
}
send_user "\nSuccessfully logged into the Delphix Engine\n"
#send "/version 1.6.1\r"
#send "/network/setup/update\r"
send_user "\nUpdating network settings...\n"
send "/network/setup/ls\r"
expect -re {Properties.*defaultRoute: (.*)\r\n.*dhcp: (.*)\r\n.*dnsDomain: (.*)\r\n.*dnsServers: (.*)\r\n.*hostname: (.*)\r\n.*primaryAddress: ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{2}).*\r\n.*} {
set defaultRoute $expect_out(1,string)
set dhcp $expect_out(2,string)
set dnsDomain $expect_out(3,string)
set dnsServers $expect_out(4,string)
set hostname $expect_out(5,string)
set primaryAddress $expect_out(6,string)
}
puts "\n"
puts "defaultRoute: $defaultRoute"
puts "dhcp: $dhcp"
puts "dnsDomain: $dnsDomain"
puts "dnsServers: $dnsServers"
puts "hostname: $hostname"
puts "primaryAddress: $primaryAddress"
if {$dhcp=="true"} {
send_user "\nTurning off dhcp\n"
send "set dhcp=false\r"
expect "$hostname network setup update *> "
set change true
} else {
send_user "\ndhcp already off"
}
if {$hostname!=$enginename} {
send_user "\nSetting hostname\n"
send "set hostname=$enginename\r"
expect "$hostname network setup update *> "
set change true
} else {
send_user "\nhostname already set to correct value"
}
if {$defaultRoute!=$gateway} {
send_user "\nSetting defaultRoute\n"
send "set defaultRoute=$gateway\r"
expect "$hostname network setup update *> "
set change true
} else {
send_user "\ndefaultRoute already set to correct value"
}
if {$dnsDomain!="delphix.local"} {
send_user "\nSetting dnsDomain\n"
send "set dnsDomain=delphix.local\r"
expect "$hostname network setup update *> "
set change true
} else {
send_user "\ndnsDomain already set to correct value"
}
if {$dnsServers!=$dnsserver} {
send_user "\nSetting dnsServers\n"
send "set dnsServers=$dnsserver\r"
expect "$hostname network setup update *> "
set change true
} else {
send_user "\ndnsServers already set to correct value"
}
if {"$primaryAddress"!="$engineip/$network"} {
#puts ""
#puts "HERE_ $primaryAddress _HERE"
#puts "HERE_ $engineip/$network _HERE"
#exit 1
send_user "\nSetting primaryAddress\n"
send "set primaryAddress=$engineip/$network\r"
expect "$hostname network setup update *> "
set change true
} else {
send_user "\nprimaryAddress already set to correct value"
}
if {$change==true} {
send_user "\nCommitting changes\n"
send "commit\r"
} else {
send_user "\nNothing to change\n"
send "discard\r"
}
expect "${enginename}> "
send "/network/setup/ls\r"
expect -re "(Properties)(.*defaultRoute.*)(Operations.*)"
set output $expect_out(2,string)
puts "$BOLD New Engine Network Settings\n$output $NORM \n"
if {$reboot=="Y"} {
send_user "\nRebooting Engine...\n"
send "/system/reboot\r"
expect "$enginename system reboot *>"
send "commit\r"
expect "Rebooting system. The current session will be terminated."
} else {
send "exit\r"
}
send_user "$argv0 is finished\n\n"