Search in sources :

Example 6 with OpsTarget

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

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

the class DirectCloudUtils method toTarget.

public OpsTarget toTarget(DirectHost host) throws OpsException {
    NetworkPoint address = NetworkPoint.forPublicHostname(host.host);
    Machine hostMachine = new OpaqueMachine(address);
    OpsTarget hostTarget = hostMachine.getTarget(service.getSshKey());
    return hostTarget;
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) Machine(org.platformlayer.ops.Machine) OpaqueMachine(org.platformlayer.ops.OpaqueMachine)

Example 8 with OpsTarget

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

the class DirectCloudUtils method getPublicAddressPool4.

public OpsProvider<ResourcePool<InetSocketAddress>> getPublicAddressPool4(final int publicPort, final List<Integer> publicPortGroup) {
    OpsProvider<ResourcePool<InetSocketAddress>> pool = new OpsProvider<ResourcePool<InetSocketAddress>>() {

        @Override
        public ResourcePool<InetSocketAddress> get() throws OpsException {
            DirectHost host = OpsContext.get().getInstance(DirectHost.class);
            OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
            PlatformLayerKey sharedNetworkKey = getSharedNetworkKey();
            // We don't skip here, at the moment.
            // We may just need a comma separated list in future...
            int skipCount = 0;
            if (sharedNetworkKey == null) {
                File poolPath = getPoolPath("sockets-ipv4-public");
                File resourceDir = new File(poolPath, "all");
                File assignedBase = new File(poolPath, "assigned");
                File perPortDir = new File(assignedBase, "port" + publicPort);
                PoolBuilder<AddressModel> poolBuilder = null;
                String ipv4Public = host.ipv4Public;
                if (ipv4Public != null) {
                    poolBuilder = new NetworkPoolBuilder(ipv4Public, skipCount);
                }
                StaticFilesystemBackedPool<AddressModel> addressPool = new StaticFilesystemBackedPool<AddressModel>(AddressModel.class, poolBuilder, target, resourceDir, perPortDir);
                return new AssignPortToAddressPool(addressPool, publicPort);
            } else {
                throw new UnsupportedOperationException();
            // DirectNetwork network = platformLayer.getItem(sharedNetworkKey, DirectNetwork.class);
            //
            // for (AddressModel net : network.getNetworks()) {
            // if (Strings.isNullOrEmpty(net.cidr)) {
            // continue;
            // }
            //
            // IpRange cidr = IpRange.parse(net.cidr);
            // if (!cidr.isIpv4()) {
            // continue;
            // }
            //
            // NetworkPoolBuilder poolBuilder = new NetworkPoolBuilder(net.cidr, skipCount, net);
            // PlatformlayerBackedPool<AddressModel> addressPool = new PlatformlayerBackedPool<AddressModel>(
            // platformLayer, sharedNetworkKey, AddressModel.class, poolBuilder);
            // return new AssignPortToAddressPool(addressPool, publicPort);
            // }
            //
            // log.warn("Unable to find an IPV4 network configured on " + sharedNetworkKey);
            // return null;
            }
        }
    };
    return pool;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) StaticFilesystemBackedPool(org.platformlayer.ops.pool.StaticFilesystemBackedPool) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ResourcePool(org.platformlayer.ops.pool.ResourcePool) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsTarget(org.platformlayer.ops.OpsTarget) OpsProvider(org.platformlayer.ops.OpsProvider) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) File(java.io.File)

Example 9 with OpsTarget

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

the class DirectCloudUtils method getUnsharedPrivatePoolProvider.

private static <T> OpsProvider<ResourcePool<T>> getUnsharedPrivatePoolProvider(final Class<T> clazz, final String key, final OpsProvider<? extends PoolBuilder<T>> poolBuilderProvider) {
    return new OpsProvider<ResourcePool<T>>() {

        @Override
        public ResourcePool<T> get() throws OpsException {
            OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
            File poolPath = getPoolPath(key);
            File resourceDir = new File(poolPath, "all");
            File assignedDir = new File(poolPath, "assigned");
            PoolBuilder<T> poolBuilder = null;
            if (poolBuilderProvider != null) {
                poolBuilder = poolBuilderProvider.get();
            }
            return new StaticFilesystemBackedPool<T>(clazz, poolBuilder, target, resourceDir, assignedDir);
        }
    };
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpsProvider(org.platformlayer.ops.OpsProvider) StaticFilesystemBackedPool(org.platformlayer.ops.pool.StaticFilesystemBackedPool) File(java.io.File)

Example 10 with OpsTarget

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

the class DirectTarget method doRecurseOperation.

@Override
public void doRecurseOperation() throws OpsException {
    Machine machine = new OpaqueMachine(address);
    OpsTarget target = machine.getTarget(sshKey);
    BindingScope scope = BindingScope.push(machine, target);
    try {
        OpsContext opsContext = OpsContext.get();
        OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
        scope.pop();
    }
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) OpsContext(org.platformlayer.ops.OpsContext) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) Machine(org.platformlayer.ops.Machine) BindingScope(org.platformlayer.ops.BindingScope)

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