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