use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.
the class Ovm3VirtualRoutingResource method prepNetBoth.
private ExecutionResult prepNetBoth(String routerName, IpAddressTO[] ips, String type) {
Xen xen = new Xen(c);
try {
Xen.Vm vm = xen.getVmConfig(routerName);
for (IpAddressTO ip : ips) {
Integer devId = vm.getVifIdByMac(ip.getVifMacAddress());
if (devId < 0 && "IpAssocVpcCommand".equals(type)) {
String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress();
logger.error(msg);
return new ExecutionResult(false, msg);
} else if (devId < 0 && "IpAssocCommand".equals(type)) {
// vm.get
String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress() + " " + " Ignoring for now (routervm)";
logger.debug(msg);
devId = 2;
}
ip.setNicDevId(devId);
}
} catch (Exception e) {
String msg = type + " failure on applying one ip due to exception: " + e;
logger.error(msg);
return new ExecutionResult(false, msg);
}
return new ExecutionResult(true, null);
}
use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
for (final IpAddressTO ip : ips) {
final VM router = getVM(conn, routerName);
final VIF correctVif = getVifByMac(conn, router, ip.getVifMacAddress());
setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif);
}
} catch (final Exception e) {
s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.getMessage());
}
return new ExecutionResult(true, null);
}
use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final IpAddressTO pubIp = cmd.getIpAddress();
try {
final VM router = getVM(conn, routerName);
final VIF correctVif = getCorrectVif(conn, router, pubIp);
pubIp.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
} catch (final Exception e) {
final String msg = "Ip SNAT failure due to " + e.toString();
s_logger.error(msg, e);
return new ExecutionResult(false, msg);
}
return new ExecutionResult(true, null);
}
use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.
the class HypervDirectConnectResource method prepareNetworkElementCommand.
private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final String controlIp = getRouterSshControlIp(cmd);
for (final IpAddressTO ip : ips) {
/**
* TODO support other networks
*/
final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + ip.getBroadcastUri());
}
final String vlanId = BroadcastDomainType.getValue(broadcastUri);
int publicNicInfo = -1;
publicNicInfo = getVmNics(routerName, vlanId);
boolean addVif = false;
if (ip.isAdd() && publicNicInfo == -1) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp());
}
addVif = true;
}
if (addVif) {
final Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(controlIp);
publicNicInfo = nicdevice.first();
if (publicNicInfo > 0) {
modifyNicVlan(routerName, vlanId, nicdevice.second());
// After modifying the vnic on VR, check the VR VNics config in the host and get the device position
publicNicInfo = getVmNics(routerName, vlanId);
// As a new nic got activated in the VR. add the entry in the NIC's table.
networkUsage(controlIp, "addVif", "eth" + publicNicInfo);
} else {
// we didn't find any eth device available in VR to configure the ip range with new VLAN
final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with.";
s_logger.error(msg);
throw new InternalErrorException(msg);
}
ip.setNicDevId(publicNicInfo);
ip.setNewNic(addVif);
} else {
ip.setNicDevId(publicNicInfo);
}
}
} catch (final Throwable e) {
s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", 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 HypervDirectConnectResource method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final IpAddressTO pubIp = cmd.getIpAddress();
try {
final String broadcastUri = pubIp.getBroadcastUri();
final String vlanId = BroadcastDomainType.getValue(broadcastUri);
final int ethDeviceNum = getVmNics(routerName, vlanId);
if (ethDeviceNum > 0) {
pubIp.setNicDevId(ethDeviceNum);
} else {
return new ExecutionResult(false, "Prepare Ip SNAT failed due to unable to find the nic");
}
} catch (final Exception e) {
final String msg = "Prepare Ip SNAT failure due to " + e.toString();
s_logger.error(msg, e);
return new ExecutionResult(false, e.toString());
}
return new ExecutionResult(true, null);
}
Aggregations