如何使用java和vsphere查找esx主机的序列号?
我想获取esx主机的序列号。我正在使用java和vSphereAPI。 我能够连接到esx server(vcenter)并从中获取一些信息 下面是连接和获取信息的代码如何使用java和vsphere查找esx主机的序列号?,java,vsphere,Java,Vsphere,我想获取esx主机的序列号。我正在使用java和vSphereAPI。 我能够连接到esx server(vcenter)并从中获取一些信息 下面是连接和获取信息的代码 String host = "192.168.xx.xx" String url = "https://" + host + "/sdk/vimService"; // List host systems try { ServiceInstance si = new ServiceInstance(new URL(url
String host = "192.168.xx.xx"
String url = "https://" + host + "/sdk/vimService";
// List host systems
try {
ServiceInstance si = new ServiceInstance(new URL(url), user, pass,
true);
ManagedEntity[] managedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("HostSystem");
System.out.println("123 ... "+ si.getAboutInfo().getVersion());
for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;
String ESXhostname = hostsys.getName();
//System.out.println("host ip address is "+hostsys.getConfig().);
HostHardwareInfo hw = hostsys.getHardware();
String ESXhostmodel = hw.getSystemInfo().getModel();
String Vendor = hw.getSystemInfo().getVendor();
long ESXhostmem = hw.getMemorySize();
short ESXhostcores = hw.getCpuInfo().getNumCpuCores();
long ESXMHZ = hw.getCpuInfo().getHz();
HostCpuPackage[] cpuPkg = hw.getCpuPkg();
String esxkey = "ESXInfo";
String esxvalue = "ESXhostname-" + ESXhostname
+ ";ESXhostmodel-" + ESXhostmodel
+ ";ESXhostmem-"+ ESXhostmem
+ ";ESXhostcores-" + ESXhostcores
+ ";ESXHz -"+ESXMHZ
+ ";Vendor-" + Vendor
+ ";OSType-" + si.getAboutInfo().getOsType()
+ ";FullName-" + si.getAboutInfo().getFullName()
+ ";OSVersion-" + si.getAboutInfo().getVersion()
;
System.out.println("Value are "+ esxvalue);
}
for (int i = 0; i < managedEntities.length; i++) {
VirtualMachine vm = (VirtualMachine) managedEntities[i];
String macAddress="";
for(VirtualDevice vd:vm.getConfig().getHardware().getDevice()){
try {
VirtualEthernetCard vEth=(VirtualEthernetCard)vd;
macAddress=vEth.macAddress;
System.out.println("Macaddress of guest is "+vEth.macAddress);
}
catch(Exception e){}
}
String vmName = vm.getName();
String vmVersion = vm.getConfig().version;
System.out.println("vm wayer version is ..from inventory.. "+ vm.getConfig().version);
System.out.println("geust os uuid "+vm.getSummary().getConfig().uuid);
System.out.println("geust mac Address of guest "+macAddress);
System.out.println("geust id is "+vm.getSummary().getGuest().guestId);
System.out.println("host id is "+vm.getSummary().getGuest().getIpAddress());
String uuid=vm.getSummary().getConfig().uuid;
VirtualMachinePowerState deviceState = vm.getSummary().runtime.powerState;
System.out.println("Powerstate of device is ......."+deviceState);
String vmIP=vm.getSummary().getGuest().getIpAddress();
VirtualMachineConfigInfo config = vm.getConfig();
VirtualHardware hw = config.getHardware();
int vmCPU = hw.getNumCPU();
int vmMem = hw.getMemoryMB();
System.out.println(vmName + vmIP + vmCPU + vmMem);
String vmkey = "vm" + i;
String vmvalues = "Name-" + vmName + ";IP-" + vmIP + ";vmCPU-"
+ vmCPU + ";vmMem-" + vmMem+";uuid-" + uuid + ";host-"+host+";macAddress-"+macAddress
+";deviceState-" + deviceState + ";vmVersion-"+vmVersion;
}
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();
}
String host=“192.168.xx.xx”
String url=“https://“+host+”/sdk/vimService”;
//列出主机系统
试一试{
ServiceInstance si=新ServiceInstance(新URL,用户,传递,
正确的);
ManagedEntity[]managedEntities=新的InventoryNavigator(
si.getRootFolder()).SearchManageIdentity(“VirtualMachine”);
ManagedEntity[]主机managedentities=新的InventoryNavigator(
si.getRootFolder()).SearchManageIdentity(“主机系统”);
System.out.println(“123…”+si.getAboutInfo().getVersion());
for(ManagedEntity hostmanagedEntity:hostmanagedEntities){
HostSystem hostsys=(HostSystem)hostmanagedEntity;
字符串ESXhostname=hostsys.getName();
//System.out.println(“主机ip地址为”+hostsys.getConfig());
HostHardwareInfo hw=hostsys.getHardware();
字符串ESXhostmodel=hw.getSystemInfo().getModel();
字符串Vendor=hw.getSystemInfo().getVendor();
long ESXhostmem=hw.getMemorySize();
短ESXhostcores=hw.getCpuInfo().getnumpucores();
long ESXMHZ=hw.getCpuInfo().getHz();
HostCpuPackage[]cpuPkg=hw.getCpuPkg();
字符串esxkey=“ESXInfo”;
字符串esxvalue=“ESXhostname-”+ESXhostname
+“ESXhostmodel-”+ESXhostmodel
+“ESXhostmem-”+ESXhostmem
+“ESXhostcores-”+ESXhostcores
+“ESXHz-”+ESXMHZ
+“供应商-”+供应商
+“OSType-”+si.getAboutInfo().getOsType()
+“全名-”+si.getAboutInfo().getFullName()
+“OSVersion-”+si.getAboutInfo().getVersion()
;
System.out.println(“值为”+esxvalue);
}
for(int i=0;i
如何获取esx主机的序列号?您需要添加以下行以获取序列号-
String serialNumber = hostsys.getSummary().getHardware().otherIdentifyingInfo[2].identifierValue;
System.out.println("srno.. " + hostsys.getSummary().getHardware().otherIdentifyingInfo[2].identifierValue);
因此,您的代码如下所示:
for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;
String ESXhostname = hostsys.getName();
//System.out.println("host ip address is "+hostsys.getConfig().);
HostHardwareInfo hw = hostsys.getHardware();
String ESXhostmodel = hw.getSystemInfo().getModel();
String Vendor = hw.getSystemInfo().getVendor();
long ESXhostmem = hw.getMemorySize();
short ESXhostcores = hw.getCpuInfo().getNumCpuCores();
long ESXMHZ = hw.getCpuInfo().getHz();
HostCpuPackage[] cpuPkg = hw.getCpuPkg();
String serialNumber = hostsys.getSummary().getHardware().otherIdentifyingInfo[2].identifierValue;
String esxkey = "ESXInfo";
String esxvalue = "ESXhostname-" + ESXhostname
+ ";ESXhostmodel-" + ESXhostmodel
+ ";ESXhostmem-"+ ESXhostmem
+ ";ESXhostcores-" + ESXhostcores
+ ";ESXHz -"+ESXMHZ
+ ";Vendor-" + Vendor
+ ";OSType-" + si.getAboutInfo().getOsType()
+ ";FullName-" + si.getAboutInfo().getFullName()
+ ";OSVersion-" + si.getAboutInfo().getVersion()
+";serialNumber" + serialNumber
;
System.out.println("Value are "+ esxvalue);
}
希望这会有帮助。可能会有帮助。为什么从数组中获取第二个值?有关于价值观的描述吗?