Example usage for com.amazonaws.services.ec2.model RevokeSecurityGroupIngressRequest setToPort

List of usage examples for com.amazonaws.services.ec2.model RevokeSecurityGroupIngressRequest setToPort

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model RevokeSecurityGroupIngressRequest setToPort.

Prototype


public void setToPort(Integer toPort) 

Source Link

Document

The end of port range for the TCP and UDP protocols, or an ICMP code number.

Usage

From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java

License:Open Source License

public static void RevokeSecurityPort(int fromPort, int toPort, String securityGroupName) throws Exception {
    try {/* w  w  w  . j  a  v a2 s  . com*/
        RevokeSecurityGroupIngressRequest revokeRequest = new RevokeSecurityGroupIngressRequest();
        revokeRequest.setFromPort(fromPort);
        revokeRequest.setIpProtocol("tcp");
        revokeRequest.setToPort(toPort);
        revokeRequest.setGroupName(securityGroupName);

        ec2.revokeSecurityGroupIngress(revokeRequest);

        System.out.println(
                "Security port revoked successfully.  from port (" + fromPort + ") - to port(" + toPort + ")");

    } catch (AmazonServiceException ase) {
        System.out.println(
                "Error : revoking security port : from port(" + fromPort + ") - to port(" + toPort + ")");
        System.out.println("Caught Exception: " + ase.getMessage());
        System.out.println("Reponse Status Code: " + ase.getStatusCode());
        System.out.println("Error Code: " + ase.getErrorCode());
        System.out.println("Request ID: " + ase.getRequestId());
    }
}

From source file:org.openinfinity.cloud.service.administrator.EC2Wrapper.java

License:Apache License

public void revokeIPs(String securityGroupName, String cidrIp, Integer fromPort, Integer toPort,
        String protocol) {//from  www . j  av a2  s  .c  o m
    try {
        RevokeSecurityGroupIngressRequest request = new RevokeSecurityGroupIngressRequest();
        request.setGroupName(securityGroupName);
        request.setCidrIp(cidrIp);
        request.setFromPort(fromPort);
        request.setToPort(toPort);
        request.setIpProtocol(protocol);
        ec2.revokeSecurityGroupIngress(request);
    } catch (Exception e) {
        String message = e.getMessage();
        LOG.error("Cloud not revoke IP.s from security group: " + message);
        ExceptionUtil.throwSystemException(message, e);
    }
}