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/onevcenter CHANGED
@@ -16,27 +16,26 @@
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"
31
- $: << REMOTES_LOCATION+"vmm/vcenter/"
29
+ $LOAD_PATH << RUBY_LIB_LOCATION
30
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
31
+ $LOAD_PATH << REMOTES_LOCATION + 'vmm/vcenter/'
32
32
 
33
33
  require 'command_parser'
34
34
  require 'one_helper/onevcenter_helper'
35
35
  require 'vcenter_driver'
36
36
 
37
- cmd=CommandParser::CmdParser.new(ARGV) do
38
-
39
- usage "`onevcenter` <command> [<args>] [<options>]"
37
+ CommandParser::CmdParser.new(ARGV) do
38
+ usage '`onevcenter` <command> [<args>] [<options>]'
40
39
  version OpenNebulaHelper::ONE_VERSION
41
40
 
42
41
  helper = OneVcenterHelper.new
@@ -45,83 +44,78 @@ cmd=CommandParser::CmdParser.new(ARGV) do
45
44
  helper.set_client(options)
46
45
  end
47
46
 
48
-
49
47
  OBJECT = {
50
- :name => "object",
51
- :short => "-o object",
52
- :large => "--object object ",
48
+ :name => 'object',
49
+ :short => '-o object',
50
+ :large => '--object object ',
53
51
  :format => String,
54
- :description => "vCenter object: [datastores, templates, networks, datastores, images]"
52
+ :description => 'vCenter object: [datastores, templates,'\
53
+ 'networks, datastores, images]'
55
54
  }
56
55
 
57
56
  HOST = {
58
- :name => "host",
59
- :short => "-h host_id",
60
- :large => "--host host_id",
57
+ :name => 'host',
58
+ :short => '-h host_id',
59
+ :large => '--host host_id',
61
60
  :format => String,
62
- :description => "OpenNebula host used to authenticate the operation"
61
+ :description => 'OpenNebula host used to authenticate the operation'
63
62
  }
64
63
 
65
64
  DATASTORE = {
66
- :name => "datastore",
67
- :short => "-d datastore_id",
68
- :large => "--datastore datastore_id",
65
+ :name => 'datastore',
66
+ :short => '-d datastore_id',
67
+ :large => '--datastore datastore_id',
69
68
  :format => String,
70
- :description => "OpenNebula datastore used"
69
+ :description => 'OpenNebula datastore used'
71
70
  }
72
71
 
73
72
  CONFIG = {
74
- :name => "configuration",
75
- :large => "--config file",
73
+ :name => 'configuration',
74
+ :large => '--config file',
76
75
  :format => String,
77
- :description => "Configuration file for custom options"
76
+ :description => 'Configuration file for custom options'
78
77
  }
79
78
 
80
79
  VCENTER = {
81
- :name => "vcenter",
82
- :large => "--vcenter vCenter" ,
83
- :description => "The vCenter hostname",
80
+ :name => 'vcenter',
81
+ :large => '--vcenter vCenter',
82
+ :description => 'The vCenter hostname',
84
83
  :format => String
85
84
  }
86
85
 
87
86
  USER = {
88
- :name => "vuser",
89
- :large => "--vuser username" ,
90
- :description => "The username to interact with vCenter",
87
+ :name => 'vuser',
88
+ :large => '--vuser username',
89
+ :description => 'The username to interact with vCenter',
91
90
  :format => String
92
91
  }
93
92
 
94
93
  PASS = {
95
- :name => "vpass",
96
- :large => "--vpass password",
97
- :description => "The password for the user",
94
+ :name => 'vpass',
95
+ :large => '--vpass password',
96
+ :description => 'The password for the user',
98
97
  :format => String
99
98
  }
100
99
 
101
100
  USE_DEFAULTS = {
102
- :name => "defaults",
103
- :large => "--use-defaults",
104
- :description => "Use defaults for answers to questions",
101
+ :name => 'defaults',
102
+ :large => '--use-defaults',
103
+ :description => 'Use defaults for answers to questions',
105
104
  :format => String
106
105
  }
107
106
 
108
107
  ALL = {
109
- :name => "all",
110
- :large => "--all",
111
- :description => "Import all list",
108
+ :name => 'all',
109
+ :large => '--all',
110
+ :description => 'Import all list',
112
111
  :format => String
113
112
  }
114
113
 
115
114
  ############################################################################
116
115
  # Global Options
117
116
  ############################################################################
118
- cmd_options=CommandParser::OPTIONS-[CommandParser::VERBOSE]
119
- set :option, cmd_options+OpenNebulaHelper::CLIENT_OPTIONS
120
-
121
- #format :oid, "vCenter Object identifier" do |arg|
122
- # puts arg
123
- #end
124
-
117
+ cmd_options = CommandParser::OPTIONS - [CommandParser::VERBOSE]
118
+ set :option, cmd_options + OpenNebulaHelper::CLIENT_OPTIONS
125
119
 
126
120
  ############################################################################
127
121
  # list resources
@@ -138,16 +132,20 @@ cmd=CommandParser::CmdParser.new(ARGV) do
138
132
 
139
133
  onevcenter list -o datastores -h <host_id> -d <ds-img_id>
140
134
  EOT
141
- command :list, list_desc, :options=>[ OBJECT, HOST, DATASTORE, VCENTER, USER, PASS ] do
135
+
136
+ command :list,
137
+ list_desc,
138
+ :options => [OBJECT, HOST, DATASTORE, VCENTER, USER, PASS] do
142
139
  begin
143
140
  args = helper.parse_opts(options)
144
141
  vi_client = VCenterDriver::VIClient.new_from_host(options[:host])
145
- importer = VCenterDriver::VcImporter.new_child(helper.client, vi_client, options[:object])
142
+ importer = VCenterDriver::VcImporter
143
+ .new_child(helper.client, vi_client, options[:object])
146
144
 
147
145
  list = importer.retrieve_resources(args)
148
146
 
149
147
  helper.list_object(options, list)
150
- rescue Exception => e
148
+ rescue StandardError => e
151
149
  puts e.message
152
150
  end
153
151
 
@@ -171,11 +169,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
171
169
  onevcenter import 0..10 -o images -h <host_id> -d <ds-img_id>
172
170
  EOT
173
171
 
174
- command :import, import_desc, [:oid, nil], :options=>[ OBJECT, HOST, DATASTORE ] do
175
-
172
+ command :import,
173
+ import_desc, [:oid, nil],
174
+ :options => [OBJECT, HOST, DATASTORE] do
176
175
  begin
177
176
  vi_client = VCenterDriver::VIClient.new_from_host(options[:host])
178
- importer = VCenterDriver::VcImporter.new_child(helper.client, vi_client, options[:object])
177
+ importer = VCenterDriver::VcImporter.new_child(helper.client,
178
+ vi_client,
179
+ options[:object])
179
180
 
180
181
  importer.retrieve_resources(helper.parse_opts(options))
181
182
  indexes = importer.get_indexes(args.first)
@@ -185,25 +186,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
185
186
  end
186
187
 
187
188
  importer.stdout
188
- rescue Exception => e
189
+ rescue StandardError => e
189
190
  puts e.message
190
191
  end
191
192
 
192
193
  exit 0
193
194
  end
194
195
 
195
- command :import_defaults, import_desc, [:oid, nil] , :options=>[ OBJECT, HOST, DATASTORE, CONFIG ] do
196
-
196
+ command :import_defaults,
197
+ import_desc,
198
+ [:oid, nil],
199
+ :options => [OBJECT, HOST, DATASTORE, CONFIG] do
197
200
  begin
198
201
  vi_client = VCenterDriver::VIClient.new_from_host(options[:host])
199
- importer = VCenterDriver::VcImporter.new_child(helper.client, vi_client, options[:object])
202
+ importer = VCenterDriver::VcImporter.new_child(helper.client,
203
+ vi_client,
204
+ options[:object])
200
205
  importer.retrieve_resources(helper.parse_opts(options))
201
206
  indexes = importer.get_indexes(args.first)
202
207
 
203
208
  importer.process_import(indexes)
204
209
 
205
210
  importer.stdout
206
- rescue Exception => e
211
+ rescue StandardError => e
207
212
  puts e.message
208
213
  end
209
214
 
@@ -221,12 +226,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
221
226
 
222
227
  onevcenter hosts --vcenter <vcenter> --vuser <vcenter_user> --vpass <password>
223
228
  EOT
224
- command :hosts, host_desc, :options=>[ VCENTER, USER, PASS, USE_DEFAULTS ] do
225
- con_ops = helper.connection_options("Hosts", options)
229
+ command :hosts,
230
+ host_desc,
231
+ :options => [VCENTER, USER, PASS, USE_DEFAULTS] do
232
+ con_ops = helper.connection_options('Hosts', options)
226
233
 
227
- VCenterDriver::Importer.import_clusters(con_ops, options)
234
+ VCenterDriver::VcImporter.import_clusters(con_ops, options)
228
235
 
229
236
  exit 0
230
237
  end
231
-
232
238
  end
data/bin/onevdc 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/onevdc_helper'
32
32
 
33
- cmd=CommandParser::CmdParser.new(ARGV) do
34
- usage "`onevdc` <command> [<args>] [<options>]"
33
+ CommandParser::CmdParser.new(ARGV) do
34
+ usage '`onevdc` <command> [<args>] [<options>]'
35
35
  version OpenNebulaHelper::ONE_VERSION
36
36
 
37
37
  helper = OneVdcHelper.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,51 +61,63 @@ cmd=CommandParser::CmdParser.new(ARGV) do
61
61
  helper.list_to_id(arg)
62
62
  end
63
63
 
64
- set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
65
- OpenNebulaHelper.rname_to_id(arg, "GROUP")
64
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
65
+ OpenNebulaHelper.rname_to_id(arg, 'GROUP')
66
66
  end
67
67
 
68
- set :format, :zoneid, OpenNebulaHelper.rname_to_id_desc("ZONE") do |arg|
69
- OpenNebulaHelper.rname_to_id(arg, "ZONE")
68
+ set :format, :zoneid, OpenNebulaHelper.rname_to_id_desc('ZONE') do |arg|
69
+ OpenNebulaHelper.rname_to_id(arg, 'ZONE')
70
70
  end
71
71
 
72
72
  set :format, :clusterid,
73
- "#{OpenNebulaHelper.rname_to_id_desc('CLUSTER')}. Can be set to ALL" do |arg|
73
+ "#{OpenNebulaHelper.rname_to_id_desc('CLUSTER')}. "\
74
+ 'Can be set to ALL' do |arg|
74
75
 
75
- if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
76
+ if !arg.nil? &&
77
+ arg.class != Integer &&
78
+ arg.casecmp('ALL').zero?
76
79
  [0, Vdc::ALL_RESOURCES]
77
80
  else
78
- OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
81
+ OpenNebulaHelper.rname_to_id(arg, 'CLUSTER')
79
82
  end
80
83
  end
81
84
 
82
85
  set :format, :hostid,
83
- "#{OpenNebulaHelper.rname_to_id_desc('HOST')}. Can be set to ALL" do |arg|
86
+ "#{OpenNebulaHelper.rname_to_id_desc('HOST')}. "\
87
+ 'Can be set to ALL' do |arg|
84
88
 
85
- if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
89
+ if !arg.nil? &&
90
+ arg.class != Integer &&
91
+ arg.casecmp('ALL').zero?
86
92
  [0, Vdc::ALL_RESOURCES]
87
93
  else
88
- OpenNebulaHelper.rname_to_id(arg, "HOST")
94
+ OpenNebulaHelper.rname_to_id(arg, 'HOST')
89
95
  end
90
96
  end
91
97
 
92
98
  set :format, :datastoreid,
93
- "#{OpenNebulaHelper.rname_to_id_desc('DATASTORE')}. Can be set to ALL" do |arg|
99
+ "#{OpenNebulaHelper.rname_to_id_desc('DATASTORE')}. "\
100
+ 'Can be set to ALL' do |arg|
94
101
 
95
- if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
102
+ if !arg.nil? &&
103
+ arg.class != Integer &&
104
+ arg.casecmp('ALL').zero?
96
105
  [0, Vdc::ALL_RESOURCES]
97
106
  else
98
- OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
107
+ OpenNebulaHelper.rname_to_id(arg, 'DATASTORE')
99
108
  end
100
109
  end
101
110
 
102
111
  set :format, :vnetid,
103
- "#{OpenNebulaHelper.rname_to_id_desc('VNET')}. Can be set to ALL" do |arg|
112
+ "#{OpenNebulaHelper.rname_to_id_desc('VNET')}. "\
113
+ 'Can be set to ALL' do |arg|
104
114
 
105
- if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
115
+ if !arg.nil? &&
116
+ arg.class != Integer &&
117
+ arg.casecmp('ALL').zero?
106
118
  [0, Vdc::ALL_RESOURCES]
107
119
  else
108
- OpenNebulaHelper.rname_to_id(arg, "VNET")
120
+ OpenNebulaHelper.rname_to_id(arg, 'VNET')
109
121
  end
110
122
  end
111
123
 
@@ -129,7 +141,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
129
141
  EOT
130
142
 
131
143
  command :rename, rename_desc, :vdcid, :name do
132
- helper.perform_action(args[0],options,"renamed") do |o|
144
+ helper.perform_action(args[0], options, 'renamed') do |o|
133
145
  o.rename(args[1])
134
146
  end
135
147
  end
@@ -140,8 +152,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
140
152
  EOT
141
153
 
142
154
  command :update, update_desc, :vdcid, [:file, nil],
143
- :options=>OpenNebulaHelper::APPEND do
144
- helper.perform_action(args[0],options,"modified") do |obj|
155
+ :options => OpenNebulaHelper::APPEND do
156
+ helper.perform_action(args[0], options, 'modified') do |obj|
145
157
  if options[:append]
146
158
  str = OpenNebulaHelper.append_template(args[0], obj, args[1])
147
159
  else
@@ -160,7 +172,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
160
172
  EOT
161
173
 
162
174
  command :delete, delete_desc, [:range, :vdcid_list] do
163
- helper.perform_actions(args[0],options,"deleted") do |obj|
175
+ helper.perform_actions(args[0], options, 'deleted') do |obj|
164
176
  obj.delete
165
177
  end
166
178
  end
@@ -170,7 +182,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
170
182
  EOT
171
183
 
172
184
  command :addgroup, add_group_desc, [:range, :vdcid_list], :groupid do
173
- helper.perform_actions(args[0],options,"group added") do |obj|
185
+ helper.perform_actions(args[0], options, 'group added') do |obj|
174
186
  obj.add_group(args[1].to_i)
175
187
  end
176
188
  end
@@ -180,7 +192,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
180
192
  EOT
181
193
 
182
194
  command :delgroup, del_group_desc, [:range, :vdcid_list], :groupid do
183
- helper.perform_actions(args[0],options,"group deleted") do |obj|
195
+ helper.perform_actions(args[0], options, 'group deleted') do |obj|
184
196
  obj.del_group(args[1].to_i)
185
197
  end
186
198
  end
@@ -189,8 +201,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
189
201
  Adds a Cluster (from a specific Zone) to the given VDC
190
202
  EOT
191
203
 
192
- command :addcluster, add_cluster_desc, [:range, :vdcid_list], :zoneid, :clusterid do
193
- helper.perform_actions(args[0],options,"cluster added") do |obj|
204
+ command :addcluster, add_cluster_desc,
205
+ [:range, :vdcid_list], :zoneid, :clusterid do
206
+ helper.perform_actions(args[0], options, 'cluster added') do |obj|
194
207
  obj.add_cluster(args[1].to_i, args[2].to_i)
195
208
  end
196
209
  end
@@ -199,8 +212,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
199
212
  Deletes a Cluster (from a specific Zone) from the given VDC
200
213
  EOT
201
214
 
202
- command :delcluster, del_cluster_desc, [:range, :vdcid_list], :zoneid, :clusterid do
203
- helper.perform_actions(args[0],options,"cluster deleted") do |obj|
215
+ command :delcluster, del_cluster_desc,
216
+ [:range, :vdcid_list], :zoneid, :clusterid do
217
+ helper.perform_actions(args[0], options, 'cluster deleted') do |obj|
204
218
  obj.del_cluster(args[1].to_i, args[2].to_i)
205
219
  end
206
220
  end
@@ -210,7 +224,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
210
224
  EOT
211
225
 
212
226
  command :addhost, add_host_desc, [:range, :vdcid_list], :zoneid, :hostid do
213
- helper.perform_actions(args[0],options,"host added") do |obj|
227
+ helper.perform_actions(args[0], options, 'host added') do |obj|
214
228
  obj.add_host(args[1].to_i, args[2].to_i)
215
229
  end
216
230
  end
@@ -220,7 +234,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
220
234
  EOT
221
235
 
222
236
  command :delhost, del_host_desc, [:range, :vdcid_list], :zoneid, :hostid do
223
- helper.perform_actions(args[0],options,"host deleted") do |obj|
237
+ helper.perform_actions(args[0], options, 'host deleted') do |obj|
224
238
  obj.del_host(args[1].to_i, args[2].to_i)
225
239
  end
226
240
  end
@@ -229,8 +243,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
229
243
  Adds a Datastore (from a specific Zone) to the given VDC
230
244
  EOT
231
245
 
232
- command :adddatastore, add_datastore_desc, [:range, :vdcid_list], :zoneid, :datastoreid do
233
- helper.perform_actions(args[0],options,"datastore added") do |obj|
246
+ command :adddatastore, add_datastore_desc,
247
+ [:range, :vdcid_list], :zoneid, :datastoreid do
248
+ helper.perform_actions(args[0], options, 'datastore added') do |obj|
234
249
  obj.add_datastore(args[1].to_i, args[2].to_i)
235
250
  end
236
251
  end
@@ -239,8 +254,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
239
254
  Deletes a Datastore (from a specific Zone) from the given VDC
240
255
  EOT
241
256
 
242
- command :deldatastore, del_datastore_desc, [:range, :vdcid_list], :zoneid, :datastoreid do
243
- helper.perform_actions(args[0],options,"datastore deleted") do |obj|
257
+ command :deldatastore, del_datastore_desc,
258
+ [:range, :vdcid_list], :zoneid, :datastoreid do
259
+ helper.perform_actions(args[0], options, 'datastore deleted') do |obj|
244
260
  obj.del_datastore(args[1].to_i, args[2].to_i)
245
261
  end
246
262
  end
@@ -250,7 +266,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
250
266
  EOT
251
267
 
252
268
  command :addvnet, add_vnet_desc, [:range, :vdcid_list], :zoneid, :vnetid do
253
- helper.perform_actions(args[0],options,"vnet added") do |obj|
269
+ helper.perform_actions(args[0], options, 'vnet added') do |obj|
254
270
  obj.add_vnet(args[1].to_i, args[2].to_i)
255
271
  end
256
272
  end
@@ -260,7 +276,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
260
276
  EOT
261
277
 
262
278
  command :delvnet, del_vnet_desc, [:range, :vdcid_list], :zoneid, :vnetid do
263
- helper.perform_actions(args[0],options,"vnet deleted") do |obj|
279
+ helper.perform_actions(args[0], options, 'vnet deleted') do |obj|
264
280
  obj.del_vnet(args[1].to_i, args[2].to_i)
265
281
  end
266
282
  end
@@ -269,7 +285,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
269
285
  Lists VDCs in the pool
270
286
  EOT
271
287
 
272
- command :list, list_desc, :options=>list_options do
288
+ command :list, list_desc, :options => list_options do
273
289
  helper.list_pool(options)
274
290
  end
275
291
 
@@ -277,7 +293,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
277
293
  Shows information for the given VDC
278
294
  EOT
279
295
 
280
- command :show, show_desc,:vdcid, :options=>OpenNebulaHelper::XML do
281
- helper.show_resource(args[0],options)
296
+ command :show, show_desc, :vdcid, :options => OpenNebulaHelper::XML do
297
+ helper.show_resource(args[0], options)
282
298
  end
283
299
  end