opennebula-cli 3.8.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/oneacct +113 -0
- data/bin/oneacl +97 -0
- data/bin/onecluster +189 -0
- data/bin/onedatastore +165 -0
- data/bin/onegroup +137 -0
- data/bin/onehost +205 -0
- data/bin/oneimage +311 -0
- data/bin/onetemplate +277 -0
- data/bin/oneuser +404 -0
- data/bin/onevm +532 -0
- data/bin/onevnet +227 -0
- data/lib/cli_helper.rb +294 -0
- data/lib/command_parser.rb +719 -0
- data/lib/one_helper/oneacct_helper.rb +179 -0
- data/lib/one_helper/oneacl_helper.rb +130 -0
- data/lib/one_helper/onecluster_helper.rb +129 -0
- data/lib/one_helper/onedatastore_helper.rb +131 -0
- data/lib/one_helper/onegroup_helper.rb +134 -0
- data/lib/one_helper/onehost_helper.rb +196 -0
- data/lib/one_helper/oneimage_helper.rb +327 -0
- data/lib/one_helper/onequota_helper.rb +256 -0
- data/lib/one_helper/onetemplate_helper.rb +123 -0
- data/lib/one_helper/oneuser_helper.rb +242 -0
- data/lib/one_helper/onevm_helper.rb +266 -0
- data/lib/one_helper/onevnet_helper.rb +156 -0
- data/lib/one_helper.rb +609 -0
- metadata +93 -0
data/bin/onetemplate
ADDED
@@ -0,0 +1,277 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# -------------------------------------------------------------------------- #
|
4
|
+
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
5
|
+
# #
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
|
+
# not use this file except in compliance with the License. You may obtain #
|
8
|
+
# a copy of the License at #
|
9
|
+
# #
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
11
|
+
# #
|
12
|
+
# Unless required by applicable law or agreed to in writing, software #
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
15
|
+
# See the License for the specific language governing permissions and #
|
16
|
+
# limitations under the License. #
|
17
|
+
#--------------------------------------------------------------------------- #
|
18
|
+
|
19
|
+
ONE_LOCATION=ENV["ONE_LOCATION"]
|
20
|
+
|
21
|
+
if !ONE_LOCATION
|
22
|
+
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
23
|
+
else
|
24
|
+
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
25
|
+
end
|
26
|
+
|
27
|
+
$: << RUBY_LIB_LOCATION
|
28
|
+
$: << RUBY_LIB_LOCATION+"/cli"
|
29
|
+
|
30
|
+
require 'command_parser'
|
31
|
+
require 'one_helper/onetemplate_helper'
|
32
|
+
|
33
|
+
cmd=CommandParser::CmdParser.new(ARGV) do
|
34
|
+
usage "`onetemplate` <command> [<args>] [<options>]"
|
35
|
+
version OpenNebulaHelper::ONE_VERSION
|
36
|
+
|
37
|
+
helper = OneTemplateHelper.new
|
38
|
+
|
39
|
+
########################################################################
|
40
|
+
# Global Options
|
41
|
+
########################################################################
|
42
|
+
set :option, CommandParser::OPTIONS
|
43
|
+
|
44
|
+
list_options = CLIHelper::OPTIONS
|
45
|
+
list_options << OpenNebulaHelper::XML
|
46
|
+
list_options << OpenNebulaHelper::NUMERIC
|
47
|
+
list_options << OpenNebulaHelper::DESCRIBE
|
48
|
+
|
49
|
+
instantiate_options = [
|
50
|
+
OneTemplateHelper::VM_NAME,
|
51
|
+
OneTemplateHelper::MULTIPLE
|
52
|
+
]
|
53
|
+
|
54
|
+
########################################################################
|
55
|
+
# Formatters for arguments
|
56
|
+
########################################################################
|
57
|
+
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
58
|
+
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
59
|
+
end
|
60
|
+
|
61
|
+
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
62
|
+
OpenNebulaHelper.rname_to_id(arg, "USER")
|
63
|
+
end
|
64
|
+
|
65
|
+
set :format, :templateid, OneTemplateHelper.to_id_desc do |arg|
|
66
|
+
helper.to_id(arg)
|
67
|
+
end
|
68
|
+
|
69
|
+
set :format, :templateid_list, OneTemplateHelper.list_to_id_desc do |arg|
|
70
|
+
helper.list_to_id(arg)
|
71
|
+
end
|
72
|
+
|
73
|
+
set :format, :filterflag, OneTemplateHelper.filterflag_to_i_desc do |arg|
|
74
|
+
helper.filterflag_to_i(arg)
|
75
|
+
end
|
76
|
+
|
77
|
+
########################################################################
|
78
|
+
# Commands
|
79
|
+
########################################################################
|
80
|
+
|
81
|
+
create_desc = <<-EOT.unindent
|
82
|
+
Creates a new VM Template from the given description
|
83
|
+
|
84
|
+
Examples:
|
85
|
+
- using a VM Template description file:
|
86
|
+
|
87
|
+
onetemplate create vm_description.tmpl
|
88
|
+
|
89
|
+
- new VM Template named "arch vm" with a disk and a nic:
|
90
|
+
|
91
|
+
onetemplate create --name "arch vm" --memory 128 --cpu 1 --disk arch \\
|
92
|
+
--network private_lan
|
93
|
+
|
94
|
+
- using two disks:
|
95
|
+
|
96
|
+
onevm create --name "test vm" --memory 128 --cpu 1 --disk arch,data
|
97
|
+
|
98
|
+
EOT
|
99
|
+
|
100
|
+
command :create, create_desc, [:file, nil], :options =>
|
101
|
+
[OneTemplateHelper::VM_NAME]+OpenNebulaHelper::TEMPLATE_OPTIONS do
|
102
|
+
|
103
|
+
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
|
104
|
+
STDERR.puts "You can not use both template file and template"<<
|
105
|
+
" creation options."
|
106
|
+
next -1
|
107
|
+
end
|
108
|
+
|
109
|
+
helper.create_resource(options) do |tmpl|
|
110
|
+
begin
|
111
|
+
if args[0]
|
112
|
+
template = File.read(args[0])
|
113
|
+
else
|
114
|
+
res = OpenNebulaHelper.create_template(options)
|
115
|
+
|
116
|
+
if res.first != 0
|
117
|
+
STDERR.puts res.last
|
118
|
+
next -1
|
119
|
+
end
|
120
|
+
|
121
|
+
template = res.last
|
122
|
+
end
|
123
|
+
|
124
|
+
tmpl.allocate(template)
|
125
|
+
rescue => e
|
126
|
+
STDERR.puts e.messsage
|
127
|
+
exit -1
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
clone_desc = <<-EOT.unindent
|
133
|
+
Creates a new Template from an existing one
|
134
|
+
EOT
|
135
|
+
|
136
|
+
command :clone, clone_desc, :templateid, :name do
|
137
|
+
helper.perform_action(args[0],options,"cloned") do |t|
|
138
|
+
res = t.clone(args[1])
|
139
|
+
|
140
|
+
if !OpenNebula.is_error?(res)
|
141
|
+
puts "ID: #{res}"
|
142
|
+
else
|
143
|
+
puts res.message
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
delete_desc = <<-EOT.unindent
|
149
|
+
Deletes the given Image
|
150
|
+
EOT
|
151
|
+
|
152
|
+
command :delete, delete_desc, [:range, :templateid_list] do
|
153
|
+
helper.perform_actions(args[0],options,"deleted") do |t|
|
154
|
+
t.delete
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
instantiate_desc = <<-EOT.unindent
|
159
|
+
Creates a new VM instance from the given Template. This VM can be
|
160
|
+
managed with the 'onevm' command
|
161
|
+
EOT
|
162
|
+
|
163
|
+
command :instantiate, instantiate_desc, :templateid,
|
164
|
+
:options=>instantiate_options do
|
165
|
+
exit_code=0
|
166
|
+
|
167
|
+
number = options[:multiple] || 1
|
168
|
+
number.times do |i|
|
169
|
+
exit_code=helper.perform_action(args[0],options,"instantiated") do |t|
|
170
|
+
name = options[:name]
|
171
|
+
name = name.gsub("%i",i.to_s) if name
|
172
|
+
res = t.instantiate(name)
|
173
|
+
|
174
|
+
if !OpenNebula.is_error?(res)
|
175
|
+
puts "VM ID: #{res}"
|
176
|
+
end
|
177
|
+
|
178
|
+
res
|
179
|
+
end
|
180
|
+
|
181
|
+
break if exit_code==-1
|
182
|
+
end
|
183
|
+
|
184
|
+
exit_code
|
185
|
+
end
|
186
|
+
|
187
|
+
publish_desc = <<-EOT.unindent
|
188
|
+
DEPRECATED, use chmod instead. Publishes the given Template. A public
|
189
|
+
Template can be seen and instantiated by other users in the Template's
|
190
|
+
group.
|
191
|
+
EOT
|
192
|
+
|
193
|
+
command :publish, publish_desc, [:range,:templateid_list] do
|
194
|
+
helper.perform_actions(args[0],options,"published") do |t|
|
195
|
+
t.publish
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
unpublish_desc = <<-EOT.unindent
|
200
|
+
DEPRECATED, use chmod instead. Unpublishes the given Template. A private
|
201
|
+
Template can't be instantiated by any other user.
|
202
|
+
EOT
|
203
|
+
|
204
|
+
command :unpublish, unpublish_desc, [:range,:templateid_list] do
|
205
|
+
helper.perform_actions(args[0],options,"unpublished") do |t|
|
206
|
+
t.unpublish
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
chgrp_desc = <<-EOT.unindent
|
211
|
+
Changes the Template group
|
212
|
+
EOT
|
213
|
+
|
214
|
+
command :chgrp, chgrp_desc,[:range, :templateid_list], :groupid do
|
215
|
+
helper.perform_actions(args[0],options,"Group changed") do |t|
|
216
|
+
t.chown(-1, args[1].to_i)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
chown_desc = <<-EOT.unindent
|
221
|
+
Changes the Template owner and group
|
222
|
+
EOT
|
223
|
+
|
224
|
+
command :chown, chown_desc, [:range, :templateid_list], :userid,
|
225
|
+
[:groupid,nil] do
|
226
|
+
gid = args[2].nil? ? -1 : args[2].to_i
|
227
|
+
helper.perform_actions(args[0],options,"Owner/Group changed") do |t|
|
228
|
+
t.chown(args[1].to_i, gid)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
chmod_desc = <<-EOT.unindent
|
233
|
+
Changes the Template permissions
|
234
|
+
EOT
|
235
|
+
|
236
|
+
command :chmod, chmod_desc, [:range, :templateid_list], :octet do
|
237
|
+
helper.perform_actions(args[0],options, "Permissions changed") do |t|
|
238
|
+
t.chmod_octet(args[1])
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
update_desc = <<-EOT.unindent
|
243
|
+
Update the template contents. If a path is not provided the editor will
|
244
|
+
be launched to modify the current content.
|
245
|
+
EOT
|
246
|
+
|
247
|
+
command :update, update_desc, :templateid, [:file, nil] do
|
248
|
+
helper.perform_action(args[0],options,"modified") do |template|
|
249
|
+
str = OpenNebulaHelper.update_template(args[0], template, args[1])
|
250
|
+
template.update(str)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
list_desc = <<-EOT.unindent
|
255
|
+
Lists Templates in the pool
|
256
|
+
EOT
|
257
|
+
|
258
|
+
command :list, list_desc, [:filterflag, nil], :options=>list_options do
|
259
|
+
helper.list_pool(options, false, args[0])
|
260
|
+
end
|
261
|
+
|
262
|
+
show_desc = <<-EOT.unindent
|
263
|
+
Shows information for the given Template
|
264
|
+
EOT
|
265
|
+
|
266
|
+
command :show, show_desc, :templateid, :options=>OpenNebulaHelper::XML do
|
267
|
+
helper.show_resource(args[0],options)
|
268
|
+
end
|
269
|
+
|
270
|
+
top_desc = <<-EOT.unindent
|
271
|
+
Lists Templates continuously
|
272
|
+
EOT
|
273
|
+
|
274
|
+
command :top, top_desc, [:filterflag, nil], :options=>list_options do
|
275
|
+
helper.list_pool(options, true, args[0])
|
276
|
+
end
|
277
|
+
end
|
data/bin/oneuser
ADDED
@@ -0,0 +1,404 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# -------------------------------------------------------------------------- #
|
4
|
+
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
5
|
+
# #
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
7
|
+
# not use this file except in compliance with the License. You may obtain #
|
8
|
+
# a copy of the License at #
|
9
|
+
# #
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
11
|
+
# #
|
12
|
+
# Unless required by applicable law or agreed to in writing, software #
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
15
|
+
# See the License for the specific language governing permissions and #
|
16
|
+
# limitations under the License. #
|
17
|
+
#--------------------------------------------------------------------------- #
|
18
|
+
|
19
|
+
ONE_LOCATION=ENV["ONE_LOCATION"]
|
20
|
+
|
21
|
+
if !ONE_LOCATION
|
22
|
+
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
23
|
+
else
|
24
|
+
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
25
|
+
end
|
26
|
+
|
27
|
+
$: << RUBY_LIB_LOCATION
|
28
|
+
$: << RUBY_LIB_LOCATION+"/cli"
|
29
|
+
|
30
|
+
require 'command_parser'
|
31
|
+
require 'one_helper/oneuser_helper'
|
32
|
+
require 'one_helper/onequota_helper'
|
33
|
+
|
34
|
+
require 'uri'
|
35
|
+
|
36
|
+
cmd=CommandParser::CmdParser.new(ARGV) do
|
37
|
+
usage "`oneuser` <command> [<args>] [<options>]"
|
38
|
+
version OpenNebulaHelper::ONE_VERSION
|
39
|
+
|
40
|
+
########################################################################
|
41
|
+
# Global Options
|
42
|
+
########################################################################
|
43
|
+
set :option, CommandParser::OPTIONS
|
44
|
+
|
45
|
+
list_options = CLIHelper::OPTIONS
|
46
|
+
list_options << OpenNebulaHelper::XML
|
47
|
+
list_options << OpenNebulaHelper::NUMERIC
|
48
|
+
list_options << OpenNebulaHelper::DESCRIBE
|
49
|
+
|
50
|
+
READ_FILE={
|
51
|
+
:name => "read_file",
|
52
|
+
:short => "-r",
|
53
|
+
:large => "--read-file",
|
54
|
+
:description => "Read password from file"
|
55
|
+
}
|
56
|
+
|
57
|
+
SHA1={
|
58
|
+
:name => "sha1",
|
59
|
+
:large => "--sha1",
|
60
|
+
:description => "The password will be hashed using the sha1 algorithm"
|
61
|
+
}
|
62
|
+
|
63
|
+
SSH={
|
64
|
+
:name => "ssh",
|
65
|
+
:large => "--ssh",
|
66
|
+
:description => "SSH Auth system",
|
67
|
+
:proc => lambda { |o, options|
|
68
|
+
options[:driver] = OpenNebula::User::SSH_AUTH
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
X509={
|
73
|
+
:name => "x509",
|
74
|
+
:large => "--x509",
|
75
|
+
:description => "x509 Auth system for x509 certificates",
|
76
|
+
:proc => lambda { |o, options|
|
77
|
+
options[:driver] = OpenNebula::User::X509_AUTH
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
X509_PROXY={
|
82
|
+
:name => "x509_proxy",
|
83
|
+
:large => "--x509_proxy",
|
84
|
+
:description => "x509 Auth system based on x509 proxy certificates",
|
85
|
+
:proc => lambda { |o, options|
|
86
|
+
options[:driver] = OpenNebula::User::X509_PROXY_AUTH
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
KEY={
|
91
|
+
:name => "key",
|
92
|
+
:short => "-k path_to_private_key_pem",
|
93
|
+
:large => "--key path_to_private_key_pem",
|
94
|
+
:format => String,
|
95
|
+
:description => "Path to the Private Key of the User"
|
96
|
+
}
|
97
|
+
|
98
|
+
CERT={
|
99
|
+
:name => "cert",
|
100
|
+
:short => "-c path_to_user_cert_pem",
|
101
|
+
:large => "--cert path_to_user_cert_pem",
|
102
|
+
:format => String,
|
103
|
+
:description => "Path to the Certificate of the User"
|
104
|
+
}
|
105
|
+
|
106
|
+
PROXY={
|
107
|
+
:name => "proxy",
|
108
|
+
:large => "--proxy path_to_user_proxy_pem",
|
109
|
+
:format => String,
|
110
|
+
:description => "Path to the user proxy certificate"
|
111
|
+
}
|
112
|
+
|
113
|
+
TIME={
|
114
|
+
:name => "time",
|
115
|
+
:large => "--time x",
|
116
|
+
:format => Integer,
|
117
|
+
:description => "Token duration in seconds, defaults to 3600 (1 h)"
|
118
|
+
}
|
119
|
+
|
120
|
+
DRIVER={
|
121
|
+
:name => "driver",
|
122
|
+
:large => "--driver driver",
|
123
|
+
:format => String,
|
124
|
+
:description => "Driver to autehnticate this user"
|
125
|
+
}
|
126
|
+
|
127
|
+
create_options = [READ_FILE, SHA1, SSH, X509, KEY, CERT, DRIVER]
|
128
|
+
login_options = [SSH, X509, X509_PROXY, KEY, CERT, PROXY, TIME]
|
129
|
+
|
130
|
+
########################################################################
|
131
|
+
# Formatters for arguments
|
132
|
+
########################################################################
|
133
|
+
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
134
|
+
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
135
|
+
end
|
136
|
+
|
137
|
+
set :format, :userid, OneUserHelper.to_id_desc do |arg|
|
138
|
+
helper = OneUserHelper.new
|
139
|
+
helper.to_id(arg)
|
140
|
+
end
|
141
|
+
|
142
|
+
set :format, :userid_list, OneUserHelper.list_to_id_desc do |arg|
|
143
|
+
helper = OneUserHelper.new
|
144
|
+
helper.list_to_id(arg)
|
145
|
+
end
|
146
|
+
|
147
|
+
set :format, :password, OneUserHelper.password_to_str_desc do |arg|
|
148
|
+
OneUserHelper.password_to_str(arg, options)
|
149
|
+
end
|
150
|
+
|
151
|
+
########################################################################
|
152
|
+
# Commands
|
153
|
+
########################################################################
|
154
|
+
|
155
|
+
create_desc = <<-EOT.unindent
|
156
|
+
Creates a new User
|
157
|
+
Examples:
|
158
|
+
oneuser create my_user my_password
|
159
|
+
oneuser create my_user -r /tmp/mypass
|
160
|
+
oneuser create my_user --ssh --key /tmp/id_rsa
|
161
|
+
oneuser create my_user --ssh -r /tmp/public_key
|
162
|
+
oneuser create my_user --x509 --cert /tmp/my_cert.pem
|
163
|
+
EOT
|
164
|
+
|
165
|
+
command :create, create_desc, :username, [:password, nil],
|
166
|
+
:options=>create_options do
|
167
|
+
helper = OneUserHelper.new
|
168
|
+
|
169
|
+
if args[1]
|
170
|
+
pass = args[1]
|
171
|
+
else
|
172
|
+
rc = helper.password(options)
|
173
|
+
if rc.first == 0
|
174
|
+
pass = rc[1]
|
175
|
+
else
|
176
|
+
exit_with_code *rc
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
driver = options[:driver] || OpenNebula::User::CORE_AUTH
|
181
|
+
|
182
|
+
helper.create_resource(options) do |user|
|
183
|
+
user.allocate(args[0], pass, driver)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
update_desc = <<-EOT.unindent
|
188
|
+
Update the template contents. If a path is not provided the editor will
|
189
|
+
be launched to modify the current content.
|
190
|
+
EOT
|
191
|
+
|
192
|
+
command :update, update_desc, :userid, [:file, nil] do
|
193
|
+
helper = OneUserHelper.new
|
194
|
+
|
195
|
+
helper.perform_action(args[0],options,"modified") do |user|
|
196
|
+
str = OpenNebulaHelper.update_template(args[0], user, args[1])
|
197
|
+
user.update(str)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
quota_desc = <<-EOT.unindent
|
202
|
+
Set the quota limits for the user. If a path is not provided the editor
|
203
|
+
will be launched to modify the current quotas.
|
204
|
+
EOT
|
205
|
+
|
206
|
+
command :quota, quota_desc, :userid, [:file, nil] do
|
207
|
+
helper = OneUserHelper.new
|
208
|
+
|
209
|
+
helper.perform_action(args[0], options, "modified") do |user|
|
210
|
+
str = OneQuotaHelper.set_quota(user, args[1])
|
211
|
+
rc = user.set_quota(str)
|
212
|
+
|
213
|
+
if OpenNebula.is_error?(rc)
|
214
|
+
puts rc.message
|
215
|
+
exit -1
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
batchquota_desc = <<-EOT.unindent
|
222
|
+
Sets the quota limits in batch for various users. If a path is not
|
223
|
+
provided the editor will be launched to create new quotas.
|
224
|
+
EOT
|
225
|
+
|
226
|
+
command :batchquota, batchquota_desc, [:range, :userid_list], [:file, nil] do
|
227
|
+
helper = OneUserHelper.new
|
228
|
+
|
229
|
+
batch_str = OneQuotaHelper.get_batch_quota(args[1])
|
230
|
+
|
231
|
+
helper.perform_actions(args[0], options, "modified") do |user|
|
232
|
+
str = OneQuotaHelper.merge_quota(user, batch_str)
|
233
|
+
|
234
|
+
if OpenNebula.is_error?(str)
|
235
|
+
str
|
236
|
+
else
|
237
|
+
rc = user.set_quota(str)
|
238
|
+
rc
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
login_desc = <<-EOT.unindent
|
244
|
+
Creates the Login token for authentication
|
245
|
+
Examples:
|
246
|
+
oneuser login my_user --ssh --key /tmp/id_rsa --time 72000
|
247
|
+
oneuser login my_user --x509 --cert /tmp/my_cert.pem
|
248
|
+
--key /tmp/my_key.pk --time 72000
|
249
|
+
oneuser login my_user --x509_proxy --proxy /tmp/my_cert.pem
|
250
|
+
--time 72000
|
251
|
+
EOT
|
252
|
+
|
253
|
+
command :login, login_desc, :username, :options=>login_options do
|
254
|
+
OneUserHelper.login(args[0], options)
|
255
|
+
end
|
256
|
+
|
257
|
+
key_desc = <<-EOT.unindent
|
258
|
+
DEPRECATED, use login to generate auth files.
|
259
|
+
|
260
|
+
Shows a public key from a private SSH key. Use it as password
|
261
|
+
for the SSH authentication mechanism.
|
262
|
+
EOT
|
263
|
+
|
264
|
+
command :key, key_desc, :options=>[KEY] do
|
265
|
+
require 'ssh_auth'
|
266
|
+
|
267
|
+
options[:key] ||= ENV['HOME']+'/.ssh/id_rsa'
|
268
|
+
|
269
|
+
begin
|
270
|
+
sshauth = SshAuth.new(:private_key=>options[:key])
|
271
|
+
rescue Exception => e
|
272
|
+
exit_with_code -1, e.message
|
273
|
+
end
|
274
|
+
|
275
|
+
puts sshauth.password
|
276
|
+
exit_with_code 0
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
delete_desc = <<-EOT.unindent
|
281
|
+
Deletes the given User
|
282
|
+
EOT
|
283
|
+
|
284
|
+
command :delete, delete_desc, [:range, :userid_list] do
|
285
|
+
helper = OneUserHelper.new
|
286
|
+
helper.perform_actions(args[0], options, "deleted") do |user|
|
287
|
+
user.delete
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
passwd_desc = <<-EOT.unindent
|
292
|
+
Changes the given User's password
|
293
|
+
EOT
|
294
|
+
|
295
|
+
command :passwd, passwd_desc, :userid, [:password, nil],
|
296
|
+
:options=>create_options do
|
297
|
+
helper = OneUserHelper.new
|
298
|
+
|
299
|
+
if args[1]
|
300
|
+
pass = args[1]
|
301
|
+
else
|
302
|
+
rc = helper.password(options)
|
303
|
+
if rc.first == 0
|
304
|
+
pass = rc[1]
|
305
|
+
else
|
306
|
+
exit_with_code *rc
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
helper.perform_action(args[0],options,"Password changed") do |user|
|
311
|
+
user.passwd(pass)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
chgrp_desc = <<-EOT.unindent
|
316
|
+
Changes the User's main group
|
317
|
+
EOT
|
318
|
+
|
319
|
+
command :chgrp, chgrp_desc, [:range, :userid_list], :groupid do
|
320
|
+
helper = OneUserHelper.new
|
321
|
+
helper.perform_actions(args[0],options,"Group changed") do |user|
|
322
|
+
user.chgrp(args[1].to_i)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
chauth_desc = <<-EOT.unindent
|
327
|
+
Changes the User's auth driver and its password (optional)
|
328
|
+
Examples:
|
329
|
+
oneuser chauth my_user core
|
330
|
+
oneuser chauth my_user core new_password
|
331
|
+
oneuser chauth my_user core -r /tmp/mypass
|
332
|
+
oneuser chauth my_user --ssh --key /home/oneadmin/.ssh/id_rsa
|
333
|
+
oneuser chauth my_user --ssh -r /tmp/public_key
|
334
|
+
oneuser chauth my_user --x509 --cert /tmp/my_cert.pem
|
335
|
+
EOT
|
336
|
+
|
337
|
+
command :chauth, chauth_desc, :userid, [:auth, nil], [:password, nil],
|
338
|
+
:options=>create_options do
|
339
|
+
if options[:driver]
|
340
|
+
driver = options[:driver]
|
341
|
+
elsif args[1]
|
342
|
+
driver = args[1]
|
343
|
+
else
|
344
|
+
exit_with_code 0, "An Auth driver should be specified"
|
345
|
+
end
|
346
|
+
|
347
|
+
helper = OneUserHelper.new
|
348
|
+
|
349
|
+
if args[2]
|
350
|
+
pass = args[2]
|
351
|
+
else
|
352
|
+
rc = helper.password(options)
|
353
|
+
if rc.first == 0
|
354
|
+
pass = rc[1]
|
355
|
+
else
|
356
|
+
pass = ""
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
helper.perform_action(args[0],
|
361
|
+
options,
|
362
|
+
"Auth driver and password changed") do |user|
|
363
|
+
user.chauth(driver, pass)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
list_desc = <<-EOT.unindent
|
368
|
+
Lists Users in the pool
|
369
|
+
EOT
|
370
|
+
|
371
|
+
command :list, list_desc, :options=>list_options do
|
372
|
+
helper = OneUserHelper.new
|
373
|
+
helper.list_pool(options)
|
374
|
+
end
|
375
|
+
|
376
|
+
show_desc = <<-EOT.unindent
|
377
|
+
Shows information for the given User
|
378
|
+
EOT
|
379
|
+
|
380
|
+
command :show, show_desc, [:userid, nil],
|
381
|
+
:options=>OpenNebulaHelper::XML do
|
382
|
+
user=args[0] || OpenNebula::User::SELF
|
383
|
+
helper = OneUserHelper.new
|
384
|
+
helper.show_resource(user,options)
|
385
|
+
end
|
386
|
+
|
387
|
+
show_desc = <<-EOT.unindent
|
388
|
+
Encodes user and password to use it with ldap
|
389
|
+
EOT
|
390
|
+
|
391
|
+
command :encode, show_desc, :username, [:password, nil] do
|
392
|
+
ar=args.compact
|
393
|
+
|
394
|
+
if defined?(URI::Parser)
|
395
|
+
parser=URI::Parser.new
|
396
|
+
else
|
397
|
+
parser=URI
|
398
|
+
end
|
399
|
+
|
400
|
+
puts ar.map{|a| parser.escape(a) }.join(':')
|
401
|
+
|
402
|
+
0
|
403
|
+
end
|
404
|
+
end
|