]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatHostManager.java
a92a9693b76dd4b382e1923e2487d7a506270697
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / lib / linux / RedhatHostManager.java
1 package org.argeo.slc.lib.linux;
2
3 import org.argeo.slc.SlcException;
4 import org.argeo.slc.core.deploy.LocalFilesDeployment;
5 import org.argeo.slc.core.deploy.ResourceSet;
6 import org.argeo.slc.core.execution.tasks.SystemCall;
7 import org.argeo.slc.jsch.RemoteExec;
8 import org.argeo.slc.jsch.SshFilesDeployment;
9 import org.argeo.slc.jsch.SshTarget;
10
11 public class RedhatHostManager {
12
13 private SimpleLinuxHost host;
14
15 // SSH
16 private Boolean useSsh = true;
17 private SshTarget sshTarget = null;
18
19 public void installPackages() {
20 StringBuffer cmd = new StringBuffer("yum --nogpgcheck -y install");
21 for (String pkg : ((RpmDistribution) host.getDistribution())
22 .getAdditionalPackages()) {
23 cmd.append(' ').append(pkg);
24 }
25 executeCommand(cmd.toString());
26
27 RedhatDeploymentData rdd = (RedhatDeploymentData) host
28 .getDeploymentData();
29 executeCommand(rdd.getRunlevelsScript());
30 }
31
32 public void deployConfig() {
33 RedhatDeploymentData rdd = (RedhatDeploymentData) host
34 .getDeploymentData();
35 deploy(rdd.getConfigurationFiles());
36 executeCommand(rdd.getPermissionsScript());
37 }
38
39 // GENERIC?
40 protected void deploy(ResourceSet resourceSet) {
41 if (useSsh)
42 new SshFilesDeployment(getSshTarget(), resourceSet).run();
43 else
44 new LocalFilesDeployment(resourceSet).run();
45
46 }
47
48 protected void executeCommand(String command) {
49 if (useSsh)
50 new RemoteExec(getSshTarget(), command).run();
51 else
52 new SystemCall(command).run();
53 }
54
55 protected SshTarget getSshTarget() {
56 if (sshTarget == null)
57 throw new SlcException("No SSH target defined");
58 return sshTarget;
59 }
60
61 public void setHost(SimpleLinuxHost host) {
62 this.host = host;
63 }
64
65 public void setUseSsh(Boolean useSsh) {
66 this.useSsh = useSsh;
67 }
68
69 public void setSshTarget(SshTarget sshTarget) {
70 this.sshTarget = sshTarget;
71 }
72
73 }