Search in sources :

Example 1 with GoogleCloudInstance

use of org.platformlayer.service.cloud.google.model.GoogleCloudInstance in project platformlayer by platformlayer.

the class GoogleCloudController method buildInstanceTemplate.

@Override
public InstanceBase buildInstanceTemplate(MachineCreationRequest request) {
    GoogleCloudInstance rawMachine = new GoogleCloudInstance();
    rawMachine.minimumMemoryMb = request.minimumMemoryMB;
    rawMachine.hostname = request.hostname;
    return rawMachine;
}
Also used : GoogleCloudInstance(org.platformlayer.service.cloud.google.model.GoogleCloudInstance)

Example 2 with GoogleCloudInstance

use of org.platformlayer.service.cloud.google.model.GoogleCloudInstance in project platformlayer by platformlayer.

the class GoogleCloudInstanceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    final GoogleCloudInstance model = OpsContext.get().getInstance(GoogleCloudInstance.class);
    PublicKey rootPublicKey;
    try {
        rootPublicKey = OpenSshUtils.readSshPublicKey(model.sshPublicKey);
    } catch (IOException e) {
        throw new OpsException("Cannot read SSH key");
    }
    CloudInstanceMapper instance;
    {
        instance = injected(CloudInstanceMapper.class);
        instance.instance = model;
        addChild(instance);
    }
    {
        SshAuthorizedKey authorizeRoot = instance.addChild(SshAuthorizedKey.class);
        authorizeRoot.user = "root";
        authorizeRoot.publicKey = rootPublicKey;
    }
    {
        instance.addChild(ConfigureSshd.class);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                GoogleComputeMachine machine = OpsContext.get().getInstance(GoogleComputeMachine.class);
                TagChanges tagChanges = new TagChanges();
                tagChanges.addTags.add(Tag.INSTANCE_KEY.build(model.getKey()));
                tagChanges.addTags.addAll(machine.buildAddressTags());
                return tagChanges;
            }
        };
        instance.addChild(Tagger.build(model, tagChanges));
    }
// Note: We can't bootstrap an instance, because we can't log in to it,
// because the public key is not our service's public key
// if (model.publicPorts != null) {
// for (int publicPort : model.publicPorts) {
// PublicPorts publicPortForward = injected(PublicPorts.class);
// publicPortForward.port = publicPort;
// publicPortForward.backendItem = model;
// kvm.addChild(publicPortForward);
// }
// }
}
Also used : OpsException(org.platformlayer.ops.OpsException) SshAuthorizedKey(org.platformlayer.ops.ssh.SshAuthorizedKey) OpsProvider(org.platformlayer.ops.OpsProvider) PublicKey(java.security.PublicKey) IOException(java.io.IOException) TagChanges(org.platformlayer.core.model.TagChanges) ConfigureSshd(org.platformlayer.ops.bootstrap.ConfigureSshd) GoogleComputeMachine(org.platformlayer.service.cloud.google.ops.compute.GoogleComputeMachine) GoogleCloudInstance(org.platformlayer.service.cloud.google.model.GoogleCloudInstance)

Example 3 with GoogleCloudInstance

use of org.platformlayer.service.cloud.google.model.GoogleCloudInstance in project platformlayer by platformlayer.

the class GoogleCloudPublicEndpointController method addChildren.

@Override
protected void addChildren() throws OpsException {
    final GoogleCloudPublicEndpoint model = OpsContext.get().getInstance(GoogleCloudPublicEndpoint.class);
    GoogleCloudInstance instance = client.getItem(model.instance, GoogleCloudInstance.class);
    CloudInstanceMapper instanceMapper;
    {
        instanceMapper = injected(CloudInstanceMapper.class);
        instanceMapper.instance = instance;
        addChild(instanceMapper);
    }
    final EnsureFirewallIngress ingress;
    {
        ingress = injected(EnsureFirewallIngress.class);
        ingress.model = model;
        instanceMapper.addChild(ingress);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                TagChanges tagChanges = new TagChanges();
                String address = ingress.getPublicAddress();
                if (Strings.isNullOrEmpty(address)) {
                    throw new IllegalStateException();
                }
                EndpointInfo endpoint = new EndpointInfo(address, model.publicPort);
                tagChanges.addTags.add(endpoint.toTag());
                return tagChanges;
            }
        };
        Tagger tagger = injected(Tagger.class);
        tagger.platformLayerKey = model.getKey();
        tagger.tagChangesProvider = tagChanges;
        instanceMapper.addChild(tagger);
        Tagger tagInstance = injected(Tagger.class);
        tagInstance.platformLayerKey = null;
        tagInstance.platformLayerKey = model.instance;
        tagInstance.tagChangesProvider = tagChanges;
        instanceMapper.addChild(tagInstance);
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsProvider(org.platformlayer.ops.OpsProvider) Tagger(org.platformlayer.ops.tagger.Tagger) GoogleCloudPublicEndpoint(org.platformlayer.service.cloud.google.model.GoogleCloudPublicEndpoint) TagChanges(org.platformlayer.core.model.TagChanges) GoogleCloudInstance(org.platformlayer.service.cloud.google.model.GoogleCloudInstance)

Aggregations

GoogleCloudInstance (org.platformlayer.service.cloud.google.model.GoogleCloudInstance)3 TagChanges (org.platformlayer.core.model.TagChanges)2 OpsProvider (org.platformlayer.ops.OpsProvider)2 IOException (java.io.IOException)1 PublicKey (java.security.PublicKey)1 EndpointInfo (org.platformlayer.core.model.EndpointInfo)1 OpsException (org.platformlayer.ops.OpsException)1 ConfigureSshd (org.platformlayer.ops.bootstrap.ConfigureSshd)1 SshAuthorizedKey (org.platformlayer.ops.ssh.SshAuthorizedKey)1 Tagger (org.platformlayer.ops.tagger.Tagger)1 GoogleCloudPublicEndpoint (org.platformlayer.service.cloud.google.model.GoogleCloudPublicEndpoint)1 GoogleComputeMachine (org.platformlayer.service.cloud.google.ops.compute.GoogleComputeMachine)1