Search in sources :

Example 1 with SetSourceNatAnswer

use of com.cloud.agent.api.routing.SetSourceNatAnswer in project cloudstack by apache.

the class HypervDirectConnectResource method execute.

protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd));
    }
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final String routerIp = getRouterSshControlIp(cmd);
    final IpAddressTO pubIp = cmd.getIpAddress();
    try {
        final int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, pubIp.getVifMacAddress());
        String args = "";
        args += " -A ";
        args += " -l ";
        args += pubIp.getPublicIp();
        args += " -c ";
        args += "eth" + ethDeviceNum;
        final String command = String.format("%s%s %s", "/opt/cloud/bin/", VRScripts.VPC_SOURCE_NAT, args);
        final Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command);
        if (!result.first()) {
            final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second();
            s_logger.error(msg);
            return new SetSourceNatAnswer(cmd, false, msg);
        }
        return new SetSourceNatAnswer(cmd, true, "success");
    } catch (final Exception e) {
        final String msg = "Ip SNAT failure due to " + e.toString();
        s_logger.error(msg, e);
        return new SetSourceNatAnswer(cmd, false, msg);
    }
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) 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) SetSourceNatAnswer(com.cloud.agent.api.routing.SetSourceNatAnswer)

Aggregations

SetSourceNatAnswer (com.cloud.agent.api.routing.SetSourceNatAnswer)1 IpAddressTO (com.cloud.agent.api.to.IpAddressTO)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 URISyntaxException (java.net.URISyntaxException)1 RemoteException (java.rmi.RemoteException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 ConfigurationException (javax.naming.ConfigurationException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1