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/onegroup ADDED
@@ -0,0 +1,137 @@
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/onegroup_helper'
32
+
33
+ cmd=CommandParser::CmdParser.new(ARGV) do
34
+ usage "`onegroup` <command> [<args>] [<options>]"
35
+ version OpenNebulaHelper::ONE_VERSION
36
+
37
+ helper = OneGroupHelper.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
+ ########################################################################
50
+ # Formatters for arguments
51
+ ########################################################################
52
+ set :format, :groupid, OneGroupHelper.to_id_desc do |arg|
53
+ helper.to_id(arg)
54
+ end
55
+
56
+ set :format, :groupid_list, OneGroupHelper.list_to_id_desc do |arg|
57
+ helper.list_to_id(arg)
58
+ end
59
+
60
+ ########################################################################
61
+ # Commands
62
+ ########################################################################
63
+
64
+ create_desc = <<-EOT.unindent
65
+ Creates a new Group
66
+ EOT
67
+
68
+ command :create, create_desc, :name do
69
+ helper.create_resource(options) do |group|
70
+ group.allocate(args[0])
71
+ end
72
+ end
73
+
74
+ delete_desc = <<-EOT.unindent
75
+ Deletes the given Group
76
+ EOT
77
+
78
+ command :delete, delete_desc, [:range, :groupid_list] do
79
+ helper.perform_actions(args[0],options,"deleted") do |obj|
80
+ obj.delete
81
+ end
82
+ end
83
+
84
+ list_desc = <<-EOT.unindent
85
+ Lists Groups in the pool
86
+ EOT
87
+
88
+ command :list, list_desc, :options=>list_options do
89
+ helper.list_pool(options)
90
+ end
91
+
92
+ show_desc = <<-EOT.unindent
93
+ Shows information for the given Group
94
+ EOT
95
+
96
+ command :show, show_desc,[:groupid, nil], :options=>OpenNebulaHelper::XML do
97
+ group = args[0] || OpenNebula::Group::SELF
98
+ helper.show_resource(group,options)
99
+ end
100
+
101
+ quota_desc = <<-EOT.unindent
102
+ Set the quota limits for the group. If a path is not provided the editor
103
+ will be launched to modify the current quotas.
104
+ EOT
105
+
106
+ command :quota, quota_desc, :groupid, [:file, nil] do
107
+ helper.perform_action(args[0], options, "modified") do |group|
108
+ str = OneQuotaHelper.set_quota(group, args[1])
109
+ rc = group.set_quota(str)
110
+
111
+ if OpenNebula.is_error?(rc)
112
+ puts rc.message
113
+ exit -1
114
+ end
115
+ end
116
+ end
117
+
118
+ batchquota_desc = <<-EOT.unindent
119
+ Sets the quota limits in batch for various groups. If a path is not
120
+ provided the editor will be launched to create new quotas.
121
+ EOT
122
+
123
+ command :batchquota, batchquota_desc, [:range, :groupid_list], [:file, nil] do
124
+ batch_str = OneQuotaHelper.get_batch_quota(args[1])
125
+
126
+ helper.perform_actions(args[0], options, "modified") do |group|
127
+ str = OneQuotaHelper.merge_quota(group, batch_str)
128
+
129
+ if OpenNebula.is_error?(str)
130
+ str
131
+ else
132
+ rc = group.set_quota(str)
133
+ rc
134
+ end
135
+ end
136
+ end
137
+ end
data/bin/onehost ADDED
@@ -0,0 +1,205 @@
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/onehost_helper'
32
+ require 'one_helper/onecluster_helper'
33
+
34
+ cmd=CommandParser::CmdParser.new(ARGV) do
35
+ usage "`onehost` <command> [<args>] [<options>]"
36
+ version OpenNebulaHelper::ONE_VERSION
37
+
38
+ helper = OneHostHelper.new
39
+
40
+ ########################################################################
41
+ # Global Options
42
+ ########################################################################
43
+ set :option, CommandParser::OPTIONS
44
+
45
+ IM = {
46
+ :name => "im",
47
+ :short => "-i im_mad",
48
+ :large => "--im im_mad" ,
49
+ :description => "Set the information driver for the host",
50
+ :format => String
51
+ }
52
+
53
+ VMM = {
54
+ :name => "vm",
55
+ :short => "-v vmm_mad",
56
+ :large => "--vm vmm_mad" ,
57
+ :description => "Set the virtualization driver for the host",
58
+ :format => String
59
+ }
60
+
61
+ VNET = {
62
+ :name => "net",
63
+ :short => "-n vnet_mad",
64
+ :large => "--net vnet_mad" ,
65
+ :description => "Set the network driver for the host",
66
+ :format => String
67
+ }
68
+
69
+ CREAT_OPTIONS = [ IM, VMM, VNET, OneClusterHelper::CLUSTER ]
70
+
71
+ ########################################################################
72
+ # Formatters for arguments
73
+ ########################################################################
74
+
75
+ set :format, :hostid, OneHostHelper.to_id_desc do |arg|
76
+ helper.to_id(arg)
77
+ end
78
+
79
+ set :format, :hostid_list, OneHostHelper.list_to_id_desc do |arg|
80
+ helper.list_to_id(arg)
81
+ end
82
+
83
+ ########################################################################
84
+ # Commands
85
+ ########################################################################
86
+
87
+ create_desc = <<-EOT.unindent
88
+ Creates a new Host
89
+ EOT
90
+
91
+ command :create, create_desc, :hostname, :options=>CREAT_OPTIONS do
92
+ if options[:im].nil? or options[:vm].nil? or options[:net].nil?
93
+ STDERR.puts "Drivers are mandatory to create a host:"
94
+ STDERR.puts "\t -i information driver"
95
+ STDERR.puts "\t -v hypervisor driver"
96
+ STDERR.puts "\t -n network driver"
97
+ exit -1
98
+ end
99
+
100
+ cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
101
+
102
+ helper.create_resource(options) do |host|
103
+ host.allocate(args[0],
104
+ options[:im],
105
+ options[:vm],
106
+ options[:net],
107
+ cid)
108
+ end
109
+ end
110
+
111
+ delete_desc = <<-EOT.unindent
112
+ Deletes the given Host
113
+ EOT
114
+
115
+ command :delete, delete_desc, [:range, :hostid_list] do
116
+ helper.perform_actions(args[0],options,"deleted") do |host|
117
+ host.delete
118
+ end
119
+ end
120
+
121
+ enable_desc = <<-EOT.unindent
122
+ Enables the given Host
123
+ EOT
124
+
125
+ command :enable, enable_desc, [:range,:hostid_list] do
126
+ helper.perform_actions(args[0],options,"enabled") do |host|
127
+ host.enable
128
+ end
129
+ end
130
+
131
+ disable_desc = <<-EOT.unindent
132
+ Disables the given Host
133
+ EOT
134
+
135
+ command :disable, disable_desc, [:range,:hostid_list] do
136
+ helper.perform_actions(args[0],options,"disabled") do |host|
137
+ host.disable
138
+ end
139
+ end
140
+
141
+ update_desc = <<-EOT.unindent
142
+ Update the template contents. If a path is not provided the editor will
143
+ be launched to modify the current content.
144
+ EOT
145
+
146
+ command :update, update_desc, :hostid, [:file, nil] do
147
+ helper.perform_action(args[0],options,"updated") do |host|
148
+ str = OpenNebulaHelper.update_template(args[0], host, args[1])
149
+ host.update(str)
150
+ end
151
+ end
152
+
153
+ sync_desc = <<-EOT.unindent
154
+ Synchronizes probes in /var/lib/one/remotes ($ONE_LOCATION/var/remotes
155
+ in self-contained installations) with Hosts.
156
+ The copy is performed the next time the Host is monitored
157
+ EOT
158
+
159
+ command :sync, sync_desc do
160
+ if ONE_LOCATION
161
+ FileUtils.touch "#{ONE_LOCATION}/var/remotes"
162
+ else
163
+ FileUtils.touch "/var/lib/one/remotes"
164
+ end
165
+ 0
166
+ end
167
+
168
+ list_desc = <<-EOT.unindent
169
+ Lists Hosts in the pool
170
+ EOT
171
+
172
+ command :list, list_desc,
173
+ :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS+
174
+ [OpenNebulaHelper::DESCRIBE] do
175
+ helper.list_pool(options)
176
+ end
177
+
178
+ show_desc = <<-EOT.unindent
179
+ Shows information for the given Host
180
+ EOT
181
+
182
+ command :show, show_desc, :hostid,
183
+ :options=>OpenNebulaHelper::XML do
184
+ helper.show_resource(args[0],options)
185
+ end
186
+
187
+ top_desc = <<-EOT.unindent
188
+ Lists Hosts continuously
189
+ EOT
190
+
191
+ command :top, top_desc,
192
+ :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
193
+ helper.list_pool(options, true)
194
+ end
195
+
196
+ flush_desc = <<-EOT.unindent
197
+ Disables the host and reschedules all the running VMs in it.
198
+ EOT
199
+
200
+ command :flush, flush_desc, [:range,:hostid_list] do
201
+ helper.perform_actions(args[0],options,"flush") do |host|
202
+ host.flush
203
+ end
204
+ end
205
+ end
data/bin/oneimage ADDED
@@ -0,0 +1,311 @@
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/oneimage_helper'
32
+ require 'one_helper/onedatastore_helper'
33
+
34
+ cmd=CommandParser::CmdParser.new(ARGV) do
35
+ usage "`oneimage` <command> [<args>] [<options>]"
36
+ version OpenNebulaHelper::ONE_VERSION
37
+
38
+ helper = OneImageHelper.new
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
+ CREATE_OPTIONS = [OneDatastoreHelper::DATASTORE]
51
+
52
+ ########################################################################
53
+ # Formatters for arguments
54
+ ########################################################################
55
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
56
+ OpenNebulaHelper.rname_to_id(arg, "GROUP")
57
+ end
58
+
59
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
60
+ OpenNebulaHelper.rname_to_id(arg, "USER")
61
+ end
62
+
63
+ set :format, :imageid, OneImageHelper.to_id_desc do |arg|
64
+ helper.to_id(arg)
65
+ end
66
+
67
+ set :format, :imageid_list, OneImageHelper.list_to_id_desc do |arg|
68
+ helper.list_to_id(arg)
69
+ end
70
+
71
+ set :format, :filterflag, OneImageHelper.filterflag_to_i_desc do |arg|
72
+ helper.filterflag_to_i(arg)
73
+ end
74
+
75
+ ########################################################################
76
+ # Commands
77
+ ########################################################################
78
+
79
+ create_desc = <<-EOT.unindent
80
+ Creates a new Image
81
+ Examples:
82
+ - using a template description file:
83
+
84
+ oneimage create -d default centOS.tmpl
85
+
86
+ - new image "arch" using a path of type centOS:
87
+
88
+ oneimage create -d default --name arch --path /tmp/arch.img
89
+
90
+ - new persistent image, OS type and qcow2 format:
91
+
92
+ oneimage create -d 1 --name ubuntu --path /tmp/ubuntu.qcow2 \\
93
+ --prefix sd --type OS --driver qcow2 \\
94
+ --description "A OS plain installation"
95
+
96
+ - a datablock image of 400MB:
97
+
98
+ oneimage create -d 1 --name data --type DATABLOCK --size 400 \\
99
+ --fstype ext2
100
+
101
+ EOT
102
+
103
+ command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS +
104
+ OneImageHelper::TEMPLATE_OPTIONS do
105
+
106
+ if options[:datastore].nil?
107
+ STDERR.puts "Datastore to save the image is mandatory: "
108
+ STDERR.puts "\t -d datastore_id"
109
+ exit -1
110
+ end
111
+
112
+ if args[0] && OpenNebulaHelper.create_template_options_used?(options)
113
+ STDERR.puts "You can not use both template file and template"<<
114
+ " creation options."
115
+ next -1
116
+ end
117
+
118
+ helper.create_resource(options) do |image|
119
+ begin
120
+ if args[0]
121
+ template=File.read(args[0])
122
+ else
123
+ res = OneImageHelper.create_image_template(options)
124
+
125
+ if res.first != 0
126
+ STDERR.puts res.last
127
+ next -1
128
+ end
129
+
130
+ template = res.last
131
+ end
132
+
133
+ image.allocate(template, options[:datastore])
134
+ rescue => e
135
+ STDERR.puts e.messsage
136
+ exit -1
137
+ end
138
+ end
139
+ end
140
+
141
+ clone_desc = <<-EOT.unindent
142
+ Creates a new Image from an existing one
143
+ EOT
144
+
145
+ command :clone, clone_desc, :imageid, :name do
146
+ helper.perform_action(args[0],options,"cloned") do |image|
147
+ res = image.clone(args[1])
148
+
149
+ if !OpenNebula.is_error?(res)
150
+ puts "ID: #{res}"
151
+ else
152
+ puts res.message
153
+ end
154
+ end
155
+ end
156
+
157
+ delete_desc = <<-EOT.unindent
158
+ Deletes the given Image
159
+ EOT
160
+
161
+ command :delete, delete_desc, [:range, :imageid_list] do
162
+ helper.perform_actions(args[0],options,"deleted") do |image|
163
+ image.delete
164
+ end
165
+ end
166
+
167
+ publish_desc = <<-EOT.unindent
168
+ DEPRECATED, use chmod instead. Publishes the given Image. A public Image
169
+ can be seen and used by other users in the Image's group.
170
+ EOT
171
+
172
+ command :publish, publish_desc, [:range,:imageid_list] do
173
+ helper.perform_actions(args[0],options,"published") do |image|
174
+ image.publish
175
+ end
176
+ end
177
+
178
+ unpublish_desc = <<-EOT.unindent
179
+ DEPRECATED, use chmod instead. Unpublishes the given Image. A private
180
+ Image can't be used by any other user.
181
+ EOT
182
+
183
+ command :unpublish, unpublish_desc, [:range,:imageid_list] do
184
+ helper.perform_actions(args[0],options,"unpublished") do |image|
185
+ image.unpublish
186
+ end
187
+ end
188
+
189
+ persistent_desc = <<-EOT.unindent
190
+ Makes the given Image persistent. A persistent Image saves the changes
191
+ made to the contents after the VM instance is shutdown (or in real time
192
+ if a shared FS is used). Persistent Images can be used by only
193
+ one VM instance at a time.
194
+ EOT
195
+
196
+ command :persistent, persistent_desc, [:range,:imageid_list] do
197
+ helper.perform_actions(args[0],options,"made persistent") do |image|
198
+ image.persistent
199
+ end
200
+ end
201
+
202
+ nonpersistent_desc = <<-EOT.unindent
203
+ Makes the given Image non persistent. See 'oneimage persistent'
204
+ EOT
205
+
206
+ command :nonpersistent, nonpersistent_desc, [:range,:imageid_list] do
207
+ helper.perform_actions(args[0],options,"made non persistent") do |image|
208
+ image.nonpersistent
209
+ end
210
+ end
211
+
212
+ update_desc = <<-EOT.unindent
213
+ Update the template contents. If a path is not provided the editor will
214
+ be launched to modify the current content.
215
+ EOT
216
+
217
+ command :update, update_desc, :imageid, [:file, nil] do
218
+ helper.perform_action(args[0],options,"modified") do |image|
219
+ str = OpenNebulaHelper.update_template(args[0], image, args[1])
220
+ image.update(str)
221
+ end
222
+ end
223
+
224
+ enable_desc = <<-EOT.unindent
225
+ Enables the given Image
226
+ EOT
227
+
228
+ command :enable, enable_desc, [:range,:imageid_list] do
229
+ helper.perform_actions(args[0],options,"enabled") do |image|
230
+ image.enable
231
+ end
232
+ end
233
+
234
+ chtype_desc = <<-EOT.unindent
235
+ Changes the Image's type
236
+ EOT
237
+
238
+ command :chtype, chtype_desc,[:range, :imageid_list], :type do
239
+ helper.perform_actions(args[0],options,"Type changed") do |image|
240
+ image.chtype(args[1])
241
+ end
242
+ end
243
+
244
+ disable_desc = <<-EOT.unindent
245
+ Disables the given Image
246
+ EOT
247
+
248
+ command :disable, disable_desc, [:range,:imageid_list] do
249
+ helper.perform_actions(args[0],options,"disabled") do |image|
250
+ image.disable
251
+ end
252
+ end
253
+
254
+ chgrp_desc = <<-EOT.unindent
255
+ Changes the Image group
256
+ EOT
257
+
258
+ command :chgrp, chgrp_desc,[:range, :imageid_list], :groupid do
259
+ helper.perform_actions(args[0],options,"Group changed") do |image|
260
+ image.chown(-1, args[1].to_i)
261
+ end
262
+ end
263
+
264
+ chown_desc = <<-EOT.unindent
265
+ Changes the Image owner and group
266
+ EOT
267
+
268
+ command :chown, chown_desc, [:range, :imageid_list], :userid,
269
+ [:groupid,nil] do
270
+ gid = args[2].nil? ? -1 : args[2].to_i
271
+ helper.perform_actions(args[0],options,
272
+ "Owner/Group changed") do |image|
273
+ image.chown(args[1].to_i, gid)
274
+ end
275
+ end
276
+
277
+ chmod_desc = <<-EOT.unindent
278
+ Changes the Image permissions
279
+ EOT
280
+
281
+ command :chmod, chmod_desc, [:range, :imageid_list], :octet do
282
+ helper.perform_actions(args[0],options,
283
+ "Permissions changed") do |image|
284
+ image.chmod_octet(args[1])
285
+ end
286
+ end
287
+
288
+ list_desc = <<-EOT.unindent
289
+ Lists Images in the pool
290
+ EOT
291
+
292
+ command :list, list_desc, [:filterflag, nil], :options=>list_options do
293
+ helper.list_pool(options, false, args[0])
294
+ end
295
+
296
+ show_desc = <<-EOT.unindent
297
+ Shows information for the given Image
298
+ EOT
299
+
300
+ command :show, show_desc, :imageid, :options=>OpenNebulaHelper::XML do
301
+ helper.show_resource(args[0],options)
302
+ end
303
+
304
+ top_desc = <<-EOT.unindent
305
+ Lists Images continuously
306
+ EOT
307
+
308
+ command :top, top_desc, [:filterflag, nil], :options=>list_options do
309
+ helper.list_pool(options, true, args[0])
310
+ end
311
+ end