images 4.36 KB
Newer Older
1
2
3
4
5
6
#
# 
#
use strict;
use libinstall;
use installvars;
7
use EmulabConstants;
8
use OSImage;
9
use OSinfo;
10

11
my $UTAHURL       = "http://www.emulab.net/downloads";
12
my $DESCRIPTORS   = "$TOP_SRCDIR/install/descriptors-v4.xml";
Leigh B Stoller's avatar
Leigh B Stoller committed
13
my $GENDEV        = "$TOP_SRCDIR/install/descriptors-gendev.xml";
14
my @MBRS          = ("emulab-mbr.dd", "emulab-mbr2.dd", "emulab-mbr3.dd");
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
my $DEFAULTIMAGE  = "UBUNTU14-64-STD";

#
# We now use image import.
#
my %STDIMAGES     = (
    $DEFAULTIMAGE      => "https://www.emulab.net/image_metadata.php?uuid=0a29c738-32b3-11e4-b30a-001143e453fe",
    "CENTOS71-64-STD"  => "https://www.emulab.net/image_metadata.php?uuid=c74d9fc1-e54b-11e4-97ea-38eaa71273fa",
    "FBSD102-64-STD"   => "https://www.emulab.net/image_metadata.php?uuid=57e6bf53-4376-11e5-bf03-38eaa71273fa",
    "XEN44-64-STD"     => "https://www.emulab.net/image_metadata.php?uuid=6f5e573e-83f3-11e5-bf03-38eaa71273fa",
);

#
# Old style mappings, but probably still in use someplace.
#
my %STDMAPPINGS = (
    "RHL-STD"   => $DEFAULTIMAGE,
    "FBSD-STD"  => "FBSD102-64-STD",
);
34
35
36
37
38
39
40
41
42

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

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

43
    Phase "IDs", "Setting up Images and OSs", sub {
44
	if ($PROTOGENI_GENIRACK) {
45
46
	    require NodeType;
	    
47
48
49
50
51
52
53
	    #
	    # 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";
54
	    my $NODETYPEXML  = "$TOP_SRCDIR/install/genirack/nodetype.xml";
55
56
57
58
	    
	    Phase "nodetype", "Creating Protogeni nodetype", sub {
		my $nodetype = NodeType->Lookup($NODETYPE);
		PhaseSkip("already created")
Leigh B Stoller's avatar
Leigh B Stoller committed
59
		    if (defined($nodetype));
60
		ExecQuietFatal("$SUDO -u $PROTOUSER ".
61
			       "         $WAP $CREATETYPE $NODETYPEXML");
62
63
64
	    };
	}
	
65
	#
66
67
	# Load up the initial descriptors. 
	# Load up the images from boss.
68
	#
69
	Phase "descriptors", "Loading the Image and OS IDs", sub {
70
71
	    ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			   "   $SUDO -u $PROTOUSER $WAP ".
72
			   "   perl load-descriptors -a $DESCRIPTORS");
73
	};
74
	Phase "gendev", "Loading additional OS IDs", sub {
Leigh B Stoller's avatar
Leigh B Stoller committed
75
76
77
78
	    ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			   "   $SUDO -u $PROTOUSER $WAP ".
			   "   perl load-descriptors $GENDEV");
	};
79
80
	foreach my $imagename (keys(%STDIMAGES)) {
	    my $url = $STDIMAGES{$imagename};
81
82
	    
	    Phase "$imagename", "Fetching $imagename. Patience!", sub {
83
		my $image = OSImage->Lookup(TBOPSPID(), $imagename);
84
85
		PhaseSkip("already fetched")
		    if (defined($image));
86
87

		ExecQuietFatal("$SUDO -u $PROTOUSER ".
88
			       "         $WAP $IMAGEIMPORT -g '$url'");
89
	    };
90
91
92
93
94
95
96
97
98
99
	}
	foreach my $mbr (@MBRS) {
	    my $localfile = "$PREFIX/images/$mbr";
	    my $url       = "$UTAHURL/$mbr";
	    
	    Phase "$mbr", "Fetching $mbr.", sub {
		DoneIfExists($localfile);
		FetchFileFatal($url, $localfile);
	    };
	}
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
	foreach my $osname (keys(%STDMAPPINGS)) {
	    my $nextosname = $STDMAPPINGS{$osname};

	    Phase "$osname", "Mapping $osname to $nextosname", sub {
		my $osinfo = OSinfo->LookupByName($osname);
		PhaseFail("Could not look up $osname osid")
		    if (!defined($osinfo));
		PhaseSkip("already set")
		    if (defined($osinfo->nextosid()));
	    
		my $nextosinfo = OSinfo->LookupByName($nextosname);
		PhaseFail("Could not look up $nextosname osid")
		    if (!defined($nextosinfo));
		$osinfo->SetNextOS($nextosinfo) == 0
		    or PhaseFail("Could not set the nextosid");
	    };
	}
	
118
119
	#
	# The sitevar is how the reload daemon knows what to reload nodes
120
	# with, by default.
121
122
123
	#
	Phase "sitevar", "Setting sitevar $DEFAULTIMAGESITEVAR", sub {
	    ExecQuietFatal("$PREFIX/sbin/setsitevar ".
124
			   "'$DEFAULTIMAGESITEVAR' '$DEFAULTIMAGE'");
125
	};
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

	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");
	    };
	}
	
142
	PhaseSucceed("done")
143
144
145
146
147
148
149
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: