use of com.cloud.agent.api.NetworkUsageAnswer in project cloudstack by apache.
the class VmwareResource method VPCNetworkUsage.
protected NetworkUsageAnswer VPCNetworkUsage(NetworkUsageCommand cmd) {
String privateIp = cmd.getPrivateIP();
String option = cmd.getOption();
String publicIp = cmd.getGatewayIP();
String args = "-l " + publicIp + " ";
if (option.equals("get")) {
args += "-g";
} else if (option.equals("create")) {
args += "-c";
String vpcCIDR = cmd.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(cmd, "success", 0L, 0L);
}
ExecutionResult callResult = executeInVR(privateIp, "vpc_netusage.sh", args);
if (!callResult.isSuccess()) {
s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIp + "), domR may not be ready yet. failure due to " + callResult.getDetails());
}
if (option.equals("get") || option.equals("vpn")) {
String result = callResult.getDetails();
if (result == null || result.isEmpty()) {
s_logger.error(" vpc network usage get returns empty ");
}
long[] stats = new long[2];
if (result != null) {
String[] splitResult = result.split(":");
int i = 0;
while (i < splitResult.length - 1) {
stats[0] += Long.parseLong(splitResult[i++]);
stats[1] += Long.parseLong(splitResult[i++]);
}
return new NetworkUsageAnswer(cmd, "success", stats[0], stats[1]);
}
}
return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
}
use of com.cloud.agent.api.NetworkUsageAnswer in project cloudstack by apache.
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, ex);
}
}
use of com.cloud.agent.api.NetworkUsageAnswer in project cloudstack by apache.
the class XenServer56NetworkUsageCommandWrapper method execute.
@Override
public Answer execute(final NetworkUsageCommand command, final XenServer56Resource xenServer56) {
if (command.isForVpc()) {
return executeNetworkUsage(command, xenServer56);
}
try {
final Connection conn = xenServer56.getConnection();
if (command.getOption() != null && command.getOption().equals("create")) {
final String result = xenServer56.networkUsage(conn, command.getPrivateIP(), "create", null);
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
return answer;
}
final long[] stats = xenServer56.getNetworkStats(conn, command.getPrivateIP());
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
return answer;
} catch (final Exception ex) {
s_logger.warn("Failed to get network usage stats due to ", ex);
return new NetworkUsageAnswer(command, ex);
}
}
use of com.cloud.agent.api.NetworkUsageAnswer in project cloudstack by apache.
the class HypervDirectConnectResource method execute.
protected Answer execute(final NetworkUsageCommand cmd) {
if (cmd.isForVpc()) {
//return VPCNetworkUsage(cmd);
}
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource NetworkUsageCommand " + s_gson.toJson(cmd));
}
if (cmd.getOption() != null && cmd.getOption().equals("create")) {
networkUsage(cmd.getPrivateIP(), "create", null);
final NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "true", 0L, 0L);
return answer;
}
final long[] stats = getNetworkStats(cmd.getPrivateIP());
final NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
return answer;
}
use of com.cloud.agent.api.NetworkUsageAnswer in project cloudstack by apache.
the class LibvirtNetworkUsageCommandWrapper method execute.
@Override
public Answer execute(final NetworkUsageCommand command, final LibvirtComputingResource libvirtComputingResource) {
if (command.isForVpc()) {
if (command.getOption() != null && command.getOption().equals("create")) {
final String result = libvirtComputingResource.configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR());
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
return answer;
} else if (command.getOption() != null && (command.getOption().equals("get") || command.getOption().equals("vpn"))) {
final long[] stats = libvirtComputingResource.getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption());
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
return answer;
} else {
final String result = libvirtComputingResource.configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR());
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
return answer;
}
} else {
if (command.getOption() != null && command.getOption().equals("create")) {
final String result = libvirtComputingResource.networkUsage(command.getPrivateIP(), "create", null);
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
return answer;
}
final long[] stats = libvirtComputingResource.getNetworkStats(command.getPrivateIP());
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
return answer;
}
}
Aggregations