Quellcode durchsuchen

Add ssh key

pull/4/head
Svitlana vor 4 Jahren
Ursprung
Commit
7f503e5703
4 geänderte Dateien mit 35 neuen und 11 gelöschten Zeilen
  1. +19
    -5
      bubble-server/src/main/java/bubble/cloud/compute/ec2/AmazonEC2Driver.java
  2. +2
    -2
      bubble-server/src/main/resources/models/defaults/cloudService.json
  3. +4
    -4
      bubble-server/src/test/resources/models/system/cloudService.json
  4. +10
    -0
      config/activation.json

+ 19
- 5
bubble-server/src/main/java/bubble/cloud/compute/ec2/AmazonEC2Driver.java Datei anzeigen

@@ -24,11 +24,13 @@ import org.cobbzilla.util.http.HttpResponseBean;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

import static bubble.model.cloud.BubbleNode.TAG_INSTANCE_ID;
import static bubble.model.cloud.BubbleNode.TAG_SSH_KEY_ID;
import static org.cobbzilla.util.daemon.ZillaRuntime.die;
import static org.cobbzilla.util.http.HttpStatusCodes.OK;
import static org.cobbzilla.util.security.RsaKeyPair.newRsaKeyPair;
import static org.cobbzilla.wizard.resources.ResourceUtil.notFoundEx;

@Slf4j
@@ -93,17 +95,24 @@ public class AmazonEC2Driver extends ComputeServiceDriverBase {
@Override public BubbleNode start(@NonNull BubbleNode node) throws Exception {
final ComputeNodeSize size = config.getSize(node.getSize());

final AmazonEC2 ec2Client = getEc2Client();

DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();

String subnetId = ec2Client.describeSubnets(describeSubnetsRequest).getSubnets().stream()
.filter(s -> s.getAvailableIpAddressCount() != 0)
.findAny().orElseThrow(() -> new NoSuchElementException("Subnet not found")).getSubnetId();

RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withImageId(config.getConfig("imageId"))
.withInstanceType(size.getInternalName())
.withMinCount(MIN_COUNT)
.withMaxCount(MAX_COUNT)
.withKeyName(node.getUuid())
.withNetworkInterfaces(new InstanceNetworkInterfaceSpecification()
.withAssociatePublicIpAddress(true)
.withSubnetId(SUBNET_ID_PREFIX + node.getUuid())
.withDeviceIndex(0)
.withSubnetId(subnetId)
.withGroups(config.getConfig("group")));

final AmazonEC2 ec2Client = getEc2Client();
RunInstancesResult runInstancesResult = ec2Client.runInstances(runInstancesRequest);

if (runInstancesResult.getSdkHttpMetadata().getHttpStatusCode() != OK)
@@ -112,10 +121,12 @@ public class AmazonEC2Driver extends ComputeServiceDriverBase {

Instance instance = runInstancesResult.getReservation().getInstances().get(0);
final String instanceId = instance.getInstanceId();
final String ip4 = instance.getPrivateIpAddress();
final String ip6 = instance.getPublicIpAddress();
final String keyId = registerSshKey(node);

node.setTag(TAG_INSTANCE_ID, instanceId);
node.setTag(TAG_SSH_KEY_ID, keyId);
instance.setKeyName(keyId);
node.setIp4(ip4).setIp6(ip6).setTag(TAG_INSTANCE_ID, instanceId).setTag(TAG_SSH_KEY_ID, keyId);

nodeDAO.update(node);

@@ -199,6 +210,9 @@ public class AmazonEC2Driver extends ComputeServiceDriverBase {
}

@Override public String registerSshKey(BubbleNode node) {
if (node.hasSshKey()) return die("registerSshKey: node already has a key: "+node.getUuid());
node.setSshKey(newRsaKeyPair());

final AmazonEC2 ec2Client = getEc2Client();
ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(node.getUuid(), node.getSshKey().getSshPublicKey());
ImportKeyPairResult importKeyPairResult = ec2Client.importKeyPair(importKeyPairRequest);


+ 2
- 2
bubble-server/src/main/resources/models/defaults/cloudService.json Datei anzeigen

@@ -272,8 +272,8 @@
"driverClass": "bubble.cloud.compute.ec2.AmazonEC2Driver",
"driverConfig": {
"regions": [{
"name": "us-east-1", "description": "US East (N. Virginia)",
"location": {"country": "US", "lat": "37.926868", "lon": "-78.024902"}
"name": "US_WEST_2", "description": "US West (Oregon)",
"location": {"country": "US", "lat": "43.8041", "lon": "120.5542"}
}],
"sizes": [
{"name": "small", "type": "small", "internalName": "t2.micro", "vcpu": 1, "memoryMB": 1024, "ssdGB": 0},


+ 4
- 4
bubble-server/src/test/resources/models/system/cloudService.json Datei anzeigen

@@ -240,8 +240,8 @@
"driverClass": "bubble.cloud.compute.ec2.AmazonEC2Driver",
"driverConfig": {
"regions": [{
"name": "us-east-1", "description": "US East (N. Virginia)",
"location": {"country": "US", "lat": "37.926868", "lon": "-78.024902"}
"name": "US_WEST_2", "description": "US West (Oregon)",
"location": {"country": "US", "lat": "43.8041", "lon": "120.5542"}
}],
"sizes": [
{"name": "small", "type": "small", "internalName": "t2.micro", "vcpu": 1, "memoryMB": 1024, "ssdGB": 0},
@@ -249,8 +249,8 @@
{"name": "large", "type": "large", "internalName": "t2.medium", "vcpu": 2, "memoryMB": 4096, "ssdGB": 80}
],
"config": [
{"name": "imageId", "value": "ami-0080e4c5bc078760e"},
{"name": "group", "value": "sg-id"}
{"name": "imageId", "value": "ami-09396c35da02d69d3"},
{"name": "group", "value": "sg-d7ed5bb3"}
]},
"credentials": {
"params": [


+ 10
- 0
config/activation.json Datei anzeigen

@@ -28,6 +28,16 @@
"DigitalOceanCompute": {
"credentials": {"apiKey": "your_digitalocean_api_key"}
},
"AmazonEC2Driver" : {
"config": {
// region must be a valid value from the Regions enum: https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/java/com/amazonaws/regions/Regions.java
"region": "US_EAST_1"
},
"credentials" : {
"AWS_ACCESS_KEY_ID": "your_aws_access_key_id",
"AWS_SECRET_KEY": "your_aws_secret_key"
}
},

// You must configure the AWS S3 Storage service in order to launch new Bubbles
"S3Storage" : {


Laden…
Abbrechen
Speichern