opennebula-cli 6.6.2 → 6.7.80.pre

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/onevmgroup CHANGED
@@ -108,7 +108,9 @@ CommandParser::CmdParser.new(ARGV) do
108
108
  end
109
109
 
110
110
  set :format, :vmgroupid, OneVMGroupHelper.to_id_desc do |arg|
111
- helper.to_id(arg)
111
+ tmp = helper.to_id(arg)
112
+ @current_vmg = tmp[1]
113
+ tmp
112
114
  end
113
115
 
114
116
  set :format, :vmgroupid_list, OneVMGroupHelper.list_to_id_desc do |arg|
@@ -119,6 +121,10 @@ CommandParser::CmdParser.new(ARGV) do
119
121
  helper.filterflag_to_i(arg)
120
122
  end
121
123
 
124
+ format :roleid, 'Role identifier' do |arg|
125
+ helper.retrieve_role_id(@current_vmg, arg)
126
+ end
127
+
122
128
  ########################################################################
123
129
  # Commands
124
130
  ########################################################################
@@ -151,7 +157,7 @@ CommandParser::CmdParser.new(ARGV) do
151
157
  end
152
158
 
153
159
  list_desc = <<-EOT.unindent
154
- Lists VM Group in the pool
160
+ Lists VM Group in the pool. #{OneVMGroupHelper.list_layout_help}
155
161
  EOT
156
162
 
157
163
  command :list, list_desc, [:filterflag, nil], :options => list_options do
@@ -270,4 +276,61 @@ CommandParser::CmdParser.new(ARGV) do
270
276
  vmg.unlock
271
277
  end
272
278
  end
279
+
280
+ role_add_desc = <<-EOT.unindent
281
+ Add role to VM Group.
282
+ EOT
283
+
284
+ command :"role-add", role_add_desc, :vmgroupid, [:file, nil] do
285
+ begin
286
+ template = File.read(args[1]) if args[1]
287
+ template = STDIN.read if STDIN.wait_readable(0)
288
+ rescue StandardError => e
289
+ STDERR.puts "Error reading template: #{e.message}."
290
+ exit(-1)
291
+ end
292
+
293
+ # Ensure the template attributes are in ROLE section
294
+ unless template.gsub(' ', '').match(/ROLE=\[/)
295
+ template = "ROLE=[\n#{template.split("\n").join(",\n")}]"
296
+ end
297
+
298
+ helper.perform_action(args[0], options, 'Role added') do |vmg|
299
+ vmg.role_add(template)
300
+ end
301
+ end
302
+
303
+ role_delete_desc = <<-EOT.unindent
304
+ Deletes role from VM Group.
305
+ EOT
306
+
307
+ command :"role-delete", role_delete_desc, :vmgroupid, :roleid do
308
+ roleid = args[1].to_i
309
+
310
+ helper.perform_action(args[0], options, 'Role removed') do |vmg|
311
+ vmg.role_delete(roleid)
312
+ end
313
+ end
314
+
315
+ role_update_desc = <<-EOT.unindent
316
+ Update VM Group role
317
+ EOT
318
+
319
+ command :"role-update", role_update_desc, :vmgroupid, :roleid, [:file, nil] do
320
+ vmg_id = args[0].to_i
321
+ role_id = args[1].to_i
322
+ file = args[2]
323
+
324
+ helper.perform_action(vmg_id, options, 'Role updated') do |vmg|
325
+ str = OpenNebulaHelper.update_template(vmg_id, vmg, file,
326
+ "ROLES/ROLE[ID=#{role_id}]")
327
+
328
+ # Ensure the updated attributes are in ROLE section
329
+ unless str.gsub(' ', '').match(/ROLE=\[/)
330
+ str = "ROLE=[\n#{str.split("\n").join(",\n")}]"
331
+ end
332
+
333
+ vmg.role_update(role_id, str)
334
+ end
335
+ end
273
336
  end
data/bin/onevnet CHANGED
@@ -161,15 +161,18 @@ CommandParser::CmdParser.new(ARGV) do
161
161
  ########################################################################
162
162
 
163
163
  create_desc = <<-EOT.unindent
164
- Creates a new Virtual Network from the given template file
164
+ Creates a new Virtual Network from the given template
165
+
166
+ #{OpenNebulaHelper::TEMPLATE_INPUT}
165
167
  EOT
166
168
 
167
- command :create, create_desc, :file, :options => CREATE_OPTIONS do
169
+ command :create, create_desc, [:file, nil], :options => CREATE_OPTIONS do
168
170
  cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
169
171
 
170
172
  helper.create_resource(options) do |vn|
171
173
  begin
172
- template = File.read(args[0])
174
+ template = File.read(args[0]) if args[0]
175
+ template = STDIN.read if STDIN.wait_readable(0)
173
176
  vn.allocate(template, cid)
174
177
  rescue StandardError => e
175
178
  STDERR.puts "Error creating network: #{e.message}"
@@ -347,7 +350,7 @@ CommandParser::CmdParser.new(ARGV) do
347
350
  end
348
351
 
349
352
  list_desc = <<-EOT.unindent
350
- Lists Virtual Networks in the pool
353
+ Lists Virtual Networks in the pool. #{OneVNetHelper.list_layout_help}
351
354
  EOT
352
355
 
353
356
  command :list, list_desc, [:filterflag, nil],
data/bin/onevntemplate CHANGED
@@ -340,7 +340,7 @@ CommandParser::CmdParser.new(ARGV) do
340
340
  end
341
341
 
342
342
  list_desc = <<-EOT.unindent
343
- Lists VN Templates in the pool
343
+ Lists VN Templates in the pool. #{OneVNTemplateHelper.list_layout_help}
344
344
  EOT
345
345
 
346
346
  rename_desc = <<-EOT.unindent
data/bin/onevrouter CHANGED
@@ -134,13 +134,14 @@ CommandParser::CmdParser.new(ARGV) do
134
134
 
135
135
  create_desc = <<-EOT.unindent
136
136
  Creates a new Virtual Router from the given description
137
+ #{OpenNebulaHelper::TEMPLATE_INPUT}
137
138
  EOT
138
139
 
139
- command :create, create_desc, :file do
140
+ command :create, create_desc, [:file, nil] do
140
141
  helper.create_resource(options) do |obj|
141
142
  begin
142
- template = File.read(args[0])
143
-
143
+ template = File.read(args[0]) if args[0]
144
+ template = STDIN.read if STDIN.wait_readable(0)
144
145
  obj.allocate(template)
145
146
  rescue StandardError => e
146
147
  STDERR.puts e.message
@@ -153,6 +154,8 @@ CommandParser::CmdParser.new(ARGV) do
153
154
  Creates a new VM instance from the given Template. This VM can be
154
155
  managed with the 'onevm' command.
155
156
 
157
+ #{OpenNebulaHelper::TEMPLATE_INPUT}
158
+
156
159
  The NIC elements defined in the Virtual Router will be used. The
157
160
  source Template can be modified adding or replacing attributes with
158
161
  the optional file argument, or with the options.
@@ -168,9 +171,10 @@ CommandParser::CmdParser.new(ARGV) do
168
171
  :vrouterid, :templateid, [:file, nil],
169
172
  :options => instantiate_options +
170
173
  OpenNebulaHelper::TEMPLATE_OPTIONS do
171
- if args[2] && OpenNebulaHelper.create_template_options_used?(options)
172
- STDERR.puts 'You cannot use both template file and template' \
173
- ' creation options.'
174
+ if (args[2] || STDIN.wait_readable(0)) &&
175
+ OpenNebulaHelper.create_template_options_used?(options)
176
+
177
+ STDERR.puts 'You cannot use both template and template creation options.'
174
178
  exit(-1)
175
179
  end
176
180
 
@@ -194,6 +198,8 @@ CommandParser::CmdParser.new(ARGV) do
194
198
 
195
199
  if args[2]
196
200
  extra_template = File.read(args[2])
201
+ elsif STDIN.wait_readable(0)
202
+ extra_template = STDIN.read
197
203
  else
198
204
  res = OpenNebulaHelper.create_template(options, t)
199
205
 
@@ -292,20 +298,15 @@ CommandParser::CmdParser.new(ARGV) do
292
298
  EOT
293
299
 
294
300
  command :"nic-attach", nic_attach_desc, :vrouterid,
295
- :options => [OneVMHelper::FILE,
301
+ :options => [OpenNebulaHelper::FILE,
296
302
  OneVMHelper::NETWORK,
297
303
  OneVMHelper::IP,
298
304
  OneVirtualRouterHelper::FLOAT] do
299
- if options[:file].nil? && options[:network].nil?
300
- STDERR.puts 'Provide a template file or a network:'
301
- STDERR.puts "\t--file <file>"
302
- STDERR.puts "\t--network <network>"
303
- exit(-1)
304
- end
305
-
306
305
  if options[:file]
307
306
  template = File.read(options[:file])
308
- else
307
+ elsif STDIN.wait_readable(0)
308
+ template = STDIN.read
309
+ elsif options[:network]
309
310
  network_id = options[:network]
310
311
  ip = options[:ip]
311
312
  float = options[:float]
@@ -321,6 +322,11 @@ CommandParser::CmdParser.new(ARGV) do
321
322
  end
322
323
 
323
324
  template += ' ]'
325
+ else
326
+ STDERR.puts 'Provide a template or a network:'
327
+ STDERR.puts "\t--file <file>"
328
+ STDERR.puts "\t--network <network>"
329
+ exit(-1)
324
330
  end
325
331
 
326
332
  helper.perform_action(args[0], options, 'Attach NIC') do |vr|
@@ -341,7 +347,7 @@ CommandParser::CmdParser.new(ARGV) do
341
347
  end
342
348
 
343
349
  list_desc = <<-EOT.unindent
344
- Lists the Virtual Routers in the pool
350
+ Lists the Virtual Routers in the pool. #{OneVirtualRouterHelper.list_layout_help}
345
351
  EOT
346
352
 
347
353
  command :list, list_desc, [:filterflag, nil], :options => list_options do
data/bin/onezone CHANGED
@@ -211,7 +211,7 @@ CommandParser::CmdParser.new(ARGV) do
211
211
  end
212
212
 
213
213
  list_desc = <<-EOT.unindent
214
- Lists Zones in the pool
214
+ Lists Zones in the pool. #{OneZoneHelper.list_layout_help}
215
215
  EOT
216
216
 
217
217
  command :list, list_desc, :options => list_options do
@@ -312,15 +312,9 @@ module CommandParser
312
312
  end
313
313
 
314
314
  def deprecated_command(name, new_command)
315
- cmd = Hash.new
316
- cmd[:desc] = "Deprecated, use #{new_command} instead"
317
- cmd[:arity] = 0
318
- cmd[:options] = []
319
- cmd[:args_format] = [[:string, nil]] * 20
315
+ cmd = @commands[name.to_sym] || Hash.new
316
+ cmd[:desc] += "\nDeprecated, use #{new_command} instead"
320
317
  cmd[:deprecated] = new_command
321
- cmd[:proc] = lambda do
322
- print_deprecated(new_command)
323
- end
324
318
 
325
319
  @commands[name.to_sym] = cmd
326
320
  end
@@ -800,7 +794,6 @@ module CommandParser
800
794
  def print_deprecated(new_command)
801
795
  puts "This command is deprecated, use instead:"
802
796
  puts " $ #{File.basename $0} #{new_command}"
803
- exit(-1)
804
797
  end
805
798
 
806
799
  def word_wrap(size, text, first_size=nil)
@@ -34,7 +34,7 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
34
34
  def self.resource_mask(str)
35
35
  resource_type=str.split('/')[0]
36
36
 
37
- mask = '------------------'
37
+ mask = '-------------------'
38
38
 
39
39
  resource_type.split('+').each do |type|
40
40
  case type
@@ -74,6 +74,8 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
74
74
  mask[16] = 'P'
75
75
  when 'VNTEMPLATE'
76
76
  mask[17] = 't'
77
+ when 'BACKUPJOB'
78
+ mask[18] = 'B'
77
79
  end
78
80
  end
79
81
  mask
@@ -128,9 +130,9 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
128
130
  d['STRING'].split(' ')[0]
129
131
  end
130
132
 
131
- column :RES_VHNIUTGDCOZSvRMAPt,
133
+ column :RES_VHNIUTGDCOZSvRMAPtB,
132
134
  'Resource to which the rule applies',
133
- :size => 22 do |d|
135
+ :size => 23 do |d|
134
136
  OneAclHelper.resource_mask d['STRING'].split(' ')[1]
135
137
  end
136
138
 
@@ -155,7 +157,7 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
155
157
  d['STRING']
156
158
  end
157
159
 
158
- default :ID, :USER, :RES_VHNIUTGDCOZSvRMAPt, :RID, :OPE_UMAC, :ZONE
160
+ default :ID, :USER, :RES_VHNIUTGDCOZSvRMAPtB, :RID, :OPE_UMAC, :ZONE
159
161
  end
160
162
  end
161
163
  # rubocop:enable Lint/IneffectiveAccessModifier
@@ -0,0 +1,284 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+ require 'one_helper'
18
+
19
+ # Helper for onebackupjob command
20
+ class OneBackupJobHelper < OpenNebulaHelper::OneHelper
21
+
22
+ def self.rname
23
+ 'BACKUPJOB'
24
+ end
25
+
26
+ def self.conf_file
27
+ 'onebackupjob.yaml'
28
+ end
29
+
30
+ TEMPLATE_OPTIONS = [
31
+ {
32
+ :name => 'name',
33
+ :large => '--name name',
34
+ :format => String,
35
+ :description => 'Name of the new backup job'
36
+ },
37
+ {
38
+ :name => 'description',
39
+ :large => '--description description',
40
+ :format => String,
41
+ :description => 'Description for the new Image'
42
+ },
43
+ {
44
+ :name => 'backup_vms',
45
+ :large => '--vms "vm_id1,vm_id2..."',
46
+ :format => String,
47
+ :description => 'List of VM IDs to backup'
48
+ },
49
+ {
50
+ :name => 'keep_last',
51
+ :large => '--keep N',
52
+ :format => String,
53
+ :description => 'Keep N backups for the VMs in this backup job'
54
+ },
55
+ {
56
+ :name => 'mode',
57
+ :large => '--mode <increment|full>',
58
+ :format => String,
59
+ :description => 'Backup mode'
60
+ }
61
+ ]
62
+
63
+ def format_pool(options)
64
+ config_file = self.class.table_conf
65
+
66
+ CLIHelper::ShowTable.new(config_file, self) do
67
+ column :ID, 'ONE identifier for the Backup Job', :size=>4 do |d|
68
+ d['ID']
69
+ end
70
+
71
+ column :USER, 'Username of the Backup Job owner', :left,
72
+ :size=>15 do |d|
73
+ helper.user_name(d, options)
74
+ end
75
+
76
+ column :GROUP, 'Group of the Backup Job', :left, :size=>15 do |d|
77
+ helper.group_name(d, options)
78
+ end
79
+
80
+ column :PRIO, 'Priority of the Backup Job', :left, :size=>4 do |d|
81
+ d['PRIORITY'].to_i
82
+ end
83
+
84
+ column :NAME, 'Date for the last backup operation', :left, :size=>15 do |d|
85
+ d['NAME']
86
+ end
87
+
88
+ column :LAST, 'Date for the last backup operation', :size => 15 do |d|
89
+ begin
90
+ btime = d['LAST_BACKUP_TIME'].to_i
91
+ rescue StandardError
92
+ btime = 0
93
+ end
94
+ OpenNebulaHelper.time_to_str(btime, false, true, true)
95
+ end
96
+
97
+ column :VMS, 'VM IDs part of this backup job', :size => 15 do |d|
98
+ begin
99
+ vm = d['TEMPLATE']['BACKUP_VMS']
100
+ vm[12..-1]='...' if vm.size > 15
101
+ vm
102
+ rescue StandardError
103
+ '-'
104
+ end
105
+ end
106
+
107
+ default :ID, :USER, :GROUP, :PRIO, :NAME, :LAST, :VMS
108
+ end
109
+ end
110
+
111
+ def schedule_actions(ids, options, warning = nil)
112
+ # Verbose by default
113
+ options[:verbose] = true
114
+
115
+ message = if options[:schedule].class == Integer
116
+ "backup scheduled at #{Time.at(options[:schedule])}"
117
+ else
118
+ "backup scheduled after #{options[:schedule]}s"
119
+ end
120
+
121
+ tmp_str = OpenNebulaHelper.schedule_action_tmpl(options, nil, warning)
122
+
123
+ perform_actions(ids, options, message) do |bj|
124
+ rc = bj.sched_action_add(tmp_str)
125
+
126
+ if OpenNebula.is_error?(rc)
127
+ STDERR.puts rc.message
128
+ exit(-1)
129
+ end
130
+ end
131
+ end
132
+
133
+ # Update schedule action
134
+ #
135
+ # @param id [Integer] BackupJob ID
136
+ # @param action_id [Integer] Sched action ID
137
+ # @param file [String] File path with update content
138
+ # @param options
139
+ def update_schedule_action(id, action_id, file, options)
140
+ perform_action(id, options, 'Sched action updated') do |bj|
141
+ rc = bj.info
142
+
143
+ if OpenNebula.is_error?(rc)
144
+ STDERR.puts "Error #{rc.message}"
145
+ exit(-1)
146
+ end
147
+
148
+ xpath = "TEMPLATE/SCHED_ACTION[ID=#{action_id}]"
149
+
150
+ unless bj.retrieve_elements(xpath)
151
+ STDERR.puts "Sched action #{action_id} not found"
152
+ exit(-1)
153
+ end
154
+
155
+ # Get user information
156
+ if file
157
+ str = File.read(file)
158
+ else
159
+ str = OpenNebulaHelper.update_template(id, bj, nil, xpath)
160
+ end
161
+
162
+ # Add the modified sched action
163
+ tmp_str = "\nSCHED_ACTION = ["
164
+ tmp_str << str.split("\n").join(',')
165
+ tmp_str << ']'
166
+
167
+ rc = bj.sched_action_update(action_id, tmp_str)
168
+
169
+ if OpenNebula.is_error?(rc)
170
+ STDERR.puts "Error updating: #{rc.message}"
171
+ exit(-1)
172
+ end
173
+ end
174
+ end
175
+
176
+ def self.create_backupjob_template(options)
177
+ template_options = TEMPLATE_OPTIONS.map do |o|
178
+ o[:name].to_sym
179
+ end
180
+
181
+ template_options << :name
182
+
183
+ t = ''
184
+ template_options.each do |n|
185
+ t << "#{n.to_s.upcase}=\"#{options[n]}\"\n" if options[n]
186
+ end
187
+
188
+ t
189
+ end
190
+
191
+ private
192
+
193
+ def factory(id = nil)
194
+ if id
195
+ OpenNebula::BackupJob.new_with_id(id, @client)
196
+ else
197
+ xml=OpenNebula::BackupJob.build_xml
198
+ OpenNebula::BackupJob.new(xml, @client)
199
+ end
200
+ end
201
+
202
+ def factory_pool(user_flag = -2)
203
+ OpenNebula::BackupJobPool.new(@client, user_flag)
204
+ end
205
+
206
+ def format_resource(bj, options = {})
207
+ bj_hash = bj.to_hash
208
+
209
+ str='%-15s: %-20s'
210
+ str_h1='%-80s'
211
+
212
+ # ----------------------------------------------------------------------
213
+ CLIHelper.print_header(
214
+ str_h1 % "BACKUP JOB #{bj['ID']} INFORMATION"
215
+ )
216
+ # ----------------------------------------------------------------------
217
+ puts format(str, 'ID', bj.id.to_s)
218
+ puts format(str, 'NAME', bj.name)
219
+ puts format(str, 'USER', bj['UNAME'])
220
+ puts format(str, 'GROUP', bj['GNAME'])
221
+ puts format(str, 'LOCK', OpenNebulaHelper.level_lock_to_str(bj['LOCK/LOCKED']))
222
+
223
+ CLIHelper.print_header(str_h1 % 'PERMISSIONS', false)
224
+
225
+ ['OWNER', 'GROUP', 'OTHER'].each do |e|
226
+ mask = '---'
227
+ mask[0] = 'u' if bj["PERMISSIONS/#{e}_U"] == '1'
228
+ mask[1] = 'm' if bj["PERMISSIONS/#{e}_M"] == '1'
229
+ mask[2] = 'a' if bj["PERMISSIONS/#{e}_A"] == '1'
230
+
231
+ puts format(str, e, mask)
232
+ end
233
+ puts
234
+
235
+ # ----------------------------------------------------------------------
236
+ CLIHelper.print_header(
237
+ str_h1 % 'LAST BACKUP JOB EXECUTION INFORMATION'
238
+ )
239
+ # ----------------------------------------------------------------------
240
+ puts format(str, 'TIME', OpenNebulaHelper.time_to_str(bj['LAST_BACKUP_TIME']))
241
+ puts format(str, 'DURATION', OpenNebulaHelper.period_to_str(bj['LAST_BACKUP_DURATION']))
242
+ puts
243
+
244
+ # ----------------------------------------------------------------------
245
+ CLIHelper.print_header(
246
+ str_h1 % 'VIRTUAL MACHINE BACKUP STATUS'
247
+ )
248
+ # ----------------------------------------------------------------------
249
+ up = bj.retrieve_elements('UPDATED_VMS/ID')
250
+ out = bj.retrieve_elements('OUTDATED_VMS/ID')
251
+ act = bj.retrieve_elements('BACKING_UP_VMS/ID')
252
+ err = bj.retrieve_elements('ERROR_VMS/ID')
253
+
254
+ up = [] if up.nil?
255
+ out = [] if out.nil?
256
+ act = [] if act.nil?
257
+ err = [] if err.nil?
258
+
259
+ puts format(str, 'UPDATED', up.join(','))
260
+ puts format(str, 'OUTDATED', out.join(','))
261
+ puts format(str, 'ONGOING', act.join(','))
262
+ puts format(str, 'ERROR', err.join(','))
263
+
264
+ if bj.has_elements?('/BACKUPJOB/TEMPLATE/SCHED_ACTION')
265
+ puts
266
+ CLIHelper.print_header(str_h1 % 'SCHEDULED ACTIONS', false)
267
+
268
+ table = OpenNebulaHelper.scheduled_action_table(self)
269
+ table.show([bj_hash['BACKUPJOB']['TEMPLATE']['SCHED_ACTION']].flatten, {})
270
+ end
271
+
272
+ if !options[:all]
273
+ bj.delete_element('/BACKUPJOB/TEMPLATE/SCHED_ACTION')
274
+ end
275
+
276
+ puts
277
+
278
+ # ----------------------------------------------------------------------
279
+ CLIHelper.print_header(str_h1 % 'TEMPLATE CONTENTS', false)
280
+ # ----------------------------------------------------------------------
281
+ puts bj.template_str
282
+ end
283
+
284
+ end