Search in sources :

Example 16 with ExecutionResult

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand cmd) {
    final NicTO nic = cmd.getNic();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final URI broadcastUri = nic.getBroadcastUri();
        final String vlanId = BroadcastDomainType.getValue(broadcastUri);
        final int ethDeviceNum = getVmNics(routerName, vlanId);
        if (ethDeviceNum > 0) {
            nic.setDeviceId(ethDeviceNum);
        } else {
            return new ExecutionResult(false, "Prepare SetNetworkACL failed due to unable to find the nic");
        }
    } 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 : ExecutionResult(com.cloud.utils.ExecutionResult) URI(java.net.URI) 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) NicTO(com.cloud.agent.api.to.NicTO)

Example 17 with ExecutionResult

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
    final NicTO nic = cmd.getNic();
    final String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final URI broadcastUri = nic.getBroadcastUri();
        final String vlanId = BroadcastDomainType.getValue(broadcastUri);
        final int ethDeviceNum = getVmNics(domrName, vlanId);
        if (ethDeviceNum > 0) {
            nic.setDeviceId(ethDeviceNum);
        } else {
            return new ExecutionResult(false, "Prepare SetupGuestNetwork failed due to unable to find the nic");
        }
    } catch (final Exception e) {
        final String msg = "Prepare SetupGuestNetwork failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) URI(java.net.URI) 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) NicTO(com.cloud.agent.api.to.NicTO)

Example 18 with ExecutionResult

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

the class HypervDirectConnectResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        for (final IpAddressTO ip : ips) {
            final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
            if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                throw new InternalErrorException("Invalid Broadcast URI " + ip.getBroadcastUri());
            }
            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
            int publicNicInfo = -1;
            publicNicInfo = getVmNics(routerName, vlanId);
            if (publicNicInfo < 0) {
                if (ip.isAdd()) {
                    throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
                } else {
                    s_logger.debug("VIF to deassociate IP with does not exist, return success");
                    continue;
                }
            }
            ip.setNicDevId(publicNicInfo);
        }
    } catch (final Exception e) {
        s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception:  ", 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) 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)

Example 19 with ExecutionResult

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

the class CitrixResourceBase method prepareNetworkElementCommand.

/**
     * @param cmd
     * @return
     */
private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
    final Connection conn = getConnection();
    final NicTO nic = cmd.getNic();
    final String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final Set<VM> vms = VM.getByNameLabel(conn, domrName);
        if (vms == null || vms.isEmpty()) {
            return new ExecutionResult(false, "Can not find VM " + domrName);
        }
        final VM vm = vms.iterator().next();
        final String mac = nic.getMac();
        VIF domrVif = null;
        for (final VIF vif : vm.getVIFs(conn)) {
            final String lmac = vif.getMAC(conn);
            if (lmac.equals(mac)) {
                domrVif = vif;
            // Do not break it! We have 2 routers.
            // break;
            }
        }
        if (domrVif == null) {
            return new ExecutionResult(false, "Can not find vif with mac " + mac + " for VM " + domrName);
        }
        nic.setDeviceId(Integer.parseInt(domrVif.getDevice(conn)));
    } catch (final Exception e) {
        final String msg = "Creating guest network failed due to " + e.toString();
        s_logger.warn(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.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) NicTO(com.cloud.agent.api.to.NicTO)

Example 20 with ExecutionResult

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

the class VirtualRoutingResourceTest method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
    final IpAddressTO ip = cmd.getIpAddress();
    ip.setNicDevId(1);
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult)

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