use of com.cloud.agent.api.routing.CreateIpAliasCommand in project cloudstack by apache.
the class CreateIpAliasConfigItem method generateConfig.
@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
final CreateIpAliasCommand command = (CreateIpAliasCommand) cmd;
final List<IpAddressAlias> ipAliases = new LinkedList<IpAddressAlias>();
final List<IpAliasTO> ipAliasTOs = command.getIpAliasList();
for (final IpAliasTO ipaliasto : ipAliasTOs) {
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);
}
use of com.cloud.agent.api.routing.CreateIpAliasCommand 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;
}
use of com.cloud.agent.api.routing.CreateIpAliasCommand in project cloudstack by apache.
the class VirtualRoutingResourceTest method generateCreateIpAliasCommand.
protected CreateIpAliasCommand generateCreateIpAliasCommand() {
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 CreateIpAliasCommand cmd = new CreateIpAliasCommand("169.254.3.10", aliases);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
return cmd;
}
use of com.cloud.agent.api.routing.CreateIpAliasCommand in project cloudstack by apache.
the class CommandSetupHelper method createIpAlias.
public void createIpAlias(final VirtualRouter router, final List<IpAliasTO> ipAliasTOs, final Long networkid, final Commands cmds) {
final String routerip = _routerControlHelper.getRouterIpInNetwork(networkid, router.getId());
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
final CreateIpAliasCommand ipaliasCmd = new CreateIpAliasCommand(routerip, ipAliasTOs);
ipaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
ipaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
ipaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, routerip);
ipaliasCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand("ipalias", ipaliasCmd);
}
Aggregations