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);
}
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"));
}
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;
}
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;
}
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);
}
Aggregations