Class: OsCtl::Cli::User
Constant Summary
collapse
- FIELDS =
%i[
pool
name
username
groupname
ugid
dataset
homedir
registered
standalone
].freeze
- FILTERS =
%i[pool registered].freeze
- DEFAULT_FIELDS =
%i[
pool
name
registered
standalone
].freeze
- IDMAP_FIELDS =
%i[type ns_id host_id count].freeze
Instance Method Summary
collapse
Methods included from Attributes
#do_set_attr, #do_unset_attr
Methods included from Assets
#print_assets
Methods inherited from Command
#cli_opt, #format_output, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, run
Instance Method Details
#assets ⇒ Object
164
165
166
167
|
# File 'lib/osctl/cli/user.rb', line 164
def assets
require_args!('name')
print_assets(:user_assets, name: args[0], pool: gopts[:pool])
end
|
#create ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/osctl/cli/user.rb', line 113
def create
require_args!('name')
if opts['map'].any?
uid_map = gid_map = opts['map']
else
uid_map = opts['map-uid']
gid_map = opts['map-gid']
end
osctld_fmt(:user_create, cmd_opts: {
name: args[0],
pool: opts[:pool] || gopts[:pool],
id_range: opts['id-range'],
block_index: opts['id-range-block-index'],
uid_map: uid_map.any? ? uid_map : nil,
gid_map: gid_map.any? ? gid_map : nil,
standalone: opts['standalone']
})
end
|
#delete ⇒ Object
135
136
137
138
|
# File 'lib/osctl/cli/user.rb', line 135
def delete
require_args!('name')
osctld_fmt(:user_delete, cmd_opts: { name: args[0], pool: gopts[:pool] })
end
|
#idmap_ls ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/osctl/cli/user.rb', line 169
def idmap_ls
param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
all_params: IDMAP_FIELDS
)
if opts[:list]
puts param_selector
return
end
require_args!('name', optional: %w[type])
cmd_opts = { name: args[0], uid: true, gid: true }
fmt_opts = {
layout: :columns,
cols: param_selector.parse_option(opts[:output])
}
case args[1]
when 'uid'
cmd_opts[:gid] = false
when 'gid'
cmd_opts[:uid] = false
when nil, 'both'
else
raise GLI::BadCommandLine, "expected uid|gid|both, got '#{args[1]}'"
end
fmt_opts[:header] = false if opts['hide-header']
osctld_fmt(
:user_idmap_list,
cmd_opts:,
fmt_opts:
)
end
|
#list ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/osctl/cli/user.rb', line 32
def list
keyring = KernelKeyring.new
param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
all_params: FIELDS + keyring.list_param_names,
default_params: DEFAULT_FIELDS
)
if opts[:list]
puts param_selector
return
end
cols = param_selector.parse_option(opts[:output])
sort = opts[:sort] && param_selector.parse_option(opts[:sort])
if sort
sort.each do |v|
cols << v unless cols.include?(v)
end
end
cmd_opts = {}
fmt_opts = {
layout: :columns,
cols:,
sort:
}
cmd_opts[:names] = args if args.count > 0
if opts[:registered]
cmd_opts[:registered] = true
elsif opts[:unregistered]
cmd_opts[:registered] = false
end
FILTERS.each do |v|
[gopts, opts].each do |options|
next unless options[v]
cmd_opts[v] = options[v].split(',')
end
end
fmt_opts[:header] = false if opts['hide-header']
users = osctld_call(:user_list, **cmd_opts)
keyring.add_user_values(users, cols, precise: gopts[:parsable])
format_output(users, **fmt_opts)
end
|
#register ⇒ Object
140
141
142
143
144
145
146
147
148
|
# File 'lib/osctl/cli/user.rb', line 140
def register
require_args!('name')
if args[0] == 'all'
osctld_fmt(:user_register, cmd_opts: { all: true })
else
osctld_fmt(:user_register, cmd_opts: { name: args[0], pool: gopts[:pool] })
end
end
|
#set_attr ⇒ Object
225
226
227
228
229
230
231
232
233
|
# File 'lib/osctl/cli/user.rb', line 225
def set_attr
require_args!('name', 'attribute', 'value')
do_set_attr(
:user_set,
{ name: args[0], pool: gopts[:pool] },
args[1],
args[2]
)
end
|
#set_standalone ⇒ Object
207
208
209
210
211
212
213
214
|
# File 'lib/osctl/cli/user.rb', line 207
def set_standalone
require_args!('name')
osctld_fmt(:user_set, cmd_opts: {
name: args[0],
pool: gopts[:pool],
standalone: true
})
end
|
#show ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/osctl/cli/user.rb', line 85
def show
keyring = KernelKeyring.new
param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
all_params: FIELDS + keyring.list_param_names,
default_params: DEFAULT_FIELDS
)
if opts[:list]
puts param_selector
return
end
require_args!('name')
fmt_opts = { layout: :rows }
fmt_opts[:header] = false if opts['hide-header']
cols = param_selector.parse_option(opts[:output])
user = osctld_call(:user_show, name: args[0], pool: gopts[:pool])
keyring.add_user_values(user, cols, precise: gopts[:parsable])
fmt_opts[:cols] = cols
format_output(user, **fmt_opts)
end
|
#subugids ⇒ Object
160
161
162
|
# File 'lib/osctl/cli/user.rb', line 160
def subugids
osctld_fmt(:user_subugids)
end
|
#unregister ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/osctl/cli/user.rb', line 150
def unregister
require_args!('name')
if args[0] == 'all'
osctld_fmt(:user_unregister, cmd_opts: { all: true })
else
osctld_fmt(:user_unregister, cmd_opts: { name: args[0], pool: gopts[:pool] })
end
end
|
#unset_attr ⇒ Object
235
236
237
238
239
240
241
242
|
# File 'lib/osctl/cli/user.rb', line 235
def unset_attr
require_args!('name', 'attribute')
do_unset_attr(
:user_unset,
{ name: args[0], pool: gopts[:pool] },
args[1]
)
end
|
#unset_standalone ⇒ Object
216
217
218
219
220
221
222
223
|
# File 'lib/osctl/cli/user.rb', line 216
def unset_standalone
require_args!('name')
osctld_fmt(:user_unset, cmd_opts: {
name: args[0],
pool: gopts[:pool],
standalone: true
})
end
|