Search in sources :

Example 1 with SshKey

use of org.platformlayer.ops.helpers.SshKey in project platformlayer by platformlayer.

the class GitHelpers method getAdminTarget.

OpsTarget getAdminTarget(OpsTarget rootTarget, Machine machine) throws OpsException, IOException {
    String adminUser = "gitadmin";
    File adminHomeDir = new File("/home", adminUser);
    File adminSshDir = new File(adminHomeDir, ".ssh");
    File privateKeyFile = new File(adminSshDir, "id_rsa");
    // File publicKeyFile = new File(adminSshDir, "id_rsa.pub");
    // File authorizedKeys = new File(adminSshDir, "authorized_keys");
    String privateKeyData = rootTarget.readTextFile(privateKeyFile);
    SshKey adminSshKey = new SshKey(null, adminUser, KeyPairUtils.deserialize(privateKeyData));
    return machine.getTarget(adminSshKey);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) File(java.io.File)

Example 2 with SshKey

use of org.platformlayer.ops.helpers.SshKey in project platformlayer by platformlayer.

the class MemcachedServiceController method doOperation.

public void doOperation(Managed<MemcachedService> managed) throws OpsException, IOException {
    String key = managed.getConductorId();
    SshKey sshKey = service.getSshKey();
    Tag tag = new Tag(Tag.CONDUCTOR_ID, key);
    DiskImageRecipe recipe = imageFactory.loadDiskImageResource(getClass(), "DiskImageRecipe.xml");
    String securityGroup = service.getSecurityGroupName();
    // TODO: This needs to be configurable. Use tags?
    int minimumMemoryMb = 2048;
    Managed<PersistentInstance> foundPersistentInstance = persistentInstances.getOrCreate(tag, recipe, managed.getModel().dnsName, sshKey.getName(), securityGroup, minimumMemoryMb);
    OpenstackComputeMachine machine = persistentInstances.getMachine(foundPersistentInstance);
// KeyPair sshKey = sshKeys.getOrCreate(sshKeyName);
// OpsTarget target = machine.getTarget(sshKey);
//
// target.mkdir(new File("/opt/scripts"));
// target.setFileContents(new File("/opt/scripts/dnsdatabasemonitor"),
// ResourceUtils.loadString(getClass(), "dnsdatabasemonitor"));
// target.setFileContents(new
// File("/etc/monit/conf.d/dnsdatabasemonitor"),
// ResourceUtils.loadString(getClass(), "monitrc"));
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) DiskImageRecipe(org.platformlayer.service.imagefactory.v1.DiskImageRecipe) PersistentInstance(org.platformlayer.service.instancesupervisor.v1.PersistentInstance) Tag(org.platformlayer.conductor.Tag) OpenstackComputeMachine(org.platformlayer.ops.OpenstackComputeMachine)

Example 3 with SshKey

use of org.platformlayer.ops.helpers.SshKey in project platformlayer by platformlayer.

the class ServiceProviderBase method getSshPublicKey.

@Override
public PublicKey getSshPublicKey() throws OpsException {
    ServiceContext serviceContext = injector.getInstance(ServiceContext.class);
    SshKey sshKey = serviceContext.getSshKey();
    if (sshKey == null) {
        return null;
    }
    PublicKey publicKey = sshKey.getKeyPair().getPublic();
    return publicKey;
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) ServiceContext(org.platformlayer.ops.helpers.ServiceContext) PublicKey(java.security.PublicKey)

Example 4 with SshKey

use of org.platformlayer.ops.helpers.SshKey in project platformlayer by platformlayer.

the class InstanceBuilder method buildPersistentInstanceTemplate.

private PersistentInstance buildPersistentInstanceTemplate() throws OpsException {
    SshKey sshKey = service.getSshKey();
    String securityGroup = service.getSecurityGroupName();
    DiskImageRecipe recipeTemplate = diskImageRecipe.get();
    if (recipeTemplate.getKey() == null) {
        // TODO: Something nicer than a UUID
        String recipeId = UUID.randomUUID().toString();
        recipeTemplate.setKey(PlatformLayerKey.fromId(recipeId));
    }
    DiskImageRecipe recipe = imageFactory.getOrCreateRecipe(recipeTemplate);
    PersistentInstance persistentInstanceTemplate = new PersistentInstance();
    persistentInstanceTemplate.setDnsName(dnsName);
    persistentInstanceTemplate.setSshPublicKey(SshKeys.serialize(sshKey.getKeyPair().getPublic()));
    persistentInstanceTemplate.setSecurityGroup(securityGroup);
    persistentInstanceTemplate.setMinimumRam(minimumMemoryMb);
    persistentInstanceTemplate.setCloud(cloud);
    persistentInstanceTemplate.setHostPolicy(hostPolicy);
    persistentInstanceTemplate.setRecipe(recipe.getKey());
    String id = dnsName;
    if (Strings.isNullOrEmpty(id)) {
        id = UUID.randomUUID().toString();
    }
    persistentInstanceTemplate.setKey(PlatformLayerKey.fromId(id));
    for (int publicPort : publicPorts) {
        persistentInstanceTemplate.getPublicPorts().add(publicPort);
    }
    return persistentInstanceTemplate;
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe) PersistentInstance(org.platformlayer.instances.model.PersistentInstance)

Example 5 with SshKey

use of org.platformlayer.ops.helpers.SshKey in project platformlayer by platformlayer.

the class RawTargetController method handler.

@Handler
public void handler(RawTarget rawTarget) throws OpsException, IOException {
    OpaqueMachine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(rawTarget.host));
    SshKey serviceSshKey = service.getSshKey();
    OpsTarget target = machine.getTarget(serviceSshKey);
    // TODO: We have a bootstrapping problem here!!
    PublicKey sshPublicKey = service.getSshKey().getKeyPair().getPublic();
    SshAuthorizedKey.ensureSshAuthorization(target, "root", sshPublicKey);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) PublicKey(java.security.PublicKey) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) Handler(org.platformlayer.ops.Handler)

Aggregations

SshKey (org.platformlayer.ops.helpers.SshKey)14 OpsTarget (org.platformlayer.ops.OpsTarget)10 OpsException (org.platformlayer.ops.OpsException)7 Handler (org.platformlayer.ops.Handler)5 Machine (org.platformlayer.ops.Machine)5 PublicKey (java.security.PublicKey)4 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)4 File (java.io.File)3 Tag (org.platformlayer.core.model.Tag)3 Tags (org.platformlayer.core.model.Tags)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 OpaqueMachine (org.platformlayer.ops.OpaqueMachine)3 OpenstackComputeMachine (org.platformlayer.ops.OpenstackComputeMachine)3 Tag (org.platformlayer.conductor.Tag)2 DiskImageRecipe (org.platformlayer.images.model.DiskImageRecipe)2 PersistentInstance (org.platformlayer.instances.model.PersistentInstance)2 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)2 GitServer (org.platformlayer.service.gitosis.model.GitServer)2 Instance (com.google.api.services.compute.model.Instance)1 Operation (com.google.api.services.compute.model.Operation)1