[workspace-commit] CVS update: MODIFIED: modes
Tim Freeman
commit at globus.org
Thu May 21 15:02:07 CDT 2009
, ContextMonitor.java
...
User: tfreeman
Date: 09/05/21 15:02:07
Modified: vm/service/client/java/source/src/org/globus/workspace/client/modes
ContextMonitor.java
Log:
hostkeydir option in cloud client (used with the context broker) will place a file for each host in a history subdirectory. filename is hostname, file contents is known_hosts format (including public key)
Revision Changes Path
1.4 +113 -18 workspace/vm/service/client/java/source/src/org/globus/workspace/client/modes/ContextMonitor.java
http://viewcvs.globus.org/viewcvs.cgi/workspace/vm/service/client/java/source/src/org/globus/workspace/client/modes/ContextMonitor.java.diff?r1=1.3&r2=1.4
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ContextMonitor.java
===================================================================
RCS file: /home/globdev/CVS/globus-packages/workspace/vm/service/client/java/source/src/org/globus/workspace/client/modes/ContextMonitor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ContextMonitor.java 9 Jan 2009 20:06:46 -0000 1.3
+++ ContextMonitor.java 21 May 2009 20:02:07 -0000 1.4
@@ -79,6 +79,7 @@
private boolean dryrun;
private long pollDelayMs;
private String sshKnownHostsPath;
+ private String sshKnownHostsDirPath;
private boolean adjustSshKnownHosts;
private AdjustTask[] adjustTasks;
@@ -109,6 +110,7 @@
this.validateReportdir();
this.validateAdjustSSHhostsList();
this.validateSSHhostsFile();
+ this.validateSSHhostsDir();
this.dryrun = this.args.dryrun;
CommonLogs.logBoolean(this.dryrun, "dryrun mode", this.pr, logger);
}
@@ -309,6 +311,30 @@
}
}
+ private void validateSSHhostsDir() throws ParameterProblem {
+
+ // dir files not needed if adjust flag is not present
+ if (!this.adjustSshKnownHosts) {
+ return; // *** EARLY RETURN ***
+ }
+
+ if (this.args.sshHostsDirPath == null) {
+ return; // *** EARLY RETURN ***
+ }
+
+ final File f = new File(this.args.sshHostsDirPath);
+ if (f.exists()) {
+ if (!f.canWrite()) {
+ throw new ParameterProblem("Given known_hosts directory ('" +
+ this.args.sshHostsDirPath + "') is not writable.");
+ }
+ this.sshKnownHostsDirPath = f.getAbsolutePath();
+ } else {
+ throw new ParameterProblem("Given known_hosts directory ('" +
+ this.args.sshHostsDirPath + "') does not exist.");
+ }
+ }
+
private void setName() {
if (this.args.shortName != null) {
@@ -450,6 +476,7 @@
try {
adjustKnownHosts(nodes,
this.sshKnownHostsPath,
+ this.sshKnownHostsDirPath,
this.adjustTasks,
this.pr);
} catch (Exception e) {
@@ -836,6 +863,7 @@
private static void adjustKnownHosts(Node_Type[] nodes,
String knownHostsPath,
+ String sshKnownHostsDirPath,
AdjustTask[] adjustTasks,
Print pr)
@@ -850,10 +878,8 @@
if (pr == null) {
throw new IllegalArgumentException("pr may not be null");
}
- if (knownHostsPath == null) {
- throw new IllegalArgumentException(
- "knownHostsPath may not be null");
- }
+
+ if (knownHostsPath != null) {
pr.debugln("\nknown_hosts adjust path: '" + knownHostsPath + "'");
@@ -874,6 +900,75 @@
}
}
+ if (sshKnownHostsDirPath != null) {
+
+ pr.debugln("\nknown_hosts directory: '" + sshKnownHostsDirPath + "'");
+
+ for (final AdjustTask task : adjustTasks) {
+ for (final Node_Type node : nodes) {
+
+ final IdentityProvides_Type[] ids = node.getIdentity();
+ if (ids != null) {
+ for (final IdentityProvides_Type id : ids) {
+ if (task.ipAddress.equals(id.getIp())) {
+ knownhostsdir_add(pr, task, node,
+ sshKnownHostsDirPath);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ private static void knownhostsdir_add(Print print,
+ AdjustTask task,
+ Node_Type node,
+ String sshKnownHostsDirPath)
+ throws SerializationException, IOException {
+
+ final IdentityProvides_Type[] ids = node.getIdentity();
+ for (final IdentityProvides_Type id : ids) {
+
+ if (id.getPubkey() == null) {
+ print.errln("No SSH key for " + id.getIp());
+ continue;
+ }
+
+ // null task.iface means 'get all'
+ if (task.iface == null
+ || task.iface.equals(id.get_interface())) {
+
+ // adding via repo.add needs the real key apparently, sending
+ // keyStr.getBytes() to HostKey constructor messes everything up
+
+ final String newEntry = id.getHostname() + "," +
+ id.getIp() + " " + id.getPubkey();
+
+ final String sendString = newEntry + "\n";
+
+ final File newfile = new File(sshKnownHostsDirPath,
+ id.getHostname());
+
+ final String newfilePath = newfile.getAbsolutePath();
+
+ FileUtils.writeStringToFile(sendString,
+ newfilePath,
+ false);
+
+ String printString =
+ "\nWrote SSH key out to: " + newfilePath;
+ if (task.printName != null) {
+ printString += " [[ " + task.printName + " ]]";
+ }
+ print.infoln(printString);
+ }
+ }
+
+ }
+
private static void knownhosts_rem(Print print,
AdjustTask task,
Node_Type node,
@@ -992,6 +1087,6 @@
AdjustTask task = new AdjustTask("1.2.3.4", null, "something");
AdjustTask[] tasks = {task};
Print pr = new Print(new PrintOpts(null), System.out, System.err, System.err);
- adjustKnownHosts(nodes, "/home/tim/known", tasks, pr);
+ adjustKnownHosts(nodes, "/home/tim/known", null, tasks, pr);
}
}
More information about the workspace-commit
mailing list