opennebula-cli 3.8.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/oneacct +113 -0
- data/bin/oneacl +97 -0
- data/bin/onecluster +189 -0
- data/bin/onedatastore +165 -0
- data/bin/onegroup +137 -0
- data/bin/onehost +205 -0
- data/bin/oneimage +311 -0
- data/bin/onetemplate +277 -0
- data/bin/oneuser +404 -0
- data/bin/onevm +532 -0
- data/bin/onevnet +227 -0
- data/lib/cli_helper.rb +294 -0
- data/lib/command_parser.rb +719 -0
- data/lib/one_helper/oneacct_helper.rb +179 -0
- data/lib/one_helper/oneacl_helper.rb +130 -0
- data/lib/one_helper/onecluster_helper.rb +129 -0
- data/lib/one_helper/onedatastore_helper.rb +131 -0
- data/lib/one_helper/onegroup_helper.rb +134 -0
- data/lib/one_helper/onehost_helper.rb +196 -0
- data/lib/one_helper/oneimage_helper.rb +327 -0
- data/lib/one_helper/onequota_helper.rb +256 -0
- data/lib/one_helper/onetemplate_helper.rb +123 -0
- data/lib/one_helper/oneuser_helper.rb +242 -0
- data/lib/one_helper/onevm_helper.rb +266 -0
- data/lib/one_helper/onevnet_helper.rb +156 -0
- data/lib/one_helper.rb +609 -0
- metadata +93 -0
data/bin/oneacct
ADDED
@@ -0,0 +1,113 @@
|
|
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/oneacct_helper'
|
32
|
+
|
33
|
+
require 'json'
|
34
|
+
|
35
|
+
cmd = CommandParser::CmdParser.new(ARGV) do
|
36
|
+
usage "`oneacct` [<options>]"
|
37
|
+
description ""
|
38
|
+
version OpenNebulaHelper::ONE_VERSION
|
39
|
+
|
40
|
+
|
41
|
+
option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS
|
42
|
+
|
43
|
+
main do
|
44
|
+
filter_flag = (options[:user] || VirtualMachinePool::INFO_ALL)
|
45
|
+
start_time = options[:start] ? options[:start].to_i : -1
|
46
|
+
end_time = options[:end] ? options[:end].to_i : -1
|
47
|
+
|
48
|
+
common_opts = {
|
49
|
+
:start_time => start_time,
|
50
|
+
:end_time => end_time,
|
51
|
+
:host => options[:host],
|
52
|
+
:group => options[:group],
|
53
|
+
:xpath => options[:xpath]
|
54
|
+
}
|
55
|
+
|
56
|
+
client = OpenNebula::Client.new
|
57
|
+
pool = OpenNebula::VirtualMachinePool.new(client)
|
58
|
+
|
59
|
+
|
60
|
+
if options[:json] || options[:xml]
|
61
|
+
xml_str = pool.accounting_xml(filter_flag, common_opts)
|
62
|
+
if OpenNebula.is_error?(xml_str)
|
63
|
+
puts acct_hash.message
|
64
|
+
exit -1
|
65
|
+
end
|
66
|
+
|
67
|
+
if options[:json]
|
68
|
+
xmldoc = XMLElement.new
|
69
|
+
xmldoc.initialize_xml(xml_str, 'HISTORY_RECORDS')
|
70
|
+
|
71
|
+
puts JSON.pretty_generate(xmldoc.to_hash)
|
72
|
+
elsif options[:xml]
|
73
|
+
puts xml_str
|
74
|
+
end
|
75
|
+
|
76
|
+
exit_code 0
|
77
|
+
else
|
78
|
+
order_by = Hash.new
|
79
|
+
order_by[:order_by_1] = 'VM/UID'
|
80
|
+
order_by[:order_by_2] = 'VM/ID' if options[:split]
|
81
|
+
|
82
|
+
acct_hash = pool.accounting(filter_flag, common_opts.merge(order_by))
|
83
|
+
if OpenNebula.is_error?(acct_hash)
|
84
|
+
puts acct_hash.message
|
85
|
+
exit -1
|
86
|
+
end
|
87
|
+
|
88
|
+
if ( start_time != -1 or end_time != -1 )
|
89
|
+
AcctHelper.print_start_end_time_header(start_time, end_time)
|
90
|
+
end
|
91
|
+
|
92
|
+
acct_hash.each { |user_id, value|
|
93
|
+
AcctHelper.print_user_header(user_id)
|
94
|
+
|
95
|
+
if options[:split]
|
96
|
+
# Use one table for each VM
|
97
|
+
value.each { |vm_id, history_array|
|
98
|
+
array = history_array['HISTORY_RECORDS']['HISTORY']
|
99
|
+
AcctHelper::ACCT_TABLE.show(array)
|
100
|
+
puts
|
101
|
+
}
|
102
|
+
else
|
103
|
+
# Use the same table for all the VMs
|
104
|
+
array = value['HISTORY_RECORDS']['HISTORY']
|
105
|
+
AcctHelper::ACCT_TABLE.show(array)
|
106
|
+
puts
|
107
|
+
end
|
108
|
+
}
|
109
|
+
|
110
|
+
exit_code 0
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/bin/oneacl
ADDED
@@ -0,0 +1,97 @@
|
|
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/oneacl_helper'
|
32
|
+
|
33
|
+
cmd = CommandParser::CmdParser.new(ARGV) do
|
34
|
+
usage "`oneacl` <command> [<args>] [<options>]"
|
35
|
+
version OpenNebulaHelper::ONE_VERSION
|
36
|
+
|
37
|
+
helper = OneAclHelper.new
|
38
|
+
|
39
|
+
########################################################################
|
40
|
+
# Global Options
|
41
|
+
########################################################################
|
42
|
+
set :option, CommandParser::OPTIONS
|
43
|
+
|
44
|
+
########################################################################
|
45
|
+
# Formatters for arguments
|
46
|
+
########################################################################
|
47
|
+
set :format, :aclid_list, OneAclHelper.list_to_id_desc do |arg|
|
48
|
+
helper.list_to_id(arg)
|
49
|
+
end
|
50
|
+
|
51
|
+
########################################################################
|
52
|
+
# Commands
|
53
|
+
########################################################################
|
54
|
+
|
55
|
+
addrule_desc = <<-EOT.unindent
|
56
|
+
Adds a new ACL rule
|
57
|
+
EOT
|
58
|
+
|
59
|
+
command :create, addrule_desc, [:user,:rulestr], [:resource, nil],
|
60
|
+
[:rights, nil] do
|
61
|
+
case args.length
|
62
|
+
when 1
|
63
|
+
new_args = Acl.parse_rule(args[0])
|
64
|
+
|
65
|
+
if OpenNebula.is_error?(new_args)
|
66
|
+
next -1, new_args.message
|
67
|
+
end
|
68
|
+
when 3
|
69
|
+
new_args=args
|
70
|
+
else
|
71
|
+
next -1, "Wrong number of arguments, must be 1 or 3"
|
72
|
+
end
|
73
|
+
|
74
|
+
helper.create_resource(options) do |rule|
|
75
|
+
rule.allocate(*new_args)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
delrule_desc = <<-EOT.unindent
|
80
|
+
Deletes an existing ACL rule
|
81
|
+
EOT
|
82
|
+
|
83
|
+
command :delete, delrule_desc, [:range] do
|
84
|
+
helper.perform_actions(args[0],options,"deleted") do |obj|
|
85
|
+
obj.delete
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
list_desc = <<-EOT.unindent
|
90
|
+
Lists the ACL rule set
|
91
|
+
EOT
|
92
|
+
|
93
|
+
command :list, list_desc,:options=>[OpenNebulaHelper::XML,
|
94
|
+
OpenNebulaHelper::DESCRIBE] do
|
95
|
+
helper.list_pool( options )
|
96
|
+
end
|
97
|
+
end
|
data/bin/onecluster
ADDED
@@ -0,0 +1,189 @@
|
|
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/onecluster_helper'
|
32
|
+
|
33
|
+
cmd=CommandParser::CmdParser.new(ARGV) do
|
34
|
+
usage "`onecluster` <command> [<args>] [<options>]"
|
35
|
+
version OpenNebulaHelper::ONE_VERSION
|
36
|
+
|
37
|
+
helper = OneClusterHelper.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, :clusterid, OneClusterHelper.to_id_desc do |arg|
|
53
|
+
helper.to_id(arg)
|
54
|
+
end
|
55
|
+
|
56
|
+
set :format, :clusterid_list, OneClusterHelper.list_to_id_desc do |arg|
|
57
|
+
helper.list_to_id(arg)
|
58
|
+
end
|
59
|
+
|
60
|
+
set :format, :vnetid, OpenNebulaHelper.rname_to_id_desc("VNET") do |arg|
|
61
|
+
OpenNebulaHelper.rname_to_id(arg, "VNET")
|
62
|
+
end
|
63
|
+
|
64
|
+
set :format, :hostid, OpenNebulaHelper.rname_to_id_desc("HOST") do |arg|
|
65
|
+
OpenNebulaHelper.rname_to_id(arg, "HOST")
|
66
|
+
end
|
67
|
+
|
68
|
+
set :format, :datastoreid, OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg|
|
69
|
+
OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
|
70
|
+
end
|
71
|
+
|
72
|
+
########################################################################
|
73
|
+
# Commands
|
74
|
+
########################################################################
|
75
|
+
|
76
|
+
create_desc = <<-EOT.unindent
|
77
|
+
Creates a new Cluster
|
78
|
+
EOT
|
79
|
+
|
80
|
+
command :create, create_desc, :name do
|
81
|
+
helper.create_resource(options) do |cluster|
|
82
|
+
cluster.allocate(args[0])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
delete_desc = <<-EOT.unindent
|
87
|
+
Deletes the given Cluster
|
88
|
+
EOT
|
89
|
+
|
90
|
+
command :delete, delete_desc, [:range, :clusterid_list] do
|
91
|
+
helper.perform_actions(args[0],options,"deleted") do |obj|
|
92
|
+
obj.delete
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
list_desc = <<-EOT.unindent
|
97
|
+
Lists Clusters in the pool
|
98
|
+
EOT
|
99
|
+
|
100
|
+
command :list, list_desc, :options=>list_options do
|
101
|
+
helper.list_pool(options)
|
102
|
+
end
|
103
|
+
|
104
|
+
show_desc = <<-EOT.unindent
|
105
|
+
Shows information for the given Cluster
|
106
|
+
EOT
|
107
|
+
|
108
|
+
command :show, show_desc,:clusterid, :options=>OpenNebulaHelper::XML do
|
109
|
+
helper.show_resource(args[0],options)
|
110
|
+
end
|
111
|
+
|
112
|
+
addhost_desc = <<-EOT.unindent
|
113
|
+
Adds a Host to the given Cluster
|
114
|
+
EOT
|
115
|
+
|
116
|
+
# TODO: allow the second param to be [:range, :hostid_list]
|
117
|
+
command :addhost, addhost_desc,:clusterid, :hostid do
|
118
|
+
helper.perform_action(args[0],options,"updated") do |cluster|
|
119
|
+
cluster.addhost(args[1].to_i)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
delhost_desc = <<-EOT.unindent
|
124
|
+
Deletes a Host from the given Cluster
|
125
|
+
EOT
|
126
|
+
|
127
|
+
# TODO: allow the second param to be [:range, :hostid_list]
|
128
|
+
command :delhost, delhost_desc, :clusterid, :hostid do
|
129
|
+
helper.perform_action(args[0],options,"updated") do |cluster|
|
130
|
+
cluster.delhost(args[1].to_i)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
adddatastore_desc = <<-EOT.unindent
|
135
|
+
Adds a Datastore to the given Cluster
|
136
|
+
EOT
|
137
|
+
|
138
|
+
# TODO: allow the second param to be [:range, :datastoreid_list]
|
139
|
+
command :adddatastore, adddatastore_desc,:clusterid, :datastoreid do
|
140
|
+
helper.perform_action(args[0],options,"updated") do |cluster|
|
141
|
+
cluster.adddatastore(args[1].to_i)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
deldatastore_desc = <<-EOT.unindent
|
146
|
+
Deletes a Datastore from the given Cluster
|
147
|
+
EOT
|
148
|
+
|
149
|
+
# TODO: allow the second param to be [:range, :datastoreid_list]
|
150
|
+
command :deldatastore, deldatastore_desc, :clusterid, :datastoreid do
|
151
|
+
helper.perform_action(args[0],options,"updated") do |cluster|
|
152
|
+
cluster.deldatastore(args[1].to_i)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
addvnet_desc = <<-EOT.unindent
|
157
|
+
Adds a Virtual Network to the given Cluster
|
158
|
+
EOT
|
159
|
+
|
160
|
+
# TODO: allow the second param to be [:range, :vnetid_list]
|
161
|
+
command :addvnet, addvnet_desc,:clusterid, :vnetid do
|
162
|
+
helper.perform_action(args[0],options,"updated") do |cluster|
|
163
|
+
cluster.addvnet(args[1].to_i)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
delvnet_desc = <<-EOT.unindent
|
168
|
+
Deletes a Virtual Network from the given Cluster
|
169
|
+
EOT
|
170
|
+
|
171
|
+
# TODO: allow the second param to be [:range, :vnetid_list]
|
172
|
+
command :delvnet, delvnet_desc,:clusterid, :vnetid do
|
173
|
+
helper.perform_action(args[0],options,"updated") do |cluster|
|
174
|
+
cluster.delvnet(args[1].to_i)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
update_desc = <<-EOT.unindent
|
179
|
+
Update the template contents. If a path is not provided the editor will
|
180
|
+
be launched to modify the current content.
|
181
|
+
EOT
|
182
|
+
|
183
|
+
command :update, update_desc, :clusterid, [:file, nil] do
|
184
|
+
helper.perform_action(args[0],options,"modified") do |obj|
|
185
|
+
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
|
186
|
+
obj.update(str)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
data/bin/onedatastore
ADDED
@@ -0,0 +1,165 @@
|
|
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/onedatastore_helper'
|
32
|
+
require 'one_helper/onecluster_helper'
|
33
|
+
|
34
|
+
cmd=CommandParser::CmdParser.new(ARGV) do
|
35
|
+
usage "`onedatastore` <command> [<args>] [<options>]"
|
36
|
+
version OpenNebulaHelper::ONE_VERSION
|
37
|
+
|
38
|
+
helper = OneDatastoreHelper.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
|
+
########################################################################
|
51
|
+
# Formatters for arguments
|
52
|
+
########################################################################
|
53
|
+
set :format, :datastoreid, OneDatastoreHelper.to_id_desc do |arg|
|
54
|
+
helper.to_id(arg)
|
55
|
+
end
|
56
|
+
|
57
|
+
set :format, :datastoreid_list, OneDatastoreHelper.list_to_id_desc do |arg|
|
58
|
+
helper.list_to_id(arg)
|
59
|
+
end
|
60
|
+
|
61
|
+
set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg|
|
62
|
+
OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
|
63
|
+
end
|
64
|
+
|
65
|
+
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
66
|
+
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
67
|
+
end
|
68
|
+
|
69
|
+
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
70
|
+
OpenNebulaHelper.rname_to_id(arg, "USER")
|
71
|
+
end
|
72
|
+
|
73
|
+
########################################################################
|
74
|
+
# Commands
|
75
|
+
########################################################################
|
76
|
+
|
77
|
+
create_desc = <<-EOT.unindent
|
78
|
+
Creates a new Datastore from the given template file
|
79
|
+
EOT
|
80
|
+
|
81
|
+
command :create, create_desc, :file, :options=>[OneClusterHelper::CLUSTER] do
|
82
|
+
|
83
|
+
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
|
84
|
+
|
85
|
+
helper.create_resource(options) do |datastore|
|
86
|
+
begin
|
87
|
+
template=File.read(args[0])
|
88
|
+
datastore.allocate(template, cid)
|
89
|
+
rescue =>e
|
90
|
+
STDERR.puts e.message
|
91
|
+
exit -1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
delete_desc = <<-EOT.unindent
|
97
|
+
Deletes the given Datastore
|
98
|
+
EOT
|
99
|
+
|
100
|
+
command :delete, delete_desc, [:range, :datastoreid_list] do
|
101
|
+
helper.perform_actions(args[0],options,"deleted") do |obj|
|
102
|
+
obj.delete
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
chgrp_desc = <<-EOT.unindent
|
107
|
+
Changes the Datastore group
|
108
|
+
EOT
|
109
|
+
|
110
|
+
command :chgrp, chgrp_desc,[:range, :datastoreid_list], :groupid do
|
111
|
+
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
112
|
+
obj.chown(-1, args[1].to_i)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
chown_desc = <<-EOT.unindent
|
117
|
+
Changes the Datastore owner and group
|
118
|
+
EOT
|
119
|
+
|
120
|
+
command :chown, chown_desc, [:range, :datastoreid_list], :userid,
|
121
|
+
[:groupid,nil] do
|
122
|
+
gid = args[2].nil? ? -1 : args[2].to_i
|
123
|
+
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
124
|
+
obj.chown(args[1].to_i, gid)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
chmod_desc = <<-EOT.unindent
|
129
|
+
Changes the Datastore permissions
|
130
|
+
EOT
|
131
|
+
|
132
|
+
command :chmod, chmod_desc, [:range, :datastoreid_list], :octet do
|
133
|
+
helper.perform_actions(args[0],options, "Permissions changed") do |obj|
|
134
|
+
obj.chmod_octet(args[1])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
list_desc = <<-EOT.unindent
|
139
|
+
Lists Datastores in the pool
|
140
|
+
EOT
|
141
|
+
|
142
|
+
command :list, list_desc, :options=>list_options do
|
143
|
+
helper.list_pool(options)
|
144
|
+
end
|
145
|
+
|
146
|
+
show_desc = <<-EOT.unindent
|
147
|
+
Shows information for the given Datastore
|
148
|
+
EOT
|
149
|
+
|
150
|
+
command :show, show_desc, :datastoreid, :options=>OpenNebulaHelper::XML do
|
151
|
+
helper.show_resource(args[0],options)
|
152
|
+
end
|
153
|
+
|
154
|
+
update_desc = <<-EOT.unindent
|
155
|
+
Update the template contents. If a path is not provided the editor will
|
156
|
+
be launched to modify the current content.
|
157
|
+
EOT
|
158
|
+
|
159
|
+
command :update, update_desc, :datastoreid, [:file, nil] do
|
160
|
+
helper.perform_action(args[0],options,"modified") do |obj|
|
161
|
+
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
|
162
|
+
obj.update(str)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|