-
Notifications
You must be signed in to change notification settings - Fork 0
/
Host.java
executable file
·51 lines (38 loc) · 1.46 KB
/
Host.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;
public class Host {
static HashMap<String,String> map = new HashMap<String,String>();
public static void main(String [] args) throws Exception
{
URL url = new URL("https://130.65.132.19/sdk");
ServiceInstance si = new ServiceInstance(url, "[email protected]", "12!@qwQW", true);
Folder rootFolder = si.getRootFolder();
ManagedEntity[] mesHost = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");
System.out.println("no.of hosts" +mesHost.length);
for (int j = 0; j < mesHost.length; j++)
{
HostSystem hs = (HostSystem) mesHost[j];
//System.out.println("Host " +hs.getName());
VirtualMachine[] mes = hs.getVms();
for (int i = 0; i < mes.length; i++)
{
VirtualMachine vm = (VirtualMachine) mes[i];
//System.out.println(vm.getName());
if(vm.getName().contains("T02"))
{
Ping.pingCommon(hs.getName());
System.out.println("inside T02 " +hs.getName());
System.out.println("inside T02 " +vm.getName() +" " + vm.getGuest().ipAddress );
map.put(hs.getName(),vm.getName());
}
}
}
}
}