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
data/bin/onemarketapp ADDED
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2016, 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
+ VAR_LOCATION = "/var/lib/one"
24
+ else
25
+ RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby"
26
+ VAR_LOCATION = ONE_LOCATION + "/var"
27
+ end
28
+
29
+ $: << RUBY_LIB_LOCATION
30
+ $: << RUBY_LIB_LOCATION+"/cli"
31
+
32
+ require 'command_parser'
33
+ require 'one_helper/onemarketapp_helper'
34
+ require 'one_helper/onemarket_helper'
35
+ require 'one_helper/onedatastore_helper'
36
+
37
+ CommandParser::CmdParser.new(ARGV) do
38
+ usage "`onemarket` <command> [<args>] [<options>]"
39
+ version OpenNebulaHelper::ONE_VERSION
40
+
41
+ helper = OneMarketPlaceAppHelper.new
42
+
43
+ before_proc do
44
+ helper.set_client(options)
45
+ end
46
+
47
+ ########################################################################
48
+ # Global Options
49
+ ########################################################################
50
+ set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
51
+
52
+ list_options = CLIHelper::OPTIONS
53
+ list_options << OpenNebulaHelper::XML
54
+ list_options << OpenNebulaHelper::NUMERIC
55
+ list_options << OpenNebulaHelper::DESCRIBE
56
+
57
+ CREATE_OPTIONS = [OneMarketPlaceHelper::MARKETPLACE]
58
+ EXPORT_OPTIONS = [OneDatastoreHelper::DATASTORE, OneMarketPlaceAppHelper::VMNAME]
59
+
60
+ ########################################################################
61
+ # Formatters for arguments
62
+ ########################################################################
63
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
64
+ OpenNebulaHelper.rname_to_id(arg, "GROUP")
65
+ end
66
+
67
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
68
+ OpenNebulaHelper.rname_to_id(arg, "USER")
69
+ end
70
+
71
+ set :format, :appid, OneMarketPlaceAppHelper.to_id_desc do |arg|
72
+ helper.to_id(arg)
73
+ end
74
+
75
+ set :format, :appid_list, OneMarketPlaceAppHelper.list_to_id_desc do |arg|
76
+ helper.list_to_id(arg)
77
+ end
78
+
79
+ set :format, :filterflag, OneMarketPlaceAppHelper.filterflag_to_i_desc do |arg|
80
+ helper.filterflag_to_i(arg)
81
+ end
82
+
83
+ ########################################################################
84
+ # Commands
85
+ ########################################################################
86
+
87
+ create_desc = <<-EOT.unindent
88
+ Creates a new marketplace app in the given marketplace
89
+ EOT
90
+
91
+ command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS +
92
+ OneMarketPlaceAppHelper::TEMPLATE_OPTIONS do
93
+
94
+ if options[:marketplace].nil?
95
+ STDERR.puts "Marketplace to save the app is mandatory: "
96
+ STDERR.puts "\t -m marketplace_id"
97
+ exit(-1)
98
+ end
99
+
100
+ if args[0] && OneMarketPlaceAppHelper.create_template_options_used?(options)
101
+ STDERR.puts "You can not use both template file and template"<<
102
+ " creation options."
103
+ next -1
104
+ end
105
+
106
+ helper.create_resource(options) do |app|
107
+ begin
108
+ if args[0]
109
+ template=File.read(args[0])
110
+ else
111
+ res = OneMarketPlaceAppHelper.create_datastore_template(options)
112
+
113
+ if res.first != 0
114
+ STDERR.puts res.last
115
+ next -1
116
+ end
117
+
118
+ template = res.last
119
+ end
120
+
121
+ if options[:dry]
122
+ puts template
123
+ exit 0
124
+ end
125
+
126
+ app.allocate(template, options[:marketplace])
127
+ rescue => e
128
+ STDERR.puts e.message
129
+ exit(-1)
130
+ end
131
+ end
132
+ end
133
+
134
+ export_desc = <<-EOT.unindent
135
+ Exports the marketplace app to the OpenNebula cloud
136
+ EOT
137
+
138
+ command :export, export_desc, :appid, :name, :options=>EXPORT_OPTIONS do
139
+ helper.perform_action(args[0], options, "exported") do |obj|
140
+
141
+ rc = obj.export({
142
+ :dsid=>options[:datastore],
143
+ :name=>args[1],
144
+ :vmtemplate_name=>options[:vmname]
145
+ })
146
+
147
+ next rc if OpenNebula.is_error?(rc)
148
+
149
+ rc.each { |key, value|
150
+ puts "#{key.to_s.upcase}"
151
+ value.each{ |id|
152
+ if OpenNebula.is_error?(id)
153
+ puts id.to_str
154
+ else
155
+ puts " ID: #{id}"
156
+ end
157
+ }
158
+ }
159
+ end
160
+ end
161
+
162
+ download_desc = <<-EOT.unindent
163
+ Downloads a MarketApp to a file
164
+ EOT
165
+
166
+ command :download, download_desc, :appid, :path,
167
+ :options => [OpenNebulaHelper::FORCE] do
168
+ helper.perform_action(args[0],options,"downloaded") do |app|
169
+ download_args = [:marketplaceapp, args[0], args[1], options[:force]]
170
+ OpenNebulaHelper.download_resource_sunstone(*download_args)
171
+ end
172
+ end
173
+
174
+ delete_desc = <<-EOT.unindent
175
+ Deletes the given marketplace app
176
+ EOT
177
+
178
+ command :delete, delete_desc, [:range, :appid_list] do
179
+ helper.perform_actions(args[0], options, "deleted") do |app|
180
+ app.delete
181
+ end
182
+ end
183
+
184
+ update_desc = <<-EOT.unindent
185
+ Update the template contents for the app. If a path is not provided the
186
+ editor will be launched to modify the current content.
187
+ EOT
188
+
189
+ command :update, update_desc, :appid, [:file, nil],
190
+ :options=>OpenNebulaHelper::APPEND do
191
+
192
+ helper.perform_action(args[0],options,"modified") do |obj|
193
+ if options[:append]
194
+ str = OpenNebulaHelper.append_template(args[0], obj, args[1])
195
+ else
196
+ str = OpenNebulaHelper.update_template(args[0], obj, args[1])
197
+ end
198
+
199
+ obj.update(str, options[:append])
200
+ end
201
+ end
202
+
203
+ chgrp_desc = <<-EOT.unindent
204
+ Changes the marketplace app group
205
+ EOT
206
+
207
+ command :chgrp, chgrp_desc,[:range, :appid_list], :groupid do
208
+ helper.perform_actions(args[0], options, "Group changed") do |app|
209
+ app.chown(-1, args[1].to_i)
210
+ end
211
+ end
212
+
213
+ chown_desc = <<-EOT.unindent
214
+ Changes the marketplace app owner and group
215
+ EOT
216
+
217
+ command :chown, chown_desc, [:range, :appid_list], :userid,
218
+ [:groupid, nil] do
219
+ gid = args[2].nil? ? -1 : args[2].to_i
220
+
221
+ helper.perform_actions(args[0], options, "Owner/Group changed") do |app|
222
+ app.chown(args[1].to_i, gid)
223
+ end
224
+ end
225
+
226
+ chmod_desc = <<-EOT.unindent
227
+ Changes the marketplace app permissions
228
+ EOT
229
+
230
+ command :chmod, chmod_desc, [:range, :appid_list], :octet do
231
+ helper.perform_actions(args[0], options, "Permissions changed") do |app|
232
+ app.chmod_octet(args[1])
233
+ end
234
+ end
235
+
236
+ rename_desc = <<-EOT.unindent
237
+ Renames the marketplace app
238
+ EOT
239
+
240
+ command :rename, rename_desc, :appid, :name do
241
+ helper.perform_action(args[0], options, "renamed") do |o|
242
+ o.rename(args[1])
243
+ end
244
+ end
245
+
246
+ list_desc = <<-EOT.unindent
247
+ Lists marketplace apps
248
+ EOT
249
+
250
+ command :list, list_desc, [:filterflag, nil], :options=>list_options do
251
+ helper.list_pool(options, false, args[0])
252
+ end
253
+
254
+ show_desc = <<-EOT.unindent
255
+ Shows information for the given marketplace app
256
+ EOT
257
+
258
+ command :show, show_desc, :appid, :options=>OpenNebulaHelper::XML do
259
+ helper.show_resource(args[0], options)
260
+ end
261
+
262
+ enable_desc = <<-EOT.unindent
263
+ Enables the marketplace app
264
+ EOT
265
+
266
+ command :enable, enable_desc, [:range, :appid_list] do
267
+ helper.perform_actions(args[0], options, "enabled") do |obj|
268
+ obj.enable
269
+ end
270
+ end
271
+
272
+ disable_desc = <<-EOT.unindent
273
+ Disables the marketplace app. A disabled marketplace app cannot be
274
+ exported to a cloud
275
+ EOT
276
+
277
+ command :disable, disable_desc, [:range, :appid_list] do
278
+ helper.perform_actions(args[0], options, "disabled") do |obj|
279
+ obj.disable
280
+ end
281
+ end
282
+ end
data/bin/onesecgroup CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
5
5
  # #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
7
  # not use this file except in compliance with the License. You may obtain #
@@ -166,6 +166,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
166
166
  str = OpenNebulaHelper.update_template(args[0], obj, args[1])
167
167
  end
168
168
 
169
+ helper.set_client(options)
170
+ obj = helper.retrieve_resource(obj.id)
171
+
169
172
  obj.update(str, options[:append])
170
173
  end
171
174
  end
@@ -180,6 +183,20 @@ cmd=CommandParser::CmdParser.new(ARGV) do
180
183
  end
181
184
  end
182
185
 
186
+ commit_desc = <<-EOT.unindent
187
+ Commit SG changes to associated VMs. This command is to propagate
188
+ security group rules to VMs when they are updated. This operation takes
189
+ time to iterate over all VMs in the security group, progress can be
190
+ checked through the outdated, updating and error VM sets.
191
+ EOT
192
+
193
+ command :commit, commit_desc, :secgroupid,
194
+ :options =>[OneSecurityGroupHelper::RECOVER] do
195
+ helper.perform_action(args[0], options, "commit") do |o|
196
+ o.commit(options[:recover]==true)
197
+ end
198
+ end
199
+
183
200
  list_desc = <<-EOT.unindent
184
201
  Lists Security Group in the pool
185
202
  EOT
data/bin/oneshowback CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
5
5
  # #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
7
  # not use this file except in compliance with the License. You may obtain #
data/bin/onetemplate CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
5
5
  # #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
7
  # not use this file except in compliance with the License. You may obtain #
@@ -55,7 +55,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
55
55
  OneTemplateHelper::VM_NAME,
56
56
  OneTemplateHelper::MULTIPLE,
57
57
  OneTemplateHelper::USERDATA,
58
- OneVMHelper::HOLD
58
+ OneVMHelper::HOLD,
59
+ OneTemplateHelper::PERSISTENT,
59
60
  ]
60
61
 
61
62
  ########################################################################
@@ -147,9 +148,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
147
148
  Creates a new Template from an existing one
148
149
  EOT
149
150
 
150
- command :clone, clone_desc, :templateid, :name do
151
+ command :clone, clone_desc, :templateid, :name,
152
+ :options =>OneTemplateHelper::RECURSIVE do
153
+
154
+ recursive = (options[:recursive] == true)
155
+
151
156
  helper.perform_action(args[0],options,"cloned") do |t|
152
- res = t.clone(args[1])
157
+ res = t.clone(args[1], recursive)
153
158
 
154
159
  if !OpenNebula.is_error?(res)
155
160
  puts "ID: #{res}"
@@ -160,12 +165,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
160
165
  end
161
166
 
162
167
  delete_desc = <<-EOT.unindent
163
- Deletes the given Image
168
+ Deletes the given Template
164
169
  EOT
165
170
 
166
- command :delete, delete_desc, [:range, :templateid_list] do
171
+ command :delete, delete_desc, [:range, :templateid_list],
172
+ :options =>OneTemplateHelper::RECURSIVE do
173
+
174
+ recursive = (options[:recursive] == true)
175
+
167
176
  helper.perform_actions(args[0],options,"deleted") do |t|
168
- t.delete
177
+ t.delete(recursive)
169
178
  end
170
179
  end
171
180
 
@@ -208,17 +217,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
208
217
 
209
218
  if args[1]
210
219
  extra_template = File.read(args[1])
211
- elsif options[:userdata]
212
- if t.has_elements?('TEMPLATE/EC2')
213
- t.add_element(
214
- 'TEMPLATE/EC2',
215
- 'USERDATA' => options[:userdata])
216
-
217
- extra_template = t.template_like_str(
218
- 'TEMPLATE', false, 'EC2')
219
- end
220
220
  else
221
- res = OpenNebulaHelper.create_template(options)
221
+ res = OpenNebulaHelper.create_template(options, t)
222
222
 
223
223
  if res.first != 0
224
224
  STDERR.puts res.last
@@ -228,11 +228,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
228
228
  extra_template = res.last
229
229
  end
230
230
 
231
- user_inputs = helper.get_user_inputs(t.to_hash) unless user_inputs
231
+ user_inputs = OneTemplateHelper.get_user_inputs(t.to_hash) unless user_inputs
232
232
 
233
233
  extra_template << "\n" << user_inputs
234
234
 
235
- res = t.instantiate(name, on_hold, extra_template)
235
+ persistent = options[:persistent] != nil
236
+
237
+ res = t.instantiate(name, on_hold, extra_template, persistent)
236
238
 
237
239
  if !OpenNebula.is_error?(res)
238
240
  puts "VM ID: #{res}"
@@ -273,9 +275,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
273
275
  Changes the Template permissions
274
276
  EOT
275
277
 
276
- command :chmod, chmod_desc, [:range, :templateid_list], :octet do
278
+ command :chmod, chmod_desc, [:range, :templateid_list], :octet,
279
+ :options =>OneTemplateHelper::RECURSIVE do
280
+
281
+ recursive = (options[:recursive] == true)
282
+
277
283
  helper.perform_actions(args[0],options, "Permissions changed") do |t|
278
- t.chmod_octet(args[1])
284
+ t.chmod_octet(args[1], recursive)
279
285
  end
280
286
  end
281
287
 
@@ -293,6 +299,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
293
299
  str = OpenNebulaHelper.update_template(args[0], obj, args[1])
294
300
  end
295
301
 
302
+ helper.set_client(options)
303
+ obj = helper.retrieve_resource(obj.id)
304
+
296
305
  obj.update(str, options[:append])
297
306
  end
298
307
  end
data/bin/oneuser CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # -------------------------------------------------------------------------- #
4
- # Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
4
+ # Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
5
5
  # #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
7
  # not use this file except in compliance with the License. You may obtain #
@@ -40,7 +40,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
40
40
  helper = OneUserHelper.new
41
41
 
42
42
  before_proc do
43
- helper.set_client(options) if @comm_name != :login
43
+ helper.set_client(options) if ![:login, :key].include?(@comm_name)
44
44
  end
45
45
 
46
46
  ########################################################################
@@ -210,6 +210,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
210
210
  str = OpenNebulaHelper.update_template(args[0], obj, args[1])
211
211
  end
212
212
 
213
+ helper.set_client(options)
214
+ obj = helper.retrieve_resource(obj.id)
215
+
213
216
  obj.update(str, options[:append])
214
217
  end
215
218
  end
@@ -229,6 +232,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
229
232
  end
230
233
 
231
234
  str = OneQuotaHelper.set_quota(user, args[1])
235
+
236
+ helper.set_client(options)
237
+ user = helper.retrieve_resource(user.id)
238
+
232
239
  rc = user.set_quota(str)
233
240
 
234
241
  if OpenNebula.is_error?(rc)
@@ -247,14 +254,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
247
254
  [:file, nil] do
248
255
  batch_str = OneQuotaHelper.get_batch_quota(args[1])
249
256
 
257
+ helper.set_client(options)
250
258
  helper.perform_actions(args[0], options, "modified") do |user|
251
259
  str = OneQuotaHelper.merge_quota(user, batch_str)
252
260
 
253
261
  if OpenNebula.is_error?(str)
254
262
  str
255
263
  else
256
- rc = user.set_quota(str)
257
- rc
264
+ user.set_quota(str)
258
265
  end
259
266
  end
260
267
  end
@@ -276,6 +283,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
276
283
 
277
284
  str = OneQuotaHelper.set_quota(default_quotas, args[0], true)
278
285
 
286
+ system = System.new(OneUserHelper.get_client(options, true))
279
287
  rc = system.set_user_quotas(str)
280
288
 
281
289
  if OpenNebula.is_error?(rc)
@@ -348,8 +356,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
348
356
  end
349
357
 
350
358
  key_desc = <<-EOT.unindent
351
- DEPRECATED, use login to generate auth files.
352
-
353
359
  Shows a public key from a private SSH key. Use it as password
354
360
  for the SSH authentication mechanism.
355
361
  EOT