Search in sources :

Example 6 with NetworkUsageAnswer

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);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer)

Example 7 with NetworkUsageAnswer

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);
    }
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer)

Example 8 with NetworkUsageAnswer

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);
    }
}
Also used : Connection(com.xensource.xenapi.Connection) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer)

Example 9 with NetworkUsageAnswer

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;
}
Also used : NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer)

Example 10 with NetworkUsageAnswer

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;
    }
}
Also used : NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer)

Aggregations

NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)10 ExecutionResult (com.cloud.utils.ExecutionResult)3 Connection (com.xensource.xenapi.Connection)2 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ConnectionException (com.cloud.exception.ConnectionException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Network (com.cloud.network.Network)1 UserStatisticsVO (com.cloud.user.UserStatisticsVO)1 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1 Nic (com.cloud.vm.Nic)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1