Search in sources :

Example 6 with DirectHost

use of org.platformlayer.service.cloud.direct.model.DirectHost 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 7 with DirectHost

use of org.platformlayer.service.cloud.direct.model.DirectHost in project platformlayer by platformlayer.

the class KvmInstance method addChildren.

@Override
protected void addChildren() throws OpsException {
    CloudInstanceMapper instance;
    {
        instance = injected(CloudInstanceMapper.class);
        instance.instance = OpsContext.get().getInstance(DirectInstance.class);
        addChild(instance);
    }
    instance.addChild(ManagedDirectory.build(getInstanceDir(), "700"));
    final NetworkAddressPoolAssignment address4;
    {
        address4 = instance.addChild(NetworkAddressPoolAssignment.class);
        address4.holder = owner;
        address4.poolProvider = DirectCloudUtils.getPrivateAddressPool4();
    }
    final NetworkAddressPoolAssignment address6;
    {
        address6 = instance.addChild(NetworkAddressPoolAssignment.class);
        address6.holder = owner;
        address6.poolProvider = directCloudHelpers.getAddressPool6();
    }
    {
        NetworkTunDevice tun = injected(NetworkTunDevice.class);
        tun.interfaceName = getEthernetDeviceName();
        tun.bridgeName = new Provider<String>() {

            @Override
            public String get() {
                DirectHost host = OpsContext.get().getInstance(DirectHost.class);
                return host.bridge;
            }
        };
        instance.addChild(tun);
    }
    final SocketAddressPoolAssignment assignMonitorPort;
    {
        assignMonitorPort = injected(SocketAddressPoolAssignment.class);
        assignMonitorPort.holder = owner;
        assignMonitorPort.poolProvider = DirectCloudUtils.getKvmMonitorPortPool();
        instance.addChild(assignMonitorPort);
    }
    final SocketAddressPoolAssignment assignVncPort;
    {
        assignVncPort = injected(SocketAddressPoolAssignment.class);
        assignVncPort.holder = owner;
        assignVncPort.poolProvider = DirectCloudUtils.getVncPortPool();
        instance.addChild(assignVncPort);
    }
    {
        ConfigIso iso = injected(ConfigIso.class);
        iso.isoFile = getConfigIsoPath();
        iso.buildDir = new File(getInstanceDir(), "config_iso_src");
        iso.model = new TemplateDataSource() {

            @Override
            public void buildTemplateModel(Map<String, Object> model) throws OpsException {
                InterfaceModel eth0 = InterfaceModel.build("eth0");
                AddressModel ipv4 = address4.get();
                eth0.addAddress(ipv4);
                AddressModel ipv6 = address6.get();
                eth0.addAddress(ipv6);
                List<InterfaceModel> interfaces = Lists.newArrayList();
                interfaces.add(eth0);
                model.put("interfaces", interfaces);
                List<String> authorizedKeys = Lists.newArrayList();
                authorizedKeys.add(OpenSshUtils.serialize(sshPublicKey));
                model.put("authorizedKeys", authorizedKeys);
            }
        };
        instance.addChild(iso);
    }
    {
        DownloadImage download = injected(DownloadImage.class);
        download.imageFile = getImagePath();
        download.recipeKey = recipeId;
        download.imageFormats = Arrays.asList(ImageFormat.DiskRaw, ImageFormat.DiskQcow2);
        instance.addChild(download);
    }
    {
        ManagedKvmInstance kvmInstance = addChild(ManagedKvmInstance.class);
        kvmInstance.id = id;
        kvmInstance.memoryMb = Math.max(256, minimumMemoryMB);
        kvmInstance.vcpus = 1;
        kvmInstance.base = getInstanceDir();
        kvmInstance.monitor = assignMonitorPort;
        kvmInstance.vnc = assignVncPort;
        kvmInstance.nics = buildVnics();
        kvmInstance.drives = buildDrives();
        kvmInstance.addresses.add(address4);
        kvmInstance.addresses.add(address6);
    }
    {
        final DirectInstance model = OpsContext.get().getInstance(DirectInstance.class);
        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();
                tagChanges.addTags.add(Tag.NETWORK_ADDRESS.build(ipv4));
                tagChanges.addTags.add(Tag.NETWORK_ADDRESS.build(ipv6));
                return tagChanges;
            }
        };
        addChild(Tagger.build(model, tagChanges));
    }
}
Also used : NetworkAddressPoolAssignment(org.platformlayer.ops.pool.NetworkAddressPoolAssignment) SocketAddressPoolAssignment(org.platformlayer.ops.pool.SocketAddressPoolAssignment) TemplateDataSource(org.platformlayer.ops.templates.TemplateDataSource) DirectInstance(org.platformlayer.service.cloud.direct.model.DirectInstance) TagChanges(org.platformlayer.core.model.TagChanges) OpsProvider(org.platformlayer.ops.OpsProvider) Provider(com.google.inject.Provider) CloudInstanceMapper(org.platformlayer.service.cloud.direct.ops.CloudInstanceMapper) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) InterfaceModel(org.platformlayer.ops.networks.InterfaceModel) OpsProvider(org.platformlayer.ops.OpsProvider) AddressModel(org.platformlayer.core.model.AddressModel) File(java.io.File) Map(java.util.Map) DownloadImage(org.platformlayer.service.cloud.direct.ops.DownloadImage)

Aggregations

DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)7 AddressModel (org.platformlayer.core.model.AddressModel)4 OpsProvider (org.platformlayer.ops.OpsProvider)4 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)3 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)3 NetworkPoolBuilder (org.platformlayer.ops.pool.NetworkPoolBuilder)3 File (java.io.File)2 OpsTarget (org.platformlayer.ops.OpsTarget)2 PoolBuilder (org.platformlayer.ops.pool.PoolBuilder)2 DirectCloud (org.platformlayer.service.cloud.direct.model.DirectCloud)2 Provider (com.google.inject.Provider)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 Tag (org.platformlayer.core.model.Tag)1 TagChanges (org.platformlayer.core.model.TagChanges)1 Handler (org.platformlayer.ops.Handler)1 OpsException (org.platformlayer.ops.OpsException)1 InterfaceModel (org.platformlayer.ops.networks.InterfaceModel)1 IpRange (org.platformlayer.ops.networks.IpRange)1 NetworkAddressPoolAssignment (org.platformlayer.ops.pool.NetworkAddressPoolAssignment)1