-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Machine Configs #3
Comments
It might be cute to have a store_machine <- function(machine)
{
nm <- deparse(substitute(machine))
dump(nm, "~/.Rprofile", append=TRUE)
invisible()
}
|
Come to think of it, a my_machines <- read_ssh_config("~/.ssh/config") Maybe something like this: # internal
parse_ssh_config <- function(lines)
{
errmsg <- "malformed ssh config file"
lines <- gsub(lines, pattern="\\s+", replacement=" ")
flags <- strsplit(lines, split=" ")
names <- sapply(flags, `[`, 1)
hostname <- grep(names, pattern="^HostName", ignore.case=TRUE, perl=TRUE)
if (length(hostname) == 0)
stop(errmsg)
host <- grep(names, pattern="^Host", ignore.case=TRUE, perl=TRUE)
host <- which(host != hostname)
if (length(hostname) == 0)
stop(errmsg)
user <- grep(names, pattern="^User", ignore.case=TRUE, perl=TRUE)
port <- grep(names, pattern="^Port", ignore.case=TRUE, perl=TRUE)
get_args <- function(x) paste0("-o ", x[1], "=", x[2])
flags_other <- flags[-c(hostname, host, user, port)]
if (length(flags_other) > 0)
args <- paste(sapply(flags_other, get_args), collapse=" ")
else
args <- ""
hostname <- flags[[hostname]][2]
host <- flags[[host]][2]
if (length(user) == 0)
user <- system("whoami")
else
user <- flags[[user]][2]
if (length(port) == 0)
port <- 22
else
port <- flags[[port]][2]
list(host=host, list(user=user, hostname=hostname, pport=port, args=args))
}
#' @export
read_ssh_config <- function(file="~/.ssh/config")
{
sshconf <- readLines(file)
breaks <- c(0, which(sshconf == ""))
# lines separated by blanks; prune multi-breaks
lines <- lapply(2:length(breaks), function(n) sshconf[(breaks[n-1]+1):(breaks[n]-1)])
lines <- lines[which(sapply(sapply(lines, nchar), sum) > 0)]
machines_parsed <- lapply(lines, parse_ssh_config)
names <- sapply(machines_parsed, `[`, 1)
machines <- sapply(machines_parsed, `[`, 2)
machines <- lapply(machines, function(m) machine(m$user, m$hostname, pport=m$pport, args=m$args))
names(machines) <- names
return(machines)
}
m <- read_ssh_config()
m This isn't perfect (didn't bother with |
If you agree with the initial post (changing to machine configs), I can submit a PR. We can talk more at length about the other stuff later. |
Just do it. I need to buy time. Please |
First post implemented in PR. Second two are the wrong approach; I have a better idea. Closing issue. |
I still think that How about add another functions for this feature, |
ssh config is only for server not client, no? plink does not use it, either. |
You're probably right about multiple calls on one machine being more likely than calls to multiple machines in a session, but I still think the machine configuration is the way to go. Having all of the This system also allows for lookups with ssh config files (which yes, is ssh only, but valuable for server and client). So you can do: m <- machine("myaws")
rpc(myaws, m) Where the string Maybe |
I goal is simply aiming for most of normal users, so that they only need two: I don't expect anyone to read those of I think I do reserve for more than config, even for searching |
Don't determine the user name from local machine. It has to be given by users or ssh config for the remote machine. |
I know that User name doesn't have to be given. It can be inferred with 100% accuracy from ssh config if using ssh and the hostname is there. If not, it defaults to guessing with the machine user name. Anyone can still manually provide the user name though. I'll send another PR tonight. |
OK. I am find with both now. I meant don't guess from windows it does not make sense. win and *nix don't talk. |
I was working on something like this a year ago, but the pbdRPC design is so radically different, it wouldn't be easy to integrate. Basically what I'd like to have is an easy way to handle multiple machine configurations. What I want to be able to do is
etc. I actually think it would be worth changing the current interface for something like this, since in the long run it would be much simpler.
In my original plan, machine configs were S4 objects, but that's not really necessary (and I'm not sure I would do it that way again anyway). But I think all of the
.pbd_env$RPC_LI$
objects could be moved to a machine "object" (maybe S3/attribute just for error checking). Maybe something like:Then you would be able to just do:
There's nothing high minded here, but I really think this way of organization is worth considering.
The text was updated successfully, but these errors were encountered: