Search in sources :

Example 6 with ExecutionResult

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ExecutionResult(com.cloud.legacymodel.ExecutionResult) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Example 7 with ExecutionResult

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());
    }
}
Also used : InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) LibvirtException(org.libvirt.LibvirtException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) ExecutionResult(com.cloud.legacymodel.ExecutionResult)

Example 8 with ExecutionResult

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());
}
Also used : ExecutionResult(com.cloud.legacymodel.ExecutionResult) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 9 with ExecutionResult

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);
}
Also used : VIF(com.xensource.xenapi.VIF) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ExecutionResult(com.cloud.legacymodel.ExecutionResult) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NicTO(com.cloud.legacymodel.to.NicTO)

Example 10 with ExecutionResult

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());
    }
}
Also used : ExecutionResult(com.cloud.legacymodel.ExecutionResult) NetworkUsageAnswer(com.cloud.legacymodel.communication.answer.NetworkUsageAnswer)

Aggregations

ExecutionResult (com.cloud.legacymodel.ExecutionResult)13 Answer (com.cloud.legacymodel.communication.answer.Answer)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 ConfigurationException (javax.naming.ConfigurationException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXException (org.xml.sax.SAXException)4 CheckS2SVpnConnectionsAnswer (com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer)3 GetDomRVersionAnswer (com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer)3 XenAPIException (com.xensource.xenapi.Types.XenAPIException)3 MalformedURLException (java.net.MalformedURLException)3 TimeoutException (java.util.concurrent.TimeoutException)3 XmlRpcException (org.apache.xmlrpc.XmlRpcException)3 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 GroupAnswer (com.cloud.legacymodel.communication.answer.GroupAnswer)2 NetworkUsageCommand (com.cloud.legacymodel.communication.command.NetworkUsageCommand)2 Connection (com.xensource.xenapi.Connection)2 URLConnection (java.net.URLConnection)2 Test (org.junit.Test)2