Search in sources :

Example 1 with AddressModel

use of org.platformlayer.core.model.AddressModel in project platformlayer by platformlayer.

the class AddressModels method build.

public static AddressModel build(Properties properties) {
    AddressModel model = new AddressModel();
    model.cidr = properties.getProperty("cidr");
    model.address = properties.getProperty("address");
    model.netmask = properties.getProperty("netmask");
    model.gateway = properties.getProperty("gateway");
    model.protocol = properties.getProperty("protocol");
    populateDefaults(model);
    return model;
}
Also used : AddressModel(org.platformlayer.core.model.AddressModel)

Example 2 with AddressModel

use of org.platformlayer.core.model.AddressModel 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) PoolBuilder(org.platformlayer.ops.pool.PoolBuilder) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 3 with AddressModel

use of org.platformlayer.core.model.AddressModel 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) PoolBuilder(org.platformlayer.ops.pool.PoolBuilder) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 4 with AddressModel

use of org.platformlayer.core.model.AddressModel 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) ResourcePool(org.platformlayer.ops.pool.ResourcePool) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) 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 5 with AddressModel

use of org.platformlayer.core.model.AddressModel in project platformlayer by platformlayer.

the class LxcInstanceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    final DirectInstance model = OpsContext.get().getInstance(DirectInstance.class);
    CloudInstanceMapper instance;
    {
        instance = injected(CloudInstanceMapper.class);
        instance.instance = OpsContext.get().getInstance(DirectInstance.class);
        addChild(instance);
    }
    instance.addChild(ManagedDirectory.build(getInstanceDir(), "700"));
    // TODO: If we're not going to assign an IPV4 redirect, we might not need this
    final Provider<AddressModel> address4;
    {
        NetworkAddressPoolAssignment provider = instance.addChild(NetworkAddressPoolAssignment.class);
        provider.holder = model.getKey();
        provider.poolProvider = DirectCloudUtils.getPrivateAddressPool4();
        address4 = provider;
    }
    final Provider<AddressModel> address6;
    {
        NetworkAddressPoolAssignment provider = instance.addChild(NetworkAddressPoolAssignment.class);
        provider.holder = model.getKey();
        provider.poolProvider = directCloudHelpers.getAddressPool6();
        address6 = provider;
    }
    // {
    // NetworkTunDevice tun = injected(NetworkTunDevice.class);
    // tun.interfaceName = getEthernetDeviceName();
    // tun.bridgeName = Providers.getProperty(assignNetworkAddress, "bridge");
    // instance.addChild(tun);
    // }
    {
        DownloadImage download = injected(DownloadImage.class);
        download.imageFile = new File(getInstanceDir(), "rootfs");
        download.recipeKey = model.recipeId;
        download.imageFormats = Collections.singletonList(ImageFormat.Tar);
        instance.addChild(download);
    }
    {
        LxcBootstrap bootstrap = injected(LxcBootstrap.class);
        bootstrap.address4 = address4;
        bootstrap.address6 = address6;
        bootstrap.lxcId = id;
        bootstrap.instanceDir = instanceDir;
        try {
            bootstrap.sshPublicKey = OpenSshUtils.readSshPublicKey(model.sshPublicKey);
        } catch (IOException e) {
            throw new OpsException("Error deserializing SSH key", e);
        }
        bootstrap.hostname = model.hostname;
        instance.addChild(bootstrap);
    }
    InstanceScript script;
    {
        script = instance.addChild(InstanceScript.class);
        script.filePath = new File(DirectHostController.LXC_INSTANCE_DIR, id);
        String key = "lxc-" + id;
        script.key = key;
        script.addresses.add(address4);
        script.addresses.add(address6);
        // script.hostPrimaryInterface = hostModel.publicInterface;
        Command command = Command.build("lxc-start");
        command.addLiteral("--name").addQuoted(id);
        script.launchInstanceCommand = command;
    }
    {
        // ManagedSupervisordInstance service = instance.addChild(ManagedSupervisordInstance.class);
        StandardService service = instance.addChild(StandardService.class);
        script.configure(model, service);
    }
    {
        OpsProvider<TagChanges> tagChanges = new OpsProvider<TagChanges>() {

            @Override
            public TagChanges get() {
                TagChanges tagChanges = new TagChanges();
                tagChanges.addTags.add(Tag.INSTANCE_KEY.build(model.getKey()));
                AddressModel ipv4 = address4.get();
                AddressModel ipv6 = address6.get();
                if (ipv4 != null) {
                    tagChanges.addTags.add(Tag.NETWORK_ADDRESS.build(ipv4));
                }
                if (ipv6 != null) {
                    tagChanges.addTags.add(Tag.NETWORK_ADDRESS.build(ipv6));
                }
                return tagChanges;
            }
        };
        instance.addChild(Tagger.build(model, tagChanges));
    }
}
Also used : NetworkAddressPoolAssignment(org.platformlayer.ops.pool.NetworkAddressPoolAssignment) OpsException(org.platformlayer.ops.OpsException) DirectInstance(org.platformlayer.service.cloud.direct.model.DirectInstance) InstanceScript(org.platformlayer.service.cloud.direct.ops.InstanceScript) StandardService(org.platformlayer.ops.supervisor.StandardService) IOException(java.io.IOException) TagChanges(org.platformlayer.core.model.TagChanges) CloudInstanceMapper(org.platformlayer.service.cloud.direct.ops.CloudInstanceMapper) OpsProvider(org.platformlayer.ops.OpsProvider) Command(org.platformlayer.ops.Command) AddressModel(org.platformlayer.core.model.AddressModel) File(java.io.File) DownloadImage(org.platformlayer.service.cloud.direct.ops.DownloadImage)

Aggregations

AddressModel (org.platformlayer.core.model.AddressModel)11 OpsProvider (org.platformlayer.ops.OpsProvider)6 DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)4 File (java.io.File)3 InetAddress (java.net.InetAddress)3 TagChanges (org.platformlayer.core.model.TagChanges)3 OpsException (org.platformlayer.ops.OpsException)3 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)3 NetworkPoolBuilder (org.platformlayer.ops.pool.NetworkPoolBuilder)3 DirectInstance (org.platformlayer.service.cloud.direct.model.DirectInstance)3 InetSocketAddress (java.net.InetSocketAddress)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 Command (org.platformlayer.ops.Command)2 InterfaceModel (org.platformlayer.ops.networks.InterfaceModel)2 IpRange (org.platformlayer.ops.networks.IpRange)2 NetworkAddressPoolAssignment (org.platformlayer.ops.pool.NetworkAddressPoolAssignment)2 PoolBuilder (org.platformlayer.ops.pool.PoolBuilder)2 SocketAddressPoolAssignment (org.platformlayer.ops.pool.SocketAddressPoolAssignment)2 CloudInstanceMapper (org.platformlayer.service.cloud.direct.ops.CloudInstanceMapper)2 DownloadImage (org.platformlayer.service.cloud.direct.ops.DownloadImage)2