use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.
the class VmwareResource method getTargetHyperHost.
private VmwareHypervisorHost getTargetHyperHost(DatacenterMO dcMo, String destIp) throws Exception {
VmwareManager mgr = dcMo.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
List<ObjectContent> ocs = dcMo.getHostPropertiesOnDatacenterHostFolder(new String[] { "name", "parent" });
if (ocs != null && ocs.size() > 0) {
for (ObjectContent oc : ocs) {
HostMO hostMo = new HostMO(dcMo.getContext(), oc.getObj());
VmwareHypervisorHostNetworkSummary netSummary = hostMo.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost(hostMo));
if (destIp.equalsIgnoreCase(netSummary.getHostIp())) {
return new HostMO(dcMo.getContext(), oc.getObj());
}
}
}
throw new Exception("Unable to locate dest host by " + destIp);
}
use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.
the class VmwareResource method gcAndKillHungWorkerVMs.
private void gcAndKillHungWorkerVMs() {
try {
// take the chance to do left-over dummy VM cleanup from previous run
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
if (hyperHost.isHyperHostConnected()) {
mgr.gcLeftOverVMs(context);
s_logger.info("Scan hung worker VM to recycle");
int workerKey = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_WORKER);
int workerTagKey = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG);
String workerPropName = String.format("value[%d]", workerKey);
String workerTagPropName = String.format("value[%d]", workerTagKey);
// GC worker that has been running for too long
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "config.template", workerPropName, workerTagPropName });
if (ocs != null) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> props = oc.getPropSet();
if (props != null) {
boolean template = false;
boolean isWorker = false;
String workerTag = null;
for (DynamicProperty prop : props) {
if (prop.getName().equals("config.template")) {
template = (Boolean) prop.getVal();
} else if (prop.getName().equals(workerPropName)) {
CustomFieldStringValue val = (CustomFieldStringValue) prop.getVal();
if (val != null && val.getValue() != null && val.getValue().equalsIgnoreCase("true"))
isWorker = true;
} else if (prop.getName().equals(workerTagPropName)) {
CustomFieldStringValue val = (CustomFieldStringValue) prop.getVal();
workerTag = val.getValue();
}
}
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
if (!template && isWorker) {
boolean recycle = false;
recycle = mgr.needRecycle(workerTag);
if (recycle) {
s_logger.info("Recycle pending worker VM: " + vmMo.getName());
vmMo.powerOff();
vmMo.detachAllDisks();
vmMo.destroy();
}
}
}
}
}
} else {
s_logger.error("Host is no longer connected.");
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
}
}
use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.
the class VmwareResource method execute.
@Override
public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd));
}
try {
VmwareContext context = getServiceContext();
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
return (PrimaryStorageDownloadAnswer) mgr.getStorageManager().execute(this, cmd);
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
String msg = "PrimaryStorageDownloadCommand failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new PrimaryStorageDownloadAnswer(msg);
}
}
use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.
the class VmwareStorageProcessor method getControllerFromConfigurationSetting.
private String getControllerFromConfigurationSetting() throws Exception {
String diskController = null;
VmwareContext context = null;
try {
context = hostService.getServiceContext(null);
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
diskController = mgr.getDataDiskController();
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
hostService.invalidateServiceContext(context);
}
String details = "Failed to connect to vCenter due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(details, e);
}
return diskController;
}
Aggregations