Search in sources :

Example 1 with DhcpConfig

use of com.cloud.agent.resource.virtualnetwork.model.DhcpConfig in project cloudstack by apache.

the class DnsMasqConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final DnsMasqConfigCommand command = (DnsMasqConfigCommand) cmd;
    final LinkedList<DhcpConfigEntry> entries = new LinkedList<DhcpConfigEntry>();
    for (final DhcpTO dhcpTo : command.getIps()) {
        final DhcpConfigEntry entry = new DhcpConfigEntry(dhcpTo.getRouterIp(), dhcpTo.getGateway(), dhcpTo.getNetmask(), dhcpTo.getStartIpOfSubnet());
        entries.add(entry);
    }
    return generateConfigItems(new DhcpConfig(entries));
}
Also used : DhcpConfig(com.cloud.agent.resource.virtualnetwork.model.DhcpConfig) DhcpConfigEntry(com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry) DhcpTO(com.cloud.agent.api.to.DhcpTO) LinkedList(java.util.LinkedList) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Example 2 with DhcpConfig

use of com.cloud.agent.resource.virtualnetwork.model.DhcpConfig in project cloudstack by apache.

the class ConfigHelperTest method testDnsMasqConfig.

@Test
public void testDnsMasqConfig() {
    final DnsMasqConfigCommand command = generateDnsMasqConfigCommand();
    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 DhcpConfig jsonClass = gson.fromJson(fileContents, DhcpConfig.class);
    assertNotNull(jsonClass);
    assertEquals(jsonClass.getType(), "dhcpconfig");
    final List<DhcpConfigEntry> entries = jsonClass.getEntries();
    assertNotNull(entries);
    assertTrue(entries.size() == 2);
    assertEquals(entries.get(0).getRouterIpAddress(), "10.1.20.2");
    final ConfigItem scriptConfig = config.get(1);
    assertNotNull(scriptConfig);
    assertTrue(scriptConfig instanceof ScriptConfigItem);
}
Also used : AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) DhcpConfig(com.cloud.agent.resource.virtualnetwork.model.DhcpConfig) DhcpConfigEntry(com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand) Test(org.junit.Test)

Aggregations

DnsMasqConfigCommand (com.cloud.agent.api.routing.DnsMasqConfigCommand)2 DhcpConfig (com.cloud.agent.resource.virtualnetwork.model.DhcpConfig)2 DhcpConfigEntry (com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry)2 DhcpTO (com.cloud.agent.api.to.DhcpTO)1 AbstractConfigItemFacade (com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1