should have been part of previous change
[nodeconfig.git] / PlanetLabConf / myplc.repo.php
1 <?php
2 //
3 // part of yum config on nodes
4 //
5 // Thierry Parmentelat 
6 // Copyright (C) 2008 INRIA
7 //
8 // $Id: myplc.repo.php 9818 2008-07-04 07:54:06Z thierry $
9 //
10
11 // For PLC_NAME and PLC_BOOT_HOST
12 include('plc_config.php');
13
14 $PLC_NAME = PLC_NAME;
15 $PLC_BOOT_HOST = PLC_BOOT_HOST;
16
17 // Get admin API handle
18 require_once 'plc_api.php';
19 global $adm;
20
21 if (isset($_REQUEST['gpgcheck'])) {
22   $gpgcheck = $_REQUEST['gpgcheck'];
23 } else {
24   $gpgcheck = 0;
25 }
26
27 # get node family
28 if ( ! isset($_REQUEST['slicefamily'])) {
29   # legacy : use the old naming scheme
30   $nodefamily="planetlab";
31   $pldistro="planetlab";
32  } else {
33   $slicefamily = $_REQUEST['slicefamily'];
34   echo "# slicefamily $slicefamily \n" ;
35   list( $pldistro, $fcdistro, $arch) = split ("-", $slicefamily);
36   $nodefamily = "$pldistro-$arch";
37   echo "# nodefamily $nodefamily \n" ;
38  }
39
40 # the nodegroups the node is part of
41 $nodegroup_names=array();
42
43 if ( ! isset($_REQUEST['node_id'])) {
44   print "# Warning : node_id not set\n";
45  } else {
46   $node_id=intval($_REQUEST['node_id']);
47   echo "# node_id $node_id \n";
48   # compute nodegroups
49   $nodes = $adm->GetNodes(array('node_id'=>$node_id));
50   $nodegroup_ids = $nodes[0]['nodegroup_ids'];
51   $nodegroups = $adm->GetNodeGroups($nodegroup_ids);
52   foreach ($nodegroups as $nodegroup) {
53     $nodegroup_name = $nodegroup['name'];
54     $nodegroup_names [] = $nodegroup_name;
55     echo "# in nodegroup $nodegroup_name \n" ;
56   }
57  }
58
59 $topdir=$_SERVER['DOCUMENT_ROOT'] . "/install-rpms/";
60 $topurl="https://$PLC_BOOT_HOST" . "/install-rpms/";
61
62
63 # locate the planetlab repo for this node family & nodegroup
64 $repo=NULL;
65 foreach ($nodegroup_names as $nodegroup_name) {
66   $groupdir = "$nodefamily-$nodegroup_name";
67   # have we got a repo like /install-rpms/planetlab-i386-alpha ?
68   echo "# trying " . $topdir . $groupdir . "\n";
69   if (is_dir (realpath($topdir . $groupdir))) {
70     $repo=array($pldistro, $groupdir, "$PLC_NAME $nodefamily $nodegroup_name");
71     break;
72   }
73 }
74
75 # if not found yet
76 if ( ! $repo) {
77   echo "# trying default " . $topdir . $nodefamily . "\n";
78   if (is_dir (realpath($topdir . $nodefamily))) {
79     $repo = array($pldistro, $nodefamily, "$PLC_NAME $nodefamily regular");
80   }
81  }
82
83 # default: if we're here it's probably very wrong
84 if ( ! $repo) {
85   echo "# WARNING: could not find a decent planetlab repo for this node\n";
86   $repo = array ($pldistro, "planetlab", "default probably wrong");
87   # don't define the repo in this case
88   exit;
89  }
90
91 list( $id, $dir, $name) = $repo;
92
93 echo <<< __PLC_REPO__
94 [$id]
95 name=$name
96 baseurl=$topurl/$dir
97 gpgcheck=$gpgcheck
98
99 __PLC_REPO__;
100
101 ?>