Search in sources :

Example 1 with DeleteIpAliasCommand

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

the class DeleteIpAliasConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final DeleteIpAliasCommand command = (DeleteIpAliasCommand) cmd;
    final List<IpAddressAlias> ipAliases = new LinkedList<IpAddressAlias>();
    final List<IpAliasTO> revokedIpAliasTOs = command.getDeleteIpAliasTos();
    for (final IpAliasTO ipAliasTO : revokedIpAliasTOs) {
        final IpAddressAlias alias = new IpAddressAlias(true, ipAliasTO.getRouterip(), ipAliasTO.getNetmask(), Long.parseLong(ipAliasTO.getAlias_count()));
        ipAliases.add(alias);
    }
    final List<IpAliasTO> activeIpAliasTOs = command.getCreateIpAliasTos();
    for (final IpAliasTO ipAliasTO : activeIpAliasTOs) {
        final IpAddressAlias alias = new IpAddressAlias(false, ipAliasTO.getRouterip(), ipAliasTO.getNetmask(), Long.parseLong(ipAliasTO.getAlias_count()));
        ipAliases.add(alias);
    }
    final IpAliases ipAliasList = new IpAliases(ipAliases);
    return generateConfigItems(ipAliasList);
}
Also used : IpAddressAlias(com.cloud.agent.resource.virtualnetwork.model.IpAddressAlias) DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand) IpAliasTO(com.cloud.agent.api.routing.IpAliasTO) IpAliases(com.cloud.agent.resource.virtualnetwork.model.IpAliases) LinkedList(java.util.LinkedList)

Example 2 with DeleteIpAliasCommand

use of com.cloud.agent.api.routing.DeleteIpAliasCommand 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 3 with DeleteIpAliasCommand

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

the class CommandSetupHelper method createDeleteIpAliasCommand.

public void createDeleteIpAliasCommand(final DomainRouterVO router, final List<IpAliasTO> deleteIpAliasTOs, final List<IpAliasTO> createIpAliasTos, final long networkId, final Commands cmds) {
    final String routerip = _routerControlHelper.getRouterIpInNetwork(networkId, router.getId());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    final DeleteIpAliasCommand deleteIpaliasCmd = new DeleteIpAliasCommand(routerip, deleteIpAliasTOs, createIpAliasTos);
    deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, routerip);
    deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand("deleteIpalias", deleteIpaliasCmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand)

Example 4 with DeleteIpAliasCommand

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

the class ConfigHelperTest method generateDeleteIpAliasCommand.

protected DeleteIpAliasCommand generateDeleteIpAliasCommand() {
    final List<IpAliasTO> aliases = new ArrayList<>();
    aliases.add(new IpAliasTO("169.254.3.10", "255.255.255.0", "1"));
    aliases.add(new IpAliasTO("169.254.3.11", "255.255.255.0", "2"));
    aliases.add(new IpAliasTO("169.254.3.12", "255.255.255.0", "3"));
    final DeleteIpAliasCommand cmd = new DeleteIpAliasCommand("169.254.10.1", aliases, aliases);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
    return cmd;
}
Also used : DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand) ArrayList(java.util.ArrayList) IpAliasTO(com.cloud.agent.api.routing.IpAliasTO)

Example 5 with DeleteIpAliasCommand

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

the class ConfigHelperTest method testDeleteIpAlias.

@Test
public void testDeleteIpAlias() {
    final DeleteIpAliasCommand command = generateDeleteIpAliasCommand();
    final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(command.getClass());
    final List<ConfigItem> config = configItemFacade.generateConfig(command);
    assertTrue(config.size() > 0);
    final ConfigItem fileConfig = config.get(0);
    assertNotNull(fileConfig);
    assertTrue(fileConfig instanceof FileConfigItem);
    final String fileContents = ((FileConfigItem) fileConfig).getFileContents();
    assertNotNull(fileContents);
    final IpAliases jsonClass = gson.fromJson(fileContents, IpAliases.class);
    assertNotNull(jsonClass);
    assertEquals(jsonClass.getType(), "ipaliases");
    final List<IpAddressAlias> aliases = jsonClass.getAliases();
    assertNotNull(aliases);
    assertTrue(aliases.size() == 6);
    assertEquals(aliases.get(0).getIpAddress(), "169.254.3.10");
    final ConfigItem scriptConfig = config.get(1);
    assertNotNull(scriptConfig);
    assertTrue(scriptConfig instanceof ScriptConfigItem);
}
Also used : IpAddressAlias(com.cloud.agent.resource.virtualnetwork.model.IpAddressAlias) AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) DeleteIpAliasCommand(com.cloud.agent.api.routing.DeleteIpAliasCommand) IpAliases(com.cloud.agent.resource.virtualnetwork.model.IpAliases) Test(org.junit.Test)

Aggregations

DeleteIpAliasCommand (com.cloud.agent.api.routing.DeleteIpAliasCommand)6 IpAliasTO (com.cloud.agent.api.routing.IpAliasTO)3 ArrayList (java.util.ArrayList)2 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 GetDomRVersionCmd (com.cloud.agent.api.GetDomRVersionCmd)1 GetVmConfigAnswer (com.cloud.agent.api.GetVmConfigAnswer)1 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)1 PingTestCommand (com.cloud.agent.api.PingTestCommand)1 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)1 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)1 StartCommand (com.cloud.agent.api.StartCommand)1 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)1 UnPlugNicCommand (com.cloud.agent.api.UnPlugNicCommand)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1