use of com.vmware.vim25.mo.HostSystem in project opennms by OpenNMS.
the class VmwareConfigBuilder method generateData.
private void generateData(String rrdRepository) throws Exception {
serviceInstance = new ServiceInstance(new URL("https://" + hostname + "/sdk"), username, password);
performanceManager = serviceInstance.getPerformanceManager();
PerfCounterInfo[] perfCounterInfos = performanceManager.getPerfCounter();
for (PerfCounterInfo perfCounterInfo : perfCounterInfos) {
perfCounterInfoMap.put(perfCounterInfo.getKey(), perfCounterInfo);
}
System.out.println("Generating configuration files for '" + serviceInstance.getAboutInfo().getFullName() + "' using rrdRepository '" + rrdRepository + "'...");
StringBuffer buffer = new StringBuffer();
buffer.append("Configuration file generated for:\n\n");
buffer.append("Full name.......: " + serviceInstance.getAboutInfo().getFullName() + "\n");
buffer.append("API type........: " + serviceInstance.getAboutInfo().getApiType() + "\n");
buffer.append("API version.....: " + serviceInstance.getAboutInfo().getApiVersion() + "\n");
buffer.append("Product name....: " + serviceInstance.getAboutInfo().getLicenseProductName() + "\n");
buffer.append("Product version.: " + serviceInstance.getAboutInfo().getLicenseProductVersion() + "\n");
buffer.append("OS type.........: " + serviceInstance.getAboutInfo().getOsType() + "\n");
versionInformation = buffer.toString();
String[] arr = serviceInstance.getAboutInfo().getApiVersion().split("\\.");
if (arr.length > 1) {
apiVersion = arr[0];
if (Integer.valueOf(apiVersion) < 4) {
apiVersion = "3";
}
}
ManagedEntity[] hostSystems, virtualMachines;
virtualMachines = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("VirtualMachine");
if (virtualMachines != null) {
if (virtualMachines.length > 0) {
for (ManagedEntity managedEntity : virtualMachines) {
if ("poweredOn".equals(((VirtualMachine) managedEntity).getRuntime().getPowerState().toString())) {
lookupMetrics("default-VirtualMachine" + apiVersion, managedEntity.getMOR().getVal());
break;
}
}
} else {
System.err.println("No virtual machines found");
}
}
hostSystems = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("HostSystem");
if (hostSystems != null) {
if (hostSystems.length > 0) {
for (ManagedEntity managedEntity : hostSystems) {
if ("poweredOn".equals(((HostSystem) managedEntity).getRuntime().getPowerState().toString())) {
lookupMetrics("default-HostSystem" + apiVersion, managedEntity.getMOR().getVal());
break;
}
}
} else {
System.err.println("No host systems found!");
}
}
saveVMwareDatacollectionConfig(rrdRepository);
saveVMwareDatacollectionInclude();
saveVMwareGraphProperties();
}
use of com.vmware.vim25.mo.HostSystem in project cloudstack by apache.
the class HostMO method getVmPropertiesOnHyperHost.
@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
TraversalSpec host2VmTraversal = new TraversalSpec();
host2VmTraversal.setType("HostSystem");
host2VmTraversal.setPath("vm");
host2VmTraversal.setName("host2VmTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(host2VmTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() done");
return properties.toArray(new ObjectContent[properties.size()]);
}
use of com.vmware.vim25.mo.HostSystem in project cloudstack by apache.
the class HostMO method getNetworkMor.
public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.getPathSet().add("summary.name");
TraversalSpec host2NetworkTraversal = new TraversalSpec();
host2NetworkTraversal.setType("HostSystem");
host2NetworkTraversal.setPath("network");
host2NetworkTraversal.setName("host2NetworkTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(host2NetworkTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
if (ocs != null) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> props = oc.getPropSet();
if (props != null) {
for (DynamicProperty prop : props) {
if (prop.getVal().equals(portGroupName))
return oc.getObj();
}
}
}
}
return null;
}
use of com.vmware.vim25.mo.HostSystem in project cloudstack by apache.
the class DatacenterMO method getHostPropertiesOnDatacenterHostFolder.
public List<ObjectContent> getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("HostSystem");
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
TraversalSpec computeResource2HostTraversal = new TraversalSpec();
computeResource2HostTraversal.setType("ComputeResource");
computeResource2HostTraversal.setPath("host");
computeResource2HostTraversal.setName("computeResource2HostTraversal");
SelectionSpec recurseFolders = new SelectionSpec();
recurseFolders.setName("folder2childEntity");
TraversalSpec folder2childEntity = new TraversalSpec();
folder2childEntity.setType("Folder");
folder2childEntity.setPath("childEntity");
folder2childEntity.setName(recurseFolders.getName());
folder2childEntity.getSelectSet().add(recurseFolders);
folder2childEntity.getSelectSet().add(computeResource2HostTraversal);
TraversalSpec dc2HostFolderTraversal = new TraversalSpec();
dc2HostFolderTraversal.setType("Datacenter");
dc2HostFolderTraversal.setPath("hostFolder");
dc2HostFolderTraversal.setName("dc2HostFolderTraversal");
dc2HostFolderTraversal.getSelectSet().add(folder2childEntity);
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(dc2HostFolderTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
}
use of com.vmware.vim25.mo.HostSystem in project cloudstack by apache.
the class VmwareManagerImpl method addHostToPodCluster.
@Override
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId, String hostInventoryPath) throws Exception {
if (serviceContext == null) {
throw new CloudRuntimeException("Invalid serviceContext");
}
ManagedObjectReference mor = serviceContext.getHostMorByPath(hostInventoryPath);
String privateTrafficLabel = null;
privateTrafficLabel = serviceContext.getStockObject("privateTrafficLabel");
if (privateTrafficLabel == null) {
privateTrafficLabel = _privateNetworkVSwitchName;
}
if (mor != null) {
List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();
if (mor.getType().equals("ComputeResource")) {
List<ManagedObjectReference> hosts = serviceContext.getVimClient().getDynamicProperty(mor, "host");
assert (hosts != null && hosts.size() > 0);
// For ESX host, we need to enable host firewall to allow VNC access
HostMO hostMo = new HostMO(serviceContext, hosts.get(0));
prepareHost(hostMo, privateTrafficLabel);
returnedHostList.add(hosts.get(0));
return returnedHostList;
} else if (mor.getType().equals("ClusterComputeResource")) {
List<ManagedObjectReference> hosts = serviceContext.getVimClient().getDynamicProperty(mor, "host");
assert (hosts != null);
if (hosts.size() > 0) {
AboutInfo about = (AboutInfo) (serviceContext.getVimClient().getDynamicProperty(hosts.get(0), "config.product"));
String version = about.getApiVersion();
int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(HypervisorType.VMware, version);
if (hosts.size() > maxHostsPerCluster) {
String msg = "Failed to add VMware cluster as size is too big, current size: " + hosts.size() + ", max. size: " + maxHostsPerCluster;
s_logger.error(msg);
throw new DiscoveredWithErrorException(msg);
}
}
for (ManagedObjectReference morHost : hosts) {
// For ESX host, we need to enable host firewall to allow VNC access
HostMO hostMo = new HostMO(serviceContext, morHost);
prepareHost(hostMo, privateTrafficLabel);
returnedHostList.add(morHost);
}
return returnedHostList;
} else if (mor.getType().equals("HostSystem")) {
// For ESX host, we need to enable host firewall to allow VNC access
HostMO hostMo = new HostMO(serviceContext, mor);
prepareHost(hostMo, privateTrafficLabel);
returnedHostList.add(mor);
return returnedHostList;
} else {
s_logger.error("Unsupport host type " + mor.getType() + ":" + mor.getValue() + " from inventory path: " + hostInventoryPath);
return null;
}
}
s_logger.error("Unable to find host from inventory path: " + hostInventoryPath);
return null;
}
Aggregations