1 package org
.argeo
.slc
.lib
.linux
;
5 import javax
.security
.auth
.callback
.CallbackHandler
;
7 import org
.argeo
.slc
.SlcException
;
8 import org
.argeo
.slc
.core
.execution
.tasks
.SystemCall
;
9 import org
.springframework
.core
.io
.ClassPathResource
;
10 import org
.springframework
.core
.io
.Resource
;
12 /** Deploy and initialize an LXC container. */
13 public class DeployLxcContainer
implements Runnable
{
15 private String chroot
;
17 private Resource hostScript
= new ClassPathResource(
18 "/org/argeo/slc/lib/linux/lxc-init-host.sh", getClass()
20 private Resource guestScript
= new ClassPathResource(
21 "/org/argeo/slc/lib/linux/lxc-init-guest.sh", getClass()
24 private CallbackHandler callbackHandler
;
26 private Integer ram
= 1024;
27 private Integer vcpu
= 2;
31 if (chroot
== null || chroot
.trim().equals(""))
32 throw new SlcException("A chroot directory must be defined");
34 File chrootDir
= new File(chroot
);
37 ScriptCall hostCall
= new ScriptCall(hostScript
);
38 hostCall
.setLogCommand(true);
40 // hostCall.getEnvironmentVariables().put("CHROOT", chroot);
42 hostCall
.setCallbackHandler(callbackHandler
);
45 ScriptCall guestCall
= new ScriptCall(guestScript
);
46 guestCall
.setLogCommand(true);
47 guestCall
.setSudo("");
48 guestCall
.setCallbackHandler(callbackHandler
);
49 guestCall
.setChroot(chroot
);
52 SystemCall virtInstall
= new SystemCall(
53 "virt-install --connect lxc:/// --name " + chrootDir
.getName()
54 + " --ram " + ram
+ " --vcpu " + vcpu
55 + " --filesystem " + chrootDir
.getAbsolutePath()
56 + ",/ --noautoconsole");
57 virtInstall
.setLogCommand(true);
58 virtInstall
.setSudo("");
62 public void setChroot(String chroot
) {
66 public void setHostScript(Resource hostScript
) {
67 this.hostScript
= hostScript
;
70 public void setGuestScript(Resource guestScript
) {
71 this.guestScript
= guestScript
;
74 public void setCallbackHandler(CallbackHandler callbackHandler
) {
75 this.callbackHandler
= callbackHandler
;
78 public void setRam(Integer ram
) {
82 public void setVcpu(Integer vcpu
) {