Added caching to clearadm
[clearscm.git] / clearadm / viewdetails.cgi
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: viewdetails.cgi,v $
6
7 View Details
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.11 $
20
21 =item Created:
22
23 Mon Oct 25 11:10:47 PDT 2008
24
25 =item Modified:
26
27 $Date: 2011/01/14 16:51:58 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage viewdetails.cgi: [-u|sage] [-r|egion <region>] -vi|ew <viewname>
34                         [-ve|rbose] [-d|ebug]
35
36  Where:
37    -u|sage:           Displays usage
38    -r|egion <region>: Region to use when looking for the view
39    -vi|ew<viewname>:  Name of view to display details for
40
41    -ve|rbose:         Be verbose
42    -d|ebug:           Output debug messages
43
44 =head2 DESCRIPTION
45
46 This script display the details for the given view
47
48 =cut
49
50 use strict;
51 use warnings;
52
53 use FindBin;
54 use Getopt::Long;
55 use CGI qw (:standard :cgi-lib *table start_Tr end_Tr);
56 use CGI::Carp 'fatalsToBrowser';
57
58 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
59
60 use Clearadm;
61 use ClearadmWeb;
62 use Clearcase;
63 use Clearcase::View;
64 use Clearcase::Views;
65 use Display;
66 use Utils;
67
68 my %opts = Vars;
69
70 my $subtitle = 'View Details';
71
72 if ($Clearcase::CC->region) {
73   $opts{region} ||= $Clearcase::CC->region;
74 } else {
75   $opts{region} ||= 'Clearcase not installed';
76 } # if
77
78 my $VERSION  = '$Revision: 1.11 $';
79   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
80
81 sub DisplayTable ($) {
82   my ($view) = @_;
83
84   my $permissions     = setField $view->owner_mode
85                       . setField $view->group_mode
86                       . setField $view->other_mode;
87   my $active          = ($view->active) ? 'YES' : 'NO';
88   my $gpath           = $view->gpath;
89
90   $gpath = font {-class => 'unknown'}, '&lt;no-gpath&gt;'
91     if $gpath eq '<no-gpath>';
92
93   display start_table {
94     -cellspacing    => 1,
95     -class          => 'main',
96   };
97
98   my $clearadm = Clearadm->new;
99
100   my %clearadmview = $clearadm->GetView($view->tag, $view->region);
101
102   display start_Tr;
103     display th {class => 'label'},              'Tag:';
104     display td {class => 'data', colspan => 3}, setField $view->tag;
105     display th {class => 'label'},              'Server:';
106     display td {class => 'data'}, a {
107       href => 'systemdetails.cgi?system=' . $view->shost
108     }, $view->shost;
109     display th {class => 'label'},               'Region:';
110     display td {class => 'data'},                 $view->region;
111   display end_Tr;
112
113   display start_Tr;
114     display th {class => 'label'},              'Properties:';
115     display td {class => 'data', colspan => 3}, $view->properties;
116     display th {class => 'label'},              'Text Mode:';
117     display td {class => 'data'},               $view->text_mode;
118     display th {class => 'label'},              'Permission:';
119     display td {class => 'data'},               $permissions;
120   display end_Tr;
121
122   display start_Tr;
123     display th {class => 'label'},              'Owner:';
124     display td {class => 'data', colspan => 3}, $view->owner;
125     display th {class => 'label'},              'Active:';
126     display td {class => 'data', colspan => 3}, $active;
127   display end_Tr;
128
129   display start_Tr;
130     display th {class => 'label'},              'Created by:';
131     display td {class => 'data', colspan => 3}, $view->created_by;
132     display th {class => 'label'},              'on:';
133     display td {class => 'data', colspan => 3}, $view->created_date;
134   display end_Tr;
135
136   display start_Tr;
137     display th {class => 'label'},              'CS Updated by:';
138     display td {class => 'data', colspan => 3}, $view->cs_updated_by;
139     display th {class => 'label'},              'on:';
140     display td {class => 'data', colspan => 3}, $view->cs_updated_date;
141   display end_Tr;
142
143   display start_Tr;
144     display th {class => 'label'},              'Global Path:';
145     display td {class => 'data', colspan => 7}, $gpath;
146   display end_Tr;
147
148   display start_Tr;
149     display th {class => 'label'},              'Access Path:';
150     display td {class => 'data', colspan => 7}, $view->access_path;
151   display end_Tr;
152
153   display start_Tr;
154     display th {class => 'label'},              'UUID:';
155     display td {class => 'data', colspan => 7}, $view->uuid;
156   display end_Tr;
157
158   display start_Tr;
159     display th {class => 'labelCentered', colspan => 10}, 'View Storage Pools';
160   display end_Tr;
161
162   my $image = $clearadmview{dbsmall}
163     ? "data:image/png;base64,$clearadmview{dbsmall}"
164     : "plotstorage.cgi?type=view&storage=db&tiny=1&tag=" . $view->tag;
165
166   display start_Tr;
167     display th {class => 'label'},                                'Database:';
168     display td {class => 'data', colspan => 3, align => 'center'}, a {href =>
169        "plot.cgi?type=view&storage=db&scaling=Day&points=7&region=" . $view->region . '&tag=' . $view->tag
170     }, img {
171       src    => $image,
172       border => 0,
173     };
174
175     $image = $clearadmview{privatesmall}
176       ? "data:image/png;base64,$clearadmview{privatesmall}"
177       : "plotstorage.cgi?type=view&storage=private&tiny=1&tag=" . $view->tag;
178
179     display th {class => 'label'},                                'Private:';
180     display td {class => 'data', colspan => 5, align => 'center'}, a {href =>
181        "plot.cgi?type=view&storage=private&scaling=Day&points=7&region=" . $view->region . '&tag=' . $view->tag
182     }, img {
183       src    => $image,
184       border => 0,
185     };
186   display end_Tr;
187
188   $image = $clearadmview{adminsmall}
189     ? "data:image/png;base64,$clearadmview{adminsmall}"
190     : "plotstorage.cgi?type=view&storage=admin&tiny=1&tag=" . $view->tag;
191
192   display start_Tr;
193     display th {class => 'label'},                                'Admin:';
194     display td {class => 'data', colspan => 3, align => 'center'}, a {href =>
195        "plot.cgi?type=view&storage=admin&scaling=Day&points=7&region=" . $view->region . '&tag=' . $view->tag
196     }, img {
197       src    => $image,
198       border => 0,
199     };
200
201     $image = $clearadmview{totalsmall}
202       ? "data:image/png;base64,$clearadmview{totalsmall}"
203       : "plotstorage.cgi?type=view&storage=total&tiny=1&tag=" . $view->tag;
204
205     display th {class => 'label'},                                'Total Space:';
206     display td {class => 'data', colspan => 5, align => 'center'}, a {href =>
207        "plot.cgi?type=view&storage=total&scaling=Day&points=7&region=" . $view->region . '&tag=' . $view->tag
208     }, img {
209       src    => $image,
210       border => 0,
211     };
212   display end_Tr;
213
214   display end_table;
215   
216   return
217 } # DisplayTable
218
219 sub DisplayRegion {
220   display start_form (action => 'viewdetails.cgi');
221
222   display 'Region ';
223
224   my ($defaultRegion, @regions) = ('', ('Clearcase not installed'));
225
226   display popup_menu (
227     -name     => 'region',
228     -values   => [@regions],
229     -default  => $defaultRegion,
230     -onchange => 'submit();',
231   );
232
233   display submit (
234     -value => 'Go',
235   );
236
237   display end_form;
238   
239   return
240 } # DisplayRegion
241
242 sub DisplayViews ($) {
243   my ($region) = @_;
244
245   my $views = Clearcase::Views->new ($region);
246   my @views = $views->views;
247
248   unless (@views) {
249     push @views, 'No Views';
250   } # unless
251
252   display start_form (action => 'viewdetails.cgi');
253
254   display 'Region ';
255
256   display popup_menu (
257     -name     => 'region',
258     -values   => [$Clearcase::CC->regions],
259     -default  => $region,
260     -onchange => 'submit();',
261   );
262
263   display b ' View: ';
264
265   display popup_menu (
266      -name     => 'view',
267      -values   => \@views,
268      -onchange => 'submit();',
269   );
270
271   display submit (
272     -value     => 'Go',
273   );
274
275   display end_form;
276   
277   return;
278 } # DisplayViews
279
280 # Main
281 GetOptions (
282   \%opts,
283   'usage'        => sub { Usage },
284   'verbose'      => sub { set_verbose },
285   'debug'        => sub { set_debug },
286   'view=s',
287   'region=s',
288 ) or Usage "Invalid parameter";
289
290 # Announce ourselves
291 verbose "$FindBin::Script v$VERSION";
292
293 heading $subtitle;
294
295 display h1 {
296   -class => 'center',
297 }, $subtitle;
298
299 unless ($opts{tag}) {
300   unless ($opts{region}) {
301     DisplayRegion;
302   } else {
303     DisplayViews $opts{region};
304   } # unless
305
306   exit;
307 } # unless
308
309 DisplayTable(Clearcase::View->new($opts{tag}, $opts{region}));
310
311 footing;
312
313 =pod
314
315 =head1 CONFIGURATION AND ENVIRONMENT
316
317 DEBUG: If set then $debug is set to this level.
318
319 VERBOSE: If set then $verbose is set to this level.
320
321 TRACE: If set then $trace is set to this level.
322
323 =head1 DEPENDENCIES
324
325 =head2 Perl Modules
326
327 L<CGI>
328
329 L<CGI::Carp|CGI::Carp>
330
331 L<FindBin>
332
333 L<Getopt::Long|Getopt::Long>
334
335 =head2 ClearSCM Perl Modules
336
337 =begin man 
338
339  Clearadm
340  ClearadmWeb
341  Clearcase
342  Clearcase::View
343  Clearcase::Views
344  Display
345  Utils
346
347 =end man
348
349 =begin html
350
351 <blockquote>
352 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
353 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
354 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a><br>
355 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/View.pm">Clearcase::View</a><br>
356 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/Views.pm">Clearcase::Views</a><br>
357 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
358 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
359 </blockquote>
360
361 =end html
362
363 =head1 BUGS AND LIMITATIONS
364
365 There are no known bugs in this script
366
367 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
368
369 =head1 LICENSE AND COPYRIGHT
370
371 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
372
373 =cut