use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
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(this.xenServer56Resource.executeInVR(networkCommand.getPrivateIP(), "vpc_netusage.sh", args)).thenReturn(executionResult);
when(executionResult.isSuccess()).thenReturn(true);
final Answer answer = wrapper.execute(networkCommand, this.xenServer56Resource);
assertTrue(answer.getResult());
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final UpdateNetworkOverviewCommand cmd) {
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(routerName);
final Map<String, Integer> bridgeToNicNum = new HashMap<>();
final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
buildBridgeToNicNumHashMap(bridgeToNicNum, pluggedNics);
return new ExecutionResult(true, null);
} catch (final LibvirtException e) {
logger.error("Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.getMessage());
}
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method executeInVR.
@Override
public ExecutionResult executeInVR(final String routerIP, final String script, final String args, final int timeout) {
final 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(this._host.getIp(), 22, this._username, null, this._password.peek(), cmdline, 60000, 60000, timeout * 1000);
} catch (final Exception e) {
return new ExecutionResult(false, e.getMessage());
}
return new ExecutionResult(result.first(), result.second());
}
use of com.cloud.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
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);
}
} 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.legacymodel.ExecutionResult in project cosmic by MissionCriticalCloud.
the class XenServer56NetworkUsageCommandWrapper method executeNetworkUsage.
protected NetworkUsageAnswer executeNetworkUsage(final NetworkUsageCommand command, final XenServer56Resource xenServer56) {
try {
final String option = command.getOption();
final String publicIp = command.getGatewayIP();
String args = " -l " + publicIp + " ";
if (option.equals("get")) {
args += "-g";
} else if (option.equals("create")) {
args += "-c";
final String vpcCIDR = command.getVpcCIDR();
args += " -v " + vpcCIDR;
} else if (option.equals("reset")) {
args += "-r";
} else if (option.equals("vpn")) {
args += "-n";
} else if (option.equals("remove")) {
args += "-d";
} else {
return new NetworkUsageAnswer(command, "success", 0L, 0L);
}
final ExecutionResult result = xenServer56.executeInVR(command.getPrivateIP(), "vpc_netusage.sh", args);
final String detail = result.getDetails();
if (!result.isSuccess()) {
throw new Exception(" vpc network usage plugin call failed ");
}
if (option.equals("get") || option.equals("vpn")) {
final long[] stats = new long[2];
if (detail != null) {
final String[] splitResult = detail.split(":");
int i = 0;
while (i < splitResult.length - 1) {
stats[0] += Long.parseLong(splitResult[i++]);
stats[1] += Long.parseLong(splitResult[i++]);
}
return new NetworkUsageAnswer(command, "success", stats[0], stats[1]);
}
}
return new NetworkUsageAnswer(command, "success", 0L, 0L);
} catch (final Exception ex) {
s_logger.warn("Failed to get network usage stats due to ", ex);
return new NetworkUsageAnswer(command, false, ex.getMessage());
}
}
Aggregations