use of com.cloud.agent.manager.Commands in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method sendLBRules.
protected boolean sendLBRules(final VirtualRouter internalLbVm, final List<LoadBalancingRule> rules, final long guestNetworkId) throws ResourceUnavailableException {
final Commands cmds = new Commands(Command.OnError.Continue);
createApplyLoadBalancingRulesCommands(rules, internalLbVm, cmds, guestNetworkId);
return sendCommandsToInternalLbVm(internalLbVm, cmds);
}
use of com.cloud.agent.manager.Commands in project cloudstack by apache.
the class OvsTunnelManagerImpl method checkAndCreateTunnel.
@DB
protected void checkAndCreateTunnel(Network nw, Host host) {
s_logger.debug("Creating tunnels with OVS tunnel manager");
long hostId = host.getId();
int key = getGreKey(nw);
String bridgeName = generateBridgeName(nw, key);
List<Long> toHostIds = new ArrayList<Long>();
List<Long> fromHostIds = new ArrayList<Long>();
List<Long> networkSpannedHosts = _ovsNetworkToplogyGuru.getNetworkSpanedHosts(nw.getId());
for (Long rh : networkSpannedHosts) {
if (rh == hostId) {
continue;
}
OvsTunnelNetworkVO ta = _tunnelNetworkDao.getByFromToNetwork(hostId, rh.longValue(), nw.getId());
// Try and create the tunnel even if a previous attempt failed
if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
if (ta == null) {
createTunnelRecord(hostId, rh.longValue(), nw.getId(), key);
}
if (!toHostIds.contains(rh)) {
toHostIds.add(rh);
}
}
ta = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(), hostId, nw.getId());
// Try and create the tunnel even if a previous attempt failed
if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
if (ta == null) {
createTunnelRecord(rh.longValue(), hostId, nw.getId(), key);
}
if (!fromHostIds.contains(rh)) {
fromHostIds.add(rh);
}
}
}
//TODO: Should we propagate the exception here?
try {
String myIp = getGreEndpointIP(host, nw);
if (myIp == null)
throw new GreTunnelException("Unable to retrieve the source " + "endpoint for the GRE tunnel." + "Failure is on host:" + host.getId());
boolean noHost = true;
for (Long i : toHostIds) {
HostVO rHost = _hostDao.findById(i);
String otherIp = getGreEndpointIP(rHost, nw);
if (otherIp == null)
throw new GreTunnelException("Unable to retrieve the remote " + "endpoint for the GRE tunnel." + "Failure is on host:" + rHost.getId());
Commands cmds = new Commands(new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, nw.getId(), myIp, bridgeName, nw.getUuid()));
s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + nw.getId());
s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
Answer[] answers = _agentMgr.send(hostId, cmds);
handleCreateTunnelAnswer(answers);
noHost = false;
}
for (Long i : fromHostIds) {
HostVO rHost = _hostDao.findById(i);
String otherIp = getGreEndpointIP(rHost, nw);
Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), nw.getId(), otherIp, bridgeName, nw.getUuid()));
s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
Answer[] answers = _agentMgr.send(i, cmds);
handleCreateTunnelAnswer(answers);
noHost = false;
}
// anyway. This will ensure VIF rules will be triggered
if (noHost) {
Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, nw.getId()));
s_logger.debug("Ask host " + hostId + " to configure bridge for network:" + nw.getId());
Answer[] answers = _agentMgr.send(hostId, cmds);
handleSetupBridgeAnswer(answers);
}
} catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) {
// I really thing we should do a better handling of these exceptions
s_logger.warn("Ovs Tunnel network created tunnel failed", e);
}
}
use of com.cloud.agent.manager.Commands in project cloudstack by apache.
the class SshKeysDistriMonitor method processConnect.
@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
if (cmd instanceof StartupRoutingCommand) {
if (((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.XenServer || ((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.LXC) {
/*TODO: Get the private/public keys here*/
String pubKey = _configDao.getValue("ssh.publickey");
String prvKey = _configDao.getValue("ssh.privatekey");
try {
ModifySshKeysCommand cmds = new ModifySshKeysCommand(pubKey, prvKey);
Commands c = new Commands(cmds);
_agentMgr.send(host.getId(), c, this);
} catch (AgentUnavailableException e) {
s_logger.debug("Failed to send keys to agent: " + host.getId());
}
}
}
}
use of com.cloud.agent.manager.Commands in project cloudstack by apache.
the class CloudZonesNetworkElement method addPasswordAndUserdata.
@Override
public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(dest, network.getTrafficType())) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
@SuppressWarnings("unchecked") UserVmVO uservm = _userVmDao.findById(vm.getId());
_userVmDao.loadDetails(uservm);
String password = (String) vm.getParameter(VirtualMachineProfile.Param.VmPassword);
String userData = uservm.getUserData();
String sshPublicKey = uservm.getDetail("SSH.PublicKey");
Commands cmds = new Commands(Command.OnError.Continue);
if (password != null && nic.isDefaultNic()) {
SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIPv4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());
cmds.addCommand("password", cmd);
}
String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText();
String zoneName = _dcDao.findById(network.getDataCenterId()).getName();
cmds.addCommand("vmdata", generateVmDataCommand(nic.getIPv4Address(), userData, serviceOffering, zoneName, nic.getIPv4Address(), uservm.getHostName(), uservm.getInstanceName(), uservm.getId(), uservm.getUuid(), sshPublicKey));
try {
_agentManager.send(dest.getHost().getId(), cmds);
} catch (OperationTimedoutException e) {
s_logger.debug("Unable to send vm data command to host " + dest.getHost());
return false;
}
Answer dataAnswer = cmds.getAnswer("vmdata");
if (dataAnswer != null && dataAnswer.getResult()) {
s_logger.info("Sent vm data successfully to vm " + uservm.getInstanceName());
return true;
}
s_logger.info("Failed to send vm data to vm " + uservm.getInstanceName());
return false;
}
return false;
}
use of com.cloud.agent.manager.Commands in project cloudstack by apache.
the class RemoteHostEndPoint method sendMessageAsync.
@Override
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
try {
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
if (newHostId != hostId) {
// update endpoint with new host if changed
setId(newHostId);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId);
}
agentMgr.send(newHostId, new Commands(cmd), new CmdRunner(callback));
} catch (AgentUnavailableException e) {
throw new CloudRuntimeException("Unable to send message", e);
}
}
Aggregations