Add deployment mechanism for hotfixes to nodes in chosen nodegroups.
[nodeconfig.git] / PlanetLabConf / hotfixes.php
1 <?php 
2
3 /*
4     hotfixes.php -- 
5         The purpose is to provide a mechanism for deploying source fixes 
6         faster than, or instead of, waiting for rpm updates.
7
8         The machanism is via tar files copied from PlanetLabConf/hotfixes/* to
9         the root filesystem of machines in a given nodegroup.
10
11     Notes:
12         Nodes call this script via ConfFiles; the tar file for the first 
13         matching nodegroup is returned to the node.
14 */
15
16 require_once 'plc_api.php';
17 global $adm;
18 if ( isset($_REQUEST['debug']) ) {
19     $debug = true;
20 }
21
22 function logit($str) 
23 {
24     global $debug;
25     if ( $debug == true ) 
26     {
27         print $str . "\n";
28     }
29 }
30
31 logit("nodeid check");
32 $ng_names = array();
33
34 if ( isset($_REQUEST['node_id']) ) {
35   logit("getnodes");
36   $nodes = $adm->GetNodes(array(intval($_REQUEST['node_id'])));
37   if (!empty($nodes)) {
38     $node = $nodes[0];
39   } else {
40     exit(1);
41   }
42   if ( count($node['nodegroup_ids']) > 0 )
43   {
44       // collect a list of all nodegroup names for this node.
45       foreach ( $node['nodegroup_ids'] as $ng_id ) {
46         $ngs = $adm->GetNodeGroups(array('nodegroup_id' => $ng_id));
47         if (!empty($ngs)) {
48             logit($ngs[0]['groupname']);
49             $ng_names[] = $ngs[0]['groupname'];
50         }
51       }
52   } else {
53     $ng_names[] = "default";
54   }
55 }
56
57 foreach ( $ng_names as $name ) 
58 {
59     logit("name: " . $name);
60     // check that directory exists
61     $file= "hotfixes/$name.tar";
62     $stat = stat($file);
63     if ( !empty ($stat) )
64     {
65         // send to client
66         readfile($file);
67         // stop after the first match.
68         exit(1);
69     } 
70 }
71
72 ?>