当前位置: 首页>>代码示例>>Java>>正文


Java CreateSecurityGroupRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.CreateSecurityGroupRequest的典型用法代码示例。如果您正苦于以下问题:Java CreateSecurityGroupRequest类的具体用法?Java CreateSecurityGroupRequest怎么用?Java CreateSecurityGroupRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreateSecurityGroupRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了CreateSecurityGroupRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSecurityGroupByClusterName

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
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.");

}
 
开发者ID:spagnuolocarmine,项目名称:aws-cluster-toolkit,代码行数:27,代码来源:AwsClusterManager.java

示例2: createSecurityGroupAsync

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
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);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:24,代码来源:AWSSecurityGroupClient.java

示例3: createSG

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
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;
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:19,代码来源:BakeAMITask.java

示例4: createSecurityGroup

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
/***
 * 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);
  }
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:23,代码来源:AWSSdkClient.java

示例5: execute

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:25,代码来源:EnsureSecurityGroupExists.java

示例6: testDeleteSecurityGroup

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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");
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:24,代码来源:DeleteSecurityGroupLiveTest.java

示例7: createSecurityGroup

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
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();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:15,代码来源:AWSSecurityGroupClient.java

示例8: createSecurityGroup

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
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;
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:9,代码来源:EC2.java

示例9: execute

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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)));
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:16,代码来源:CreateSGTask.java

示例10: createSecurityGroupIfDoesNotExist

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
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);
    }
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:32,代码来源:EC2.java

示例11: createSecurityGroup

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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());
}
 
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:11,代码来源:VpcImpl.java

示例12: createSecurityGroup

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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());
}
 
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:11,代码来源:EC2Impl.java

示例13: create

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@Override
public void create(String groupName, String dataCenter) {
  client(dataCenter).createSecurityGroup(new CreateSecurityGroupRequest()
      .withGroupName(groupName)
      // description is required for EC2
      .withDescription("Agathon Cassandra Group"));
}
 
开发者ID:signal,项目名称:agathon,代码行数:8,代码来源:Ec2SecurityGroupService.java

示例14: testEc2AddGrp

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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"));
    }
}
 
开发者ID:barnyard,项目名称:pi,代码行数:14,代码来源:AwsJavaSdkTestCase.java

示例15: beforeEachTestRuns

import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; //导入依赖的package包/类
@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();
}
 
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:13,代码来源:TestManageSecGroups.java


注:本文中的com.amazonaws.services.ec2.model.CreateSecurityGroupRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。