use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
final VM router = getVM(conn, routerName);
final NicTO nic = cmd.getNic();
if (nic != null) {
final VIF vif = getVifByMac(conn, router, nic.getMac());
if (vif == null) {
final String msg = "Prepare SetNetworkACL failed due to VIF is null for : " + nic.getMac() + " with routername: " + routerName;
s_logger.error(msg);
return new ExecutionResult(false, msg);
}
nic.setDeviceId(Integer.parseInt(vif.getDevice(conn)));
} else {
final String msg = "Prepare SetNetworkACL failed due to nic is null for : " + routerName;
s_logger.error(msg);
return new ExecutionResult(false, msg);
}
} catch (final Exception e) {
final String msg = "Prepare SetNetworkACL failed due to " + e.toString();
s_logger.error(msg, e);
return new ExecutionResult(false, msg);
}
return new ExecutionResult(true, null);
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
for (final IpAddressTO ip : ips) {
final VM router = getVM(conn, routerName);
final NicTO nic = new NicTO();
nic.setMac(ip.getVifMacAddress());
nic.setType(ip.getTrafficType());
if (ip.getBroadcastUri() == null) {
nic.setBroadcastType(BroadcastDomainType.Native);
} else {
final URI uri = BroadcastDomainType.fromString(ip.getBroadcastUri());
nic.setBroadcastType(BroadcastDomainType.getSchemeValue(uri));
nic.setBroadcastUri(uri);
}
nic.setDeviceId(0);
nic.setNetworkRateMbps(ip.getNetworkRate());
nic.setName(ip.getNetworkName());
final Network network = getNetwork(conn, nic);
// Determine the correct VIF on DomR to associate/disassociate
// the
// IP address with
VIF correctVif = getCorrectVif(conn, router, network);
// If we are associating an IP address and DomR doesn't have a
// VIF
// for the specified vlan ID, we need to add a VIF
// If we are disassociating the last IP address in the VLAN, we
// need
// to remove a VIF
boolean addVif = false;
if (ip.isAdd() && correctVif == null) {
addVif = true;
}
if (addVif) {
// Add a new VIF to DomR
final String vifDeviceNum = getLowestAvailableVIFDeviceNum(conn, router);
if (vifDeviceNum == null) {
throw new InternalErrorException("There were no more available slots for a new VIF on router: " + router.getNameLabel(conn));
}
nic.setDeviceId(Integer.parseInt(vifDeviceNum));
correctVif = createVif(conn, routerName, router, null, nic);
correctVif.plug(conn);
// Add iptables rule for network usage
networkUsage(conn, routerIp, "addVif", "eth" + correctVif.getDevice(conn));
}
if (ip.isAdd() && correctVif == null) {
throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
}
if (correctVif != null) {
ip.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
ip.setNewNic(addVif);
}
}
} catch (final InternalErrorException e) {
s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.getMessage());
} catch (final Exception 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 CitrixResourceBase method executeInVR.
@Override
public ExecutionResult executeInVR(final String routerIP, final String script, final String args, final Duration timeout) {
Pair<Boolean, String> result;
String cmdline = "/opt/cloud/bin/router_proxy.sh " + script + " " + routerIP + " " + args;
// semicolon need to be escape for bash
cmdline = cmdline.replaceAll(";", "\\\\;");
try {
s_logger.debug("Executing command in VR: " + cmdline);
result = SshHelper.sshExecute(_host.getIp(), 22, _username, null, _password.peek(), cmdline, VRScripts.CONNECTION_TIMEOUT, VRScripts.CONNECTION_TIMEOUT, timeout);
} catch (final Exception e) {
return new ExecutionResult(false, e.getMessage());
}
return new ExecutionResult(result.first(), result.second());
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class XenServer56WrapperTest method testNetworkUsageCommandCreateVpc.
@Test
public void testNetworkUsageCommandCreateVpc() {
final ExecutionResult executionResult = Mockito.mock(ExecutionResult.class);
final NetworkUsageCommand networkCommand = new NetworkUsageCommand("192.168.10.10", "domRName", true, "192.168.10.1", "10.1.1.1/24");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final String args = " -l 192.168.10.1 -c -v 10.1.1.1/24";
when(xenServer56Resource.executeInVR(networkCommand.getPrivateIP(), "vpc_netusage.sh", args)).thenReturn(executionResult);
when(executionResult.isSuccess()).thenReturn(true);
final Answer answer = wrapper.execute(networkCommand, xenServer56Resource);
assertTrue(answer.getResult());
}
use of com.cloud.utils.ExecutionResult in project cloudstack by apache.
the class LibvirtComputingResource method createFileInVR.
@Override
public ExecutionResult createFileInVR(final String routerIp, final String path, final String filename, final String content) {
final File permKey = new File("/root/.ssh/id_rsa.cloud");
String error = null;
try {
SshHelper.scpTo(routerIp, 3922, "root", permKey, null, path, content.getBytes(), filename, null);
} catch (final Exception e) {
s_logger.warn("Fail to create file " + path + filename + " in VR " + routerIp, e);
error = e.getMessage();
}
return new ExecutionResult(error == null, error);
}
Aggregations