220 3.72 KB
Newer Older
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
#
# Add Emulab Features.
#
use strict;
use libdb;
use EmulabFeatures;
use EmulabConstants;
use Project;

sub DoUpdate($$$)
{
    my ($dbhandle, $dbname, $version) = @_;

    DBQueryFatal("CREATE TABLE `emulab_features` ( ".
		 " `feature` varchar(64) NOT NULL default '', ".
		 " `description` mediumtext, ".
		 " `added` datetime NOT NULL, ".
		 " `enabled` tinyint(1) NOT NULL default '0', ".
		 " `disabled` tinyint(1) NOT NULL default '0', ".
		 " PRIMARY KEY (`feature`) ".
		 ") ENGINE=MyISAM DEFAULT CHARSET=latin1")
	if (! DBTableExists("emulab_features"));

    DBQueryFatal("CREATE TABLE `group_features` ( ".
		 " `feature` varchar(64) NOT NULL default '', ".
		 " `added` datetime NOT NULL, ".
		 " `pid_idx` mediumint(8) unsigned NOT NULL default '0', ".
		 " `gid_idx` mediumint(8) unsigned NOT NULL default '0', ".
		 " `pid` varchar(12) NOT NULL default '', ".
		 " `gid` varchar(12) NOT NULL default '', ".
		 " PRIMARY KEY (`feature`,`gid_idx`) ".
		 ") ENGINE=MyISAM DEFAULT CHARSET=latin1")
	if (! DBTableExists("group_features"));

    DBQueryFatal("CREATE TABLE `user_features` ( ".
		 " `feature` varchar(64) NOT NULL default '', ".
		 " `added` datetime NOT NULL, ".
		 " `uid_idx` mediumint(8) unsigned NOT NULL default '0', ".
		 " `uid` varchar(8) NOT NULL default '', ".
		 "PRIMARY KEY (`feature`,`uid_idx`) ".
		 ") ENGINE=MyISAM DEFAULT CHARSET=latin1")
	if (! DBTableExists("user_features"));

    DBQueryFatal("CREATE TABLE `experiment_features` ( ".
		 " `feature` varchar(64) NOT NULL default '', ".
		 " `added` datetime NOT NULL, ".
		 " `exptidx` int(11) NOT NULL default '0', ".
		 " `pid` varchar(12) NOT NULL default '', ".
		 " `eid` varchar(32) NOT NULL default '', ".
		 "PRIMARY KEY (`feature`,`exptidx`) ".
		 ") ENGINE=MyISAM DEFAULT CHARSET=latin1")
	if (! DBTableExists("experiment_features"));

    my $emulabops = Project->Lookup("emulab-ops");
    my $testbed   = Project->Lookup("testbed");

    #
    # These are the features in production code at this time.
    #
    my $feature = EmulabFeatures->Lookup("SyncVlans");
    if (!defined($feature)) {
	$feature = EmulabFeatures->Create("SyncVlans",
			"Use SyncVlansFromTables() instead of ".
			"DoVlansFromTables() in snmpit, which reduces ".
			"churning on the switches.");
    }
    return -1
	if (!defined($feature));
    $feature->Enable($emulabops) == 0
	or return -1 if (defined($emulabops));
    
    $feature = EmulabFeatures->Lookup("NewMapper");
    if (!defined($feature)) {
	$feature = EmulabFeatures->Create("NewMapper",
			"Use mapper instead of assign_wrapper. ".
			"The mapper replaces assign_wrapper.");
    }
    return -1
	if (!defined($feature));
    $feature->Enable($emulabops) == 0
	or return -1 if (defined($emulabops));
    $feature->Enable($testbed) == 0
	or return -1 if (defined($testbed));
    
    $feature = EmulabFeatures->Lookup("NewOsSetup");
    if (!defined($feature)) {
	$feature = EmulabFeatures->Create("NewOsSetup",
			  "Use os_setup_new instead of os_setup. ".
			  "os_setup_new will eventually replace os_setup.");
    }
    return -1
	if (!defined($feature));
    $feature->Enable($emulabops) == 0
	or return -1 if (defined($emulabops));
    $feature->Enable($testbed) == 0
	or return -1 if (defined($testbed));

    #
    # Utah only ...
    #
    if ($EmulabConstants::MAINSITE) {
	foreach my $projname ("tbres", "geni", "utahstud", "ClemsonGENI",
103 104
			      "ResiliNets", "gec8tutorial",
			      "gec9tutorial", "GPO-GENI") {
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

	    my $project = Project->Lookup($projname);
	    next
		if (!defined($project));

	    foreach my $fname ("NewMapper", "NewOsSetup", "SyncVlans") {
		$feature = EmulabFeatures->Lookup($fname);
		return -1
		    if (!defined($feature));

		$feature->Enable($project) == 0
		    or return -1;
	    }
	}
    }
    return 0;
}
1;