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);
// }
// }
}
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;
}
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));
}
}
Aggregations