Search in sources :

Example 31 with Handler

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

the class ApacheBootstrap method handler.

@Handler
public void handler() throws OpsException {
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    target.rm(new File("/etc/apache2/sites-enabled/000-default"));
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 32 with Handler

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

the class LdapMasterPassword method doOperation.

@Handler
public void doOperation(OpsTarget target) throws OpsException {
    // TODO: Make this idempotent
    LdifRecord configLdif;
    {
        Command ldapSearch = Command.build("ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config olcRootDN=cn=admin,cn=config dn olcRootDN olcRootPW");
        List<LdifRecord> ldifs = LdifRecord.parse(target.executeCommand(ldapSearch).getStdOut());
        if (ldifs.size() != 1) {
            throw new OpsException("Expected exactly one LDIF record for config");
        }
        configLdif = ldifs.get(0);
    }
    {
        StringBuilder modify = new StringBuilder();
        modify.append("dn: " + configLdif.getLdapDn().toString() + "\n");
        modify.append("replace: olcRootPW\n");
        modify.append("olcRootPW: " + LdapPasswords.getLdapPasswordEncoded(ldapSecret.plaintext()) + "\n");
        modify.append("\n");
        File tempDir = target.createTempDir();
        File modifyFile = new File(tempDir, "modifypw.ldif");
        FileUpload.upload(target, modifyFile, modify.toString());
        Command ldapModify = Command.build("ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f {0}", modifyFile);
        target.executeCommand(ldapModify);
    }
    ldap.writeLdapServerPassword(target, ldapSecret);
}
Also used : OpsException(org.platformlayer.ops.OpsException) Command(org.platformlayer.ops.Command) List(java.util.List) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 33 with Handler

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

the class PostgresqlServerBootstrap method handler.

@Handler
public void handler() throws OpsException {
    PostgresqlServer model = OpsContext.get().getInstance(PostgresqlServer.class);
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    // su postgres -c "psql --command=\"ALTER USER postgres WITH PASSWORD 'secret';\""
    String password = model.rootPassword.plaintext();
    String sql = String.format("ALTER USER postgres WITH PASSWORD '%s';", password);
    String psql = String.format("psql --command=\"%s\"", sql);
    Command command = Command.build("su postgres -c {0}", psql);
    target.executeCommand(command);
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command) PostgresqlServer(org.platformlayer.service.postgresql.model.PostgresqlServer) Handler(org.platformlayer.ops.Handler)

Example 34 with Handler

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

the class NginxServerBootstrap method handler.

@Handler
public void handler() throws OpsException {
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    target.rm(new File("/etc/nginx/sites-enabled/default"));
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 35 with Handler

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

the class InstanceBuilder method doOperation.

@Handler
public void doOperation() throws OpsException, IOException {
    ItemBase item = ops.getInstance(ItemBase.class);
    Tag parentTag = Tag.buildParentTag(item.getKey());
    PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
    persistentInstanceTemplate.getTags().add(parentTag);
    // Set during doOperation
    Machine machine = null;
    PersistentInstance persistentInstance = null;
    InstanceBase instance = null;
    OpsTarget target = null;
    persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
    if (persistentInstance != null) {
        // We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
        // TODO: Should we always use the instance id??
        instance = instances.findInstance(persistentInstance);
        if (instance == null && !OpsContext.isDelete()) {
            // A machine has not (yet) been assigned
            throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
        }
    }
    if (instance != null) {
        machine = cloudHelpers.toMachine(instance);
    }
    if (addTagToManaged && !OpsContext.isDelete()) {
        // Add tag with instance id to persistent instance (very helpful for
        // DNS service!)
        PlatformLayerKey machineKey = machine.getKey();
        platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
    }
    SshKey sshKey = service.getSshKey();
    if (machine != null) {
        if (OpsContext.isDelete()) {
            target = null;
            machine = null;
        } else {
            target = machine.getTarget(sshKey);
        }
    }
    RecursionState recursion = getRecursionState();
    if (OpsContext.isDelete() && machine == null) {
        // Don't recurse into no machine :-)
        recursion.setPreventRecursion(true);
    }
    recursion.pushChildScope(Machine.class, machine);
    recursion.pushChildScope(PersistentInstance.class, persistentInstance);
    recursion.pushChildScope(InstanceBase.class, instance);
    recursion.pushChildScope(OpsTarget.class, target);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) PersistentInstance(org.platformlayer.instances.model.PersistentInstance) ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Tag(org.platformlayer.core.model.Tag) InstanceBase(org.platformlayer.core.model.InstanceBase) Machine(org.platformlayer.ops.Machine) Handler(org.platformlayer.ops.Handler)

Aggregations

Handler (org.platformlayer.ops.Handler)58 File (java.io.File)21 Command (org.platformlayer.ops.Command)17 OpsException (org.platformlayer.ops.OpsException)17 OpsTarget (org.platformlayer.ops.OpsTarget)17 Tag (org.platformlayer.core.model.Tag)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)5 SshKey (org.platformlayer.ops.helpers.SshKey)5 Machine (org.platformlayer.ops.Machine)4 PublicKey (java.security.PublicKey)3 Action (org.platformlayer.core.model.Action)3 EndpointInfo (org.platformlayer.core.model.EndpointInfo)3 ItemBase (org.platformlayer.core.model.ItemBase)3 Tags (org.platformlayer.core.model.Tags)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 Map (java.util.Map)2 OpenstackComputeClient (org.openstack.client.common.OpenstackComputeClient)2 SecurityGroup (org.openstack.model.compute.SecurityGroup)2 Server (org.openstack.model.compute.Server)2 PlatformLayerClientException (org.platformlayer.PlatformLayerClientException)2