Skip to content

Commit

Permalink
wreck: add flux wreck environment manipulation commands
Browse files Browse the repository at this point in the history
Add flux-wreck setenv, getenv, unsetenv commands to set, get, and
manipulate the global wreck environment under lwj.environ.
  • Loading branch information
grondo committed Mar 31, 2018
1 parent fee1ac9 commit e1fb7d3
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/cmd/flux-wreck
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,66 @@ prog:SubCommand {
end
}

prog:SubCommand {
name = "setenv",
usage = "[VAR=VALUE|all]",
description = "Export environment to all jobs",
handler = function (self, arg)
local f = assert (require 'flux'.new ())
local getenv = wreck.get_filtered_env
local env = f:kvs_get ("lwj.environ") or {}
for _,expr in ipairs (arg) do
if expr == "all" then
for k,v in pairs(getenv()) do
env[k] = v
end
else
local var,val = expr:match("(.*)=(.*)")
env[var] = val
end
end
f:kvs_put ("lwj.environ", env)
f:kvs_commit ()
end
}

prog:SubCommand {
name = "unsetenv",
usage = "VAR [VAR...]",
description = "Export environment to all jobs",
handler = function (self, arg)
local f = assert (require 'flux'.new ())
local env = f:kvs_get ("lwj.environ") or {}
for _,var in ipairs (arg) do
env[var] = nil
end
f:kvs_put ("lwj.environ", env)
f:kvs_commit ()
end
}

prog:SubCommand {
name = "getenv",
usage = "VAR [VAR...]",
description = "Export environment to all jobs",
handler = function (self, arg)
local f = assert (require 'flux'.new ())
local env = f:kvs_get ("lwj.environ") or {}
if #arg == 0 then
for k,v in pairs (env) do
print (k.."="..v)
end
end
for _,k in ipairs (arg) do
local v = env[k] or ""
print (k.."="..v)
end
end
}




-- return keys in dir as a table sorted by number
local function sorted_keys (dir)
local results = {}
Expand Down

0 comments on commit e1fb7d3

Please sign in to comment.