images 4.29 KB
Newer Older
1
2
3
4
5
6
#
# 
#
use strict;
use libinstall;
use installvars;
7
use EmulabConstants;
8

9
10
my $UTAHURL       = "http://www.emulab.net/downloads";
my $DESCRIPTORS   = "$TOP_SRCDIR/install/descriptors-v3.xml";
Leigh B Stoller's avatar
Leigh B Stoller committed
11
my $GENDEV        = "$TOP_SRCDIR/install/descriptors-gendev.xml";
12
my @STDIMAGES     = ("FBSD83-STD", "UBUNTU12-64-STD");
13
my @MBRS          = ("emulab-mbr.dd", "emulab-mbr2.dd", "emulab-mbr3.dd");
14
my $STDIMAGESURL  = "$UTAHURL/images-STD";
15
16
17
18
19
20
21
22
23

sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;

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

24
    # Others for the rack.
25
    if ($PROTOGENI_GENIRACK) {
26
27
	push(@STDIMAGES, "UBUNTU14-64-STD");
	push(@STDIMAGES, "FBSD100-64-STD");
28
    }
29
30
31
    else {
	$DESCRIPTORS = "$TOP_SRCDIR/install/descriptors-v4.xml";
    }
32

33
    Phase "IDs", "Setting up Images and OSs", sub {
34
	if ($PROTOGENI_GENIRACK) {
35
36
	    require NodeType;
	    
37
38
39
40
41
42
43
	    #
	    # Load up the nodetype. It will be the same on every machine,
	    # and if we do it before loading the descriptors, then we
	    # do not have to go back and change the type mappings.
	    #
	    my $NODETYPE     = "dl360";
	    my $CREATETYPE   = "$PREFIX/bin/editnodetype";
44
	    my $NODETYPEXML  = "$TOP_SRCDIR/install/genirack/nodetype.xml";
45
46
47
48
	    
	    Phase "nodetype", "Creating Protogeni nodetype", sub {
		my $nodetype = NodeType->Lookup($NODETYPE);
		PhaseSkip("already created")
Leigh B Stoller's avatar
Leigh B Stoller committed
49
		    if (defined($nodetype));
50
		ExecQuietFatal("$SUDO -u $PROTOUSER ".
51
			       "         $WAP $CREATETYPE $NODETYPEXML");
52
53
54
	    };
	}
	
55
	#
56
57
	# Load up the initial descriptors. 
	# Load up the images from boss.
58
	#
59
	Phase "descriptors", "Loading the Image and OS IDs", sub {
60
61
	    ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			   "   $SUDO -u $PROTOUSER $WAP ".
62
			   "   perl load-descriptors -a $DESCRIPTORS");
63
	};
64
	Phase "gendev", "Loading additional OS IDs", sub {
Leigh B Stoller's avatar
Leigh B Stoller committed
65
66
67
68
	    ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			   "   $SUDO -u $PROTOUSER $WAP ".
			   "   perl load-descriptors $GENDEV");
	};
69
70
71
72
73
74
75
76
	foreach my $imagename (@STDIMAGES) {
	    my $localfile = "$PREFIX/images/${imagename}.ndz";
	    my $url       = "$STDIMAGESURL/${imagename}.ndz";
	    
	    Phase "$imagename", "Fetching $imagename. Patience!", sub {
		DoneIfExists($localfile);
		FetchFileFatal($url, $localfile);
	    };
Leigh B Stoller's avatar
Leigh B Stoller committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
	    
	    $localfile = "$PREFIX/images/${imagename}.xml";
	    $url       = "$STDIMAGESURL/${imagename}.xml";
	    
	    Phase "${imagename}_xml", "Fetching $imagename metadata", sub {
		DoneIfExists($localfile);
		FetchFileFatal($url, $localfile);
	    };

	    Phase "${imagename}_load", "Loading the image descriptor.", sub {
		ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			       "   $SUDO -u $PROTOUSER $WAP ".
			       "   perl load-descriptors -a $localfile");
	    };
91
92
93
94
95

	    #
	    # XXX the metadata file may not contain any or all of the newer
	    # DB state. So we update the metadata using imagevalidate.
	    #
96
	    Phase "${imagename}_validate", "Validating DB info for image.",sub {
97
		my $iname = TBOPSPID() . "/" . $imagename;
98
99
		ExecQuietFatal("$SUDO -u $PROTOUSER ".
			       "$PREFIX/sbin/imagerelease -f -m $iname");
100
101
102
		ExecQuietFatal("$SUDO -u $PROTOUSER ".
			       "$PREFIX/sbin/imagevalidate -uq $iname");
	    };
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	}
	foreach my $mbr (@MBRS) {
	    my $localfile = "$PREFIX/images/$mbr";
	    my $url       = "$UTAHURL/$mbr";
	    
	    Phase "$mbr", "Fetching $mbr.", sub {
		DoneIfExists($localfile);
		FetchFileFatal($url, $localfile);
	    };
	}
	#
	# The sitevar is how the reload daemon knows what to reload nodes
	# with, by default. Now a comma separated list.
	#
	my $idlist = join(",", @STDIMAGES);
	
	Phase "sitevar", "Setting sitevar $DEFAULTIMAGESITEVAR", sub {
	    ExecQuietFatal("$PREFIX/sbin/setsitevar ".
			   "'$DEFAULTIMAGESITEVAR' '$idlist'");
	};
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

	if ($PROTOGENI_GENIRACK) {
	    #
	    # Load up second half of the nodetype, which defines the osids
	    # and images it needs, which has to be done after the above.
	    #
	    my $NODETYPE     = "dl360";
	    my $CREATETYPE   = "$PREFIX/bin/editnodetype";
	    my $NODETYPEXML  = "$TOP_SRCDIR/install/genirack/nodetypeB.xml";
	    
	    Phase "nodetype", "Creating Protogeni nodetype", sub {
		ExecQuietFatal("$SUDO -u $PROTOUSER ".
			       "         $WAP $CREATETYPE $NODETYPEXML");
	    };
	}
	
139
	PhaseSucceed("done")
140
141
142
143
144
145
146
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: