opennebula-cli 4.14.2 → 4.90.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/NOTICE +1 -1
  3. data/bin/oneacct +1 -1
  4. data/bin/oneacl +1 -1
  5. data/bin/onecluster +4 -1
  6. data/bin/onedatastore +4 -1
  7. data/bin/oneflow +26 -1
  8. data/bin/oneflow-template +57 -1
  9. data/bin/onegroup +4 -1
  10. data/bin/onehost +24 -15
  11. data/bin/oneimage +5 -3
  12. data/bin/onemarket +178 -0
  13. data/bin/onemarketapp +282 -0
  14. data/bin/onesecgroup +18 -1
  15. data/bin/oneshowback +1 -1
  16. data/bin/onetemplate +30 -21
  17. data/bin/oneuser +12 -6
  18. data/bin/oneuser.backup +522 -0
  19. data/bin/onevcenter +287 -1
  20. data/bin/onevdc +4 -1
  21. data/bin/onevm +78 -56
  22. data/bin/onevnet +10 -4
  23. data/bin/onevrouter +305 -0
  24. data/bin/onezone +4 -1
  25. data/lib/cli_helper.rb +1 -1
  26. data/lib/command_parser.rb +1 -1
  27. data/lib/one_helper/oneacct_helper.rb +1 -1
  28. data/lib/one_helper/oneacl_helper.rb +11 -5
  29. data/lib/one_helper/onecluster_helper.rb +1 -1
  30. data/lib/one_helper/onedatastore_helper.rb +17 -7
  31. data/lib/one_helper/onegroup_helper.rb +1 -1
  32. data/lib/one_helper/onehost_helper.rb +2 -5
  33. data/lib/one_helper/oneimage_helper.rb +1 -15
  34. data/lib/one_helper/onemarket_helper.rb +152 -0
  35. data/lib/one_helper/onemarketapp_helper.rb +223 -0
  36. data/lib/one_helper/onequota_helper.rb +1 -1
  37. data/lib/one_helper/onesecgroup_helper.rb +46 -3
  38. data/lib/one_helper/onetemplate_helper.rb +146 -11
  39. data/lib/one_helper/oneuser_helper.rb +1 -1
  40. data/lib/one_helper/onevdc_helper.rb +1 -1
  41. data/lib/one_helper/onevm_helper.rb +37 -53
  42. data/lib/one_helper/onevnet_helper.rb +23 -11
  43. data/lib/one_helper/onevrouter_helper.rb +221 -0
  44. data/lib/one_helper/onezone_helper.rb +1 -1
  45. data/lib/one_helper.rb +193 -25
  46. metadata +21 -10
@@ -0,0 +1,522 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
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
+ helper = OneUserHelper.new
41
+
42
+ before_proc do
43
+ helper.set_client(options) if ![:login, :key].include?(@comm_name)
44
+ end
45
+
46
+ ########################################################################
47
+ # Global Options
48
+ ########################################################################
49
+ set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
50
+
51
+ list_options = CLIHelper::OPTIONS
52
+ list_options << OpenNebulaHelper::XML
53
+ list_options << OpenNebulaHelper::NUMERIC
54
+ list_options << OpenNebulaHelper::DESCRIBE
55
+
56
+ READ_FILE={
57
+ :name => "read_file",
58
+ :short => "-r",
59
+ :large => "--read-file",
60
+ :description => "Read password from file"
61
+ }
62
+
63
+ SHA1={
64
+ :name => "sha1",
65
+ :large => "--sha1",
66
+ :description => "The password will be hashed using the sha1\n"<<
67
+ " "*31<<"algorithm"
68
+ }
69
+
70
+ SSH={
71
+ :name => "ssh",
72
+ :large => "--ssh",
73
+ :description => "SSH Auth system",
74
+ :proc => lambda { |o, options|
75
+ options[:driver] = OpenNebula::User::SSH_AUTH
76
+ }
77
+ }
78
+
79
+ X509={
80
+ :name => "x509",
81
+ :large => "--x509",
82
+ :description => "x509 Auth system for x509 certificates",
83
+ :proc => lambda { |o, options|
84
+ options[:driver] = OpenNebula::User::X509_AUTH
85
+ }
86
+ }
87
+
88
+ X509_PROXY={
89
+ :name => "x509_proxy",
90
+ :large => "--x509_proxy",
91
+ :description => "x509 Auth system based on x509 proxy certificates",
92
+ :proc => lambda { |o, options|
93
+ options[:driver] = OpenNebula::User::X509_PROXY_AUTH
94
+ }
95
+ }
96
+
97
+ KEY={
98
+ :name => "key",
99
+ :short => "-k path_to_private_key_pem",
100
+ :large => "--key path_to_private_key_pem",
101
+ :format => String,
102
+ :description => "Path to the Private Key of the User"
103
+ }
104
+
105
+ CERT={
106
+ :name => "cert",
107
+ :short => "-c path_to_user_cert_pem",
108
+ :large => "--cert path_to_user_cert_pem",
109
+ :format => String,
110
+ :description => "Path to the Certificate of the User"
111
+ }
112
+
113
+ PROXY={
114
+ :name => "proxy",
115
+ :large => "--proxy path_to_user_proxy_pem",
116
+ :format => String,
117
+ :description => "Path to the user proxy certificate"
118
+ }
119
+
120
+ TIME={
121
+ :name => "time",
122
+ :large => "--time x",
123
+ :format => Integer,
124
+ :description => "Token duration in seconds, defaults to 36000 (10 h). "\
125
+ "To reset the token set time to 0." \
126
+ "To generate a non-expiring token use -1"\
127
+ " (not valid for ssh and x509 tokens). "\
128
+ }
129
+
130
+ DRIVER={
131
+ :name => "driver",
132
+ :large => "--driver driver",
133
+ :format => String,
134
+ :description => "Driver to autehnticate this user"
135
+ }
136
+
137
+ FORCE = {
138
+ :name => "force",
139
+ :large => "--force" ,
140
+ :description => "Force one_auth file rewrite"
141
+ }
142
+
143
+ create_options = [READ_FILE, SHA1, SSH, X509, KEY, CERT, DRIVER]
144
+ login_options = [SSH, X509, X509_PROXY, KEY, CERT, PROXY, TIME, FORCE]
145
+
146
+ ########################################################################
147
+ # Formatters for arguments
148
+ ########################################################################
149
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
150
+ OpenNebulaHelper.rname_to_id(arg, "GROUP")
151
+ end
152
+
153
+ set :format, :userid, OneUserHelper.to_id_desc do |arg|
154
+ helper.to_id(arg)
155
+ end
156
+
157
+ set :format, :userid_list, OneUserHelper.list_to_id_desc do |arg|
158
+ helper.list_to_id(arg)
159
+ end
160
+
161
+ set :format, :password, OneUserHelper.password_to_str_desc do |arg|
162
+ OneUserHelper.password_to_str(arg, options)
163
+ end
164
+
165
+ ########################################################################
166
+ # Commands
167
+ ########################################################################
168
+
169
+ create_desc = <<-EOT.unindent
170
+ Creates a new User
171
+ Examples:
172
+ oneuser create my_user my_password
173
+ oneuser create my_user -r /tmp/mypass
174
+ oneuser create my_user --ssh --key /tmp/id_rsa
175
+ oneuser create my_user --ssh -r /tmp/public_key
176
+ oneuser create my_user --x509 --cert /tmp/my_cert.pem
177
+ EOT
178
+
179
+ command :create, create_desc, :username, [:password, nil],
180
+ :options=>create_options do
181
+ if args[1]
182
+ pass = args[1]
183
+ else
184
+ rc = helper.password(options)
185
+ if rc.first == 0
186
+ pass = rc[1]
187
+ else
188
+ exit_with_code *rc
189
+ end
190
+ end
191
+
192
+ driver = options[:driver] || OpenNebula::User::CORE_AUTH
193
+
194
+ helper.create_resource(options) do |user|
195
+ user.allocate(args[0], pass, driver)
196
+ end
197
+ end
198
+
199
+ update_desc = <<-EOT.unindent
200
+ Update the template contents. If a path is not provided the editor will
201
+ be launched to modify the current content.
202
+ EOT
203
+
204
+ command :update, update_desc, :userid, [:file, nil],
205
+ :options=>OpenNebulaHelper::APPEND do
206
+ helper.perform_action(args[0],options,"modified") do |obj|
207
+ if options[:append]
208
+ str = OpenNebulaHelper.append_template(args[0], obj, args[1])
209
+ else
210
+ str = OpenNebulaHelper.update_template(args[0], obj, args[1])
211
+ end
212
+
213
+ helper.set_client(options)
214
+ obj = helper.retrieve_resource(obj.id)
215
+
216
+ obj.update(str, options[:append])
217
+ end
218
+ end
219
+
220
+ quota_desc = <<-EOT.unindent
221
+ Set the quota limits for the user. If a path is not provided the editor
222
+ will be launched to modify the current quotas.
223
+ EOT
224
+
225
+ command :quota, quota_desc, :userid, [:file, nil] do
226
+ helper.perform_action(args[0], options, "modified") do |user|
227
+ rc = user.info
228
+
229
+ if OpenNebula.is_error?(rc)
230
+ puts rc.message
231
+ exit -1
232
+ end
233
+
234
+ str = OneQuotaHelper.set_quota(user, args[1])
235
+
236
+ helper.set_client(options)
237
+ user = helper.retrieve_resource(user.id)
238
+
239
+ rc = user.set_quota(str)
240
+
241
+ if OpenNebula.is_error?(rc)
242
+ puts rc.message
243
+ exit -1
244
+ end
245
+ end
246
+ end
247
+
248
+ batchquota_desc = <<-EOT.unindent
249
+ Sets the quota limits in batch for various users. If a path is not
250
+ provided the editor will be launched to create new quotas.
251
+ EOT
252
+
253
+ command :batchquota, batchquota_desc, [:range, :userid_list],
254
+ [:file, nil] do
255
+ batch_str = OneQuotaHelper.get_batch_quota(args[1])
256
+
257
+ helper.perform_actions(args[0], options, "modified") do |user|
258
+ str = OneQuotaHelper.merge_quota(user, batch_str)
259
+
260
+ if OpenNebula.is_error?(str)
261
+ str
262
+ else
263
+ helper.set_client(options)
264
+ user = helper.retrieve_resource(user.id)
265
+
266
+ rc = user.set_quota(str)
267
+ rc
268
+ end
269
+ end
270
+ end
271
+
272
+ defaultquota_desc = <<-EOT.unindent
273
+ Sets the default quota limits for the users. If a path is not provided
274
+ the editor will be launched to modify the current default quotas.
275
+ EOT
276
+
277
+ command :defaultquota, defaultquota_desc, [:file, nil] do
278
+ system = System.new(OneUserHelper.get_client(options))
279
+
280
+ default_quotas = system.get_user_quotas()
281
+
282
+ if OpenNebula.is_error?(default_quotas)
283
+ puts default_quotas.message
284
+ exit(-1)
285
+ end
286
+
287
+ str = OneQuotaHelper.set_quota(default_quotas, args[0], true)
288
+
289
+ system = System.new(OneUserHelper.get_client(options))
290
+ rc = system.set_user_quotas(str)
291
+
292
+ if OpenNebula.is_error?(rc)
293
+ puts rc.message
294
+ exit(-1)
295
+ end
296
+
297
+ exit 0
298
+ end
299
+
300
+ umask_desc = <<-EOT.unindent
301
+ Changes the umask used to create the default permissions. In a similar
302
+ way to the Unix umask command, the expected value is a three-digit
303
+ base-8 number. Each digit is a mask that disables permissions for the
304
+ owner, group and other, respectively.
305
+
306
+ If mask is not given, or if it is an empty string, the umask will
307
+ be unset
308
+ EOT
309
+
310
+ command :umask, umask_desc, [:range, :userid_list], [:mask, nil] do
311
+ helper.perform_actions(args[0],options,
312
+ "umask changed") do |user|
313
+
314
+ rc = user.info
315
+
316
+ if OpenNebula.is_error?(rc)
317
+ puts rc.message
318
+ exit -1
319
+ end
320
+
321
+ user.delete_element('/USER/TEMPLATE/UMASK')
322
+
323
+ tmp_str = user.template_str
324
+
325
+ if !args[1].nil? && args[1] != ""
326
+ tmp_str << "\nUMASK = #{args[1]}"
327
+ end
328
+
329
+ user.update(tmp_str)
330
+ end
331
+ end
332
+
333
+ login_desc = <<-EOT.unindent
334
+ Creates the login token for authentication. The token can be used
335
+ together with any authentication driver. The token will be stored in
336
+ $HOME/.one/one_auth, and can be used subsequently to authenticate with
337
+ oned through API, CLI or Sunstone.
338
+
339
+ Example, request a valid token for a generic driver (e.g. core auth, LDAP...):
340
+ oneuser login my_user --time 3600
341
+
342
+ Example, generate and set a token for SSH based authentication:
343
+ oneuser login my_user --ssh --key /tmp/id_rsa --time 72000
344
+
345
+ Example, same using X509 certificates:
346
+ oneuser login my_user --x509 --cert /tmp/my_cert.pem
347
+ --key /tmp/my_key.pk --time 72000
348
+
349
+ Example, now with a X509 proxy certificate
350
+ oneuser login my_user --x509_proxy --proxy /tmp/my_cert.pem
351
+ --time 72000
352
+ EOT
353
+
354
+ command :login, login_desc, :username, :options=>login_options do
355
+
356
+ options[:time] ||= 36000
357
+
358
+ helper.login(args[0], options)
359
+ end
360
+
361
+ key_desc = <<-EOT.unindent
362
+ Shows a public key from a private SSH key. Use it as password
363
+ for the SSH authentication mechanism.
364
+ EOT
365
+
366
+ command :key, key_desc, :options=>[KEY] do
367
+ require 'opennebula/ssh_auth'
368
+
369
+ options[:key] ||= ENV['HOME']+'/.ssh/id_rsa'
370
+
371
+ begin
372
+ sshauth = SshAuth.new(:private_key=>options[:key])
373
+ rescue Exception => e
374
+ exit_with_code -1, e.message
375
+ end
376
+
377
+ puts sshauth.password
378
+ exit_with_code 0
379
+ end
380
+
381
+
382
+ delete_desc = <<-EOT.unindent
383
+ Deletes the given User
384
+ EOT
385
+
386
+ command :delete, delete_desc, [:range, :userid_list] do
387
+ helper.perform_actions(args[0], options, "deleted") do |user|
388
+ user.delete
389
+ end
390
+ end
391
+
392
+ passwd_desc = <<-EOT.unindent
393
+ Changes the given User's password
394
+ EOT
395
+
396
+ command :passwd, passwd_desc, :userid, [:password, nil],
397
+ :options=>create_options do
398
+ if args[1]
399
+ pass = args[1]
400
+ else
401
+ rc = helper.password(options)
402
+ if rc.first == 0
403
+ pass = rc[1]
404
+ else
405
+ exit_with_code *rc
406
+ end
407
+ end
408
+
409
+ helper.perform_action(args[0],options,"Password changed") do |user|
410
+ user.passwd(pass)
411
+ end
412
+ end
413
+
414
+ chgrp_desc = <<-EOT.unindent
415
+ Changes the User's primary group
416
+ EOT
417
+
418
+ command :chgrp, chgrp_desc, [:range, :userid_list], :groupid do
419
+ helper.perform_actions(args[0],options,"Group changed") do |user|
420
+ user.chgrp(args[1].to_i)
421
+ end
422
+ end
423
+
424
+ addgroup_desc = <<-EOT.unindent
425
+ Adds the User to a secondary group
426
+ EOT
427
+
428
+ command :addgroup, addgroup_desc, [:range, :userid_list], :groupid do
429
+ gid = args[1]
430
+
431
+ helper.perform_actions(args[0],options,"group added") do |user|
432
+ user.addgroup( gid )
433
+ end
434
+ end
435
+
436
+ delgroup_desc = <<-EOT.unindent
437
+ Removes the User from a secondary group
438
+ EOT
439
+
440
+ command :delgroup, delgroup_desc, [:range, :userid_list], :groupid do
441
+ gid = args[1]
442
+
443
+ helper.perform_actions(args[0],options,"group deleted") do |user|
444
+ user.delgroup( gid )
445
+ end
446
+ end
447
+
448
+ chauth_desc = <<-EOT.unindent
449
+ Changes the User's auth driver and its password (optional)
450
+ Examples:
451
+ oneuser chauth my_user core
452
+ oneuser chauth my_user core new_password
453
+ oneuser chauth my_user core -r /tmp/mypass
454
+ oneuser chauth my_user --ssh --key /home/oneadmin/.ssh/id_rsa
455
+ oneuser chauth my_user --ssh -r /tmp/public_key
456
+ oneuser chauth my_user --x509 --cert /tmp/my_cert.pem
457
+ EOT
458
+
459
+ command :chauth, chauth_desc, :userid, [:auth, nil], [:password, nil],
460
+ :options=>create_options do
461
+ if options[:driver]
462
+ driver = options[:driver]
463
+ elsif args[1]
464
+ driver = args[1]
465
+ else
466
+ exit_with_code 0, "An Auth driver should be specified"
467
+ end
468
+
469
+ if args[2]
470
+ pass = args[2]
471
+ else
472
+ rc = helper.password(options)
473
+ if rc.first == 0
474
+ pass = rc[1]
475
+ else
476
+ pass = ""
477
+ end
478
+ end
479
+
480
+ helper.perform_action(args[0],
481
+ options,
482
+ "Auth driver and password changed") do |user|
483
+ user.chauth(driver, pass)
484
+ end
485
+ end
486
+
487
+ list_desc = <<-EOT.unindent
488
+ Lists Users in the pool
489
+ EOT
490
+
491
+ command :list, list_desc, :options=>list_options do
492
+ helper.list_pool(options)
493
+ end
494
+
495
+ show_desc = <<-EOT.unindent
496
+ Shows information for the given User
497
+ EOT
498
+
499
+ command :show, show_desc, [:userid, nil],
500
+ :options=>OpenNebulaHelper::XML do
501
+ user=args[0] || OpenNebula::User::SELF
502
+ helper.show_resource(user,options)
503
+ end
504
+
505
+ show_desc = <<-EOT.unindent
506
+ Encodes user and password to use it with ldap
507
+ EOT
508
+
509
+ command :encode, show_desc, :username, [:password, nil] do
510
+ ar=args.compact
511
+
512
+ if defined?(URI::Parser)
513
+ parser=URI::Parser.new
514
+ else
515
+ parser=URI
516
+ end
517
+
518
+ puts ar.map{|a| parser.escape(a) }.join(':')
519
+
520
+ 0
521
+ end
522
+ end