Java 类com.amazonaws.services.ec2.model.CreateSecurityGroupRequest 实例源码

项目:aws-cluster-toolkit    文件:AwsClusterManager.java   
private void createSecurityGroupByClusterName(String GROUP_NAME) {
    System.out.println("Creating security group for cluster "+name);
    CreateSecurityGroupRequest csgr = new CreateSecurityGroupRequest();

    csgr.withGroupName(GROUP_NAME).withDescription("AWS Cluster toolkit security group");
    CreateSecurityGroupResult createSecurityGroupResult =ec2.createSecurityGroup(csgr);

    IpPermission ipPermission =
            new IpPermission();

    IpRange ipRange1 = new IpRange().withCidrIp("0.0.0.0/0");


    ipPermission.withIpv4Ranges(Arrays.asList(new IpRange[] {ipRange1}))
    .withIpProtocol("tcp")
    .withFromPort(0)
    .withToPort(65535);
    AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
            new AuthorizeSecurityGroupIngressRequest();

    authorizeSecurityGroupIngressRequest.withGroupName(GROUP_NAME)
    .withIpPermissions(ipPermission);
    ec2.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
    System.out.println("Created new security group "+GROUP_NAME+" with /usr/bin/ssh enabled.");

}
项目:photon-model    文件:AWSSecurityGroupClient.java   
public DeferredResult<String> createSecurityGroupAsync(String name, String description,
        String vpcId) {

    CreateSecurityGroupRequest req = new CreateSecurityGroupRequest()
            .withDescription(description)
            .withGroupName(name);

    // set vpc for the security group if provided
    if (vpcId != null) {
        req = req.withVpcId(vpcId);
    }

    String message = "Create AWS Security Group with name [" + name
            + "] on VPC [" + vpcId + "].";

    AWSDeferredResultAsyncHandler<CreateSecurityGroupRequest, CreateSecurityGroupResult>
            handler = new AWSDeferredResultAsyncHandler<>(this.service, message);

    this.client.createSecurityGroupAsync(req, handler);

    return handler.toDeferredResult()
            .thenApply(CreateSecurityGroupResult::getGroupId);
}
项目:cmn-project    文件:BakeAMITask.java   
private String createSG(Environment env) throws Exception {
    String sgName = env.name + ":" + resourceId;
    CreateSecurityGroupRequest request = new CreateSecurityGroupRequest(sgName, sgName);
    if (bakeSubnet != null) request.setVpcId(bakeSubnet.getVpcId());

    String sgId = AWS.ec2.createSecurityGroup(request).getGroupId();
    AWS.ec2.createSGIngressRules(sgId, Lists.newArrayList(new IpPermission()
        .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0"))
        .withFromPort(22)
        .withToPort(22)
        .withIpProtocol("tcp")));

    AWS.ec2.createTags(new CreateTagsRequest()
        .withResources(sgId)
        .withTags(tagHelper.name(resourceId), tagHelper.env(), tagHelper.resourceId(resourceId)));

    return sgId;
}
项目:incubator-gobblin    文件:AWSSdkClient.java   
/***
 * Create an Amazon AWS security group
 *
 * @param groupName Security group name
 * @param description Security group description
 */
public void createSecurityGroup(String groupName,
    String description) {

  AmazonEC2 amazonEC2 = getEc2Client();
  try {
    final CreateSecurityGroupRequest securityGroupRequest = new CreateSecurityGroupRequest()
        .withGroupName(groupName)
        .withDescription(description);
    amazonEC2.createSecurityGroup(securityGroupRequest);

    LOGGER.info("Created Security Group: " + groupName);
  } catch (AmazonServiceException ase) {
    // This might mean that security group is already created, hence ignore
    LOGGER.warn("Issue in creating security group", ase);
  }
}
项目:incubator-provisionr    文件:EnsureSecurityGroupExists.java   
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) {
    final String businessKey = execution.getProcessBusinessKey();
    final String groupName = SecurityGroups.formatNameFromBusinessKey(businessKey);

    try {
        LOG.info(">> Creating Security Group with name {}", groupName);
        CreateSecurityGroupRequest request = new CreateSecurityGroupRequest()
            .withGroupName(groupName).withDescription("Security Group for " + businessKey);

        CreateSecurityGroupResult result = client.createSecurityGroup(request);
        LOG.info("<< Created Security Group with ID {}", result.getGroupId());

    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals(ErrorCodes.DUPLICATE_SECURITY_GROUP)) {
            LOG.warn(String.format("<< Security Group %s already exists. " +
                "Synchronizing ingress rules.", groupName), e);
        } else {
            throw Throwables.propagate(e);
        }
    }

    synchronizeIngressRules(client, groupName, pool.getNetwork());
}
项目:incubator-provisionr    文件:DeleteSecurityGroupLiveTest.java   
@Test
public void testDeleteSecurityGroup() throws Exception {
    DelegateExecution execution = mock(DelegateExecution.class);
    Pool pool = mock(Pool.class);

    when(pool.getProvider()).thenReturn(provider);
    when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
    when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);

    client.createSecurityGroup(new CreateSecurityGroupRequest()
        .withGroupName(SECURITY_GROUP_NAME).withDescription("Just for test"));

    activity.execute(execution);

    try {
        client.describeSecurityGroups(new DescribeSecurityGroupsRequest()
            .withGroupNames(SECURITY_GROUP_NAME));
        fail("Did not throw AmazonServiceException as expected");

    } catch (AmazonServiceException e) {
        assertThat(e.getErrorCode()).isEqualTo("InvalidGroup.NotFound");
    }
}
项目:photon-model    文件:AWSSecurityGroupClient.java   
public String createSecurityGroup(String name, String description, String vpcId) {
    CreateSecurityGroupRequest req = new CreateSecurityGroupRequest()
            .withDescription(description)
            .withGroupName(name);

    // set vpc for the security group if provided
    if (vpcId != null) {
        req = req.withVpcId(vpcId);
    }

    CreateSecurityGroupResult result = this.client.createSecurityGroup(req);

    return result.getGroupId();
}
项目:cmn-project    文件:EC2.java   
public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request) {
    logger.info("create security group, groupName={}", request.getGroupName());
    SecurityGroup securityGroup = new SecurityGroup();
    CreateSecurityGroupResult result = ec2.createSecurityGroup(request);
    securityGroup.setGroupName(request.getGroupName());
    securityGroup.setGroupId(result.getGroupId());
    return securityGroup;
}
项目:cmn-project    文件:CreateSGTask.java   
@Override
public void execute(Context context) throws Exception {
    EC2TagHelper tags = new EC2TagHelper(context.env);

    String description = context.env.name + ":" + resource.id;
    CreateSecurityGroupRequest request = new CreateSecurityGroupRequest(resource.name, description);
    if (resource.vpc != null) request.withVpcId(resource.vpc.remoteVPC.getVpcId());
    resource.remoteSecurityGroup = AWS.ec2.createSecurityGroup(request);

    Threads.sleepRoughly(Duration.ofSeconds(5));    // wait small period of time, for sg to be visible for creating tag

    AWS.ec2.createTags(new CreateTagsRequest()
        .withResources(resource.remoteSecurityGroup.getGroupId())
        .withTags(tags.env(), tags.resourceId(resource.id), tags.name(resource.id)));
}
项目:dohko    文件:EC2.java   
public void createSecurityGroupIfDoesNotExist(String groupName)
{
    checkState(!isNullOrEmpty(groupName));

    List<SecurityGroup> groups = newArrayList();

    try
    {
        LOG.debug("checking if the security group [{}] already exists on region [{}].", groupName, DEFAULT_API_REGION.getName());
        groups = ec2_.describeSecurityGroups(new DescribeSecurityGroupsRequest().withGroupNames(groupName)).getSecurityGroups();
    }
    catch (AmazonServiceException exception)
    {
        LOG.debug("The security group {} does not already exist on region {}.", groupName, DEFAULT_API_REGION.getName());
    }

    if (groups.isEmpty())
    {
        LOG.debug("Creating the security group [{}] on region [{}].", groupName, DEFAULT_API_REGION.getName());

        CreateSecurityGroupResult createSecurityGroup = ec2_.createSecurityGroup(new CreateSecurityGroupRequest()
                .withGroupName(groupName)
                .withDescription("default-app-group"));

        LOG.debug("The security group [{}] was created on region [{}], and its id is [{}]", groupName, 
                DEFAULT_API_REGION.getName(), 
                createSecurityGroup.getGroupId());

        authorizeTcpAndSshIngressTraffic(groupName);
    }
}
项目:aws-sdk-java-resources    文件:VpcImpl.java   
@Override
public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request,
        ResultCapture<CreateSecurityGroupResult> extractor) {

    ActionResult result = resource.performAction("CreateSecurityGroup",
            request, extractor);

    if (result == null) return null;
    return new SecurityGroupImpl(result.getResource());
}
项目:aws-sdk-java-resources    文件:EC2Impl.java   
@Override
public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request,
        ResultCapture<CreateSecurityGroupResult> extractor) {

    ActionResult result = service.performAction("CreateSecurityGroup",
            request, extractor);

    if (result == null) return null;
    return new SecurityGroupImpl(result.getResource());
}
项目:aws-sdk-java-resources    文件:EC2Impl.java   
@Override
public SecurityGroup createSecurityGroup(String description, String
        groupName, ResultCapture<CreateSecurityGroupResult> extractor) {

    CreateSecurityGroupRequest request = new CreateSecurityGroupRequest()
        .withDescription(description)
        .withGroupName(groupName);
    return createSecurityGroup(request, extractor);
}
项目:agathon    文件:Ec2SecurityGroupService.java   
@Override
public void create(String groupName, String dataCenter) {
  client(dataCenter).createSecurityGroup(new CreateSecurityGroupRequest()
      .withGroupName(groupName)
      // description is required for EC2
      .withDescription("Agathon Cassandra Group"));
}
项目:pi    文件:AwsJavaSdkTestCase.java   
@Override
public void testEc2AddGrp() throws Exception {
    // setup
    CreateSecurityGroupRequest createSecurityGroupRequest = new CreateSecurityGroupRequest("default", "just testing");

    // act
    try {
        ec2.createSecurityGroup(createSecurityGroupRequest);
        fail("expected Amazon Service Exception");
    } catch (AmazonServiceException e) {
        assertTrue(e.getMessage().contains("version 2010-08-31 is not supported"));
    }
}
项目:cfnassist    文件:TestManageSecGroups.java   
@Before
public void beforeEachTestRuns() {  
    client = new CloudClient(ec2Client, new DefaultAwsRegionProviderChain());

    deleteGroupIfPresent();

    CreateSecurityGroupRequest createRequest = new CreateSecurityGroupRequest().
            withDescription("test group").
            withGroupName(GROUP_NAME);
    CreateSecurityGroupResult result = ec2Client.createSecurityGroup(createRequest);
    groupId = result.getGroupId();
}
项目:usergrid    文件:AmazonIpRuleManager.java   
@Override
public boolean createRuleSet( final String name ) {
    try {
        CreateSecurityGroupRequest request = new CreateSecurityGroupRequest();

        request = request.withGroupName( name ).withDescription( "Judo Chop Security Group" );
        CreateSecurityGroupResult result = client.createSecurityGroup( request );
        return ( result != null && result.getGroupId() != null && ! result.getGroupId().isEmpty() );
    }
    catch ( AmazonServiceException e ) {
        LOG.warn( "Error while trying to create security group", e );
        return false;
    }
}
项目:aws-mock    文件:BaseTest.java   
/**
 * Create Security Group.
 *
 * @param groupName the group Name
 * @param groupDescription the group Description
 * @param vpcId vpcId for Sg
 * @return Security Group Id
 */
protected final String createSecurityGroup(final String groupName, final String groupDescription, final String vpcId) {
    String groupId = null;

    CreateSecurityGroupRequest req = new CreateSecurityGroupRequest();
    req.setGroupName(groupName);
    req.setDescription(groupDescription);
    req.setVpcId(vpcId);
    CreateSecurityGroupResult result = amazonEC2Client.createSecurityGroup(req);
    if (result != null) {
        groupId = result.getGroupId();
    }

    return groupId;
}
项目:elasticsearch_my    文件:AmazonEC2Mock.java   
@Override
public CreateSecurityGroupResult createSecurityGroup(CreateSecurityGroupRequest createSecurityGroupRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
项目:aws-doc-sdk-examples    文件:CreateSecurityGroup.java   
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply a group name, group description and vpc id\n" +
        "Ex: CreateSecurityGroup <group-name> <group-description> <vpc-id>\n";

    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String group_name = args[0];
    String group_desc = args[1];
    String vpc_id = args[2];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    CreateSecurityGroupRequest create_request = new
        CreateSecurityGroupRequest()
            .withGroupName(group_name)
            .withDescription(group_desc)
            .withVpcId(vpc_id);

    CreateSecurityGroupResult create_response =
        ec2.createSecurityGroup(create_request);

    System.out.printf(
        "Successfully created security group named %s",
        group_name);

    IpRange ip_range = new IpRange()
        .withCidrIp("0.0.0.0/0");

    IpPermission ip_perm = new IpPermission()
        .withIpProtocol("tcp")
        .withToPort(80)
        .withFromPort(80)
        .withIpv4Ranges(ip_range);

    IpPermission ip_perm2 = new IpPermission()
        .withIpProtocol("tcp")
        .withToPort(22)
        .withFromPort(22)
        .withIpv4Ranges(ip_range);

    AuthorizeSecurityGroupIngressRequest auth_request = new
        AuthorizeSecurityGroupIngressRequest()
            .withGroupName(group_name)
            .withIpPermissions(ip_perm, ip_perm2);

    AuthorizeSecurityGroupIngressResult auth_response =
        ec2.authorizeSecurityGroupIngress(auth_request);

    System.out.printf(
        "Successfully added ingress policy to security group %s",
        group_name);
}
项目:aws-sdk-java-resources    文件:VpcImpl.java   
@Override
public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request)
        {

    return createSecurityGroup(request, null);
}
项目:aws-sdk-java-resources    文件:EC2Impl.java   
@Override
public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request)
        {

    return createSecurityGroup(request, null);
}
项目:aws-sdk-java-resources    文件:Vpc.java   
/**
 * Performs the <code>CreateSecurityGroup</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Vpc</code> resource, and any conflicting parameter value set in the
 * request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>VpcId</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The <code>SecurityGroup</code> resource object associated with
 *         the result of this action.
 * @see CreateSecurityGroupRequest
 */
SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request);
项目:aws-sdk-java-resources    文件:Vpc.java   
/**
 * Performs the <code>CreateSecurityGroup</code> action and use a
 * ResultCapture to retrieve the low-level client response.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Vpc</code> resource, and any conflicting parameter value set in the
 * request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>VpcId</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The <code>SecurityGroup</code> resource object associated with
 *         the result of this action.
 * @see CreateSecurityGroupRequest
 */
SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request,
        ResultCapture<CreateSecurityGroupResult> extractor);
项目:aws-sdk-java-resources    文件:EC2.java   
/**
 * Performs the <code>CreateSecurityGroup</code> action.
 *
 * <p>
 *
 * @return The <code>SecurityGroup</code> resource object associated with
 *         the result of this action.
 * @see CreateSecurityGroupRequest
 */
com.amazonaws.resources.ec2.SecurityGroup createSecurityGroup(
        CreateSecurityGroupRequest request);
项目:aws-sdk-java-resources    文件:EC2.java   
/**
 * Performs the <code>CreateSecurityGroup</code> action and use a
 * ResultCapture to retrieve the low-level client response.
 *
 * <p>
 *
 * @return The <code>SecurityGroup</code> resource object associated with
 *         the result of this action.
 * @see CreateSecurityGroupRequest
 */
com.amazonaws.resources.ec2.SecurityGroup createSecurityGroup(
        CreateSecurityGroupRequest request,
        ResultCapture<CreateSecurityGroupResult> extractor);