use of com.cloud.host.HostVO in project cloudstack by apache.
the class HypervServerDiscoverer method processConnect.
@Override
public final void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
// Limit the commands we can process
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
// assert
if (startup.getHypervisorType() != HypervisorType.Hyperv) {
s_logger.debug("Not Hyper-V hypervisor, so moving on.");
return;
}
long agentId = agent.getId();
HostVO host = _hostDao.findById(agentId);
// Our Hyper-V machines are not participating in pools, and the pool id
// we provide them is not persisted.
// This means the pool id can vary.
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
SetupAnswer answer = (SetupAnswer) _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult()) {
host.setSetup(true);
// TODO: clean up magic numbers below
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
_hostDao.update(host.getId(), host);
if (answer.needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
String reason = answer.getDetails();
if (reason == null) {
reason = " details were null";
}
s_logger.warn("Unable to setup agent " + agentId + " due to " + reason);
}
// Error handling borrowed from XcpServerDiscoverer, may need to be
// updated.
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class BaremetalDhcpManagerImpl method addVirtualMachineIntoNetwork.
@Override
public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
Long zoneId = profile.getVirtualMachine().getDataCenterId();
Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
if (hosts.size() == 0) {
throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
}
if (hosts.size() > 1) {
throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
}
HostVO h = hosts.get(0);
String dns = nic.getIPv4Dns1();
if (dns == null) {
dns = nic.getIPv4Dns2();
}
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null, _ntwkModel.getExecuteInSeqNtwkElmtCmd());
String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName());
// prepareBareMetalDhcpEntry(nic, dhcpCommand);
try {
Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
if (ans.getResult()) {
s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
return true;
} else {
s_logger.debug(errMsg + " " + ans.getDetails());
throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId);
}
} catch (Exception e) {
s_logger.debug(errMsg, e);
throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId);
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class Ovm3FenceBuilder method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.Ovm3) {
LOGGER.debug("Don't know how to fence non Ovm3 hosts " + host.getHypervisorType());
return null;
} else {
LOGGER.debug("Fencing " + vm + " on host " + host + " with params: " + fenceParams);
}
List<HostVO> hosts = resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.Ovm3 && h.getStatus() == Status.Up && h.getId() != host.getId()) {
FenceAnswer answer;
try {
answer = (FenceAnswer) agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException | OperationTimedoutException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class Ovm3VmSupport method execute.
/* do migrations of VMs in a simple way just inside a cluster for now */
public MigrateAnswer execute(final MigrateCommand cmd) {
final String vmName = cmd.getVmName();
String destUuid = cmd.getHostGuid();
String destIp = cmd.getDestinationIp();
State state = State.Error;
/*
* TODO: figure out non pooled migration, works from CLI but not from
* the agent... perhaps pause the VM and then migrate it ? for now just
* stop the VM.
*/
String msg = "Migrating " + vmName + " to " + destIp;
LOGGER.info(msg);
if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
HostVO destHost = resourceMgr.findHostByGuid(destUuid);
if (destHost == null) {
msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp;
LOGGER.info(msg);
return new MigrateAnswer(cmd, false, msg, null);
}
xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
msg = destHost.toString();
state = State.Stopping;
return new MigrateAnswer(cmd, false, msg, null);
} catch (Ovm3ResourceException e) {
msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage();
LOGGER.debug(msg, e);
return new MigrateAnswer(cmd, false, msg, null);
} finally {
/* shouldn't we just reinitialize completely as a last resort ? */
hypervisor.setVmState(vmName, state);
}
} else {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
if (vm == null) {
state = State.Stopped;
msg = vmName + " is no running on " + config.getAgentHostname();
return new MigrateAnswer(cmd, false, msg, null);
}
/* not a storage migration!!! */
xen.migrateVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid(), destIp);
state = State.Stopping;
msg = "Migration of " + vmName + " successfull";
return new MigrateAnswer(cmd, true, msg, null);
} catch (Ovm3ResourceException e) {
msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage();
LOGGER.debug(msg, e);
return new MigrateAnswer(cmd, false, msg, null);
} finally {
hypervisor.setVmState(vmName, state);
}
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class XenServerFencer method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType());
return null;
}
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.XenServer) {
if (h.getStatus() != Status.Up) {
continue;
}
if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
Answer ans = _agentMgr.send(h.getId(), fence);
if (!(ans instanceof FenceAnswer)) {
s_logger.debug("Answer is not fenceanswer. Result = " + ans.getResult() + "; Details = " + ans.getDetails());
continue;
}
answer = (FenceAnswer) ans;
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
}
continue;
} catch (OperationTimedoutException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
Aggregations