use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand 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);
}
}
use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.
the class CommandSetupHelper method createApplyPortForwardingRulesCommands.
public void createApplyPortForwardingRulesCommands(final List<? extends PortForwardingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
final List<PortForwardingRuleTO> rulesTO = new ArrayList<PortForwardingRuleTO>();
if (rules != null) {
for (final PortForwardingRule rule : rules) {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, null, sourceIp.getAddress().addr());
rulesTO.add(ruleTO);
}
}
SetPortForwardingRulesCommand cmd = null;
if (router.getVpcId() != null) {
cmd = new SetPortForwardingRulesVpcCommand(rulesTO);
} else {
cmd = new SetPortForwardingRulesCommand(rulesTO);
}
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand(cmd);
}
use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.
the class SetPortForwardingRulesConfigItem method generateConfig.
@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
final SetPortForwardingRulesCommand command = (SetPortForwardingRulesCommand) cmd;
final List<ForwardingRule> rules = new ArrayList<ForwardingRule>();
for (final PortForwardingRuleTO rule : command.getRules()) {
final ForwardingRule fwdRule = new ForwardingRule(rule.revoked(), rule.getProtocol().toLowerCase(), rule.getSrcIp(), rule.getStringSrcPortRange(), rule.getDstIp(), rule.getStringDstPortRange());
rules.add(fwdRule);
}
final ForwardingRules ruleSet = new ForwardingRules(rules.toArray(new ForwardingRule[rules.size()]));
return generateConfigItems(ruleSet);
}
use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.
the class CiscoVnmcElement method applyPFRules.
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.PortForwarding, Provider.CiscoVnmc)) {
s_logger.error("Port forwarding service is not provided by Cisco Vnmc device on network " + network.getName());
return false;
}
// Find VNMC host for physical network
List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No Cisco Vnmc device on network " + network.getName());
return true;
}
// Find if ASA 1000v is associated with network
NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId());
if (asaForNetwork == null) {
s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName());
return true;
}
if (network.getState() == Network.State.Allocated) {
s_logger.debug("External firewall was asked to apply port forwarding rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
return true;
}
CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
List<PortForwardingRuleTO> rulesTO = new ArrayList<PortForwardingRuleTO>();
for (PortForwardingRule rule : rules) {
IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
rulesTO.add(ruleTO);
}
if (!rulesTO.isEmpty()) {
SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rulesTO);
cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, BroadcastDomainType.getValue(network.getBroadcastUri()));
cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, network.getCidr());
Answer answer = _agentMgr.easySend(ciscoVnmcHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
String details = (answer != null) ? answer.getDetails() : "details unavailable";
String msg = "Unable to apply port forwarding rules to Cisco ASA 1000v appliance due to: " + details + ".";
s_logger.error(msg);
throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
}
}
return true;
}
use of com.cloud.agent.api.routing.SetPortForwardingRulesCommand in project cloudstack by apache.
the class CiscoVnmcResourceTest method testPortForwarding.
@Test
public void testPortForwarding() throws ConfigurationException, Exception {
long vlanId = 123;
List<PortForwardingRuleTO> rules = new ArrayList<PortForwardingRuleTO>();
PortForwardingRuleTO active = new PortForwardingRuleTO(1, "1.2.3.4", 22, 22, "5.6.7.8", 22, 22, "tcp", false, false);
rules.add(active);
PortForwardingRuleTO revoked = new PortForwardingRuleTO(1, "1.2.3.4", 22, 22, "5.6.7.8", 22, 22, "tcp", false, false);
rules.add(revoked);
SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rules);
cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, Long.toString(vlanId));
cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, "1.2.3.4/32");
_resource.setConnection(_connection);
when(_connection.createTenantVDCNatPolicySet(anyString())).thenReturn(true);
when(_connection.createTenantVDCAclPolicySet(anyString(), anyBoolean())).thenReturn(true);
when(_connection.createTenantVDCPFPolicy(anyString(), anyString())).thenReturn(true);
when(_connection.createTenantVDCPFPolicyRef(anyString(), anyString())).thenReturn(true);
when(_connection.createTenantVDCAclPolicy(anyString(), anyString())).thenReturn(true);
when(_connection.createTenantVDCAclPolicyRef(anyString(), anyString(), anyBoolean())).thenReturn(true);
when(_connection.deleteTenantVDCPFRule(anyString(), anyLong(), anyString())).thenReturn(true);
when(_connection.deleteTenantVDCAclRule(anyString(), anyLong(), anyString())).thenReturn(true);
when(_connection.createTenantVDCPFIpPool(anyString(), anyString(), anyString())).thenReturn(true);
when(_connection.createTenantVDCPFPortPool(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
when(_connection.createTenantVDCPFRule(anyString(), anyLong(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true);
when(_connection.createTenantVDCAclRuleForPF(anyString(), anyLong(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true);
when(_connection.associateAclPolicySet(anyString())).thenReturn(true);
Answer answer = _resource.executeRequest(cmd);
System.out.println(answer.getDetails());
assertTrue(answer.getResult());
}
Aggregations