use of com.cloud.agent.api.routing.IpAssocAnswer in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
public Answer execute(IpAssocCommand cmd) {
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String[] results = new String[cmd.getIpAddresses().length];
Connect conn;
try {
conn = LibvirtConnection.getConnection();
List<InterfaceDef> nics = getInterfaces(conn, routerName);
Map<String, Integer> vlanAllocatedToVM = new HashMap<String, Integer>();
Integer nicPos = 0;
for (InterfaceDef nic : nics) {
if (nic.getBrName().equalsIgnoreCase(_linkLocalBridgeName)) {
vlanAllocatedToVM.put("LinkLocal", nicPos);
} else {
String vlanId = getVlanIdFromBridge(nic.getBrName());
if (vlanId != null) {
vlanAllocatedToVM.put(vlanId, nicPos);
} else {
vlanAllocatedToVM.put(Vlan.UNTAGGED, nicPos);
}
}
nicPos++;
}
IpAddressTO[] ips = cmd.getIpAddresses();
int i = 0;
String result = null;
int nicNum = 0;
for (IpAddressTO ip : ips) {
if (!vlanAllocatedToVM.containsKey(ip.getVlanId())) {
/* plug a vif into router */
VifHotPlug(conn, routerName, ip.getVlanId(), ip.getVifMacAddress());
vlanAllocatedToVM.put(ip.getVlanId(), nicPos++);
}
nicNum = vlanAllocatedToVM.get(ip.getVlanId());
networkUsage(routerIp, "addVif", "eth" + nicNum);
result = _virtRouterResource.assignPublicIpAddress(routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getVlanId(), ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getGuestIp(), nicNum);
if (result != null) {
results[i++] = IpAssocAnswer.errorResult;
} else {
results[i++] = ip.getPublicIp() + " - success";
;
}
}
return new IpAssocAnswer(cmd, results);
} catch (LibvirtException e) {
return new IpAssocAnswer(cmd, results);
} catch (InternalErrorException e) {
return new IpAssocAnswer(cmd, results);
}
}
use of com.cloud.agent.api.routing.IpAssocAnswer in project cloudstack by apache.
the class HypervDirectConnectResource method execute.
protected Answer execute(final IpAssocCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd));
}
int i = 0;
final String[] results = new String[cmd.getIpAddresses().length];
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final String controlIp = getRouterSshControlIp(cmd);
for (final IpAddressTO ip : ips) {
assignPublicIpAddress(routerName, controlIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(), ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress());
results[i++] = ip.getPublicIp() + " - success";
}
for (; i < cmd.getIpAddresses().length; i++) {
results[i++] = IpAssocAnswer.errorResult;
}
} catch (final Throwable e) {
s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
for (; i < cmd.getIpAddresses().length; i++) {
results[i++] = IpAssocAnswer.errorResult;
}
}
return new IpAssocAnswer(cmd, results);
}
use of com.cloud.agent.api.routing.IpAssocAnswer in project cloudstack by apache.
the class F5BigIpResource method execute.
private synchronized Answer execute(IpAssocCommand cmd, int numRetries) {
String[] results = new String[cmd.getIpAddresses().length];
int i = 0;
try {
IpAddressTO[] ips = cmd.getIpAddresses();
for (IpAddressTO ip : ips) {
// is it saver to use Long.valueOf(BroadcastDomain.getValue(ip.getBroadcastUri())) ???
// i.o.w. can this contain vlan:// then change !!!
long guestVlanTag = Long.parseLong(ip.getBroadcastUri());
// It's a hack, using isOneToOneNat field for indicate if it's inline or not
boolean inline = ip.isOneToOneNat();
String vlanSelfIp = inline ? tagAddressWithRouteDomain(ip.getVlanGateway(), guestVlanTag) : ip.getVlanGateway();
String vlanNetmask = ip.getVlanNetmask();
// Delete any existing guest VLAN with this tag, self IP, and netmask
deleteGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask, inline);
if (ip.isAdd()) {
// Add a new guest VLAN
addGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask, inline);
}
saveConfiguration();
results[i++] = ip.getPublicIp() + " - success";
}
} catch (ExecutionException e) {
s_logger.error("Failed to execute IPAssocCommand due to " + e);
if (shouldRetry(numRetries)) {
return retry(cmd, numRetries);
} else {
results[i++] = IpAssocAnswer.errorResult;
}
}
return new IpAssocAnswer(cmd, results);
}
use of com.cloud.agent.api.routing.IpAssocAnswer in project cloudstack by apache.
the class PaloAltoResource method execute.
private Answer execute(IpAssocCommand cmd, int numRetries) {
String[] results = new String[cmd.getIpAddresses().length];
int i = 0;
try {
IpAddressTO ip;
if (cmd.getIpAddresses().length != 1) {
throw new ExecutionException("Received an invalid number of guest IPs to associate.");
} else {
ip = cmd.getIpAddresses()[0];
}
String sourceNatIpAddress = null;
GuestNetworkType type = GuestNetworkType.INTERFACE_NAT;
if (ip.isSourceNat()) {
type = GuestNetworkType.SOURCE_NAT;
if (ip.getPublicIp() == null) {
throw new ExecutionException("Source NAT IP address must not be null.");
} else {
sourceNatIpAddress = ip.getPublicIp();
}
}
long guestVlanTag = Long.parseLong(cmd.getAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG));
String guestVlanGateway = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
String cidr = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR);
long cidrSize = NetUtils.cidrToLong(cidr)[1];
String guestVlanSubnet = NetUtils.getCidrSubNet(guestVlanGateway, cidrSize);
Long publicVlanTag = null;
if (ip.getBroadcastUri() != null) {
String parsedVlanTag = parsePublicVlanTag(ip.getBroadcastUri());
if (!parsedVlanTag.equals("untagged")) {
try {
publicVlanTag = Long.parseLong(parsedVlanTag);
} catch (Exception e) {
throw new ExecutionException("Could not parse public VLAN tag: " + parsedVlanTag);
}
}
}
ArrayList<IPaloAltoCommand> commandList = new ArrayList<IPaloAltoCommand>();
if (ip.isAdd()) {
// Implement the guest network for this VLAN
implementGuestNetwork(commandList, type, publicVlanTag, sourceNatIpAddress, guestVlanTag, guestVlanGateway, guestVlanSubnet, cidrSize);
} else {
// Remove the guest network:
shutdownGuestNetwork(commandList, type, publicVlanTag, sourceNatIpAddress, guestVlanTag, guestVlanGateway, guestVlanSubnet, cidrSize);
}
boolean status = requestWithCommit(commandList);
results[i++] = ip.getPublicIp() + " - success";
} catch (ExecutionException e) {
s_logger.error(e);
if (numRetries > 0 && refreshPaloAltoConnection()) {
int numRetriesRemaining = numRetries - 1;
s_logger.debug("Retrying IPAssocCommand. Number of retries remaining: " + numRetriesRemaining);
return execute(cmd, numRetriesRemaining);
} else {
results[i++] = IpAssocAnswer.errorResult;
}
}
return new IpAssocAnswer(cmd, results);
}
use of com.cloud.agent.api.routing.IpAssocAnswer in project cloudstack by apache.
the class NetScalerControlCenterResource method execute.
private synchronized Answer execute(IpAssocCommand cmd, int numRetries) {
String[] results = new String[cmd.getIpAddresses().length];
int i = 0;
IpAddressTO[] ips = cmd.getIpAddresses();
for (IpAddressTO ip : ips) {
results[i++] = ip.getPublicIp() + " - success";
}
return new IpAssocAnswer(cmd, results);
}
Aggregations