Search in sources :

Example 11 with ExecutionResult

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

the class CitrixResourceBase method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
    final Connection conn = getConnection();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        for (final IpAddressTO ip : ips) {
            final VM router = getVM(conn, routerName);
            final VIF correctVif = getVifByMac(conn, router, ip.getVifMacAddress());
            setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif);
        }
    } catch (final Exception e) {
        s_logger.error("Ip Assoc failure on applying one ip due to exception:  ", e);
        return new ExecutionResult(false, e.getMessage());
    }
    return new ExecutionResult(true, null);
}
Also used : VIF(com.xensource.xenapi.VIF) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ExecutionResult(com.cloud.utils.ExecutionResult) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 12 with ExecutionResult

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

the class CitrixResourceBase method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
    final Connection conn = getConnection();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final IpAddressTO pubIp = cmd.getIpAddress();
    try {
        final VM router = getVM(conn, routerName);
        final VIF correctVif = getCorrectVif(conn, router, pubIp);
        pubIp.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
    } catch (final Exception e) {
        final String msg = "Ip SNAT failure 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) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ExecutionResult(com.cloud.utils.ExecutionResult) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 13 with ExecutionResult

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

the class XenServer56WrapperTest method testNetworkUsageCommandCreateVpcFailure.

@Test
public void testNetworkUsageCommandCreateVpcFailure() {
    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(xenServer56Resource.executeInVR(networkCommand.getPrivateIP(), "vpc_netusage.sh", args)).thenReturn(executionResult);
    when(executionResult.isSuccess()).thenReturn(false);
    final Answer answer = wrapper.execute(networkCommand, xenServer56Resource);
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) ExecutionResult(com.cloud.utils.ExecutionResult) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) Test(org.junit.Test)

Example 14 with ExecutionResult

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
        final String controlIp = getRouterSshControlIp(cmd);
        for (final IpAddressTO ip : ips) {
            /**
                 * TODO support other networks
                 */
            final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
            if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + ip.getBroadcastUri());
            }
            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
            int publicNicInfo = -1;
            publicNicInfo = getVmNics(routerName, vlanId);
            boolean addVif = false;
            if (ip.isAdd() && publicNicInfo == -1) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp());
                }
                addVif = true;
            }
            if (addVif) {
                final Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(controlIp);
                publicNicInfo = nicdevice.first();
                if (publicNicInfo > 0) {
                    modifyNicVlan(routerName, vlanId, nicdevice.second());
                    // After modifying the vnic on VR, check the VR VNics config in the host and get the device position
                    publicNicInfo = getVmNics(routerName, vlanId);
                    // As a new nic got activated in the VR. add the entry in the NIC's table.
                    networkUsage(controlIp, "addVif", "eth" + publicNicInfo);
                } else {
                    // we didn't find any eth device available in VR to configure the ip range with new VLAN
                    final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with.";
                    s_logger.error(msg);
                    throw new InternalErrorException(msg);
                }
                ip.setNicDevId(publicNicInfo);
                ip.setNewNic(addVif);
            } else {
                ip.setNicDevId(publicNicInfo);
            }
        }
    } catch (final Throwable e) {
        s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult) InternalErrorException(com.cloud.exception.InternalErrorException) URI(java.net.URI)

Example 15 with ExecutionResult

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final IpAddressTO pubIp = cmd.getIpAddress();
    try {
        final String broadcastUri = pubIp.getBroadcastUri();
        final String vlanId = BroadcastDomainType.getValue(broadcastUri);
        final int ethDeviceNum = getVmNics(routerName, vlanId);
        if (ethDeviceNum > 0) {
            pubIp.setNicDevId(ethDeviceNum);
        } else {
            return new ExecutionResult(false, "Prepare Ip SNAT failed due to unable to find the nic");
        }
    } catch (final Exception e) {
        final String msg = "Prepare Ip SNAT failure due to " + e.toString();
        s_logger.error(msg, e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException)

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