Search in sources :

Example 16 with OpsTarget

use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.

the class BackupDirectory method doBackup.

@Handler(BackupAction.class)
public void doBackup() throws OpsException, IOException {
    OpsContext opsContext = OpsContext.get();
    // Machine machine = opsContext.getInstance(Machine.class);
    OpsTarget target = opsContext.getInstance(OpsTarget.class);
    BackupContext backup = backups.getContext();
    DirectoryBackup request = new DirectoryBackup();
    request.target = target;
    request.rootDirectory = backupRoot;
    request.exclude.addAll(this.excludes);
    backup.doBackup(request);
    backup.add(new BackupItem(itemKey, FORMAT, request.objectName));
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpsContext(org.platformlayer.ops.OpsContext) Handler(org.platformlayer.ops.Handler)

Example 17 with OpsTarget

use of org.platformlayer.ops.OpsTarget 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)

Example 18 with OpsTarget

use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.

the class ImageStoreController method getImageStore.

@Override
public org.platformlayer.ops.images.ImageStore getImageStore() throws OpsException {
    String endpoint = model.getTags().findUnique("endpoint");
    if (endpoint == null) {
        log.warn("ImageStore not yet active: " + model);
        return null;
    }
    URI url;
    try {
        url = new URI(endpoint);
    } catch (URISyntaxException e) {
        throw new OpsException("Cannot parse endpoint: " + endpoint, e);
    }
    if (url.getScheme().equals("ssh")) {
        String myAddress = url.getHost();
        Machine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(myAddress));
        // This is nasty; we're in the context of another service here...
        SshKey sshKey = sshKeys.findOtherServiceKey(new ServiceType("imagestore"));
        OpsTarget target = machine.getTarget("imagestore", sshKey.getKeyPair());
        DirectImageStore directImageStore = OpsContext.get().getInjector().getInstance(DirectImageStore.class);
        directImageStore.connect(target);
        return directImageStore;
    } else {
        throw new OpsException("Unknown protocol for endpoint: " + endpoint);
    }
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsException(org.platformlayer.ops.OpsException) OpsTarget(org.platformlayer.ops.OpsTarget) ServiceType(org.platformlayer.ids.ServiceType) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Machine(org.platformlayer.ops.Machine) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) DirectImageStore(org.platformlayer.ops.images.direct.DirectImageStore)

Example 19 with OpsTarget

use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.

the class MysqlTarget method changePassword.

public void changePassword(Secret newPassword) throws OpsException {
    OpsTarget target = getOpsTarget();
    Command command = Command.build("mysqladmin");
    command.addQuoted("--user=", username);
    command.addQuoted("--host=", hostname);
    command.addQuoted("--password=", password);
    command.addLiteral("password");
    command.addQuoted(newPassword);
    target.executeCommand(command);
    password = newPassword;
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command)

Example 20 with OpsTarget

use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.

the class MysqlTarget method execute.

public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
    OpsTarget target = getOpsTarget();
    Command command = Command.build("mysql");
    command.addQuoted("--user=", username);
    command.addQuoted("--host=", hostname);
    command.addQuoted("--password=", password);
    command.addArgument(Argument.buildQuoted("--execute=", sql).setMasked("--execute=" + Command.MASKED));
    return target.executeCommand(command);
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command)

Aggregations

OpsTarget (org.platformlayer.ops.OpsTarget)41 Handler (org.platformlayer.ops.Handler)17 File (java.io.File)14 Machine (org.platformlayer.ops.Machine)12 OpsException (org.platformlayer.ops.OpsException)11 SshKey (org.platformlayer.ops.helpers.SshKey)10 Command (org.platformlayer.ops.Command)9 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)6 OpaqueMachine (org.platformlayer.ops.OpaqueMachine)6 OpsContext (org.platformlayer.ops.OpsContext)6 ItemBase (org.platformlayer.core.model.ItemBase)4 PublicKey (java.security.PublicKey)3 Tag (org.platformlayer.core.model.Tag)3 Tags (org.platformlayer.core.model.Tags)3 BindingScope (org.platformlayer.ops.BindingScope)3 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 FilesystemInfo (org.platformlayer.ops.filesystem.FilesystemInfo)3 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)3 ServiceType (org.platformlayer.ids.ServiceType)2