2016-09-17 8 views
0

jclouds를 사용하여 EC2 인스턴스를 조작하기 시작합니다.jclouds의 기존 securityGroup 및 pem 파일 사용 - Java

private ComputeService compute; 

public void add(Integer instances) { 
     try { 
      logger.info("------------------------------------------------------"); 
      logger.info(String.format(">> adding node to group %s%n", this.groupname)); 
      // Default template chooses the smallest size on an operating system 
      // that tested to work with java, which tends to be Ubuntu or CentOS 
      TemplateBuilder templateBuilder = this.compute.templateBuilder(); 
      // note this will create a user with the same name as you on the 
      // node. ex. you can connect via ssh publicip 
      Statement bootInstructions = AdminAccess.standard(); 

      // to run commands as root, we use the runScript option in the template. 
      templateBuilder.options(runScript(bootInstructions)); 

      Template template = templateBuilder.build(); 
      // add a custom security group 

      NodeMetadata node = getOnlyElement(this.compute.createNodesInGroup(this.groupname, instances, template)); 
      logger.info(String.format("<< node %s: %s%n", node.getId(), 
         concat(node.getPrivateAddresses(), node.getPublicAddresses()))); 
      logger.info("------------------------------------------------------"); 
     } catch (Exception e) { 
      logger.error(e.getMessage()); 
      logger.info("------------------------------------------------------"); 
     } 
    } 

인증이 올바른지 가정 groupname = default하십시오 : 따라서, 나는 다음과 같은 방법이있다. 나는 하나 개의 인스턴스가 생성하더라도

this.compute.add(1); 

을 실행하면 jclouds 새로운 security groupkey pair 때마다 생성됩니다. 기존의 foo.pem 파일과 default 보안 그룹이 있습니다. 예 : security group = jclouds#default. 기존 보안 그룹과 핵심 가치를 어떻게 활용할 수 있습니까? 보안 그룹이나 키 쌍을 기존 사용하려면

답변

0

, 당신은 템플릿 빌더에게 제공하여 작업을 수행 할 수 있습니다

templateBuilder.securityGroups(<existing security groups>); 
templateBuilder.as(AWSEC2TemplateOptions.class).keyPair(<existing key pair>); 
templateBuilder.options(runScript(bootInstructions)); 

주 당신이 옵션을 주조하는 데 필요한 keypair 방법을 사용하기 위해 이 옵션은 휴대용 인터페이스에서 사용할 수 없으므로 AWS 클래스에 추가해야합니다.

또한 키 기반 액세스를 사용하여 SSH (스크립트 실행)를 통해 노드에 액세스 할 때 jclouds는 "개인 키"를 노드에 제공해야합니다. 두 가지 옵션이 있습니다. 미리 ssh-agent에 키를로드하거나 templateOptions.overrideLoginPrivateKey을 사용하여 jclouds가 노드에 올바르게 로그인 할 수 있도록 개인 키를 제공하십시오.