Search in sources :

Example 1 with TemplateDataSource

use of org.platformlayer.ops.templates.TemplateDataSource in project platformlayer by platformlayer.

the class InstanceBootstrap method addChildren.

@Override
protected void addChildren() throws OpsException {
    addChild(PersistIptablesScripts.class);
    addChild(DefaultAptSourcesConfigurationFile.class);
    {
        File aptConfDir = new File("/etc/apt/apt.conf.d");
        TemplateDataSource template = new TemplateDataSource() {

            @Override
            public void buildTemplateModel(Map<String, Object> model) throws OpsException {
            }
        };
        addChild(TemplatedFile.build(template, new File(aptConfDir, "90-install-recommends")));
        addChild(TemplatedFile.build(template, new File(aptConfDir, "90-install-suggests")));
    }
    addChild(BootstrapLocales.class);
    addChild(ConfigureSshd.class);
    // We always install curl, because we use it to check for http proxy responsiveness
    // TODO: Switch to netcat, to avoid using curl here - it's quite big
    addChild(PackageDependency.build("curl"));
    PeerToPeerCopy peerToPeerCopy = Injection.getInstance(PeerToPeerCopy.class);
    peerToPeerCopy.addChildren(this);
// if (OpsContext.isDelete()) {
// OpenstackComputeMachine machine = OpsContext.get().getInstance(OpenstackComputeMachine.class);
// 
// OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
// 
// OpenstackInstance model = OpsContext.get().getInstance(OpenstackInstance.class);
// 
// if (model.recipeId != null) {
// DiskImageRecipe recipe = platformLayerClient.getItem(DiskImageRecipe.class, model.recipeId);
// 
// diskImageRecipeHelper.applyRecipe(target, recipe);
// }
// }
}
Also used : OpsException(org.platformlayer.ops.OpsException) PeerToPeerCopy(org.platformlayer.ops.images.direct.PeerToPeerCopy) TemplateDataSource(org.platformlayer.ops.templates.TemplateDataSource) TemplatedFile(org.platformlayer.ops.filesystem.TemplatedFile) DefaultAptSourcesConfigurationFile(org.platformlayer.ops.packages.AptSourcesConfigurationFile.DefaultAptSourcesConfigurationFile) File(java.io.File)

Example 2 with TemplateDataSource

use of org.platformlayer.ops.templates.TemplateDataSource in project platformlayer by platformlayer.

the class TemplatedFile method buildModel.

protected Map<String, Object> buildModel() throws OpsException {
    Map<String, Object> model = Maps.newHashMap();
    TemplateDataSource templateDataSource = getTemplateDataSource();
    if (templateDataSource != null) {
        templateDataSource.buildTemplateModel(model);
    }
    return model;
}
Also used : TemplateDataSource(org.platformlayer.ops.templates.TemplateDataSource)

Example 3 with TemplateDataSource

use of org.platformlayer.ops.templates.TemplateDataSource 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

TemplateDataSource (org.platformlayer.ops.templates.TemplateDataSource)3 File (java.io.File)2 Provider (com.google.inject.Provider)1 Map (java.util.Map)1 AddressModel (org.platformlayer.core.model.AddressModel)1 TagChanges (org.platformlayer.core.model.TagChanges)1 OpsException (org.platformlayer.ops.OpsException)1 OpsProvider (org.platformlayer.ops.OpsProvider)1 TemplatedFile (org.platformlayer.ops.filesystem.TemplatedFile)1 PeerToPeerCopy (org.platformlayer.ops.images.direct.PeerToPeerCopy)1 InterfaceModel (org.platformlayer.ops.networks.InterfaceModel)1 DefaultAptSourcesConfigurationFile (org.platformlayer.ops.packages.AptSourcesConfigurationFile.DefaultAptSourcesConfigurationFile)1 NetworkAddressPoolAssignment (org.platformlayer.ops.pool.NetworkAddressPoolAssignment)1 SocketAddressPoolAssignment (org.platformlayer.ops.pool.SocketAddressPoolAssignment)1 DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)1 DirectInstance (org.platformlayer.service.cloud.direct.model.DirectInstance)1 CloudInstanceMapper (org.platformlayer.service.cloud.direct.ops.CloudInstanceMapper)1 DownloadImage (org.platformlayer.service.cloud.direct.ops.DownloadImage)1