Search in sources :

Example 1 with OpsProvider

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

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

the class DirectCloudUtils method getPrivateAddressPool4.

public static OpsProvider<ResourcePool<AddressModel>> getPrivateAddressPool4() {
    OpsProvider<PoolBuilder<AddressModel>> poolBuilder = new OpsProvider<PoolBuilder<AddressModel>>() {

        @Override
        public PoolBuilder<AddressModel> get() {
            DirectHost host = OpsContext.get().getInstance(DirectHost.class);
            String privateCidr = host.ipv4Private;
            if (privateCidr != null) {
                // Skip the first entries in the CIDR as it's probably not valid
                // 0: Network identifier
                // 1: Gateway (?)
                // 2: Host (?)
                int skipCount = 3;
                return new NetworkPoolBuilder(privateCidr, skipCount);
            }
            return null;
        }
    };
    return getUnsharedPrivatePoolProvider(AddressModel.class, "addresses-ipv4-private", poolBuilder);
}
Also used : DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsProvider(org.platformlayer.ops.OpsProvider) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) PoolBuilder(org.platformlayer.ops.pool.PoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 3 with OpsProvider

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

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

the class DirectCloudUtils method getAddressPool6.

public OpsProvider<ResourcePool<AddressModel>> getAddressPool6() {
    OpsProvider<PoolBuilder<AddressModel>> poolBuilder = new OpsProvider<PoolBuilder<AddressModel>>() {

        @Override
        public PoolBuilder<AddressModel> get() throws OpsException {
            DirectHost host = OpsContext.get().getInstance(DirectHost.class);
            PlatformLayerKey sharedNetworkKey = getSharedNetworkKey();
            // Skip the first entries in the CIDR as it's probably not valid
            // 0: Network identifier
            // 1: Gateway
            // 2: Host
            int skipCount = 3;
            if (sharedNetworkKey != null) {
                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.isIpv6()) {
                        continue;
                    }
                    return new NetworkPoolBuilder(net.cidr, skipCount, net);
                }
                log.warn("Unable to find an IPV6 network configured on " + sharedNetworkKey);
                return null;
            } else {
                String privateCidr = host.ipv6;
                if (privateCidr != null) {
                    return new NetworkPoolBuilder(privateCidr, skipCount, null);
                }
                return null;
            }
        }
    };
    return getNetworkPoolProvider(AddressModel.class, "addresses-ipv6", poolBuilder);
}
Also used : IpRange(org.platformlayer.ops.networks.IpRange) DirectNetwork(org.platformlayer.service.cloud.direct.model.DirectNetwork) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsProvider(org.platformlayer.ops.OpsProvider) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) PoolBuilder(org.platformlayer.ops.pool.PoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 5 with OpsProvider

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

the class GoogleCloudInstanceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    final GoogleCloudInstance model = OpsContext.get().getInstance(GoogleCloudInstance.class);
    PublicKey rootPublicKey;
    try {
        rootPublicKey = OpenSshUtils.readSshPublicKey(model.sshPublicKey);
    } catch (IOException e) {
        throw new OpsException("Cannot read SSH key");
    }
    CloudInstanceMapper instance;
    {
        instance = injected(CloudInstanceMapper.class);
        instance.instance = model;
        addChild(instance);
    }
    {
        SshAuthorizedKey authorizeRoot = instance.addChild(SshAuthorizedKey.class);
        authorizeRoot.user = "root";
        authorizeRoot.publicKey = rootPublicKey;
    }
    {
        instance.addChild(ConfigureSshd.class);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                GoogleComputeMachine machine = OpsContext.get().getInstance(GoogleComputeMachine.class);
                TagChanges tagChanges = new TagChanges();
                tagChanges.addTags.add(Tag.INSTANCE_KEY.build(model.getKey()));
                tagChanges.addTags.addAll(machine.buildAddressTags());
                return tagChanges;
            }
        };
        instance.addChild(Tagger.build(model, tagChanges));
    }
// Note: We can't bootstrap an instance, because we can't log in to it,
// because the public key is not our service's public key
// if (model.publicPorts != null) {
// for (int publicPort : model.publicPorts) {
// PublicPorts publicPortForward = injected(PublicPorts.class);
// publicPortForward.port = publicPort;
// publicPortForward.backendItem = model;
// kvm.addChild(publicPortForward);
// }
// }
}
Also used : OpsException(org.platformlayer.ops.OpsException) SshAuthorizedKey(org.platformlayer.ops.ssh.SshAuthorizedKey) OpsProvider(org.platformlayer.ops.OpsProvider) PublicKey(java.security.PublicKey) IOException(java.io.IOException) TagChanges(org.platformlayer.core.model.TagChanges) ConfigureSshd(org.platformlayer.ops.bootstrap.ConfigureSshd) GoogleComputeMachine(org.platformlayer.service.cloud.google.ops.compute.GoogleComputeMachine) GoogleCloudInstance(org.platformlayer.service.cloud.google.model.GoogleCloudInstance)

Aggregations

OpsProvider (org.platformlayer.ops.OpsProvider)14 TagChanges (org.platformlayer.core.model.TagChanges)9 AddressModel (org.platformlayer.core.model.AddressModel)6 File (java.io.File)5 OpsException (org.platformlayer.ops.OpsException)5 Tagger (org.platformlayer.ops.tagger.Tagger)5 EndpointInfo (org.platformlayer.core.model.EndpointInfo)4 DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)4 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)3 NetworkPoolBuilder (org.platformlayer.ops.pool.NetworkPoolBuilder)3 DirectInstance (org.platformlayer.service.cloud.direct.model.DirectInstance)3 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 OpsTarget (org.platformlayer.ops.OpsTarget)2 NetworkAddressPoolAssignment (org.platformlayer.ops.pool.NetworkAddressPoolAssignment)2 PoolBuilder (org.platformlayer.ops.pool.PoolBuilder)2 SocketAddressPoolAssignment (org.platformlayer.ops.pool.SocketAddressPoolAssignment)2 StaticFilesystemBackedPool (org.platformlayer.ops.pool.StaticFilesystemBackedPool)2 CloudInstanceMapper (org.platformlayer.service.cloud.direct.ops.CloudInstanceMapper)2