genirack 9.13 KB
Newer Older
1
2
3
#
# Additional stuff for setting up the geni racks. 
#
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Switch tasks:
#  2610> vlan 1 ip address 10.1.1.253/24
#  2610> ip default-gateway 10.1.1.254
#  5400> vlan 1 ip address 10.2.1.253/24
#  5400> ip default-gateway 10.2.1.254
#  2610> show ip igmp
#  2610> vlan 1 ip igmp
#  2610> vlan 1 ip igmp querier
#  both> no web-management
#  both> password all (type in password).
#  both> no snmp-server community public
#  both> snmp-server community XXXXX manager unrestricted
#  both> write memory
#
# Control node image changes before it can booted.
#  fix up the interfaces file.
Leigh B Stoller's avatar
Leigh B Stoller committed
20
#  Add /etc/hostname.
21
22
#  Add /etc/resolv.conf
#  Set Root password.
23
24
25
26
27
#
use strict;
use libinstall;
use installvars;
use libtestbed;
28
29
30
31
use emutil;
use emdb;
use User;
use NodeType;
Leigh B Stoller's avatar
Leigh B Stoller committed
32
use OSinfo;
33
34
35

my $EMULABDEVEL  = "git://git-public.flux.utah.edu/emulab-devel.git";
my $EMULABSTABLE = "git://git-public.flux.utah.edu/emulab-stable.git";
36
37
38
my $NODETYPEXML  = "$TOP_SRCDIR/install/genirack/nodetype.xml";
my $SWITCHSQL    = "$TOP_SRCDIR/install/genirack/tbdb.sql";
my $CONFIGVARS   = "$PREFIX/configvars.txt";
Leigh B Stoller's avatar
Leigh B Stoller committed
39
my $ILOPASSWORD  = "$PREFIX/etc/ilo.pswd";
40
my $PORTSRC      = "http://www.emulab.net/downloads/FreeBSD-8.2-ports.tar.gz";
Leigh B Stoller's avatar
Leigh B Stoller committed
41
42
43
my $ZZZ		 = "/usr/local/etc/rc.d/zzz-inelab.sh";
my $DEFAULTOSID  = "FEDORA15-STD";
my $PGOSSITEVAR  = "protogeni/default_osname";
44
45
46
47
48

my %INTERFACES = (
    "xn1"   => "inet 10.1.1.1 netmask 255.255.255.0",
    "xn2"   => "inet 10.2.1.1 netmask 255.255.255.0",
    "xn3"   => "inet 10.3.1.1 netmask 255.255.255.0",
Leigh B Stoller's avatar
Leigh B Stoller committed
49
50
    # Direct connect to FOAM VM on the same node.
    "xn4"   => "inet 10.4.1.1 netmask 255.255.255.0",
51
52
);

Leigh B Stoller's avatar
Leigh B Stoller committed
53
my %HOSTNAMES = (
54
55
56
    "procurve1"       => "10.1.1.253",
    "procurve2"       => "10.2.1.253",
    "procurve1-alt"   => "10.3.1.253",
Leigh B Stoller's avatar
Leigh B Stoller committed
57
    "foamvm"	      => "10.4.1.5",
58
);
59
60
61
62

sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;
63
    my %configvars = ();
64
65
66
67
68

    # Replace if this script does an update for ip/domain.
    return 0
	if ($isupdate);

69
70
    SET_TESTBED_VERSION("Genirack");

71
72
73
74
    Phase "genirack", "Doing additional Geni Rack tasks", sub {
	PhaseSkip("Not a Rack")
	    if (!$PROTOGENI_GENIRACK);

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	Phase "config", "Reading in config variables", sub {
	    PhaseFail("No config file")
		if (! -e $CONFIGVARS);
	    
	    open(CN, $CONFIGVARS)
		 or PhaseFail("Could not open $CONFIGVARS: $!");
	    while (<CN>) {
		if ($_ =~ /^([-\w]*)\s*=\s*(.*)$/) {
		    my $key = $1;
		    my $val = $2;
		    if ($val =~ /^'(.*)'$/) {
			$val = $1;
		    }
		    $configvars{$key} = "$val";
		}
	    }
	    close(CN);
	};

94
95
96
97
98
99
100
101
102
	#
	# Have not figured this out yet; it runs during boss setup but
        # the line in fstab gets lost. Run again and it works fine. 
	#
	Phase "swapon", "Reruning rc.freebsd", sub {
	    PhaseSkip("already enabled") unless `grep -q swap $FSTAB`;
	    ExecQuietFatal("/usr/local/etc/emulab/rc/rc.freebsd");
	};

Leigh B Stoller's avatar
Leigh B Stoller committed
103
104
105
106
107
108
	Phase "rclocal", "Removing $ZZZ", sub {
	    PhaseSkip("already deleted")
		if (! -e $ZZZ);
	    DeleteFileFatal($ZZZ);
	};

109
	#
Leigh B Stoller's avatar
Leigh B Stoller committed
110
	# Update geniuser password.
111
112
113
114
115
116
117
118
119
120
	#
	if (exists($configvars{'PROTOGENI_PASSWORD'}) &&
	    $configvars{'PROTOGENI_PASSWORD'} ne "") {
	    my $geniuser = User->Lookup("geniuser");
	    PhaseFail("No geniuser account")
		if (!defined($geniuser));
	    my $passhash = PassWordHash($configvars{'PROTOGENI_PASSWORD'});
	    $geniuser->SetPassword($passhash);
	}

Leigh B Stoller's avatar
Leigh B Stoller committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
	#
	# This is the password to use when creating the elabman user
	# on each node iLo.
	#
	if (exists($configvars{'GENIRACK_ILO_PASSWORD'}) &&
	    $configvars{'GENIRACK_ILO_PASSWORD'} ne "" &&
	    ! -e $ILOPASSWORD) {
	    CreateFileFatal($ILOPASSWORD, $configvars{'GENIRACK_ILO_PASSWORD'});
	    ExecQuietFatal("$CHMOD 400 $ILOPASSWORD");
	}

	#
	# A reasonable default image.
	#
	Phase "sitevar", "Setting sitevar $PGOSSITEVAR", sub {
	    my $osinfo = OSinfo->LookupByName($DEFAULTOSID);
	    PhaseFail("Could not look up $DEFAULTOSID osid")
		if (!defined($osinfo));
	    
	    ExecQuietFatal("$PREFIX/sbin/setsitevar ".
			   "'$PGOSSITEVAR' '$DEFAULTOSID'");
	};
	
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	#
	# Create a clone of emulab-devel while we are close to the server.
	#
	Phase "cloning1", "Cloning emulab-devel repository", sub {
	    DoneIfExists("$PREFIX/src/emulab-devel");
	    ExecQuietFatal("cd $PREFIX/src; ".
			   "    git clone $EMULABDEVEL emulab-devel");
	};
	Phase "cloning2", "Cloning emulab-stable repository", sub {
	    DoneIfExists("$PREFIX/src/emulab-stable");
	    ExecQuietFatal("cd $PREFIX/src; ".
			   "    git clone $EMULABSTABLE emulab-stable");
	};

158
159
160
161
162
163
164
165
166
167
168
169
	#
	# Also grab the port source while close to the server.
	#
	Phase "portsrc", "Getting port source tarball", sub {
	    DoneIfExists("$PREFIX/ports.tar.gz");
	    FetchFileFatal($PORTSRC, "$PREFIX/ports.tar.gz");
	};
	Phase "ports", "Unpacking port source tarball", sub {
	    DoneIfExists("$PREFIX/ports/Mk");
	    ExecQuietFatal("cd $PREFIX; $TAR zxf $PREFIX/ports.tar.gz");
	};
	
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
	#
	# Shutdown the testbed for this.
	#
	Phase "shutdown", "Shutting down the testbed", sub {
	    PhaseSkip("not running")
		if (!CheckDaemonRunning("stated"));
	    ExecQuietFatal("$TESTBED_CONTROL shutdown");
	};

	#
	# Need to remove the ELABINELAB flag.
	#
	my $OLDDEFSFILE = "$main::TOP_SRCDIR/defs-elabinelab";
	my $NEWDEFSFILE = "$main::TOP_SRCDIR/defs-genirack";
	
	Phase "elabinelab", "Removing ELABINELAB from defs file", sub {
	    DoneIfExists($NEWDEFSFILE);
	    ExecQuietFatal("cat $OLDDEFSFILE | ".
			   "   sed -e 's/^ELABINELAB/#ELABINELAB/' ".
			   "   > $NEWDEFSFILE");
	};

	#
	# Build and install software without ELABINELAB defined.
	#
	Phase "Software", "Rebuilding and Reinstalling Software", sub {
	    Phase "cleaning", "Cleaning (please be patient)", sub {
		ExecQuietFatal("cd $TOP_OBJDIR; $GMAKE clean");
	    };
	    Phase "config", "Configuring (please be patient)", sub {
		ExecQuietFatal("cd $TOP_OBJDIR; ".
			       "   $main::TOP_SRCDIR/configure ".
			       "      --with-TBDEFS=$NEWDEFSFILE ".
			       "      --disable-windows");
	    };
	    Phase "building", "Building (please be patient)", sub {
		ExecQuietFatal("cd $TOP_OBJDIR; $GMAKE");
	    };
	    Phase "installing", "Installing (please be patient)", sub {
		ExecQuietFatal("cd $TOP_OBJDIR; $GMAKE boss-install");
	    };
	    Phase "postinstall", "Post Installing Testbed Software", sub {
		ExecQuietFatal("cd $TOP_OBJDIR; $GMAKE post-install");
	    };
	    Phase "rc.testbed", "Installing testbed RC scripts", sub {
		ExecQuietFatal("$GMAKE -C $TOP_OBJDIR/rc.d install");
	    };
	};
218
219

	#
Leigh B Stoller's avatar
Leigh B Stoller committed
220
	# Add /etc/hosts entries for the switches. 
221
222
223
224
	#
	Phase "etchosts", "Adding hosts entries for switches", sub {
	    my @strings = ();
	    
Leigh B Stoller's avatar
Leigh B Stoller committed
225
226
	    foreach my $switch (keys(%HOSTNAMES)) {
		my $ip = $HOSTNAMES{$switch};
227
228
229
230
231
		push(@strings, "$ip\t$switch");
	    }
	    DoneIfEdited($HOSTS);
	    AppendToFileFatal($HOSTS, @strings);
	};
Leigh B Stoller's avatar
Leigh B Stoller committed
232
233
234
235
236
237
238
239
240
241
242
243

	#
	# Also need to do:
	#
	# * Comment out all the natd stuff.
	# * Comment out all static route lines except frisbee.
	# * Comment out firewall stuff.
	# * Comment out xn0 alias.
	# * Set the xn0 config to the real config.
	# * Set the defaultrouter to the real one. 
	
	Phase "rcconf", "Updating rcconf for actual boot", sub {
244
245
246
	    my @strings = ();
	    my @ifaces  = ();

Leigh B Stoller's avatar
Leigh B Stoller committed
247
	    # /etc/rc.conf entries for the switches.
248
249
250
251
252
	    foreach my $iface (keys(%INTERFACES)) {
		my $line = $INTERFACES{$iface};
		push(@strings, "ifconfig_${iface}=\"$line\"");
		push(@ifaces, $iface);
	    }
Leigh B Stoller's avatar
Leigh B Stoller committed
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
	    push(@strings,
		 "network_interfaces=\"\$network_interfaces @ifaces\"");
	    push(@strings,
		 "ifconfig_xn0=\"inet ". $configvars{"GENIRACK_BOSSIP"} . 
		 " netmask " . $configvars{"GENIRACK_NETMASK"} . " -tso\"");
	    # Jail network.
	    push(@strings,
		 "ifconfig_xn0_alias0=\"inet 172.17.254.254 ".
		 "netmask 255.240.0.0\"");
	    # Actual default router.
	    push(@strings,
		 "defaultrouter=\"" . $configvars{"GENIRACK_ROUTER"} . "\"");
	    # Going to lose all static routes below, so add this back.
	    push(@strings,
		 "static_routes=\"\$static_routes frisbee\"");

	    #
	    # Okay, we want to comment out a bunch of stuff.
	    #
	    my @patterns = (qr(^natd),
			    qr(^firewall),
			    qr(^defaultrouter),
			    qr(^static_routes),
			    qr(^route_genirack),
			    qr(^route_outerboss),
			    qr(^route_vnodes),
			    qr(^ifconfig_xn0),
			    qr(^ifconfig_xn0_alias0),
	    );
282
	    DoneIfEdited($RCCONF);
Leigh B Stoller's avatar
Leigh B Stoller committed
283
	    UpdateFileFatal($RCCONF, \@patterns, @strings);
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
	};

	#
	# Add in the switch stuff which is all hard coded sql.
	#
	Phase "sql", "Adding switch goo to the database", sub {
	    ExecQuietFatal("$MYSQL $DBNAME < $SWITCHSQL");
	};

	#
	# Update the DB with the switch community string.
	#
	if (exists($configvars{'GENIRACK_COMMUNITY'})) {
	    my $safe_password = DBQuoteSpecial($configvars{'GENIRACK_COMMUNITY'});
	    DBQueryWarn("update switch_stack_types set ".
			"snmp_community=$safe_password")
		or PhaseFail("Could not set snmp community strings");
	}

	#
	# Shutdown DHCP and fix the dynamic range that rc.mkelab changed.
	# This is okay since the subnet is different then Emulab.
	#
	Phase "dhcpd", "Fixing dhcpd configuration", sub {
	    ExecQuietFatal("/bin/rm -f $DHCPD_TEMPLATE");
	    ExecQuietFatal("cd $TOP_OBJDIR/dhcpd; $GMAKE install");
	    ExecQuietFatal("$DHCPD_MAKECONF -i");
	};
312
313
314
315
316
317
318
319
	PhaseSucceed("Rack Setup Done");
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: