FOSSology  4.4.0
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  SPDX-FileCopyrightText: © 2012 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
16 require_once('../lib/common-vm.php');
17 
18 $vmServers = array(
19 // 'foss-vmhost1.usa.hp.com',
20 // 'foss-vmhost2.usa.hp.com',
21 // 'foss-vmhost3.usa.hp.com',
22 // 'foss-vmhost4.usa.hp.com',
23  'haymitch.fc.hp.com',
24  'primrose.fc.hp.com',
25  'madge.fc.hp.com',
26  'buttercup.fc.hp.com'
27 );
28 
29 // vmware does not change the name of the initial vm, it just displays the new
30 // name.
31 /*
32 $pkgVms = array(
33  'squeze32',
34  'squeze64',
35  'fed15-32',
36  'fed15-64',
37  'rhel6-232',
38  'rhel6-264_1',
39  'u10-043-32_1',
40  'u10-043-64',
41  'ubun11-0432',
42  'ubun11.04.64',
43  'u1110-32',
44  'u1110-64',
45 );
46 */
47 $pkgVms = array(
48  'fo-debian-squeeze32.fc.hp.com',
49  'fo-debian-squeeze64.fc.hp.com',
50  'fo-debian-wheezy32.fc.hp.com',
51  'fo-debian-wheezy64.fc.hp.com',
52  'fo-centos-6-32.fc.hp.com',
53  'fo-centos-6-64.fc.hp.com',
54  'fo-fedora-19-32.fc.hp.com',
55  'fo-fedora-19-64.fc.hp.com',
56  'fo-fedora-18-32.fc.hp.com',
57  'fo-fedora-18-64.fc.hp.com',
58  'fo-ubuntu-1204-32.fc.hp.com',
59  'fo-ubuntu-1204-64.fc.hp.com',
60  'fo-ubuntu-1210-32.fc.hp.com',
61  'fo-ubuntu-1210-64.fc.hp.com',
62  'fo-ubuntu-1304-32.fc.hp.com',
63  'fo-ubuntu-1304-64.fc.hp.com',
64  'fo-ubuntu-1310-32.fc.hp.com',
65  'fo-ubuntu-1310-64.fc.hp.com',
66  'fo-fedora-20-32.fc.hp.com',
67  'fo-fedora-20-64.fc.hp.com',
68  'fo-ubuntu-1404-32.fc.hp.com',
69  'fo-ubuntu-1404-64.fc.hp.com',
70 );
71 
72 
73 $hosts = array();
74 $listOut = array();
75 $vmList = array();
76 
77 // gather vm's on each server
78 // determine what server each vm is on, build an array with [vmhost][vmname]
79 
80 foreach($vmServers as $host)
81 {
82  $host = trim($host);
83  $cmd = "vmware-cmd -H $host -U root -P iforgot -l";
84  $last = exec($cmd, $listOut, $rtn);
85  foreach($listOut as $vmMachine)
86  {
87  if(empty($vmMachine))
88  {
89  continue;
90  }
91  $parts = explode('/', $vmMachine);
92  if(in_array(trim($parts[4]), $pkgVms))
93  {
94  //echo "DB: matched! {$parts[4]}\n";
95  $vmList[] = $vmMachine;
96  }
97  $hosts[$host] = $vmList;
98  } // foreach
99  $vmList = array();
100  $listOut = array();
101 } // foreach
102 
103 /*
104  * For each machine, turn it on, make sure there is a snapshot record machines
105  * that are ready to test in an array. Write the array to a vm.ini file. This
106  * file will be used by vmrevert to revert the vms to the current snapshot.
107  *
108  */
109 $machinesReady = array();
110 foreach($hosts as $host => $vms)
111 {
112  if(empty($vms))
113  {
114  echo "Note: no vm's for host $host\n";
115  continue;
116  }
117  foreach($vms as $vm)
118  {
119  if(!vmOps($host, $vm, 'getstate'))
120  {
121  echo "Warning: $vm would not start, not in this test run.\n";
122  continue;
123  }
124  if(!vmOps($host, $vm, 'hassnapshot'))
125  {
126  echo "Warning: $vm does not have a snapshot!\n";
127 
128  }
129  $machinesReady[$host][] = $vm;
130  }
131 }
132 //echo "DB: the machines that will be used to test are:\n";
133 //print_r($machinesReady) . "\n";
134 
135 // create ini file, use vmname=vm for entries.
136 
137 $dataFile = 'vm.ini';
138 $VM = fopen($dataFile, 'w') or die("FATAL! Cannot open $dataFile\n");
139 $message = "; This file was generated by vmcheck.php on:" .
140  date("D M j G:i:s T Y") . "\n\n";
141 fwrite($VM, $message);
142 foreach ($machinesReady as $host => $vms)
143 {
144  if(!fwrite($VM, '[' . $host . "]\n"))
145  {
146  echo "FATAL! could not write to $dataFile\n";
147  exit(1);
148  }
149  foreach ($vms as $vm)
150  {
151  $vmParts = explode('/', $vm);
152  if(!fwrite($VM, $vmParts[4] . '=' . "$vm\n"))
153  {
154  echo "FATAL! could not write to $dataFile\n";
155  exit(1);
156  }
157  }
158 
159 }
160 exit(0);
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:37
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
#define FATAL(...)
Definition: logging.h:63