use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.
the class HypervDirectConnectResource method execute.
protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd));
}
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final String routerIp = getRouterSshControlIp(cmd);
final IpAddressTO pubIp = cmd.getIpAddress();
try {
final int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, pubIp.getVifMacAddress());
String args = "";
args += " -A ";
args += " -l ";
args += pubIp.getPublicIp();
args += " -c ";
args += "eth" + ethDeviceNum;
final String command = String.format("%s%s %s", "/opt/cloud/bin/", VRScripts.VPC_SOURCE_NAT, args);
final Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command);
if (!result.first()) {
final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second();
s_logger.error(msg);
return new SetSourceNatAnswer(cmd, false, msg);
}
return new SetSourceNatAnswer(cmd, true, "success");
} catch (final Exception e) {
final String msg = "Ip SNAT failure due to " + e.toString();
s_logger.error(msg, e);
return new SetSourceNatAnswer(cmd, false, msg);
}
}
use of com.cloud.agent.api.to.IpAddressTO 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.to.IpAddressTO in project cloudstack by apache.
the class HypervDirectConnectResource method prepareNetworkElementCommand.
private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
for (final IpAddressTO ip : ips) {
final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
throw new InternalErrorException("Invalid Broadcast URI " + ip.getBroadcastUri());
}
final String vlanId = BroadcastDomainType.getValue(broadcastUri);
int publicNicInfo = -1;
publicNicInfo = getVmNics(routerName, vlanId);
if (publicNicInfo < 0) {
if (ip.isAdd()) {
throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
} else {
s_logger.debug("VIF to deassociate IP with does not exist, return success");
continue;
}
}
ip.setNicDevId(publicNicInfo);
}
} catch (final Exception e) {
s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.toString());
}
return new ExecutionResult(true, null);
}
use of com.cloud.agent.api.to.IpAddressTO 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.to.IpAddressTO 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);
}
Aggregations