Example usage for com.amazonaws.services.ec2.model DeleteSecurityGroupRequest DeleteSecurityGroupRequest

List of usage examples for com.amazonaws.services.ec2.model DeleteSecurityGroupRequest DeleteSecurityGroupRequest

Introduction

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

Prototype

public DeleteSecurityGroupRequest(String groupName) 

Source Link

Document

Constructs a new DeleteSecurityGroupRequest object.

Usage

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

License:Open Source License

public static void DeleteSecurityGroup(String name) throws Exception {
    try {/*from   ww w .  j  a  v a2 s  . c o m*/
        DeleteSecurityGroupRequest deleteSecurityGroupRequest = new DeleteSecurityGroupRequest(name);
        // newSecurityGroup.setDescription(name);
        // newSecurityGroup.setGroupName(description);

        ec2.deleteSecurityGroup(deleteSecurityGroupRequest);

        System.out.println("Security group deleted : " + name);
    } catch (AmazonServiceException ase) {
        System.out.println("Error : Adding new security group");
        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:com.norbl.cbp.ppe.SecurityGroupFactory.java

License:Open Source License

/** This method deletes <i>all</i> security groups owned by the
 *  user that have names starting with "&lt;User name&gt;_mpi_ec2_",
 *  where &lt;User name&gt is the value of the system property
 *  user.name.//www  .  ja va  2 s . co  m
 *
 * @throws MissingParamsException
 */
public int deleteOneTimeSecurityGroups() throws MissingParamsException {

    DescribeSecurityGroupsResult sgr = ec2Client.describeSecurityGroups();

    int nDeleted = 0;

    String prefix = buildSecurityGroupNamePrefix();
    for (SecurityGroup sg : sgr.getSecurityGroups()) {
        if (sg.getGroupName().startsWith(prefix)) {
            DeleteSecurityGroupRequest dr = new DeleteSecurityGroupRequest(sg.getGroupName());
            ec2Client.deleteSecurityGroup(dr);
            ++nDeleted;
        }
    }
    return (nDeleted);
}

From source file:com.norbl.cbp.ppe.SecurityGroupFactory.java

License:Open Source License

/** If the specified group is not a 'one time' group, this
 *  method does nothing.  A 'one time' group has a name that
 *  starts with prefix created by {@link #buildSecurityGroupNamePrefix()}.
 *
 * @param securityGroupName//  ww  w. j a va2s  . c  om
 */
public void deleteOneTimeSecurityGroup(String securityGroupName) {

    if (!securityGroupName.startsWith(buildSecurityGroupNamePrefix()))
        return;

    DeleteSecurityGroupRequest dr = new DeleteSecurityGroupRequest(securityGroupName);
    ec2Client.deleteSecurityGroup(dr);
}