Search in sources :

Example 56 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final IpAssociationRules ipRules) throws ResourceUnavailableException {
    final Network network = ipRules.getNetwork();
    final VirtualRouter router = ipRules.getRouter();
    final Commands commands = new Commands(Command.OnError.Continue);
    final List<? extends PublicIpAddress> ips = ipRules.getIpAddresses();
    _commandSetupHelper.createAssociateIPCommands(router, ips, commands, network.getId());
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 57 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@SuppressWarnings("unchecked")
@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
    final Network network = firewall.getNetwork();
    final VirtualRouter router = firewall.getRouter();
    final List<? extends FirewallRule> rules = firewall.getRules();
    final List<LoadBalancingRule> loadbalancingRules = firewall.getLoadbalancingRules();
    final Purpose purpose = firewall.getPurpose();
    final Commands cmds = new Commands(Command.OnError.Continue);
    if (purpose == Purpose.LoadBalancing) {
        _commandSetupHelper.createApplyLoadBalancingRulesCommands(loadbalancingRules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.PortForwarding) {
        _commandSetupHelper.createApplyPortForwardingRulesCommands((List<? extends PortForwardingRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.StaticNat) {
        _commandSetupHelper.createApplyStaticNatRulesCommands((List<StaticNatRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.Firewall) {
        _commandSetupHelper.createApplyFirewallRulesCommands(rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    }
    s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
    return false;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) Purpose(com.cloud.network.rules.FirewallRule.Purpose) List(java.util.List) ArrayList(java.util.ArrayList) StaticNatRule(com.cloud.network.rules.StaticNatRule) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 58 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class OvsTunnelManagerImpl method getGreEndpointIP.

private String getGreEndpointIP(Host host, Network nw) throws AgentUnavailableException, OperationTimedoutException {
    String endpointIp = null;
    // Fetch fefault name for network label from configuration
    String physNetLabel = _configDao.getValue(Config.OvsTunnelNetworkDefaultLabel.key());
    Long physNetId = nw.getPhysicalNetworkId();
    PhysicalNetworkTrafficType physNetTT = _physNetTTDao.findBy(physNetId, TrafficType.Guest);
    HypervisorType hvType = host.getHypervisorType();
    String label = null;
    switch(hvType) {
        case XenServer:
            label = physNetTT.getXenNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        case KVM:
            label = physNetTT.getKvmNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        default:
            throw new CloudRuntimeException("Hypervisor " + hvType.toString() + " unsupported by OVS Tunnel Manager");
    }
    // Try to fetch GRE endpoint IP address for cloud db
    // If not found, then find it on the hypervisor
    OvsTunnelInterfaceVO tunnelIface = _tunnelInterfaceDao.getByHostAndLabel(host.getId(), physNetLabel);
    if (tunnelIface == null) {
        //Now find and fetch configuration for physical interface
        //for network with label on target host
        Commands fetchIfaceCmds = new Commands(new OvsFetchInterfaceCommand(physNetLabel));
        s_logger.debug("Ask host " + host.getId() + " to retrieve interface for phy net with label:" + physNetLabel);
        Answer[] fetchIfaceAnswers = _agentMgr.send(host.getId(), fetchIfaceCmds);
        //And finally save it for future use
        endpointIp = handleFetchInterfaceAnswer(fetchIfaceAnswers, host.getId());
    } else {
        endpointIp = tunnelIface.getIp();
    }
    return endpointIp;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) OvsTunnelInterfaceVO(com.cloud.network.ovs.dao.OvsTunnelInterfaceVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Commands(com.cloud.agent.manager.Commands) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 59 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class OvsTunnelManagerImpl method checkAndCreateVpcTunnelNetworks.

@DB
protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) {
    long hostId = host.getId();
    String bridgeName = generateBridgeNameForVpc(vpcId);
    List<Long> vmIds = _ovsNetworkToplogyGuru.getActiveVmsInVpcOnHost(vpcId, hostId);
    if (vmIds == null || vmIds.isEmpty()) {
        // since this is the first VM from the VPC being launched on the host, first setup the bridge
        try {
            Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, null));
            s_logger.debug("Ask host " + hostId + " to create bridge for vpc " + vpcId + " and configure the " + " bridge for distributed routing.");
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleSetupBridgeAnswer(answers);
        } catch (OperationTimedoutException | AgentUnavailableException e) {
            s_logger.warn("Ovs Tunnel network created tunnel failed", e);
        }
        // now that bridge is setup, populate network acl's before the VM gets created
        OvsVpcRoutingPolicyConfigCommand cmd = prepareVpcRoutingPolicyUpdate(vpcId);
        cmd.setSequenceNumber(getNextRoutingPolicyUpdateSequenceNumber(vpcId));
        if (!sendVpcRoutingPolicyChangeUpdate(cmd, hostId, bridgeName)) {
            s_logger.debug("Failed to send VPC routing policy change update to host : " + hostId + ". But moving on with sending the updates to the rest of the hosts.");
        }
    }
    List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
    List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
    for (Network vpcNetwork : vpcNetworks) {
        if (vpcNetwork.getState() != Network.State.Implemented && vpcNetwork.getState() != Network.State.Implementing && vpcNetwork.getState() != Network.State.Setup)
            continue;
        int key = getGreKey(vpcNetwork);
        List<Long> toHostIds = new ArrayList<Long>();
        List<Long> fromHostIds = new ArrayList<Long>();
        OvsTunnelNetworkVO tunnelRecord = null;
        for (Long rh : vpcSpannedHostIds) {
            if (rh == hostId) {
                continue;
            }
            tunnelRecord = _tunnelNetworkDao.getByFromToNetwork(hostId, rh.longValue(), vpcNetwork.getId());
            // Try and create the tunnel if does not exit or previous attempt failed
            if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) {
                s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
                if (tunnelRecord == null) {
                    createTunnelRecord(hostId, rh.longValue(), vpcNetwork.getId(), key);
                }
                if (!toHostIds.contains(rh)) {
                    toHostIds.add(rh);
                }
            }
            tunnelRecord = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(), hostId, vpcNetwork.getId());
            // Try and create the tunnel if does not exit or previous attempt failed
            if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) {
                s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
                if (tunnelRecord == null) {
                    createTunnelRecord(rh.longValue(), hostId, vpcNetwork.getId(), key);
                }
                if (!fromHostIds.contains(rh)) {
                    fromHostIds.add(rh);
                }
            }
        }
        try {
            String myIp = getGreEndpointIP(host, vpcNetwork);
            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, vpcNetwork);
                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, vpcNetwork.getId(), myIp, bridgeName, vpcNetwork.getUuid()));
                s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + vpcNetwork.getId());
                s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
                Answer[] answers = _agentMgr.send(hostId, cmds);
                handleCreateTunnelAnswer(answers);
            }
            for (Long i : fromHostIds) {
                HostVO rHost = _hostDao.findById(i);
                String otherIp = getGreEndpointIP(rHost, vpcNetwork);
                Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), vpcNetwork.getId(), otherIp, bridgeName, vpcNetwork.getUuid()));
                s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
                Answer[] answers = _agentMgr.send(i, cmds);
                handleCreateTunnelAnswer(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);
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) ArrayList(java.util.ArrayList) OvsVpcRoutingPolicyConfigCommand(com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand) HostVO(com.cloud.host.HostVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) DB(com.cloud.utils.db.DB)

Example 60 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VirtualMachineManagerImpl method processConnect.

@Override
public void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Received startup command from hypervisor host. host id: " + agent.getId());
    }
    _syncMgr.resetHostSyncState(agent.getId());
    if (forRebalance) {
        s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process");
        return;
    }
    final Long clusterId = agent.getClusterId();
    final long agentId = agent.getId();
    if (agent.getHypervisorType() == HypervisorType.XenServer) {
        // only for Xen
        // initiate the cron job
        final ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand(ClusterVMMetaDataSyncInterval.value(), clusterId);
        try {
            final long seq_no = _agentMgr.send(agentId, new Commands(syncVMMetaDataCmd), this);
            s_logger.debug("Cluster VM metadata sync started with jobid " + seq_no);
        } catch (final AgentUnavailableException e) {
            s_logger.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e);
        }
    }
}
Also used : ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Aggregations

Commands (com.cloud.agent.manager.Commands)64 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)22 VirtualRouter (com.cloud.network.router.VirtualRouter)19 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 Answer (com.cloud.agent.api.Answer)16 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)13 Network (com.cloud.network.Network)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 NicVO (com.cloud.vm.NicVO)10 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)9 ArrayList (java.util.ArrayList)9 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)8 UserVmVO (com.cloud.vm.UserVmVO)8 DataCenter (com.cloud.dc.DataCenter)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)7 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)6 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)6 StartAnswer (com.cloud.agent.api.StartAnswer)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6