]> 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
Add distribution cache in CreateSrpm
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / lib / linux / RedhatHostManager.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.lib.linux;
18
19 import org.argeo.slc.SlcException;
20 import org.argeo.slc.core.deploy.LocalFilesDeployment;
21 import org.argeo.slc.core.deploy.ResourceSet;
22 import org.argeo.slc.core.execution.tasks.SystemCall;
23 import org.argeo.slc.jsch.RemoteExec;
24 import org.argeo.slc.jsch.SshFilesDeployment;
25 import org.argeo.slc.jsch.SshTarget;
26
27 public class RedhatHostManager {
28
29 private SimpleLinuxHost host;
30
31 // SSH
32 private Boolean useSsh = true;
33 private SshTarget sshTarget = null;
34
35 public void installPackages() {
36 StringBuffer cmd = new StringBuffer("yum --nogpgcheck -y install");
37 for (String pkg : ((RpmDistribution) host.getDistribution())
38 .getAdditionalPackages()) {
39 cmd.append(' ').append(pkg);
40 }
41 executeCommand(cmd.toString());
42
43 RedhatDeploymentData rdd = (RedhatDeploymentData) host
44 .getDeploymentData();
45 executeCommand(rdd.getRunlevelsScript());
46 }
47
48 public void deployConfig() {
49 RedhatDeploymentData rdd = (RedhatDeploymentData) host
50 .getDeploymentData();
51 deploy(rdd.getConfigurationFiles());
52 executeCommand(rdd.getPermissionsScript());
53 }
54
55 // GENERIC?
56 protected void deploy(ResourceSet resourceSet) {
57 if (useSsh)
58 new SshFilesDeployment(getSshTarget(), resourceSet).run();
59 else
60 new LocalFilesDeployment(resourceSet).run();
61
62 }
63
64 protected void executeCommand(String command) {
65 if (command == null)
66 return;
67
68 if (useSsh) {
69 RemoteExec rExec = new RemoteExec(getSshTarget(), command);
70 rExec.setFailOnBadExitStatus(false);
71 rExec.run();
72 } else
73 new SystemCall(command).run();
74 }
75
76 protected SshTarget getSshTarget() {
77 if (sshTarget == null)
78 throw new SlcException("No SSH target defined");
79 return sshTarget;
80 }
81
82 public void setHost(SimpleLinuxHost host) {
83 this.host = host;
84 }
85
86 public void setUseSsh(Boolean useSsh) {
87 this.useSsh = useSsh;
88 }
89
90 public void setSshTarget(SshTarget sshTarget) {
91 this.sshTarget = sshTarget;
92 }
93
94 }