use of com.vmware.vim25.mo.ClusterComputeResource in project CloudStack-archive by CloudStack-extras.
the class ClusterMO 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.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.setPathSet(propertyPaths);
TraversalSpec host2VmFolderTraversal = new TraversalSpec();
host2VmFolderTraversal.setType("HostSystem");
host2VmFolderTraversal.setPath("vm");
host2VmFolderTraversal.setName("host2VmFolderTraversal");
TraversalSpec cluster2HostFolderTraversal = new TraversalSpec();
cluster2HostFolderTraversal.setType("ClusterComputeResource");
cluster2HostFolderTraversal.setPath("host");
cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal");
cluster2HostFolderTraversal.setSelectSet(new SelectionSpec[] { host2VmFolderTraversal });
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(getMor());
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { cluster2HostFolderTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ObjectContent[] properties = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() done");
return properties;
}
use of com.vmware.vim25.mo.ClusterComputeResource in project CloudStack-archive by CloudStack-extras.
the class ClusterMO method getDatastorePropertiesOnHyperHost.
@Override
public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.setPathSet(propertyPaths);
TraversalSpec cluster2DatastoreTraversal = new TraversalSpec();
cluster2DatastoreTraversal.setType("ClusterComputeResource");
cluster2DatastoreTraversal.setPath("datastore");
cluster2DatastoreTraversal.setName("cluster2DatastoreTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { cluster2DatastoreTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ObjectContent[] properties = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() done");
return properties;
}
use of com.vmware.vim25.mo.ClusterComputeResource in project CloudStack-archive by CloudStack-extras.
the class HypervisorHostHelper method prepareNetwork.
public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix, HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs, boolean syncPeerHosts) throws Exception {
HostVirtualSwitch vSwitch;
vSwitch = hostMo.getHostVirtualSwitchByName(vSwitchName);
if (vSwitch == null) {
String msg = "Unable to find vSwitch" + vSwitchName;
s_logger.error(msg);
throw new Exception(msg);
}
boolean createGCTag = false;
String networkName;
Integer vid = null;
if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
createGCTag = true;
vid = Integer.parseInt(vlanId);
}
networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, vSwitchName);
HostNetworkTrafficShapingPolicy shapingPolicy = null;
if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
shapingPolicy = new HostNetworkTrafficShapingPolicy();
shapingPolicy.setEnabled(true);
shapingPolicy.setAverageBandwidth((long) networkRateMbps.intValue() * 1024L * 1024L);
//
// TODO : people may have different opinion on how to set the following
//
// give 50% premium to peek
shapingPolicy.setPeakBandwidth((long) (shapingPolicy.getAverageBandwidth() * 1.5));
// allow 5 seconds of burst transfer
shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
}
boolean bWaitPortGroupReady = false;
if (!hostMo.hasPortGroup(vSwitch, networkName)) {
hostMo.createPortGroup(vSwitch, networkName, vid, shapingPolicy);
bWaitPortGroupReady = true;
} else {
HostPortGroupSpec spec = hostMo.getPortGroupSpec(networkName);
if (!isSpecMatch(spec, vid, shapingPolicy)) {
hostMo.updatePortGroup(vSwitch, networkName, vid, shapingPolicy);
bWaitPortGroupReady = true;
}
}
ManagedObjectReference morNetwork;
if (bWaitPortGroupReady)
morNetwork = waitForNetworkReady(hostMo, networkName, timeOutMs);
else
morNetwork = hostMo.getNetworkMor(networkName);
if (morNetwork == null) {
String msg = "Failed to create guest network " + networkName;
s_logger.error(msg);
throw new Exception(msg);
}
if (createGCTag) {
NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true");
}
if (syncPeerHosts) {
ManagedObjectReference morParent = hostMo.getParentMor();
if (morParent != null && morParent.getType().equals("ClusterComputeResource")) {
// to be conservative, lock cluster
GlobalLock lock = GlobalLock.getInternLock("ClusterLock." + morParent.get_value());
try {
if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
try {
ManagedObjectReference[] hosts = (ManagedObjectReference[]) hostMo.getContext().getServiceUtil().getDynamicProperty(morParent, "host");
if (hosts != null) {
for (ManagedObjectReference otherHost : hosts) {
if (!otherHost.get_value().equals(hostMo.getMor().get_value())) {
HostMO otherHostMo = new HostMO(hostMo.getContext(), otherHost);
try {
if (s_logger.isDebugEnabled())
s_logger.debug("Prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
prepareNetwork(vSwitchName, namePrefix, otherHostMo, vlanId, networkRateMbps, networkRateMulticastMbps, timeOutMs, false);
} catch (Exception e) {
s_logger.warn("Unable to prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
}
}
}
}
} finally {
lock.unlock();
}
} else {
s_logger.warn("Unable to lock cluster to prepare guest network, vlan: " + vlanId);
}
} finally {
lock.releaseRef();
}
}
}
s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
}
use of com.vmware.vim25.mo.ClusterComputeResource in project CloudStack-archive by CloudStack-extras.
the class VmwareContext method getHostMorByPath.
public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
assert (inventoryPath != null);
String[] tokens;
if (inventoryPath.startsWith("/"))
tokens = inventoryPath.substring(1).split("/");
else
tokens = inventoryPath.split("/");
ManagedObjectReference mor = getRootFolder();
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
ObjectContent[] ocs;
if (mor.getType().equalsIgnoreCase("Datacenter")) {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("ManagedEntity");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec dcHostFolderTraversal = new TraversalSpec();
dcHostFolderTraversal.setType("Datacenter");
dcHostFolderTraversal.setPath("hostFolder");
dcHostFolderTraversal.setName("dcHostFolderTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { dcHostFolderTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
} else if (mor.getType().equalsIgnoreCase("Folder")) {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("ManagedEntity");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec folderChildrenTraversal = new TraversalSpec();
folderChildrenTraversal.setType("Folder");
folderChildrenTraversal.setPath("childEntity");
folderChildrenTraversal.setName("folderChildrenTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { folderChildrenTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
} else if (mor.getType().equalsIgnoreCase("ClusterComputeResource")) {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("ManagedEntity");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec clusterHostTraversal = new TraversalSpec();
clusterHostTraversal.setType("ClusterComputeResource");
clusterHostTraversal.setPath("host");
clusterHostTraversal.setName("folderChildrenTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { clusterHostTraversal });
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
} else {
s_logger.error("Invalid inventory path, path element can only be datacenter and folder");
return null;
}
if (ocs != null && ocs.length > 0) {
boolean found = false;
for (ObjectContent oc : ocs) {
String name = oc.getPropSet()[0].getVal().toString();
if (name.equalsIgnoreCase(token) || name.equalsIgnoreCase("host")) {
mor = oc.getObj();
found = true;
if (name.equalsIgnoreCase("host"))
i--;
break;
}
}
if (!found) {
s_logger.error("Path element points to an un-existing inventory entity");
return null;
}
} else {
s_logger.error("Path element points to an un-existing inventory entity");
return null;
}
}
return mor;
}
use of com.vmware.vim25.mo.ClusterComputeResource in project coprhd-controller by CoprHD.
the class VcenterApiClient method createManagedEntityMap.
/*
* Provide names of the vCenter elements and method will locate the MangedEntity representation
* Each search is done within context of previous entity thus there is a dependency
* Cluster
* Datacenter
* Host
* Parameters are optional (ie, leave host null to only search datacenter and cluster)
* Must provide parent element name or child will not be searched
* hostConnectedPoweredOn ensures host is operational and ready for calls
*/
private Map<String, ManagedEntity> createManagedEntityMap(String datacenterName, String clusterNameOrMoRef, String hostname, boolean hostConnectedPoweredOn) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
if (serviceInstance == null) {
_log.error("Invoke setup to open connection before using client");
throw new VcenterSystemException("Invoke setup to open connection before using client");
}
try {
Map<String, ManagedEntity> vcenterManagedEntityMap = new HashMap<String, ManagedEntity>();
if (datacenterName != null && !datacenterName.trim().equals("")) {
Datacenter datacenter = (Datacenter) new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntity("Datacenter", datacenterName);
if (datacenter == null) {
_log.error("Datacenter " + datacenterName + " does not exist");
throw new VcenterObjectNotFoundException("Datacenter " + datacenterName + " does not exist");
}
vcenterManagedEntityMap.put("Datacenter", datacenter);
if (clusterNameOrMoRef != null && !clusterNameOrMoRef.trim().equals("")) {
ClusterComputeResource clusterComputeResource = searchClusterComputeResource(datacenterName, clusterNameOrMoRef);
vcenterManagedEntityMap.put("ClusterComputeResource", clusterComputeResource);
if (hostname != null && !hostname.trim().equals("")) {
HostSystem hostSystem = findByHostname(clusterComputeResource, hostname);
if (hostSystem == null) {
_log.error("Host " + hostname + " does not exist");
throw new VcenterObjectNotFoundException("Host " + hostname + " does not exist");
}
if (hostConnectedPoweredOn) {
checkHostConnectedPoweredOn(hostSystem);
}
vcenterManagedEntityMap.put("HostSystem", hostSystem);
}
}
}
return vcenterManagedEntityMap;
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
throw e;
} catch (Exception e) {
_log.error("getVcenterObjects exception " + e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
}
Aggregations