Search in sources :

Example 6 with IpAddressTO

use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.

the class Ovm3VirtualRoutingResource method prepNetBoth.

private ExecutionResult prepNetBoth(String routerName, IpAddressTO[] ips, String type) {
    Xen xen = new Xen(c);
    try {
        Xen.Vm vm = xen.getVmConfig(routerName);
        for (IpAddressTO ip : ips) {
            Integer devId = vm.getVifIdByMac(ip.getVifMacAddress());
            if (devId < 0 && "IpAssocVpcCommand".equals(type)) {
                String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress();
                logger.error(msg);
                return new ExecutionResult(false, msg);
            } else if (devId < 0 && "IpAssocCommand".equals(type)) {
                // vm.get
                String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress() + " " + " Ignoring for now (routervm)";
                logger.debug(msg);
                devId = 2;
            }
            ip.setNicDevId(devId);
        }
    } catch (Exception e) {
        String msg = type + " failure on applying one ip due to exception:  " + e;
        logger.error(msg);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult)

Example 7 with IpAddressTO

use of com.cloud.agent.api.to.IpAddressTO 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 8 with IpAddressTO

use of com.cloud.agent.api.to.IpAddressTO 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 9 with IpAddressTO

use of com.cloud.agent.api.to.IpAddressTO 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 10 with IpAddressTO

use of com.cloud.agent.api.to.IpAddressTO 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

IpAddressTO (com.cloud.agent.api.to.IpAddressTO)41 ExecutionResult (com.cloud.utils.ExecutionResult)16 InternalErrorException (com.cloud.exception.InternalErrorException)14 IOException (java.io.IOException)12 ConfigurationException (javax.naming.ConfigurationException)12 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)9 IpAssocCommand (com.cloud.agent.api.routing.IpAssocCommand)8 ArrayList (java.util.ArrayList)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 URISyntaxException (java.net.URISyntaxException)7 HashMap (java.util.HashMap)7 Answer (com.cloud.agent.api.Answer)6 ConnectException (java.net.ConnectException)6 RemoteException (java.rmi.RemoteException)6 IpAssocVpcCommand (com.cloud.agent.api.routing.IpAssocVpcCommand)5 URI (java.net.URI)5 Connect (org.libvirt.Connect)5 LibvirtException (org.libvirt.LibvirtException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 ExecutionException (com.cloud.utils.exception.ExecutionException)4