(*) slices list has links towards the slice page with the details area closed and...
[plewww.git] / planetlab / tags / tag.php
1 <?php
2
3 // $Id$
4
5 // Require login
6 require_once 'plc_login.php';
7
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api;
11
12 // Print header
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
15
16 // Common functions
17 require_once 'plc_functions.php';
18 require_once 'linetabs.php';
19 require_once 'details.php';
20 require_once 'table.php';
21 require_once 'form.php';
22 require_once 'toggle.php';
23
24 // -------------------- 
25 // recognized URL arguments
26 $tag_type_id=intval($_GET['id']);
27 if ( ! $tag_type_id ) { 
28   plc_error('Malformed URL - id not set'); 
29   return;
30  }
31
32 // --- decoration
33 $title="Tag Type";
34 $tabs=array();
35 $tabs []= tab_tags();
36
37 // -------------------- 
38 $tag_types= $api->GetTagTypes( array( $tag_type_id ) );
39 $tag_type=$tag_types[0];
40   
41 $tagname=$tag_type['tagname'];
42 $min_role_id= $tag_type['min_role_id'];
43 $description= $tag_type['description'];
44 $category=$tag_type['category'];
45
46 // where is it used 
47 $filter=array('tag_type_id'=>$tag_type_id);
48 $node_tags=$api->GetNodeTags($filter);
49 $interface_tags=$api->GetInterfaceTags($filter);
50 // split slice tags into 3 families, whether this applies to the whole slice, or a nodegroup, or a node
51 // using filters for this purpose does not work out very well, maybe a bug in the filter stuff
52 // anyway this is more efficient, and we compute the related node(groups) in the same pass
53 $slice_tags=$api->GetSliceTags(array_merge($filter));
54 $count_slice=0;
55 $count_nodegroup=0;
56 $nodegroup_ids=array();
57 $count_node=0;
58 $node_ids=array();
59 foreach ($slice_tags as $slice_tag) {
60   if ($slice_tag['node_id']) {
61     $node_ids []= $slice_tag['node_id'];
62     $count_node += 1;
63   } else if ($slice_tag['nodegroup_id']) {
64     $nodegroup_ids []= $slice_tag['nodegroup_id'];
65     $count_nodegroup += 1;
66   } else {
67     $count_slice += 1;
68   }
69 }
70
71 $nodes=$api->GetNodes($node_ids,array('hostname','node_id'));
72 $node_hash=array();
73 foreach ($nodes as $node) $node_hash[$node['node_id']]=$node;
74 $nodegroups=$api->GetNodeGroups($nodegroup_ids,array('groupname','nodegroup_id'));
75 $nodegroup_hash=array();
76 foreach ($nodegroups as $nodegroup) $nodegroup_hash[$nodegroup['nodegroup_id']]=$nodegroup;
77
78
79 drupal_set_title("Details for tag type $tagname");
80 plekit_linetabs($tabs);
81
82 // ----------
83 $toggle = new PlekitToggle ('details','Details');
84 $toggle->start();
85 $can_update=plc_is_admin();
86 $details=new PlekitDetails ($can_update);
87
88 $details->form_start(l_actions(),array("action"=>"update-tag-type",
89                                        "tag_type_id"=>$tag_type_id));
90 $details->start();
91 $details->th_td("Name",$tagname,"tagname");
92 $details->th_td("Category",$category,"category",array('width'=>30));
93 $details->th_td("Description",$description,"description",array('width'=>40));
94
95 if ($can_update) {
96 // select the option corresponding with min_role_id
97   $selectors = $details->form()->role_selectors($api,"",$min_role_id);
98   $select_field = $details->form()->select_html("min_role_id",$selectors);
99   // xxx would need to turn role_id into role name
100   $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id));
101  } else {
102   $details->th_td("Min role",$min_role_id);
103  }
104 if ($can_update) 
105   $details->tr_submit('update-tag-type',"Update tag type");
106
107 $details->space();
108 $details->th_td("Used in nodes",count($node_tags));
109 $details->th_td("Used in interfaces",count($interface_tags));
110 $details->th_td("Used in slices/node",$count_node);
111 $details->th_td("Used in slices/nodegroup",$count_nodegroup);
112 $details->th_td("Used in slices",$count_slice);
113
114 $details->end();
115 $details->form_end();
116 $toggle->end();
117
118 // common options for tables below
119 $table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10);
120
121 // xxx could outline values corresponding to a nodegroup
122 if (count ($node_tags)) {
123   $toggle=new PlekitToggle('tag_nodes',"Nodes");
124   $toggle->start();
125   $table=new PlekitTable ("tag_nodes",array("Hostname"=>"string","value"=>"string"),0,$table_options);
126   $table->start();
127   foreach ($node_tags as $node_tag) {
128     $table->row_start();
129     $table->cell(href(l_node($node_tag['node_id']),$node_tag['hostname']));
130     $table->cell($node_tag['value']);
131     $table->row_end();
132   }
133   $table->end();
134   $toggle->end();
135  }
136
137 if (count ($interface_tags)) {
138   $toggle=new PlekitToggle('tag_interfaces',"Interfaces");
139   $toggle->start();
140   $table=new PlekitTable ("tag_interfaces",array("IP"=>"IPAddress","value"=>"string"),0,$table_options);
141   $table->start();
142   foreach ($interface_tags as $interface_tag) {
143     $table->row_start();
144     $table->cell(href(l_interface($interface_tag['interface_id']),$interface_tag['ip']));
145     $table->cell($interface_tag['value']);
146     $table->row_end();
147   }
148   $table->end();
149   $toggle->end();
150  }
151
152 if (count ($slice_tags)) {
153   $toggle=new PlekitToggle('tag_slices',"Slice tags");
154   $toggle->start();
155   $headers=array();
156   $headers["slice"]='string';
157   $headers["value"]='string';
158   $headers["node"]='string';
159   $headers["nodegroup"]='string';
160   $table=new PlekitTable ("tag_slices",$headers,0,$table_options);
161   $table->start();
162   foreach ($slice_tags as $slice_tag) {
163     $table->row_start();
164     $table->cell(href(l_slice($slice_tag['slice_id']),$slice_tag['name']));
165     $table->cell($slice_tag['value']);
166
167     $node_text="all";
168     if ($slice_tag['node_id']) {
169       $node_id=$slice_tag['node_id'];
170       $node=$node_hash[$node_id];
171       $node_text=l_node_obj($node);
172     }
173     $table->cell($node_text);
174
175     $nodegroup_text="all";
176     if ($slice_tag['nodegroup_id']) {
177       $nodegroup_id=$slice_tag['nodegroup_id'];
178       $nodegroup=$nodegroup_hash[$nodegroup_id];
179       $nodegroup_text=l_nodegroup_obj($nodegroup);
180     }
181     $table->cell($nodegroup_text);
182
183     $table->row_end();
184   }
185   $table->end();
186   $toggle->end();
187  }
188
189 //plekit_linetabs ($tabs,"bottom");
190
191 // Print footer
192 include 'plc_footer.php';
193
194 ?>