Search in sources :

Example 46 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class Ovm3VirtualRoutingSupport method networkUsage.

/* copy paste, why isn't this just generic in the VirtualRoutingResource ? */
private String networkUsage(final String privateIpAddress, final String option, final String ethName) {
    String args = null;
    if ("get".equals(option)) {
        args = "-g";
    } else if (CREATE.equals(option)) {
        args = "-c";
    } else if ("reset".equals(option)) {
        args = "-r";
    } else if ("addVif".equals(option)) {
        args = "-a";
        args += ethName;
    } else if ("deleteVif".equals(option)) {
        args = "-d";
        args += ethName;
    }
    ExecutionResult result = vrr.executeInVR(privateIpAddress, "netusage.sh", args);
    if (result == null || !result.isSuccess()) {
        return null;
    }
    return result.getDetails();
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult)

Example 47 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class Ovm3VirtualRoutingResource method createFileInVR.

@Override
public ExecutionResult createFileInVR(String routerIp, String path, String filename, String content) {
    String error = null;
    logger.debug("createFileInVR via " + agentName + " on " + routerIp + ": " + path + "/" + filename + ", content: " + content);
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        boolean result = cSp.ovsDomrUploadFile(routerIp, path, filename, content);
        return new ExecutionResult(result, "");
    } catch (Exception e) {
        error = e.getMessage();
        logger.warn("createFileInVR failed for " + path + "/" + filename + " in VR " + routerIp + " via " + agentName + ": " + error, e);
    }
    return new ExecutionResult(error == null, error);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 48 with ExecutionResult

use of com.cloud.utils.ExecutionResult 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 49 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class VmwareResource method createFileInVR.

@Override
public ExecutionResult createFileInVR(String routerIp, String filePath, String fileName, String content) {
    VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    File keyFile = mgr.getSystemVMKeyFile();
    try {
        SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes("UTF-8"), fileName, null);
    } catch (Exception e) {
        s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e);
        return new ExecutionResult(false, e.getMessage());
    }
    return new ExecutionResult(true, null);
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) ExecutionResult(com.cloud.utils.ExecutionResult) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) File(java.io.File) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 50 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class VmwareResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(SetNetworkACLCommand cmd) {
    NicTO nic = cmd.getNic();
    String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    String routerIp = getRouterSshControlIp(cmd);
    try {
        int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, nic.getMac());
        nic.setDeviceId(ethDeviceNum);
    } catch (Exception e) {
        String msg = "Prepare SetNetworkACL failed due to " + e.toString();
        s_logger.error(msg, e);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO)

Aggregations

ExecutionResult (com.cloud.utils.ExecutionResult)50 InternalErrorException (com.cloud.exception.InternalErrorException)23 IOException (java.io.IOException)20 ConfigurationException (javax.naming.ConfigurationException)20 IpAddressTO (com.cloud.agent.api.to.IpAddressTO)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 URISyntaxException (java.net.URISyntaxException)13 NicTO (com.cloud.agent.api.to.NicTO)11 ConnectException (java.net.ConnectException)11 RemoteException (java.rmi.RemoteException)11 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 SAXException (org.xml.sax.SAXException)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)8 MalformedURLException (java.net.MalformedURLException)8 TimeoutException (java.util.concurrent.TimeoutException)8 XmlRpcException (org.apache.xmlrpc.XmlRpcException)8 CloudException (com.cloud.exception.CloudException)7 Connection (com.xensource.xenapi.Connection)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 URI (java.net.URI)7