I am using vmware API. By using this API I am able to get information of ESX devices. Now I want to get information about vcenter using this API, but get exception "Java.rmi.remoteException: VI SDK Invoke exception : javax.net.ssl.SSLHandShakeException: java.security."
Here is a code:
public void realesx(){
System.out.println("Running ESX Realtime for host ..."+host);
JSONObject esxcmdout = new JSONObject();
String url = "https://" + host + "/sdk/vimService";
try {
ServiceInstance si = new ServiceInstance(new URL(url), user, pass,true);
System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName());
System.out.println(" Version is .. " +si.getAboutInfo().version);
System.out.println(" os type is .. " +si.getAboutInfo().osType);
System.out.println("Vendor is .. " + si.getAboutInfo().vendor);
System.out.println("name is" + si.getAboutInfo().name);
try{
esxcmdout.put("vmWayerVersion", si.getAboutInfo().version);
esxcmdout.put("vmWayerOSType", si.getAboutInfo().osType);
esxcmdout.put("vmWayerVendor", si.getAboutInfo().vendor);
esxcmdout.put("vmWayerName", si.getpublic void realesx(){
System.out.println("Running ESX Realtime for host ..."+host);
JSONObject esxcmdout = new JSONObject();
String url = "https://" + host + "/sdk/vimService";
try {
ServiceInstance si = new ServiceInstance(new URL(url), user, pass,true);
System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName());
System.out.println(" Version is .. " +si.getAboutInfo().version);
System.out.println(" os type is .. " +si.getAboutInfo().osType);
System.out.println("Vendor is .. " + si.getAboutInfo().vendor);
System.out.println("name is" + si.getAboutInfo().name);
try{
esxcmdout.put("vmWayerVersion", si.getAboutInfo().version);
esxcmdout.put("vmWayerOSType", si.getAboutInfo().osType);
esxcmdout.put("vmWayerVendor", si.getAboutInfo().vendor);
esxcmdout.put("vmWayerName", si.getAboutInfo().name);
}
catch (Exception e){
e.printStackTrace();
}
ManagedEntity[] managedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("HostSystem");
for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;
String ESXhostname = hostsys.getName();
//System.out.println("main system version is .. " + hostsys.getConfig());
HostListSummary hls = hostsys.getSummary();
HostHardwareSummary hosthwi = hls.getHardware();
HostListSummaryQuickStats hqs = hls.getQuickStats();
Datastore[] HDS = hostsys.getDatastores();
StringBuilder DS = new StringBuilder();
for (int i=0;i <HDS.length;i++){
DatastoreSummary dsm =HDS[i].getSummary();
DS.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-");
}
int MEM=hqs.overallMemoryUsage;
int UPT=hqs.getUptime();
Integer CPU=hqs.getOverallCpuUsage();
String esxkey = "ESXRealInfo";
String esxvalue = "ESXhostname-" + ESXhostname
+ ";CPU Usage-" + CPU + ";MEM Usage-"
+ MEM + ";UPTIME-" + UPT+"; Datastores -"+DS;
try {
esxcmdout.put(esxkey, esxvalue);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for (int i = 0; i < managedEntities.length; i++) {
VirtualMachine vm = (VirtualMachine) managedEntities[i];
String vmName = vm.getName();
String vmIP = vm.getGuest().getIpAddress();
VirtualMachineConfigInfo config = vm.getConfig();
VirtualHardware hw = config.getHardware();
String vmVersion = config.version;
System.out.println("######### vm version is ###### ... "+ vmVersion);
int vmCPU = hw.getNumCPU();
int vmMem = hw.getMemoryMB();
String vmkey = "vm" + i;
String vmvalues = "Name-" + vmName + ";IP-" + vmIP + ";vmCPU-"
+ vmCPU + ";vmMem-" + vmMem + ";vmVersion-" + vmVersion;
System.out.println("string to write is... "+vmvalues);
try {
esxcmdout.put(vmkey, vmvalues);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
si.getServerConnection().logout();
}
catch (InvalidProperty e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RuntimeFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
runMT.httpput(runtype, host, vmwtype, esxcmdout);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}AboutInfo().name);
}
catch (Exception e){
e.printStackTrace();
}
ManagedEntity[] managedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("HostSystem");
for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;
String ESXhostname = hostsys.getName();
//System.out.println("main system version is .. " + hostsys.getConfig());
HostListSummary hls = hostsys.getSummary();
HostHardwareSummary hosthwi = hls.getHardware();
HostListSummaryQuickStats hqs = hls.getQuickStats();
Datastore[] HDS = hostsys.getDatastores();
StringBuilder DS = new StringBuilder();
for (int i=0;i <HDS.length;i++){
DatastoreSummary dsm =HDS[i].getSummary();
DS.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-");
}
int MEM=hqs.overallMemoryUsage;
int UPT=hqs.getUptime();
Integer CPU=hqs.getOverallCpuUsage();
String esxkey = "ESXRealInfo";
String esxvalue = "ESXhostname-" + ESXhostname
+ ";CPU Usage-" + CPU + ";MEM Usage-"
+ MEM + ";UPTIME-" + UPT+"; Datastores -"+DS;
try {
esxcmdout.put(esxkey, esxvalue);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for (int i = 0; i < managedEntities.length; i++) {
VirtualMachine vm = (VirtualMachine) managedEntities[i];
String vmName = vm.getName();
String vmIP = vm.getGuest().getIpAddress();
VirtualMachineConfigInfo config = vm.getConfig();
VirtualHardware hw = config.getHardware();
String vmVersion = config.version;
System.out.println("######### vm version is ###### ... "+ vmVersion);
int vmCPU = hw.getNumCPU();
int vmMem = hw.getMemoryMB();
//sasSystem.out.println(vmName + vmIP + vmCPU + vmMem);
String vmkey = "vm" + i;
String vmvalues = "Name-" + vmName + ";IP-" + vmIP + ";vmCPU-"
+ vmCPU + ";vmMem-" + vmMem + ";vmVersion-" + vmVersion;
System.out.println("string to write is... "+vmvalues);
try {
esxcmdout.put(vmkey, vmvalues);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
si.getServerConnection().logout();
}
catch (InvalidProperty e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RuntimeFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
runMT.httpput(runtype, host, vmwtype, esxcmdout);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This code works fine for collecting information of ESX devices. How do I resolve error of certificate for vcenter? Is there any alternative way to do this?