]>
git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.support/src/org/argeo/slc/lib/linux/DeployLxcContainer.java
1 package org
.argeo
.slc
.lib
.linux
;
5 import org
.argeo
.slc
.SlcException
;
6 import org
.argeo
.slc
.core
.execution
.tasks
.SystemCall
;
7 import org
.springframework
.core
.io
.ClassPathResource
;
8 import org
.springframework
.core
.io
.Resource
;
10 /** Deploy and initialize an LXC container. */
11 public class DeployLxcContainer
implements Runnable
{
13 private String chroot
;
15 private Resource hostScript
= new ClassPathResource(
16 "/org/argeo/slc/lib/linux/lxc-init-host.sh", getClass()
18 private Resource guestScript
= new ClassPathResource(
19 "/org/argeo/slc/lib/linux/lxc-init-guest.sh", getClass()
22 // private CallbackHandler callbackHandler;
24 private Integer ram
= 1024;
25 private Integer vcpu
= 2;
29 if (chroot
== null || chroot
.trim().equals(""))
30 throw new SlcException("A chroot directory must be defined");
32 File chrootDir
= new File(chroot
);
35 ScriptCall hostCall
= new ScriptCall(hostScript
);
36 hostCall
.setLogCommand(true);
38 // hostCall.getEnvironmentVariables().put("CHROOT", chroot);
39 // hostCall.setSudo("");
40 // hostCall.setCallbackHandler(callbackHandler);
43 ScriptCall guestCall
= new ScriptCall(guestScript
);
44 guestCall
.setLogCommand(true);
45 // guestCall.setSudo("");
46 // guestCall.setCallbackHandler(callbackHandler);
47 guestCall
.setChroot(chroot
);
50 SystemCall virtInstall
= new SystemCall(
51 "virt-install --connect lxc:/// --name " + chrootDir
.getName()
52 + " --ram " + ram
+ " --vcpu " + vcpu
53 + " --filesystem " + chrootDir
.getAbsolutePath()
54 + ",/ --noautoconsole");
55 virtInstall
.setLogCommand(true);
56 // virtInstall.setSudo("");
60 public void setChroot(String chroot
) {
64 public void setHostScript(Resource hostScript
) {
65 this.hostScript
= hostScript
;
68 public void setGuestScript(Resource guestScript
) {
69 this.guestScript
= guestScript
;
72 // public void setCallbackHandler(CallbackHandler callbackHandler) {
73 // this.callbackHandler = callbackHandler;
76 public void setRam(Integer ram
) {
80 public void setVcpu(Integer vcpu
) {