use the deployment tag to get the repo directory.
[nodeconfig.git] / yum / 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 $deployment = "";
44 if ( ! isset($_REQUEST['node_id'])) {
45   print "# Warning : node_id not set\n";
46  } else {
47   $node_id=intval($_REQUEST['node_id']);
48   echo "# node_id $node_id \n";
49   # compute nodegroups
50   $nodes = $adm->GetNodes(array('node_id'=>$node_id));
51   $nodegroup_ids = $nodes[0]['nodegroup_ids'];
52   $nodegroups = $adm->GetNodeGroups($nodegroup_ids);
53   foreach ($nodegroups as $nodegroup) {
54     $nodegroup_name = $nodegroup['groupname'];
55     $nodegroup_names [] = $nodegroup_name;
56     echo "# in nodegroup $nodegroup_name \n" ;
57   }
58   $node_tag_ids = $nodes[0]['node_tag_ids'];
59   $node_tags = $adm->GetNodeTags($node_tag_ids);
60   foreach ($node_tags as $node_tag) {
61     if ($node_tag['tagname'] == 'deployment') {
62       $deployment = $node_tag['value'];
63       break;
64     }
65   }
66  }
67
68 $topdir=$_SERVER['DOCUMENT_ROOT'] . "/install-rpms/";
69 $topurl="https://$PLC_BOOT_HOST" . "/install-rpms/";
70
71 if ($deployment == 'alpha') {
72   $topdir = $topdir . "alpha/";
73   $topurl = $topurl . "alpha/";
74 }
75
76 # locate the planetlab repo for this node family & nodegroup
77 $repo=NULL;
78 foreach ($nodegroup_names as $nodegroup_name) {
79   $groupdir = "$nodefamily-$nodegroup_name";
80   # have we got a repo like /install-rpms/planetlab-i386-alpha ?
81   echo "# trying " . $topdir . $groupdir . "\n";
82   if (is_dir (realpath($topdir . $groupdir))) {
83     $repo=array($pldistro, $groupdir, "$PLC_NAME $nodefamily $nodegroup_name");
84     break;
85   }
86 }
87
88 # if not found yet
89 if ( ! $repo) {
90   echo "# trying default " . $topdir . $nodefamily . "\n";
91   if (is_dir (realpath($topdir . $nodefamily))) {
92     $repo = array($pldistro, $nodefamily, "$PLC_NAME $nodefamily regular");
93   }
94  }
95
96 # default: if we're here it's probably very wrong
97 if ( ! $repo) {
98   echo "# WARNING: could not find a decent planetlab repo for this node\n";
99   $repo = array ($pldistro, "planetlab", "default probably wrong");
100   # don't define the repo in this case
101   exit;
102  }
103
104 list( $id, $dir, $name) = $repo;
105
106 echo <<< __PLC_REPO__
107 [$id]
108 name=$name
109 baseurl=$topurl/$dir
110 gpgcheck=$gpgcheck
111
112 __PLC_REPO__;
113
114 ?>