Search in sources :

Example 1 with IpAssocCommand

use of com.cloud.agent.api.routing.IpAssocCommand in project CloudStack-archive by CloudStack-extras.

the class SimulatorManagerImpl method simulate.

@DB
@Override
public Answer simulate(Command cmd, String hostGuid) {
    Transaction txn = Transaction.currentTxn();
    txn.transitToUserManagedConnection(_concierge.conn());
    try {
        MockHost host = _mockHost.findByGuid(hostGuid);
        String cmdName = cmd.toString();
        int index = cmdName.lastIndexOf(".");
        if (index != -1) {
            cmdName = cmdName.substring(index + 1);
        }
        MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
        SimulatorInfo info = new SimulatorInfo();
        info.setHostUuid(hostGuid);
        if (config != null) {
            Map<String, String> configParameters = config.getParameters();
            for (Map.Entry<String, String> entry : configParameters.entrySet()) {
                if (entry.getKey().equalsIgnoreCase("enabled")) {
                    info.setEnabled(Boolean.parseBoolean(entry.getValue()));
                } else if (entry.getKey().equalsIgnoreCase("timeout")) {
                    try {
                        info.setTimeout(Integer.valueOf(entry.getValue()));
                    } catch (NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    }
                } else if (entry.getKey().equalsIgnoreCase("wait")) {
                    try {
                        int wait = Integer.valueOf(entry.getValue());
                        Thread.sleep(wait * 1000);
                    } catch (NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    } catch (InterruptedException e) {
                        s_logger.debug("thread is interrupted: " + e.toString());
                    }
                }
            }
        }
        if (cmd instanceof GetHostStatsCommand) {
            return _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
        } else if (cmd instanceof CheckHealthCommand) {
            return _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
        } else if (cmd instanceof PingTestCommand) {
            return _mockAgentMgr.pingTest((PingTestCommand) cmd);
        } else if (cmd instanceof MigrateCommand) {
            return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
        } else if (cmd instanceof StartCommand) {
            return _mockVmMgr.startVM((StartCommand) cmd, info);
        } else if (cmd instanceof CheckSshCommand) {
            return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
        } else if (cmd instanceof SetStaticNatRulesCommand) {
            return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
        } else if (cmd instanceof SetPortForwardingRulesCommand) {
            return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
        } else if (cmd instanceof NetworkUsageCommand) {
            return _mockVmMgr.getNetworkUsage((NetworkUsageCommand) cmd);
        } else if (cmd instanceof IpAssocCommand) {
            return _mockVmMgr.IpAssoc((IpAssocCommand) cmd);
        } else if (cmd instanceof LoadBalancerConfigCommand) {
            return _mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
        } else if (cmd instanceof DhcpEntryCommand) {
            return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
        } else if (cmd instanceof VmDataCommand) {
            return _mockVmMgr.setVmData((VmDataCommand) cmd);
        } else if (cmd instanceof CleanupNetworkRulesCmd) {
            return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
        } else if (cmd instanceof CheckNetworkCommand) {
            return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
        } else if (cmd instanceof StopCommand) {
            return _mockVmMgr.stopVM((StopCommand) cmd);
        } else if (cmd instanceof RebootCommand) {
            return _mockVmMgr.rebootVM((RebootCommand) cmd);
        } else if (cmd instanceof GetVncPortCommand) {
            return _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
        } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
            return _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
        } else if (cmd instanceof WatchConsoleProxyLoadCommand) {
            return _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
        } else if (cmd instanceof SecurityGroupRulesCmd) {
            return _mockVmMgr.AddSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
        } else if (cmd instanceof SavePasswordCommand) {
            return _mockVmMgr.SavePassword((SavePasswordCommand) cmd);
        } else if (cmd instanceof PrimaryStorageDownloadCommand) {
            return _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
        } else if (cmd instanceof CreateCommand) {
            return _mockStorageMgr.createVolume((CreateCommand) cmd);
        } else if (cmd instanceof AttachVolumeCommand) {
            return _mockStorageMgr.AttachVolume((AttachVolumeCommand) cmd);
        } else if (cmd instanceof AttachIsoCommand) {
            return _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
        } else if (cmd instanceof DeleteStoragePoolCommand) {
            return _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
        } else if (cmd instanceof ModifyStoragePoolCommand) {
            return _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
        } else if (cmd instanceof CreateStoragePoolCommand) {
            return _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
        } else if (cmd instanceof SecStorageSetupCommand) {
            return _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
        } else if (cmd instanceof ListTemplateCommand) {
            return _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
        } else if (cmd instanceof DestroyCommand) {
            return _mockStorageMgr.Destroy((DestroyCommand) cmd);
        } else if (cmd instanceof DownloadProgressCommand) {
            return _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
        } else if (cmd instanceof DownloadCommand) {
            return _mockStorageMgr.Download((DownloadCommand) cmd);
        } else if (cmd instanceof GetStorageStatsCommand) {
            return _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
        } else if (cmd instanceof ManageSnapshotCommand) {
            return _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
        } else if (cmd instanceof BackupSnapshotCommand) {
            return _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
        } else if (cmd instanceof DeleteSnapshotBackupCommand) {
            return _mockStorageMgr.DeleteSnapshotBackup((DeleteSnapshotBackupCommand) cmd);
        } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
            return _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
        } else if (cmd instanceof DeleteTemplateCommand) {
            return _mockStorageMgr.DeleteTemplate((DeleteTemplateCommand) cmd);
        } else if (cmd instanceof SecStorageVMSetupCommand) {
            return _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
            return _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (cmd instanceof ComputeChecksumCommand) {
            return _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
            return _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (cmd instanceof MaintainCommand) {
            return _mockAgentMgr.MaintainCommand((MaintainCommand) cmd);
        } else if (cmd instanceof GetVmStatsCommand) {
            return _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
        } else if (cmd instanceof GetDomRVersionCmd) {
            return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
        } else if (cmd instanceof ClusterSyncCommand) {
            return new Answer(cmd);
        } else if (cmd instanceof CopyVolumeCommand) {
            return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
        } else {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
    } catch (Exception e) {
        s_logger.debug("Failed execute cmd: " + e.toString());
        txn.rollback();
        return new Answer(cmd, false, e.toString());
    } finally {
        txn.transitToAutoManagedConnection(Transaction.CLOUD_DB);
    }
}
Also used : GetDomRVersionCmd(com.cloud.agent.api.GetDomRVersionCmd) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) ComputeChecksumCommand(com.cloud.agent.api.ComputeChecksumCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) AttachVolumeCommand(com.cloud.agent.api.AttachVolumeCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) DeleteSnapshotBackupCommand(com.cloud.agent.api.DeleteSnapshotBackupCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) CreateCommand(com.cloud.agent.api.storage.CreateCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) StopCommand(com.cloud.agent.api.StopCommand) Transaction(com.cloud.utils.db.Transaction) SecStorageVMSetupCommand(com.cloud.agent.api.SecStorageVMSetupCommand) Map(java.util.Map) HashMap(java.util.HashMap) MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) RebootCommand(com.cloud.agent.api.RebootCommand) StartCommand(com.cloud.agent.api.StartCommand) CheckConsoleProxyLoadCommand(com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) DownloadCommand(com.cloud.agent.api.storage.DownloadCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) WatchConsoleProxyLoadCommand(com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) DeleteTemplateCommand(com.cloud.agent.api.storage.DeleteTemplateCommand) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) ClusterSyncCommand(com.cloud.agent.api.ClusterSyncCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) DownloadProgressCommand(com.cloud.agent.api.storage.DownloadProgressCommand) Answer(com.cloud.agent.api.Answer) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) MockHost(com.cloud.simulator.MockHost) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) DB(com.cloud.utils.db.DB)

Example 2 with IpAssocCommand

use of com.cloud.agent.api.routing.IpAssocCommand in project cloudstack by apache.

the class IpAssociationConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final IpAssocCommand command = (IpAssocCommand) cmd;
    final List<IpAddress> ips = new LinkedList<IpAddress>();
    for (final IpAddressTO ip : command.getIpAddresses()) {
        final IpAddress ipAddress = new IpAddress(ip.getPublicIp(), ip.isSourceNat(), ip.isAdd(), ip.isOneToOneNat(), ip.isFirstIP(), ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNicDevId(), ip.isNewNic(), ip.getTrafficType().toString());
        ips.add(ipAddress);
    }
    final IpAssociation ipAssociation = new IpAssociation(ips.toArray(new IpAddress[ips.size()]));
    return generateConfigItems(ipAssociation);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) IpAddress(com.cloud.agent.resource.virtualnetwork.model.IpAddress) IpAssociation(com.cloud.agent.resource.virtualnetwork.model.IpAssociation) LinkedList(java.util.LinkedList)

Example 3 with IpAssocCommand

use of com.cloud.agent.api.routing.IpAssocCommand in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method manageGuestNetworkWithExternalLoadBalancer.

@Override
public boolean manageGuestNetworkWithExternalLoadBalancer(boolean add, Network guestConfig) throws ResourceUnavailableException, InsufficientCapacityException {
    if (guestConfig.getTrafficType() != TrafficType.Guest) {
        s_logger.trace("External load balancer can only be used for guest networks.");
        return false;
    }
    long zoneId = guestConfig.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    HostVO externalLoadBalancer = null;
    if (add) {
        ExternalLoadBalancerDeviceVO lbDeviceVO = null;
        // on restart network, device could have been allocated already, skip allocation if a device is assigned
        lbDeviceVO = getExternalLoadBalancerForNetwork(guestConfig);
        if (lbDeviceVO == null) {
            // allocate a load balancer device for the network
            lbDeviceVO = allocateLoadBalancerForNetwork(guestConfig);
            if (lbDeviceVO == null) {
                String msg = "failed to alloacate a external load balancer for the network " + guestConfig.getId();
                s_logger.error(msg);
                throw new InsufficientNetworkCapacityException(msg, DataCenter.class, guestConfig.getDataCenterId());
            }
        }
        externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        s_logger.debug("Allocated external load balancer device:" + lbDeviceVO.getId() + " for the network: " + guestConfig.getId());
    } else {
        // find the load balancer device allocated for the network
        ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(guestConfig);
        if (lbDeviceVO == null) {
            s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." + " Either network implement failed half way through or already network shutdown is completed. So just returning.");
            return true;
        }
        externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        assert (externalLoadBalancer != null) : "There is no device assigned to this network how did shutdown network ended up here??";
    }
    // Send a command to the external load balancer to implement or shutdown the guest network
    String guestVlanTag = BroadcastDomainType.getValue(guestConfig.getBroadcastUri());
    String selfIp = null;
    String guestVlanNetmask = NetUtils.cidr2Netmask(guestConfig.getCidr());
    Integer networkRate = _networkModel.getNetworkRate(guestConfig.getId(), null);
    if (add) {
        // on restart network, network could have already been implemented. If already implemented then return
        Nic selfipNic = getPlaceholderNic(guestConfig);
        if (selfipNic != null) {
            return true;
        }
        // Acquire a self-ip address from the guest network IP address range
        selfIp = _ipAddrMgr.acquireGuestIpAddress(guestConfig, null);
        if (selfIp == null) {
            String msg = "failed to acquire guest IP address so not implementing the network on the external load balancer ";
            s_logger.error(msg);
            throw new InsufficientNetworkCapacityException(msg, Network.class, guestConfig.getId());
        }
    } else {
        // get the self-ip used by the load balancer
        Nic selfipNic = getPlaceholderNic(guestConfig);
        if (selfipNic == null) {
            s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." + " Either network implement failed half way through or already network shutdown is completed. So just returning.");
            return true;
        }
        selfIp = selfipNic.getIPv4Address();
    }
    // It's a hack, using isOneToOneNat field for indicate if it's inline or not
    boolean inline = _networkMgr.isNetworkInlineMode(guestConfig);
    IpAddressTO ip = new IpAddressTO(guestConfig.getAccountId(), null, add, false, true, guestVlanTag, selfIp, guestVlanNetmask, null, networkRate, inline);
    IpAddressTO[] ips = new IpAddressTO[1];
    ips[0] = ip;
    IpAssocCommand cmd = new IpAssocCommand(ips);
    Answer answer = _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        String action = add ? "implement" : "shutdown";
        String answerDetails = (answer != null) ? answer.getDetails() : null;
        answerDetails = (answerDetails != null) ? " due to " + answerDetails : "";
        String msg = "External load balancer was unable to " + action + " the guest network on the external load balancer in zone " + zone.getName() + answerDetails;
        s_logger.error(msg);
        throw new ResourceUnavailableException(msg, Network.class, guestConfig.getId());
    }
    if (add) {
        // Insert a new NIC for this guest network to reserve the self IP
        _networkMgr.savePlaceholderNic(guestConfig, selfIp, null, null);
    } else {
        // release the self-ip obtained from guest network
        Nic selfipNic = getPlaceholderNic(guestConfig);
        _nicDao.remove(selfipNic.getId());
        // release the load balancer allocated for the network
        boolean releasedLB = freeLoadBalancerForNetwork(guestConfig);
        if (!releasedLB) {
            String msg = "Failed to release the external load balancer used for the network: " + guestConfig.getId();
            s_logger.error(msg);
        }
    }
    if (s_logger.isDebugEnabled()) {
        Account account = _accountDao.findByIdIncludingRemoved(guestConfig.getAccountId());
        String action = add ? "implemented" : "shut down";
        s_logger.debug("External load balancer has " + action + " the guest network for account " + account.getAccountName() + "(id = " + account.getAccountId() + ") with VLAN tag " + guestVlanTag);
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) Nic(com.cloud.vm.Nic) HostVO(com.cloud.host.HostVO) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) DestroyLoadBalancerApplianceAnswer(com.cloud.network.resource.DestroyLoadBalancerApplianceAnswer) Answer(com.cloud.agent.api.Answer) CreateLoadBalancerApplianceAnswer(com.cloud.network.resource.CreateLoadBalancerApplianceAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 4 with IpAssocCommand

use of com.cloud.agent.api.routing.IpAssocCommand in project cloudstack by apache.

the class HypervDirectConnectResource method executeRequest.

// TODO: Is it valid to return NULL, or should we throw on error?
@Override
public final Answer executeRequest(final Command cmd) {
    // Set HTTP POST destination URI
    // Using java.net.URI, see
    // http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URI.html
    URI agentUri = null;
    final Class<? extends Command> clazz = cmd.getClass();
    Answer answer = null;
    try {
        final String cmdName = cmd.getClass().getName();
        agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + cmdName, null, null);
    } catch (final URISyntaxException e) {
        // TODO add proper logging
        final String errMsg = "Could not generate URI for Hyper-V agent";
        s_logger.error(errMsg, e);
        return null;
    }
    if (cmd instanceof NetworkElementCommand) {
        return _vrResource.executeRequest((NetworkElementCommand) cmd);
    }
    if (clazz == CheckSshCommand.class) {
        answer = execute((CheckSshCommand) cmd);
    } else if (clazz == GetDomRVersionCmd.class) {
        answer = execute((GetDomRVersionCmd) cmd);
    } else if (cmd instanceof NetworkUsageCommand) {
        answer = execute((NetworkUsageCommand) cmd);
    } else if (clazz == IpAssocCommand.class) {
        answer = execute((IpAssocCommand) cmd);
    } else if (clazz == DnsMasqConfigCommand.class) {
        return execute((DnsMasqConfigCommand) cmd);
    } else if (clazz == CreateIpAliasCommand.class) {
        return execute((CreateIpAliasCommand) cmd);
    } else if (clazz == DhcpEntryCommand.class) {
        answer = execute((DhcpEntryCommand) cmd);
    } else if (clazz == VmDataCommand.class) {
        answer = execute((VmDataCommand) cmd);
    } else if (clazz == SavePasswordCommand.class) {
        answer = execute((SavePasswordCommand) cmd);
    } else if (clazz == SetFirewallRulesCommand.class) {
        answer = execute((SetFirewallRulesCommand) cmd);
    } else if (clazz == LoadBalancerConfigCommand.class) {
        answer = execute((LoadBalancerConfigCommand) cmd);
    } else if (clazz == DeleteIpAliasCommand.class) {
        return execute((DeleteIpAliasCommand) cmd);
    } else if (clazz == PingTestCommand.class) {
        answer = execute((PingTestCommand) cmd);
    } else if (clazz == SetStaticNatRulesCommand.class) {
        answer = execute((SetStaticNatRulesCommand) cmd);
    } else if (clazz == CheckRouterCommand.class) {
        answer = execute((CheckRouterCommand) cmd);
    } else if (clazz == SetPortForwardingRulesCommand.class) {
        answer = execute((SetPortForwardingRulesCommand) cmd);
    } else if (clazz == SetSourceNatCommand.class) {
        answer = execute((SetSourceNatCommand) cmd);
    } else if (clazz == Site2SiteVpnCfgCommand.class) {
        answer = execute((Site2SiteVpnCfgCommand) cmd);
    } else if (clazz == CheckS2SVpnConnectionsCommand.class) {
        answer = execute((CheckS2SVpnConnectionsCommand) cmd);
    } else if (clazz == RemoteAccessVpnCfgCommand.class) {
        answer = execute((RemoteAccessVpnCfgCommand) cmd);
    } else if (clazz == VpnUsersCfgCommand.class) {
        answer = execute((VpnUsersCfgCommand) cmd);
    } else if (clazz == SetStaticRouteCommand.class) {
        answer = execute((SetStaticRouteCommand) cmd);
    } else if (clazz == SetMonitorServiceCommand.class) {
        answer = execute((SetMonitorServiceCommand) cmd);
    } else if (clazz == PlugNicCommand.class) {
        answer = execute((PlugNicCommand) cmd);
    } else if (clazz == UnPlugNicCommand.class) {
        answer = execute((UnPlugNicCommand) cmd);
    } else if (clazz == CopyCommand.class) {
        answer = execute((CopyCommand) cmd);
    } else {
        if (clazz == StartCommand.class) {
            final VirtualMachineTO vmSpec = ((StartCommand) cmd).getVirtualMachine();
            if (vmSpec.getType() != VirtualMachine.Type.User) {
                if (s_hypervMgr != null) {
                    final String secondary = s_hypervMgr.prepareSecondaryStorageStore(Long.parseLong(_zoneId));
                    if (secondary != null) {
                        ((StartCommand) cmd).setSecondaryStorage(secondary);
                    }
                } else {
                    s_logger.error("Hyperv manager isn't available. Couldn't check and copy the systemvm iso.");
                }
            }
        }
        // Send the cmd to hyperv agent.
        final String ansStr = postHttpRequest(s_gson.toJson(cmd), agentUri);
        if (ansStr == null) {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        // Only Answer instances are returned by remote agents.
        // E.g. see Response.getAnswers()
        final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
        final String logResult = cleanPassword(s_gson.toJson(result));
        s_logger.debug("executeRequest received response " + logResult);
        if (result.length > 0) {
            return result[0];
        }
    }
    return answer;
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) Site2SiteVpnCfgCommand(com.cloud.agent.api.routing.Site2SiteVpnCfgCommand) StartCommand(com.cloud.agent.api.StartCommand) GetDomRVersionCmd(com.cloud.agent.api.GetDomRVersionCmd) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) URISyntaxException(java.net.URISyntaxException) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) URI(java.net.URI) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) SetMonitorServiceCommand(com.cloud.agent.api.routing.SetMonitorServiceCommand) CreateIpAliasCommand(com.cloud.agent.api.routing.CreateIpAliasCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand) SetStaticRouteCommand(com.cloud.agent.api.routing.SetStaticRouteCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) SetPortForwardingRulesAnswer(com.cloud.agent.api.routing.SetPortForwardingRulesAnswer) SetSourceNatAnswer(com.cloud.agent.api.routing.SetSourceNatAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) GetVmConfigAnswer(com.cloud.agent.api.GetVmConfigAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) SetFirewallRulesAnswer(com.cloud.agent.api.routing.SetFirewallRulesAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) SetStaticRouteAnswer(com.cloud.agent.api.routing.SetStaticRouteAnswer) RemoteAccessVpnCfgCommand(com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand)

Example 5 with IpAssocCommand

use of com.cloud.agent.api.routing.IpAssocCommand in project cloudstack by apache.

the class VirtualRoutingResourceTest method testIpAssocCommand.

@Test
public void testIpAssocCommand() {
    final IpAssocCommand cmd = generateIpAssocCommand();
    _count = 0;
    final Answer answer = _resource.executeRequest(cmd);
    assertTrue(answer instanceof GroupAnswer);
    assertEquals(2, ((GroupAnswer) answer).getResults().length);
    assertTrue(answer.getResult());
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Answer(com.cloud.agent.api.Answer) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) Test(org.junit.Test)

Aggregations

IpAssocCommand (com.cloud.agent.api.routing.IpAssocCommand)16 IpAddressTO (com.cloud.agent.api.to.IpAddressTO)8 Answer (com.cloud.agent.api.Answer)7 Test (org.junit.Test)6 GetDomRVersionCmd (com.cloud.agent.api.GetDomRVersionCmd)3 CloudStackPluginTest (com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest)3 ConnectionTest (com.cloud.hypervisor.ovm3.objects.ConnectionTest)3 LinuxTest (com.cloud.hypervisor.ovm3.objects.LinuxTest)3 NetworkTest (com.cloud.hypervisor.ovm3.objects.NetworkTest)3 XenTest (com.cloud.hypervisor.ovm3.objects.XenTest)3 XmlTestResultTest (com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)3 Ovm3ConfigurationTest (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)3 Ovm3SupportTest (com.cloud.hypervisor.ovm3.support.Ovm3SupportTest)3 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)2 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)2 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)2 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)2 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)2 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)2