use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class LibvirtComputingResource method cleanupNetworkElementCommand.
protected ExecutionResult cleanupNetworkElementCommand(final IpAssocCommand cmd) {
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
final String lastIp = cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
Connect conn;
try {
conn = LibvirtConnection.getConnectionByVmName(routerName);
final List<InterfaceDef> nics = getInterfaces(conn, routerName);
final Map<String, Integer> broadcastUriAllocatedToVM = new HashMap<String, Integer>();
Integer nicPos = 0;
for (final InterfaceDef nic : nics) {
if (nic.getBrName().equalsIgnoreCase(_linkLocalBridgeName)) {
broadcastUriAllocatedToVM.put("LinkLocal", nicPos);
} else {
if (nic.getBrName().equalsIgnoreCase(_publicBridgeName) || nic.getBrName().equalsIgnoreCase(_privBridgeName) || nic.getBrName().equalsIgnoreCase(_guestBridgeName)) {
broadcastUriAllocatedToVM.put(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString(), nicPos);
} else {
final String broadcastUri = getBroadcastUriFromBridge(nic.getBrName());
broadcastUriAllocatedToVM.put(broadcastUri, nicPos);
}
}
nicPos++;
}
final IpAddressTO[] ips = cmd.getIpAddresses();
final int numOfIps = ips.length;
int nicNum = 0;
for (final IpAddressTO ip : ips) {
if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) {
/* plug a vif into router */
VifHotPlug(conn, routerName, ip.getBroadcastUri(), ip.getVifMacAddress());
broadcastUriAllocatedToVM.put(ip.getBroadcastUri(), nicPos++);
}
nicNum = broadcastUriAllocatedToVM.get(ip.getBroadcastUri());
if (org.apache.commons.lang.StringUtils.equalsIgnoreCase(lastIp, "true") && !ip.isAdd()) {
// in isolated network eth2 is the default public interface. We don't want to delete it.
if (nicNum != 2) {
vifHotUnPlug(conn, routerName, ip.getVifMacAddress());
networkUsage(routerIp, "deleteVif", "eth" + nicNum);
}
}
}
} catch (final LibvirtException e) {
s_logger.error("ipassoccmd failed", e);
return new ExecutionResult(false, e.getMessage());
} catch (final InternalErrorException e) {
s_logger.error("ipassoccmd failed", e);
return new ExecutionResult(false, e.getMessage());
}
return new ExecutionResult(true, null);
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class LibvirtComputingResource method prepareNetworkElementCommand.
private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
Connect conn;
final NicTO nic = cmd.getNic();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
conn = LibvirtConnection.getConnectionByVmName(routerName);
final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
InterfaceDef routerNic = null;
for (final InterfaceDef pluggedNic : pluggedNics) {
if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
routerNic = pluggedNic;
break;
}
}
if (routerNic == null) {
return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
}
return new ExecutionResult(true, null);
} catch (final LibvirtException e) {
final String msg = "Creating guest network failed due to " + e.toString();
s_logger.warn(msg, e);
return new ExecutionResult(false, msg);
}
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class LibvirtComputingResource method executeInVR.
@Override
public ExecutionResult executeInVR(final String routerIp, final String script, final String args, final Duration timeout) {
final Script command = new Script(_routerProxyPath, timeout, s_logger);
final AllLinesParser parser = new AllLinesParser();
command.add(script);
command.add(routerIp);
if (args != null) {
command.add(args);
}
String details = command.execute(parser);
if (details == null) {
details = parser.getLines();
}
return new ExecutionResult(command.getExitValue() == 0, details);
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class Ovm3VirtualRoutingResource method executeInVR.
@Override
public ExecutionResult executeInVR(String routerIp, String script, String args, Duration timeout) {
if (!script.contains(domRCloudPath)) {
script = domRCloudPath + "/" + script;
}
String cmd = script + " " + args;
logger.debug("executeInVR via " + agentName + " on " + routerIp + ": " + cmd);
try {
CloudstackPlugin cSp = new CloudstackPlugin(c);
CloudstackPlugin.ReturnCode result;
result = cSp.domrExec(routerIp, cmd);
return new ExecutionResult(result.getRc(), result.getStdOut());
} catch (Exception e) {
logger.error("executeInVR FAILED via " + agentName + " on " + routerIp + ":" + cmd + ", " + e.getMessage(), e);
}
return new ExecutionResult(false, "");
}
use of com.cloud.utils.ExecutionResult 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);
}
Aggregations