opennebula-cli 4.10.2 → 4.11.80.beta

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b27f616d275440e4bfb83d9ec0b519361ed4abf
4
- data.tar.gz: c104259923ec8765e0e1cefcdf504204ec743ea4
3
+ metadata.gz: 6e4f0451ba3ef3e474e98228a2a9b1868f1a27d3
4
+ data.tar.gz: 1dd02015422f89b681ba391dd50b5b12d611c010
5
5
  SHA512:
6
- metadata.gz: 1ea168960417e9bf0efd193f4f9cc89a9faa88ffe7a459ae438051ba5944828ae2407f4002ac032be8ad713ac2c1be6a9e1274fd4bbc6454cfe67b8fd4c479ff
7
- data.tar.gz: 598dc916b8552ada376587ac6940fccb443efe8401bb912d1aa7074e7461bcc2ad2f2edadc7fe9d1c1403d737618f986f1546ab7aa0bc4f13bb18a02655c1297
6
+ metadata.gz: 5cfcc2c25006feb5fc24d715d759fa8e920699a413472f29dff1eb8ab9a1cc01e6c5d7f2d385f002e32807a5a6247b2bbc5425b5ec7b7232258235369a74e6a4
7
+ data.tar.gz: dba097702f2bac297a871367aca4345ad97ad245c921591f5cdae8bd646e1433ca0fe612ed2fb2d4036a254d21091eec4db8eaaa2c69cbcef8727b9c241c36bb
data/bin/oneacct CHANGED
@@ -55,7 +55,21 @@ cmd = CommandParser::CmdParser.new(ARGV) do
55
55
 
56
56
  filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
57
57
  start_time = options[:start_time] ? options[:start_time].to_i : -1
58
- end_time = options[:end_time] ? options[:end_time].to_i : -1
58
+
59
+ end_time = -1
60
+
61
+ if (!options[:end_time].nil?)
62
+ # Not the safest way to add a day, but since managing date/time
63
+ # in ruby is... not entirely convenient, this will do
64
+
65
+ t = options[:end_time]
66
+
67
+ if (t.hour == 0 && t.min == 0 && t.sec == 0)
68
+ t += 24*60*60
69
+ end
70
+
71
+ end_time = t.to_i
72
+ end
59
73
 
60
74
  common_opts = {
61
75
  :start_time => start_time,
@@ -70,7 +84,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do
70
84
  if options[:json] || options[:xml]
71
85
  xml_str = pool.accounting_xml(filter_flag, common_opts)
72
86
  if OpenNebula.is_error?(xml_str)
73
- puts acct_hash.message
87
+ puts xml_str.message
74
88
  exit -1
75
89
  end
76
90
 
data/bin/onedatastore CHANGED
@@ -184,4 +184,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
184
184
  o.rename(args[1])
185
185
  end
186
186
  end
187
+
188
+ enable_desc = <<-EOT.unindent
189
+ Enables the given Datastore. Only available for System Datastores
190
+ EOT
191
+
192
+ command :enable, enable_desc, [:range,:datastoreid_list] do
193
+ helper.perform_actions(args[0],options,"enabled") do |obj|
194
+ obj.enable
195
+ end
196
+ end
197
+
198
+ disable_desc = <<-EOT.unindent
199
+ Disables the given Datastore. Only available for System Datastores
200
+ EOT
201
+
202
+ command :disable, disable_desc, [:range,:datastoreid_list] do
203
+ helper.perform_actions(args[0],options,"disabled") do |obj|
204
+ obj.disable
205
+ end
206
+ end
187
207
  end
data/bin/onegroup CHANGED
@@ -61,12 +61,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
61
61
  helper.list_to_id(arg)
62
62
  end
63
63
 
64
- set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg|
65
- OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
66
- end
67
-
68
- set :format, :zoneid, OpenNebulaHelper.rname_to_id_desc("ZONE") do |arg|
69
- OpenNebulaHelper.rname_to_id(arg, "ZONE")
64
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
65
+ OpenNebulaHelper.rname_to_id(arg, "USER")
70
66
  end
71
67
 
72
68
  ########################################################################
@@ -75,18 +71,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
75
71
 
76
72
  create_desc = <<-EOT.unindent
77
73
  Creates a new Group. A group name can be passed as the only argument,
78
- or a file containing a group template or via command line arguments
74
+ or via command line arguments
79
75
 
80
76
  Examples:
81
77
 
82
- - create a group with admin user and allow group users
83
- to only create new templates and VMs, and group admin to manage
84
- templates, vms, images and virtual networks
78
+ - create a group with an admin user and allow group users
79
+ to only create new templates and VMs
85
80
 
86
81
  onegroup create --name groupA
87
82
  --admin_user admin_userA --admin_password somestr
88
83
  --resources TEMPLATE+VM
89
- --admin_resources TEMPLATE+VM+IMAGE+NET
90
84
 
91
85
  EOT
92
86
 
@@ -95,7 +89,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
95
89
 
96
90
 
97
91
  if !args[0] && options.empty?
98
- STDERR.puts "Please use either a group name or command arguments"
92
+ STDERR.puts "Please use either a group name or command arguments."<<
93
+ " Run onegroup create -h for more information"
99
94
  next -1
100
95
  end
101
96
 
@@ -109,7 +104,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
109
104
  admin_user[:name] = options[:admin_user]
110
105
  admin_user[:password] = options[:admin_password]
111
106
  admin_user[:auth_driver]= options[:admin_driver] if options[:admin_driver]
112
- admin_user[:resources] = options[:admin_resources] if options[:admin_resources]
113
107
 
114
108
  options[:group_admin] = admin_user
115
109
  end
@@ -167,6 +161,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
167
161
  helper.show_resource(group,options)
168
162
  end
169
163
 
164
+ add_admin_desc = <<-EOT.unindent
165
+ Adds a User to the Group administrators set
166
+ EOT
167
+
168
+ command :addadmin, add_admin_desc, [:range, :groupid_list], :userid do
169
+ helper.perform_actions(args[0],options,"admin added") do |obj|
170
+ obj.add_admin(args[1].to_i)
171
+ end
172
+ end
173
+
174
+ del_admin_desc = <<-EOT.unindent
175
+ Removes a User from the Group administrators set
176
+ EOT
177
+
178
+ command :deladmin, del_admin_desc, [:range, :groupid_list], :userid do
179
+ helper.perform_actions(args[0],options,"admin deleted") do |obj|
180
+ obj.del_admin(args[1].to_i)
181
+ end
182
+ end
183
+
170
184
  quota_desc = <<-EOT.unindent
171
185
  Set the quota limits for the group. If a path is not provided the
172
186
  editor will be launched to modify the current quotas.
@@ -239,33 +253,4 @@ cmd=CommandParser::CmdParser.new(ARGV) do
239
253
 
240
254
  exit 0
241
255
  end
242
-
243
- add_provider_desc = <<-EOT.unindent
244
- Adds a resource provider (cluster of a zone) to the given group.
245
- clusterid can be set to ALL
246
- EOT
247
-
248
- command :add_provider, add_provider_desc, [:range, :groupid_list], :zoneid, :clusterid do
249
- if args[2] and args[2].class != Fixnum and args[2].upcase == "ALL"
250
- args[2]=10
251
- end
252
-
253
- helper.perform_actions(args[0],options,"resource provider added") do |obj|
254
- obj.add_provider(args[1].to_i, args[2].to_i)
255
- end
256
- end
257
-
258
- del_provider_desc = <<-EOT.unindent
259
- Deletes a resource provider (cluster of a zone) from the given group
260
- clusterid can be set to ALL
261
- EOT
262
-
263
- command :del_provider, del_provider_desc, [:range, :groupid_list], :zoneid, :clusterid do
264
- if args[2] and args[2].class != Fixnum and args[2].upcase == "ALL"
265
- args[2]=10
266
- end
267
- helper.perform_actions(args[0],options,"resource provider deleted") do |obj|
268
- obj.del_provider(args[1].to_i, args[2].to_i)
269
- end
270
- end
271
256
  end
data/bin/onesecgroup ADDED
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
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/onesecgroup_helper'
32
+
33
+ cmd=CommandParser::CmdParser.new(ARGV) do
34
+ usage "`onesecgroup` <command> [<args>] [<options>]"
35
+ version OpenNebulaHelper::ONE_VERSION
36
+
37
+ helper = OneSecurityGroupHelper.new
38
+
39
+ before_proc do
40
+ helper.set_client(options)
41
+ end
42
+
43
+ ########################################################################
44
+ # Global Options
45
+ ########################################################################
46
+ set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
47
+
48
+ list_options = CLIHelper::OPTIONS
49
+ list_options << OpenNebulaHelper::XML
50
+ list_options << OpenNebulaHelper::NUMERIC
51
+ list_options << OpenNebulaHelper::DESCRIBE
52
+
53
+ ########################################################################
54
+ # Formatters for arguments
55
+ ########################################################################
56
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
57
+ OpenNebulaHelper.rname_to_id(arg, "GROUP")
58
+ end
59
+
60
+ set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
61
+ OpenNebulaHelper.rname_to_id(arg, "USER")
62
+ end
63
+
64
+ set :format, :secgroupid, OneSecurityGroupHelper.to_id_desc do |arg|
65
+ helper.to_id(arg)
66
+ end
67
+
68
+ set :format, :secgroupid_list, OneSecurityGroupHelper.list_to_id_desc do |arg|
69
+ helper.list_to_id(arg)
70
+ end
71
+
72
+ set :format, :filterflag, OneSecurityGroupHelper.filterflag_to_i_desc do |arg|
73
+ helper.filterflag_to_i(arg)
74
+ end
75
+
76
+ ########################################################################
77
+ # Commands
78
+ ########################################################################
79
+
80
+ create_desc = <<-EOT.unindent
81
+ Creates a new Security Group from the given description
82
+ EOT
83
+
84
+ command :create, create_desc, :file do
85
+ helper.create_resource(options) do |obj|
86
+ begin
87
+ template = File.read(args[0])
88
+
89
+ obj.allocate(template)
90
+ rescue => e
91
+ STDERR.puts e.messsage
92
+ exit -1
93
+ end
94
+ end
95
+ end
96
+
97
+ clone_desc = <<-EOT.unindent
98
+ Creates a new Security Group from an existing one
99
+ EOT
100
+
101
+ command :clone, clone_desc, :secgroupid, :name do
102
+ helper.perform_action(args[0],options,"cloned") do |obj|
103
+ res = obj.clone(args[1])
104
+
105
+ if !OpenNebula.is_error?(res)
106
+ puts "ID: #{res}"
107
+ else
108
+ puts res.message
109
+ end
110
+ end
111
+ end
112
+
113
+ delete_desc = <<-EOT.unindent
114
+ Deletes the given Security Group
115
+ EOT
116
+
117
+ command :delete, delete_desc, [:range, :secgroupid_list] do
118
+ helper.perform_actions(args[0],options,"deleted") do |obj|
119
+ obj.delete
120
+ end
121
+ end
122
+
123
+ chgrp_desc = <<-EOT.unindent
124
+ Changes the Security Group's group
125
+ EOT
126
+
127
+ command :chgrp, chgrp_desc,[:range, :secgroupid_list], :groupid do
128
+ helper.perform_actions(args[0],options,"Group changed") do |obj|
129
+ obj.chown(-1, args[1].to_i)
130
+ end
131
+ end
132
+
133
+ chown_desc = <<-EOT.unindent
134
+ Changes the Security Group's owner and group
135
+ EOT
136
+
137
+ command :chown, chown_desc, [:range, :secgroupid_list], :userid,
138
+ [:groupid,nil] do
139
+ gid = args[2].nil? ? -1 : args[2].to_i
140
+ helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
141
+ obj.chown(args[1].to_i, gid)
142
+ end
143
+ end
144
+
145
+ chmod_desc = <<-EOT.unindent
146
+ Changes the Security Group permissions
147
+ EOT
148
+
149
+ command :chmod, chmod_desc, [:range, :secgroupid_list], :octet do
150
+ helper.perform_actions(args[0],options, "Permissions changed") do |t|
151
+ t.chmod_octet(args[1])
152
+ end
153
+ end
154
+
155
+ update_desc = <<-EOT.unindent
156
+ Update the template contents. If a path is not provided the editor will
157
+ be launched to modify the current content.
158
+ EOT
159
+
160
+ command :update, update_desc, :secgroupid, [:file, nil],
161
+ :options=>OpenNebulaHelper::APPEND do
162
+ helper.perform_action(args[0],options,"modified") do |obj|
163
+ if options[:append]
164
+ str = OpenNebulaHelper.append_template(args[0], obj, args[1])
165
+ else
166
+ str = OpenNebulaHelper.update_template(args[0], obj, args[1])
167
+ end
168
+
169
+ obj.update(str, options[:append])
170
+ end
171
+ end
172
+
173
+ rename_desc = <<-EOT.unindent
174
+ Renames the Security Group
175
+ EOT
176
+
177
+ command :rename, rename_desc, :secgroupid, :name do
178
+ helper.perform_action(args[0],options,"renamed") do |o|
179
+ o.rename(args[1])
180
+ end
181
+ end
182
+
183
+ list_desc = <<-EOT.unindent
184
+ Lists Security Group in the pool
185
+ EOT
186
+
187
+ command :list, list_desc, [:filterflag, nil], :options=>list_options do
188
+ helper.list_pool(options, false, args[0])
189
+ end
190
+
191
+ show_desc = <<-EOT.unindent
192
+ Shows information for the given Security Group
193
+ EOT
194
+
195
+ command :show, show_desc, :secgroupid, :options=>OpenNebulaHelper::XML do
196
+ helper.show_resource(args[0],options)
197
+ end
198
+ end
data/bin/oneshowback ADDED
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
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
+
37
+ @formats = Hash.new
38
+
39
+ usage "`oneshowback` <command> [<options>]"
40
+ description ""
41
+ version OpenNebulaHelper::ONE_VERSION
42
+
43
+ helper=OpenNebulaHelper::OneHelper.new
44
+
45
+ before_proc do
46
+ helper.set_client(options)
47
+ end
48
+
49
+ command :list, "Returns the showback records", :options =>
50
+ AcctHelper::SHOWBACK_OPTIONS + CommandParser::OPTIONS +
51
+ [OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
52
+ OpenNebulaHelper::CLIENT_OPTIONS do
53
+
54
+ if options[:describe]
55
+ AcctHelper::SHOWBACK_TABLE.describe_columns
56
+ exit(0)
57
+ end
58
+
59
+ filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
60
+
61
+ start_month = -1
62
+ start_year = -1
63
+
64
+ if (options[:start_time])
65
+ start_month = options[:start_time].month
66
+ start_year = options[:start_time].year
67
+ end
68
+
69
+ end_month = -1
70
+ end_year = -1
71
+
72
+ if (options[:end_time])
73
+ end_month = options[:end_time].month
74
+ end_year = options[:end_time].year
75
+ end
76
+
77
+ common_opts = {
78
+ :start_month => start_month,
79
+ :start_year => start_year,
80
+ :end_month => end_month,
81
+ :end_year => end_year,
82
+ :group => options[:group],
83
+ :xpath => options[:xpath]
84
+ }
85
+
86
+ pool = OpenNebula::VirtualMachinePool.new(helper.client)
87
+
88
+ if options[:json] || options[:xml]
89
+ xml_str = pool.showback_xml(filter_flag, common_opts)
90
+ if OpenNebula.is_error?(xml_str)
91
+ puts xml_str.message
92
+ exit -1
93
+ end
94
+
95
+ if options[:json]
96
+ xmldoc = XMLElement.new
97
+ xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
98
+
99
+ puts JSON.pretty_generate(xmldoc.to_hash)
100
+ elsif options[:xml]
101
+ puts xml_str
102
+ end
103
+
104
+ exit_code 0
105
+ else
106
+
107
+ order_by = Hash.new
108
+ if !options[:csv]
109
+ order_by[:order_by_1] = 'YEAR'
110
+ order_by[:order_by_2] = 'MONTH'
111
+ end
112
+
113
+ data_hash = pool.showback(filter_flag,
114
+ common_opts.merge(order_by))
115
+ if OpenNebula.is_error?(data_hash)
116
+ puts data_hash.message
117
+ exit -1
118
+ end
119
+
120
+ if options[:csv]
121
+ a = Array.new
122
+
123
+ if data_hash['SHOWBACK_RECORDS']
124
+ a = data_hash['SHOWBACK_RECORDS']['SHOWBACK']
125
+ end
126
+
127
+ AcctHelper::SHOWBACK_TABLE.show(a, options)
128
+ exit(0)
129
+ end
130
+
131
+ data_hash.each { |year, value|
132
+ value.each { |month, showback_array|
133
+ AcctHelper.print_month_header(year, month)
134
+
135
+ array = showback_array['SHOWBACK_RECORDS']['SHOWBACK']
136
+ AcctHelper::SHOWBACK_TABLE.show(array, options)
137
+ puts
138
+ }
139
+
140
+ }
141
+
142
+ exit_code 0
143
+ end
144
+ end
145
+
146
+ command :"calculate", "Calculates the showback records", :options =>
147
+ [AcctHelper::START_TIME_SHOWBACK, AcctHelper::END_TIME_SHOWBACK] do
148
+
149
+
150
+ start_month = -1
151
+ start_year = -1
152
+
153
+ if (options[:start_time])
154
+ start_month = options[:start_time].month
155
+ start_year = options[:start_time].year
156
+ end
157
+
158
+ end_month = -1
159
+ end_year = -1
160
+
161
+ if (options[:end_time])
162
+ end_month = options[:end_time].month
163
+ end_year = options[:end_time].year
164
+ end
165
+
166
+ rc = OpenNebula::VirtualMachinePool.new(helper.client).
167
+ calculate_showback(start_month, start_year, end_month, end_year)
168
+
169
+ if OpenNebula.is_error?(rc)
170
+ warn rc.message
171
+ exit -1
172
+ else
173
+ puts rc
174
+ exit_code 0
175
+ end
176
+
177
+ end
178
+ end