opennebula-cli 5.6.2 → 5.7.80.pre

Sign up to get free protection for your applications and to get access to all the features.
data/bin/onegroup CHANGED
@@ -16,22 +16,22 @@
16
16
  # limitations under the License. #
17
17
  #--------------------------------------------------------------------------- #
18
18
 
19
- ONE_LOCATION=ENV["ONE_LOCATION"]
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
20
 
21
21
  if !ONE_LOCATION
22
- RUBY_LIB_LOCATION="/usr/lib/one/ruby"
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
23
  else
24
- RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
24
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
25
25
  end
26
26
 
27
- $: << RUBY_LIB_LOCATION
28
- $: << RUBY_LIB_LOCATION+"/cli"
27
+ $LOAD_PATH << RUBY_LIB_LOCATION
28
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
29
29
 
30
30
  require 'command_parser'
31
31
  require 'one_helper/onegroup_helper'
32
32
 
33
- cmd=CommandParser::CmdParser.new(ARGV) do
34
- usage "`onegroup` <command> [<args>] [<options>]"
33
+ CommandParser::CmdParser.new(ARGV) do
34
+ usage '`onegroup` <command> [<args>] [<options>]'
35
35
  version OpenNebulaHelper::ONE_VERSION
36
36
 
37
37
  helper = OneGroupHelper.new
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
43
43
  ########################################################################
44
44
  # Global Options
45
45
  ########################################################################
46
- set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
46
+ set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
47
47
 
48
48
  list_options = CLIHelper::OPTIONS
49
49
  list_options << OpenNebulaHelper::XML
@@ -61,8 +61,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
61
61
  helper.list_to_id(arg)
62
62
  end
63
63
 
64
- set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
65
- OpenNebulaHelper.rname_to_id(arg, "USER")
64
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc('USER') do |arg|
65
+ OpenNebulaHelper.rname_to_id(arg, 'USER')
66
66
  end
67
67
 
68
68
  ########################################################################
@@ -89,14 +89,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
89
89
 
90
90
  if options && options[:admin_user]
91
91
  if !options[:admin_password]
92
- STDERR.puts "Admin user needs password"
92
+ STDERR.puts 'Admin user needs password'
93
93
  next -1
94
94
  end
95
95
 
96
- admin_user=Hash.new
96
+ admin_user = {}
97
97
  admin_user[:name] = options[:admin_user]
98
98
  admin_user[:password] = options[:admin_password]
99
- admin_user[:auth_driver]= options[:admin_driver] if options[:admin_driver]
99
+ if options[:admin_driver]
100
+ admin_user[:auth_driver] = options[:admin_driver]
101
+ end
100
102
 
101
103
  options[:group_admin] = admin_user
102
104
  end
@@ -107,8 +109,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
107
109
  elsif options[:name]
108
110
  helper.create_complete_resource(options)
109
111
  else
110
- STDERR.puts "Please use either a group name or command arguments."<<
111
- " Run onegroup create -h for more information"
112
+ STDERR.puts 'Please use either a group name or command arguments.'\
113
+ ' Run onegroup create -h for more information'
112
114
  next -1
113
115
  end
114
116
  end
@@ -119,8 +121,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
119
121
  EOT
120
122
 
121
123
  command :update, update_desc, :groupid, [:file, nil],
122
- :options=>OpenNebulaHelper::APPEND do
123
- helper.perform_action(args[0],options,"modified") do |obj|
124
+ :options => OpenNebulaHelper::APPEND do
125
+ helper.perform_action(args[0], options, 'modified') do |obj|
124
126
  if options[:append]
125
127
  str = OpenNebulaHelper.append_template(args[0], obj, args[1])
126
128
  else
@@ -139,7 +141,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
139
141
  EOT
140
142
 
141
143
  command :delete, delete_desc, [:range, :groupid_list] do
142
- helper.perform_actions(args[0],options,"deleted") do |obj|
144
+ helper.perform_actions(args[0], options, 'deleted') do |obj|
143
145
  obj.delete
144
146
  end
145
147
  end
@@ -148,7 +150,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
148
150
  Lists Groups in the pool
149
151
  EOT
150
152
 
151
- command :list, list_desc, :options=>list_options do
153
+ command :list, list_desc, :options => list_options do
152
154
  helper.list_pool(options)
153
155
  end
154
156
 
@@ -156,9 +158,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
156
158
  Shows information for the given Group
157
159
  EOT
158
160
 
159
- command :show, show_desc,[:groupid, nil], :options=>OpenNebulaHelper::XML do
161
+ command :show, show_desc, [:groupid, nil],
162
+ :options => OpenNebulaHelper::XML do
160
163
  group = args[0] || OpenNebula::Group::SELF
161
- helper.show_resource(group,options)
164
+ helper.show_resource(group, options)
162
165
  end
163
166
 
164
167
  add_admin_desc = <<-EOT.unindent
@@ -166,7 +169,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
166
169
  EOT
167
170
 
168
171
  command :addadmin, add_admin_desc, [:range, :groupid_list], :userid do
169
- helper.perform_actions(args[0],options,"admin added") do |obj|
172
+ helper.perform_actions(args[0], options, 'admin added') do |obj|
170
173
  obj.add_admin(args[1].to_i)
171
174
  end
172
175
  end
@@ -176,7 +179,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
176
179
  EOT
177
180
 
178
181
  command :deladmin, del_admin_desc, [:range, :groupid_list], :userid do
179
- helper.perform_actions(args[0],options,"admin deleted") do |obj|
182
+ helper.perform_actions(args[0], options, 'admin deleted') do |obj|
180
183
  obj.del_admin(args[1].to_i)
181
184
  end
182
185
  end
@@ -187,12 +190,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
187
190
  EOT
188
191
 
189
192
  command :quota, quota_desc, :groupid, [:file, nil] do
190
- helper.perform_action(args[0], options, "modified") do |group|
193
+ helper.perform_action(args[0], options, 'modified') do |group|
191
194
  rc = group.info
192
195
 
193
196
  if OpenNebula.is_error?(rc)
194
197
  puts rc.message
195
- exit -1
198
+ exit(-1)
196
199
  end
197
200
 
198
201
  str = OneQuotaHelper.set_quota(group, args[1])
@@ -200,7 +203,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
200
203
 
201
204
  if OpenNebula.is_error?(rc)
202
205
  puts rc.message
203
- exit -1
206
+ exit(-1)
204
207
  end
205
208
  end
206
209
  end
@@ -214,19 +217,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
214
217
  [:file, nil] do
215
218
  batch_str = OneQuotaHelper.get_batch_quota(args[1])
216
219
 
217
- helper.perform_actions(args[0], options, "modified") do |group|
220
+ helper.perform_actions(args[0], options, 'modified') do |group|
218
221
  str = OneQuotaHelper.merge_quota(group, batch_str)
219
222
 
220
223
  if OpenNebula.is_error?(str)
221
224
  str
222
225
  else
223
- rc = group.set_quota(str)
226
+ rc = group.set_quota(str)
224
227
  rc
225
228
  end
226
229
  end
227
230
  end
228
231
 
229
-
230
232
  defaultquota_desc = <<-EOT.unindent
231
233
  Sets the default quota limits for the groups. If a path is not provided
232
234
  the editor will be launched to modify the current default quotas.
@@ -235,7 +237,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
235
237
  command :defaultquota, defaultquota_desc, [:file, nil] do
236
238
  system = System.new(OneGroupHelper.get_client(options))
237
239
 
238
- default_quotas = system.get_group_quotas()
240
+ default_quotas = system.get_group_quotas
239
241
 
240
242
  if OpenNebula.is_error?(default_quotas)
241
243
  puts default_quotas.message
data/bin/onehost CHANGED
@@ -16,25 +16,25 @@
16
16
  # limitations under the License. #
17
17
  #--------------------------------------------------------------------------- #
18
18
 
19
- ONE_LOCATION=ENV["ONE_LOCATION"]
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
20
 
21
21
  if !ONE_LOCATION
22
- RUBY_LIB_LOCATION="/usr/lib/one/ruby"
23
- REMOTES_LOCATION="/var/lib/one/remotes/"
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
+ REMOTES_LOCATION = '/var/lib/one/remotes/'
24
24
  else
25
- RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
26
- REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/"
25
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
26
+ REMOTES_LOCATION = ONE_LOCATION + '/var/remotes/'
27
27
  end
28
28
 
29
- $: << RUBY_LIB_LOCATION
30
- $: << RUBY_LIB_LOCATION+"/cli"
29
+ $LOAD_PATH << RUBY_LIB_LOCATION
30
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
31
31
 
32
32
  require 'command_parser'
33
33
  require 'one_helper/onehost_helper'
34
34
  require 'one_helper/onecluster_helper'
35
35
 
36
- cmd=CommandParser::CmdParser.new(ARGV) do
37
- usage "`onehost` <command> [<args>] [<options>]"
36
+ CommandParser::CmdParser.new(ARGV) do
37
+ usage '`onehost` <command> [<args>] [<options>]'
38
38
  version OpenNebulaHelper::ONE_VERSION
39
39
 
40
40
  helper = OneHostHelper.new
@@ -46,49 +46,50 @@ cmd=CommandParser::CmdParser.new(ARGV) do
46
46
  ########################################################################
47
47
  # Global Options
48
48
  ########################################################################
49
- cmd_options=CommandParser::OPTIONS-[CommandParser::VERBOSE]
50
- set :option, cmd_options+OpenNebulaHelper::CLIENT_OPTIONS
49
+ cmd_options = CommandParser::OPTIONS - [CommandParser::VERBOSE]
50
+ set :option, cmd_options + OpenNebulaHelper::CLIENT_OPTIONS
51
51
 
52
52
  IM = {
53
- :name => "im",
54
- :short => "-i im_mad",
55
- :large => "--im im_mad" ,
56
- :description => "Set the information driver for the host",
57
- :format => String
53
+ :name => 'im',
54
+ :short => '-i im_mad',
55
+ :large => '--im im_mad',
56
+ :description => 'Set the information driver for the host',
57
+ :format => String
58
58
  }
59
59
 
60
60
  VMM = {
61
- :name => "vm",
62
- :short => "-v vmm_mad",
63
- :large => "--vm vmm_mad" ,
64
- :description => "Set the virtualization driver for the host",
65
- :format => String
61
+ :name => 'vm',
62
+ :short => '-v vmm_mad',
63
+ :large => '--vm vmm_mad',
64
+ :description => 'Set the virtualization driver for the host',
65
+ :format => String
66
66
  }
67
67
 
68
68
  FORCE = {
69
- :name => "force",
70
- :large => "--force" ,
71
- :description => "Force probe upgrade in onehost sync"
69
+ :name => 'force',
70
+ :large => '--force',
71
+ :description => 'Force probe upgrade in onehost sync'
72
72
  }
73
73
 
74
74
  RSYNC = {
75
- :name => "rsync",
76
- :large => "--rsync" ,
77
- :description => "Use rsync to synchronize remotes. In case some " <<
78
- "probes are no longer in the fronted are deleted in the hosts." <<
79
- " rsync command must be installed in the frontend and nodes."
75
+ :name => 'rsync',
76
+ :large => '--rsync',
77
+ :description => 'Use rsync to synchronize remotes. In case some '\
78
+ 'probes are no longer in the fronted ithey will be '\
79
+ 'deleted in the hosts. rsync command must be '\
80
+ 'installed in the frontend and nodes.'
80
81
  }
81
82
 
82
83
  TYPE = {
83
- :name => "type",
84
- :short => "-t remote_provider",
85
- :large => "--type remote_provider",
86
- :description => "Use type to create a host using Cloud Bursting ",
84
+ :name => 'type',
85
+ :short => '-t remote_provider',
86
+ :large => '--type remote_provider',
87
+ :description => 'Use type to create a host using Cloud Bursting',
87
88
  :format => String
88
89
  }
89
90
 
90
- CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, TYPE ]
91
- SYNC_OPTIONS = [ OneClusterHelper::CLUSTER, FORCE, RSYNC ]
91
+ CREAT_OPTIONS = [IM, VMM, OneClusterHelper::CLUSTER, TYPE]
92
+ SYNC_OPTIONS = [OneClusterHelper::CLUSTER, FORCE, RSYNC]
92
93
 
93
94
  ########################################################################
94
95
  # Formatters for arguments
@@ -110,12 +111,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
110
111
  Creates a new Host
111
112
  EOT
112
113
 
113
- command :create, create_desc, :hostname, [:file, nil], :options=>CREAT_OPTIONS do
114
+ command :create, create_desc, :hostname,
115
+ [:file, nil], :options => CREAT_OPTIONS do
114
116
  if options[:im].nil? || options[:vm].nil?
115
- STDERR.puts "Drivers are mandatory to create a host:"
116
- STDERR.puts "\t -i information driver"
117
- STDERR.puts "\t -v hypervisor driver"
118
- exit -1
117
+ STDERR.puts 'Drivers are mandatory to create a host:'
118
+ STDERR.puts '\t -i information driver'
119
+ STDERR.puts '\t -v hypervisor driver'
120
+ exit(-1)
119
121
  end
120
122
 
121
123
  cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
@@ -124,7 +126,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
124
126
  str = helper.set_hybrid(options[:type], args[1])
125
127
  end
126
128
  rc = host.allocate(args[0], options[:im], options[:vm], cid)
127
- host.update(str, true) if !OpenNebula.is_error?(rc) && !options[:type].nil?
129
+ if !OpenNebula.is_error?(rc) && !options[:type].nil?
130
+ host.update(str, true)
131
+ end
128
132
 
129
133
  rc
130
134
  end
@@ -135,7 +139,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
135
139
  EOT
136
140
 
137
141
  command :delete, delete_desc, [:range, :hostid_list] do
138
- helper.perform_actions(args[0],options,"deleted") do |host|
142
+ helper.perform_actions(args[0], options, 'deleted') do |host|
139
143
  host.delete
140
144
  end
141
145
  end
@@ -144,8 +148,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
144
148
  Enables the given host, fully operational
145
149
  EOT
146
150
 
147
- command :enable, enable_desc, [:range,:hostid_list] do
148
- helper.perform_actions(args[0],options,"enabled") do |host|
151
+ command :enable, enable_desc, [:range, :hostid_list] do
152
+ helper.perform_actions(args[0], options, 'enabled') do |host|
149
153
  host.enable
150
154
  end
151
155
  end
@@ -157,8 +161,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
157
161
  - manual deployment: enabled
158
162
  EOT
159
163
 
160
- command :disable, disable_desc, [:range,:hostid_list] do
161
- helper.perform_actions(args[0],options,"disabled") do |host|
164
+ command :disable, disable_desc, [:range, :hostid_list] do
165
+ helper.perform_actions(args[0], options, 'disabled') do |host|
162
166
  host.disable
163
167
  end
164
168
  end
@@ -170,8 +174,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
170
174
  - manual deployment: disabled
171
175
  EOT
172
176
 
173
- command :offline, offline_desc, [:range,:hostid_list] do
174
- helper.perform_actions(args[0],options,"offline") do |host|
177
+ command :offline, offline_desc, [:range, :hostid_list] do
178
+ helper.perform_actions(args[0], options, 'offline') do |host|
175
179
  host.offline
176
180
  end
177
181
  end
@@ -182,8 +186,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
182
186
  EOT
183
187
 
184
188
  command :update, update_desc, :hostid, [:file, nil],
185
- :options=>OpenNebulaHelper::APPEND do
186
- helper.perform_action(args[0],options,"updated") do |obj|
189
+ :options => OpenNebulaHelper::APPEND do
190
+ helper.perform_action(args[0], options, 'updated') do |obj|
187
191
  if options[:append]
188
192
  str = OpenNebulaHelper.append_template(args[0], obj, args[1])
189
193
  else
@@ -207,7 +211,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
207
211
  EOT
208
212
 
209
213
  command :sync, sync_desc, [:range, :hostid_list, nil],
210
- :options=>SYNC_OPTIONS do
214
+ :options => SYNC_OPTIONS do
211
215
  helper.sync(args[0], options)
212
216
  end
213
217
 
@@ -216,8 +220,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
216
220
  EOT
217
221
 
218
222
  command :list, list_desc,
219
- :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+
220
- [OpenNebulaHelper::DESCRIBE] do
223
+ :options => CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS +
224
+ [OpenNebulaHelper::DESCRIBE] do
221
225
  helper.list_pool(options)
222
226
  end
223
227
 
@@ -226,8 +230,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
226
230
  EOT
227
231
 
228
232
  command :show, show_desc, :hostid,
229
- :options=>OpenNebulaHelper::XML do
230
- helper.show_resource(args[0],options)
233
+ :options => OpenNebulaHelper::XML do
234
+ helper.show_resource(args[0], options)
231
235
  end
232
236
 
233
237
  top_desc = <<-EOT.unindent
@@ -235,7 +239,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
235
239
  EOT
236
240
 
237
241
  command :top, top_desc,
238
- :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
242
+ :options => CLIHelper::OPTIONS + OpenNebulaHelper::OPTIONS do
239
243
  helper.list_pool(options, true)
240
244
  end
241
245
 
@@ -243,17 +247,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
243
247
  Disables the host and reschedules all the running VMs in it.
244
248
  EOT
245
249
 
246
- command :flush, flush_desc, [:range,:hostid_list] do
250
+ command :flush, flush_desc, [:range, :hostid_list] do
247
251
  begin
248
252
  if !ONE_LOCATION
249
- action = YAML.load_file("/etc/one/cli/onehost.yaml")[:default_actions][0][:flush]
253
+ action = YAML.load_file('/etc/one/cli/onehost.yaml')
250
254
  else
251
- action = YAML.load_file("#{ONE_LOCATION}/etc/cli/onehost.yaml")[:default_actions][0][:flush]
255
+ action = YAML.load_file("#{ONE_LOCATION}/etc/cli/onehost.yaml")
252
256
  end
253
- rescue Exception => e
257
+ action = action[:default_actions][0][:flush]
258
+ rescue StandardError => e
254
259
  STDERR.puts e
255
260
  end
256
- helper.perform_actions(args[0],options,"flush") do |host|
261
+ helper.perform_actions(args[0], options, 'flush') do |host|
257
262
  host.flush action
258
263
  end
259
264
  end
@@ -263,7 +268,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
263
268
  EOT
264
269
 
265
270
  command :rename, rename_desc, :hostid, :name do
266
- helper.perform_action(args[0],options,"renamed") do |o|
271
+ helper.perform_action(args[0], options, 'renamed') do |o|
267
272
  o.rename(args[1])
268
273
  end
269
274
  end
@@ -273,7 +278,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
273
278
  EOT
274
279
 
275
280
  command :importvm, importvm_desc, :hostid, :name do
276
- helper.perform_action(args[0], options, "imported") do |o|
281
+ helper.perform_action(args[0], options, 'imported') do |o|
277
282
  rc = o.info
278
283
  next rc if OpenNebula.is_error?(rc)
279
284