Search in sources :

Example 11 with OpsTarget

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

the class MountCgroups method handler.

@Handler
public void handler() throws OpsException, IOException {
    // TODO: Only if not installed
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    File cgroupsFile = new File("/cgroup");
    FilesystemInfo info = target.getFilesystemInfoFile(cgroupsFile);
    if (info != null) {
        // TODO: Better idempotency
        return;
    }
    String fstabLine = "\ncgroup\t/cgroup\tcgroup\tdefaults\t0\t0";
    File fstabFile = new File("/etc/fstab");
    String fstab = target.readTextFile(fstabFile);
    fstab += fstabLine;
    FileUpload.upload(target, fstabFile, fstab);
    target.mkdir(cgroupsFile);
    Command mountCommand = Command.build("mount cgroup");
    target.executeCommand(mountCommand);
// mkdir /cgroup
// echo -e "cgroup\t/cgroup\tcgroup\tdefaults\t0\t0" >> /etc/fstab
// mount cgroup
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) FilesystemInfo(org.platformlayer.ops.filesystem.FilesystemInfo) Command(org.platformlayer.ops.Command) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 12 with OpsTarget

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

the class CloudMap method getHosts.

private List<DirectCloudHost> getHosts(PlatformLayerKey cloudKey) throws OpsException {
    if (this.hosts == null) {
        List<DirectCloudHost> hosts = Lists.newArrayList();
        for (DirectHost host : platformLayer.listItems(DirectHost.class)) {
            if (!Objects.equal(host.cloud, cloudKey)) {
                continue;
            }
            if (host.lifecycle != null) {
                switch(host.lifecycle) {
                    case Stopping:
                        log.info("Host is terminating; won't allocate to it {}", host.getKey());
                        continue;
                }
            }
            OpsTarget target = directHelpers.toTarget(host);
            hosts.add(new DirectCloudHost(host, target));
        }
        this.hosts = hosts;
    }
    return this.hosts;
}
Also used : DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsTarget(org.platformlayer.ops.OpsTarget)

Example 13 with OpsTarget

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

the class LxcBootstrap method setupIpv6Script.

void setupIpv6Script() throws OpsException {
    File file = new File(getRoot(), "etc/network/if-up.d/ipv6");
    OpsTarget target = getTarget();
    FileUpload.upload(target, file, runTemplate("ipv6"));
    target.chmod(file, "755");
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) ChrootOpsTarget(org.platformlayer.ops.ChrootOpsTarget) File(java.io.File)

Example 14 with OpsTarget

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

the class SshPostgresTarget method execute.

public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
    OpsTarget target = getOpsTarget();
    // We probably want psql -A -t -c "command"
    Command command = Command.build("psql");
    command.addQuoted("--username=", username);
    command.addQuoted("--host=", hostname);
    command.addArgument(Argument.buildQuoted("--command=", sql).setMasked("--command=" + Command.MASKED));
    CommandEnvironment env = new CommandEnvironment();
    env.put("PGPASSWORD", password.plaintext());
    command.setEnvironment(env);
    return target.executeCommand(command);
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Example 15 with OpsTarget

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

the class DnsResolverModuleBuilder method buildTemplateModel.

@Override
public void buildTemplateModel(Map<String, Object> model) throws OpsException {
    List<String> nameservers = Lists.newArrayList();
    for (ProviderOf<DnsResolverProvider> entry : providers.listItemsProviding(DnsResolverProvider.class)) {
        DnsResolverProvider dnsResolverProvider = entry.get();
        List<InetAddress> addresses = dnsResolverProvider.findAddresses(NetworkPoint.forTargetInContext());
        for (InetAddress address : addresses) {
            nameservers.add(address.getHostAddress());
        }
    }
    if (nameservers.isEmpty()) {
        log.warn("No (internal) resolvers found; will set up default public nameservers; reconfigure needed if this changes");
        if (usePrivateResolvers) {
            OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
            AsBlock as = AsBlock.find(target);
            if (as != null) {
            // We had problems with the SL resolvers...
            /*
					 * if (Objects.equal(AsBlock.SOFTLAYER, as)) { log.warn("Adding private Softlayer resolvers");
					 * nameservers.add("10.0.80.11"); nameservers.add("10.0.80.12"); }
					 * 
					 * if (Objects.equal(AsBlock.HETZNER, as)) { log.warn("Adding private Hetzner resolvers");
					 * nameservers.add("213.133.99.99"); nameservers.add("213.133.100.100");
					 * nameservers.add("213.133.98.98"); }
					 */
            }
        }
        nameservers.add("8.8.8.8");
        nameservers.add("8.8.4.4");
        nameservers.add("2001:4860:4860::8888");
        nameservers.add("2001:4860:4860::8844");
    // So a reconfigure is needed!
    }
    model.put("nameservers", nameservers);
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) AsBlock(org.platformlayer.ops.packages.AsBlock) InetAddress(java.net.InetAddress)

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