FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
vmcheck.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 /*
4  Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
27 require_once('../lib/common-vm.php');
28 
29 $vmServers = array(
30 // 'foss-vmhost1.usa.hp.com',
31 // 'foss-vmhost2.usa.hp.com',
32 // 'foss-vmhost3.usa.hp.com',
33 // 'foss-vmhost4.usa.hp.com',
34  'haymitch.fc.hp.com',
35  'primrose.fc.hp.com',
36  'madge.fc.hp.com',
37  'buttercup.fc.hp.com'
38 );
39 
40 // vmware does not change the name of the initial vm, it just displays the new
41 // name.
42 /*
43 $pkgVms = array(
44  'squeze32',
45  'squeze64',
46  'fed15-32',
47  'fed15-64',
48  'rhel6-232',
49  'rhel6-264_1',
50  'u10-043-32_1',
51  'u10-043-64',
52  'ubun11-0432',
53  'ubun11.04.64',
54  'u1110-32',
55  'u1110-64',
56 );
57 */
58 $pkgVms = array(
59  'fo-debian-squeeze32.fc.hp.com',
60  'fo-debian-squeeze64.fc.hp.com',
61  'fo-debian-wheezy32.fc.hp.com',
62  'fo-debian-wheezy64.fc.hp.com',
63  'fo-centos-6-32.fc.hp.com',
64  'fo-centos-6-64.fc.hp.com',
65  'fo-fedora-19-32.fc.hp.com',
66  'fo-fedora-19-64.fc.hp.com',
67  'fo-fedora-18-32.fc.hp.com',
68  'fo-fedora-18-64.fc.hp.com',
69  'fo-ubuntu-1204-32.fc.hp.com',
70  'fo-ubuntu-1204-64.fc.hp.com',
71  'fo-ubuntu-1210-32.fc.hp.com',
72  'fo-ubuntu-1210-64.fc.hp.com',
73  'fo-ubuntu-1304-32.fc.hp.com',
74  'fo-ubuntu-1304-64.fc.hp.com',
75  'fo-ubuntu-1310-32.fc.hp.com',
76  'fo-ubuntu-1310-64.fc.hp.com',
77  'fo-fedora-20-32.fc.hp.com',
78  'fo-fedora-20-64.fc.hp.com',
79  'fo-ubuntu-1404-32.fc.hp.com',
80  'fo-ubuntu-1404-64.fc.hp.com',
81 );
82 
83 
84 $hosts = array();
85 $listOut = array();
86 $vmList = array();
87 
88 // gather vm's on each server
89 // determine what server each vm is on, build an array with [vmhost][vmname]
90 
91 foreach($vmServers as $host)
92 {
93  $host = trim($host);
94  $cmd = "vmware-cmd -H $host -U root -P iforgot -l";
95  $last = exec($cmd, $listOut, $rtn);
96  foreach($listOut as $vmMachine)
97  {
98  if(empty($vmMachine))
99  {
100  continue;
101  }
102  $parts = explode('/', $vmMachine);
103  if(in_array(trim($parts[4]), $pkgVms))
104  {
105  //echo "DB: matched! {$parts[4]}\n";
106  $vmList[] = $vmMachine;
107  }
108  $hosts[$host] = $vmList;
109  } // foreach
110  $vmList = array();
111  $listOut = array();
112 } // foreach
113 
114 /*
115  * For each machine, turn it on, make sure there is a snapshot record machines
116  * that are ready to test in an array. Write the array to a vm.ini file. This
117  * file will be used by vmrevert to revert the vms to the current snapshot.
118  *
119  */
120 $machinesReady = array();
121 foreach($hosts as $host => $vms)
122 {
123  if(empty($vms))
124  {
125  echo "Note: no vm's for host $host\n";
126  continue;
127  }
128  foreach($vms as $vm)
129  {
130  if(!vmOps($host, $vm, 'getstate'))
131  {
132  echo "Warning: $vm would not start, not in this test run.\n";
133  continue;
134  }
135  if(!vmOps($host, $vm, 'hassnapshot'))
136  {
137  echo "Warning: $vm does not have a snapshot!\n";
138 
139  }
140  $machinesReady[$host][] = $vm;
141  }
142 }
143 //echo "DB: the machines that will be used to test are:\n";
144 //print_r($machinesReady) . "\n";
145 
146 // create ini file, use vmname=vm for entries.
147 
148 $dataFile = 'vm.ini';
149 $VM = fopen($dataFile, 'w') or die("FATAL! Cannot open $dataFile\n");
150 $message = "; This file was generated by vmcheck.php on:" .
151  date("D M j G:i:s T Y") . "\n\n";
152 fwrite($VM, $message);
153 foreach ($machinesReady as $host => $vms)
154 {
155  if(!fwrite($VM, '[' . $host . "]\n"))
156  {
157  echo "FATAL! could not write to $dataFile\n";
158  exit(1);
159  }
160  foreach ($vms as $vm)
161  {
162  $vmParts = explode('/', $vm);
163  if(!fwrite($VM, $vmParts[4] . '=' . "$vm\n"))
164  {
165  echo "FATAL! could not write to $dataFile\n";
166  exit(1);
167  }
168  }
169 
170 }
171 exit(0);
172 ?>
#define FATAL(...)
Definition: logging.h:74
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:48
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695