use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.
the class VmwareResource method execute.
private Answer execute(GetUnmanagedInstancesCommand cmd) {
VmwareContext context = getServiceContext();
HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>();
try {
VmwareHypervisorHost hyperHost = getHyperHost(context);
String vmName = cmd.getInstanceName();
List<VirtualMachineMO> vmMos = hyperHost.listVmsOnHyperHostWithHypervisorName(vmName);
for (VirtualMachineMO vmMo : vmMos) {
if (vmMo == null) {
continue;
}
if (vmMo.isTemplate()) {
continue;
}
// Filter managed instances
if (cmd.hasManagedInstance(vmMo.getName())) {
continue;
}
// Filter instance if answer is requested for a particular instance name
if (StringUtils.isNotEmpty(cmd.getInstanceName()) && !cmd.getInstanceName().equals(vmMo.getVmName())) {
continue;
}
UnmanagedInstanceTO instance = getUnmanagedInstance(hyperHost, vmMo);
if (instance != null) {
unmanagedInstances.put(instance.getName(), instance);
}
}
} catch (Exception e) {
s_logger.info("GetUnmanagedInstancesCommand failed due to " + VmwareHelper.getExceptionMessage(e));
}
return new GetUnmanagedInstancesAnswer(cmd, "", unmanagedInstances);
}
use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.
the class VmwareResource method fillHostNetworkInfo.
private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException {
try {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
assert (hyperHost instanceof HostMO);
VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
VmwareHypervisorHostNetworkSummary summary = hyperHost.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost((HostMO) hyperHost));
if (summary == null) {
throw new Exception("No ESX(i) host found");
}
if (s_logger.isInfoEnabled()) {
s_logger.info("Startup report on host network info. " + _gson.toJson(summary));
}
cmd.setPrivateIpAddress(summary.getHostIp());
cmd.setPrivateNetmask(summary.getHostNetmask());
cmd.setPrivateMacAddress(summary.getHostMacAddress());
cmd.setStorageIpAddress(summary.getHostIp());
cmd.setStorageNetmask(summary.getHostNetmask());
cmd.setStorageMacAddress(summary.getHostMacAddress());
} catch (Throwable e) {
String msg = "querying host network info failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
throw new CloudRuntimeException(msg);
}
}
use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.
the class VmwareResource method execute.
/**
* UnregisterNicCommand is used to remove a portgroup created for this
* specific nic. The portgroup will have the name set to the UUID of the
* nic. Introduced to cleanup the portgroups created for each nic that is
* plugged into an lswitch (Nicira NVP plugin)
*
* @param cmd
* @return
*/
protected Answer execute(UnregisterNicCommand cmd) {
if (_guestTrafficInfo == null) {
return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up");
}
try {
if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
// on the standard switches
return new Answer(cmd, true, "Nothing to do");
}
s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName());
VmwareContext context = getServiceContext();
VmwareHypervisorHost host = getHyperHost(context);
ManagedObjectReference clusterMO = host.getHyperHostCluster();
// Get a list of all the hosts in this cluster
@SuppressWarnings("unchecked") List<ManagedObjectReference> hosts = (List<ManagedObjectReference>) context.getVimClient().getDynamicProperty(clusterMO, "host");
if (hosts == null) {
return new Answer(cmd, false, "No hosts in cluster, which is pretty weird");
}
for (ManagedObjectReference hostMOR : hosts) {
HostMO hostMo = new HostMO(context, hostMOR);
hostMo.deletePortGroup(cmd.getNicUuid().toString());
s_logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName());
}
return new Answer(cmd, true, "Unregistered resources for NIC " + cmd.getNicUuid());
} catch (Exception e) {
return new Answer(cmd, false, createLogMessageException(e, cmd));
}
}
use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.
the class VmwareResource method getIqn.
private String getIqn() {
try {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
if (hyperHost instanceof HostMO) {
HostMO host = (HostMO) hyperHost;
HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
if (hba instanceof HostInternetScsiHba) {
HostInternetScsiHba hostInternetScsiHba = (HostInternetScsiHba) hba;
if (hostInternetScsiHba.isIsSoftwareBased()) {
return ((HostInternetScsiHba) hba).getIScsiName();
}
}
}
}
} catch (Exception ex) {
s_logger.info("Could not locate an IQN for this host.");
}
return null;
}
use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(MigrateCommand cmd) {
final String vmName = cmd.getVmName();
try {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
// find VM through datacenter (VM is not at the target host yet)
VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
if (vmMo == null) {
String msg = "VM " + vmName + " does not exist in VMware datacenter";
s_logger.error(msg);
throw new Exception(msg);
}
VmwareHypervisorHost destHyperHost = getTargetHyperHost(new DatacenterMO(hyperHost.getContext(), morDc), cmd.getDestinationIp());
ManagedObjectReference morTargetPhysicalHost = destHyperHost.findMigrationTarget(vmMo);
if (morTargetPhysicalHost == null) {
throw new Exception("Unable to find a target capable physical host");
}
if (!vmMo.migrate(destHyperHost.getHyperHostOwnerResourcePool(), morTargetPhysicalHost)) {
throw new Exception("Migration failed");
}
return new MigrateAnswer(cmd, true, "migration succeeded", null);
} catch (Throwable e) {
return new MigrateAnswer(cmd, false, createLogMessageException(e, cmd), null);
}
}
Aggregations