| Module | VirtP2V::UI::Convert |
| In: |
lib/virt-p2v/ui/convert.rb
lib/virt-p2v/ui/convert.rb |
| CONVERT_PROFILE_NAME | = | 0 |
| CONVERT_NETWORK_CONVERT | = | 0 |
| CONVERT_NETWORK_DEVICE | = | 1 |
| CONVERT_FIXED_CONVERT | = | 0 |
| CONVERT_FIXED_DEVICE | = | 1 |
| CONVERT_FIXED_PROGRESS | = | 2 |
| CONVERT_REMOVABLE_CONVERT | = | 0 |
| CONVERT_REMOVABLE_DEVICE | = | 1 |
| CONVERT_REMOVABLE_TYPE | = | 2 |
| UI_STATE_INVALID | = | 0 |
| UI_STATE_VALID | = | 1 |
| UI_STATE_CONNECTING | = | 2 |
| UI_STATE_CONVERTING | = | 3 |
| UI_STATE_COMPLETE | = | 4 |
| EV_VALID | = | 0 |
| EV_BUTTON | = | 1 |
| EV_CONNECTION | = | 2 |
| EV_CONVERTED | = | 3 |
| CONVERT_PROFILE_NAME | = | 0 |
| CONVERT_NETWORK_CONVERT | = | 0 |
| CONVERT_NETWORK_DEVICE | = | 1 |
| CONVERT_FIXED_CONVERT | = | 0 |
| CONVERT_FIXED_DEVICE | = | 1 |
| CONVERT_FIXED_PROGRESS | = | 2 |
| CONVERT_REMOVABLE_CONVERT | = | 0 |
| CONVERT_REMOVABLE_DEVICE | = | 1 |
| CONVERT_REMOVABLE_TYPE | = | 2 |
| UI_STATE_INVALID | = | 0 |
| UI_STATE_VALID | = | 1 |
| UI_STATE_CONNECTING | = | 2 |
| UI_STATE_CONVERTING | = | 3 |
| UI_STATE_COMPLETE | = | 4 |
| EV_VALID | = | 0 |
| EV_BUTTON | = | 1 |
| EV_CONNECTION | = | 2 |
| EV_CONVERTED | = | 3 |
# File lib/virt-p2v/ui/convert.rb, line 381
381: def self.check_numeric(widget)
382: value = widget.text
383: if value.nil? ? false : begin
384: value = Integer(value)
385: value > 0
386: rescue
387: false
388: end
389: then
390: widget.secondary_icon_name = nil
391: else
392: widget.secondary_icon_name = 'gtk-dialog-warning'
393: widget.secondary_icon_tooltip_text =
394: 'Value must be an integer greater than 0'
395: end
396:
397: update_values
398: end
# File lib/virt-p2v/ui/convert.rb, line 381
381: def self.check_numeric(widget)
382: value = widget.text
383: if value.nil? ? false : begin
384: value = Integer(value)
385: value > 0
386: rescue
387: false
388: end
389: then
390: widget.secondary_icon_name = nil
391: else
392: widget.secondary_icon_name = 'gtk-dialog-warning'
393: widget.secondary_icon_tooltip_text =
394: 'Value must be an integer greater than 0'
395: end
396:
397: update_values
398: end
# File lib/virt-p2v/ui/convert.rb, line 233
233: def self.convert
234: @converter.convert(
235: # status
236: lambda { |msg|
237: @status.text = msg
238: },
239: # progress
240: lambda { |dev, progress|
241: @fixeds.each { |model, path, iter|
242: next unless iter[CONVERT_FIXED_DEVICE] == dev
243:
244: iter[CONVERT_FIXED_PROGRESS] = progress
245: break
246: }
247: }
248: ) { |result|
249: # N.B. Explicit test against true is required here, as result may be
250: # an Exception, which would also return true if evaluated alone
251: if result == true then
252: @status.text = ''
253: event(EV_CONVERTED, true)
254: else
255: @status.text = result.message
256: event(EV_CONVERTED, false)
257: end
258: }
259: end
# File lib/virt-p2v/ui/convert.rb, line 233
233: def self.convert
234: @converter.convert(
235: # status
236: lambda { |msg|
237: @status.text = msg
238: },
239: # progress
240: lambda { |dev, progress|
241: @fixeds.each { |model, path, iter|
242: next unless iter[CONVERT_FIXED_DEVICE] == dev
243:
244: iter[CONVERT_FIXED_PROGRESS] = progress
245: break
246: }
247: }
248: ) { |result|
249: # N.B. Explicit test against true is required here, as result may be
250: # an Exception, which would also return true if evaluated alone
251: if result == true then
252: @status.text = ''
253: event(EV_CONVERTED, true)
254: else
255: @status.text = result.message
256: event(EV_CONVERTED, false)
257: end
258: }
259: end
# File lib/virt-p2v/ui/convert.rb, line 415
415: def self.convert_button_clicked
416: event(EV_BUTTON, true)
417: end
# File lib/virt-p2v/ui/convert.rb, line 415
415: def self.convert_button_clicked
416: event(EV_BUTTON, true)
417: end
# File lib/virt-p2v/ui/convert.rb, line 373
373: def self.convert_cpus_changed
374: check_numeric(@cpus)
375: end
# File lib/virt-p2v/ui/convert.rb, line 373
373: def self.convert_cpus_changed
374: check_numeric(@cpus)
375: end
# File lib/virt-p2v/ui/convert.rb, line 274
274: def self.convert_fixed_list_row_changed(model, path, iter)
275: update_values
276: end
# File lib/virt-p2v/ui/convert.rb, line 274
274: def self.convert_fixed_list_row_changed(model, path, iter)
275: update_values
276: end
# File lib/virt-p2v/ui/convert.rb, line 400
400: def self.convert_fixed_select_toggled(widget, path)
401: iter = @fixeds.get_iter(path)
402: iter[CONVERT_FIXED_CONVERT] = !iter[CONVERT_FIXED_CONVERT]
403: end
# File lib/virt-p2v/ui/convert.rb, line 400
400: def self.convert_fixed_select_toggled(widget, path)
401: iter = @fixeds.get_iter(path)
402: iter[CONVERT_FIXED_CONVERT] = !iter[CONVERT_FIXED_CONVERT]
403: end
# File lib/virt-p2v/ui/convert.rb, line 377
377: def self.convert_memory_changed
378: check_numeric(@memory)
379: end
# File lib/virt-p2v/ui/convert.rb, line 377
377: def self.convert_memory_changed
378: check_numeric(@memory)
379: end
# File lib/virt-p2v/ui/convert.rb, line 410
410: def self.convert_network_select_toggled(widget, path)
411: iter = @nics.get_iter(path)
412: iter[CONVERT_NETWORK_CONVERT] = !iter[CONVERT_NETWORK_CONVERT]
413: end
# File lib/virt-p2v/ui/convert.rb, line 410
410: def self.convert_network_select_toggled(widget, path)
411: iter = @nics.get_iter(path)
412: iter[CONVERT_NETWORK_CONVERT] = !iter[CONVERT_NETWORK_CONVERT]
413: end
# File lib/virt-p2v/ui/convert.rb, line 405
405: def self.convert_removable_select_toggled(widget, path)
406: iter = @removables.get_iter(path)
407: iter[CONVERT_REMOVABLE_CONVERT] = !iter[CONVERT_REMOVABLE_CONVERT]
408: end
# File lib/virt-p2v/ui/convert.rb, line 405
405: def self.convert_removable_select_toggled(widget, path)
406: iter = @removables.get_iter(path)
407: iter[CONVERT_REMOVABLE_CONVERT] = !iter[CONVERT_REMOVABLE_CONVERT]
408: end
# File lib/virt-p2v/ui/convert.rb, line 145
145: def self.event(event, status)
146: case @state
147: when UI_STATE_INVALID
148: case event
149: when EV_VALID
150: set_state(UI_STATE_VALID) if status
151: else
152: raise "Unexpected event: #{@state} #{event}"
153: end
154: when UI_STATE_VALID
155: case event
156: when EV_VALID
157: set_state(UI_STATE_INVALID) if !status
158: when EV_BUTTON
159: if @converter.connection.connected? then
160: set_state(UI_STATE_CONVERTING)
161: convert
162: else
163: set_state(UI_STATE_CONNECTING)
164: reconnect
165: end
166: else
167: raise "Unexpected event: #{@state} #{event}"
168: end
169: when UI_STATE_CONNECTING
170: case event
171: when EV_CONNECTION
172: if status then
173: set_state(UI_STATE_CONVERTING)
174: convert
175: else
176: set_state(UI_STATE_VALID)
177: end
178: when EV_VALID
179: # update_values will be called when the profile list is cleared
180: # and repopulated during connection. Untidy, but ignore it.
181: else
182: raise "Unexpected event: #{@state} #{event}" \
183: unless event == EV_CONNECTION
184: end
185: when UI_STATE_CONVERTING
186: case event
187: when EV_CONVERTED
188: if status then
189: set_state(UI_STATE_COMPLETE)
190: else
191: set_state(UI_STATE_VALID)
192: end
193: when EV_VALID
194: # update_values will be called when the list stores are updated.
195: # Untidy, but ignore it
196: else
197: raise "Unexpected event: #{@state} #{event}"
198: end
199: else
200: raise "Unexpected UI state: #{@state}"
201: end
202: end
# File lib/virt-p2v/ui/convert.rb, line 145
145: def self.event(event, status)
146: case @state
147: when UI_STATE_INVALID
148: case event
149: when EV_VALID
150: set_state(UI_STATE_VALID) if status
151: else
152: raise "Unexpected event: #{@state} #{event}"
153: end
154: when UI_STATE_VALID
155: case event
156: when EV_VALID
157: set_state(UI_STATE_INVALID) if !status
158: when EV_BUTTON
159: if @converter.connection.connected? then
160: set_state(UI_STATE_CONVERTING)
161: convert
162: else
163: set_state(UI_STATE_CONNECTING)
164: reconnect
165: end
166: else
167: raise "Unexpected event: #{@state} #{event}"
168: end
169: when UI_STATE_CONNECTING
170: case event
171: when EV_CONNECTION
172: if status then
173: set_state(UI_STATE_CONVERTING)
174: convert
175: else
176: set_state(UI_STATE_VALID)
177: end
178: when EV_VALID
179: # update_values will be called when the profile list is cleared
180: # and repopulated during connection. Untidy, but ignore it.
181: else
182: raise "Unexpected event: #{@state} #{event}" \
183: unless event == EV_CONNECTION
184: end
185: when UI_STATE_CONVERTING
186: case event
187: when EV_CONVERTED
188: if status then
189: set_state(UI_STATE_COMPLETE)
190: else
191: set_state(UI_STATE_VALID)
192: end
193: when EV_VALID
194: # update_values will be called when the list stores are updated.
195: # Untidy, but ignore it
196: else
197: raise "Unexpected event: #{@state} #{event}"
198: end
199: else
200: raise "Unexpected UI state: #{@state}"
201: end
202: end
# File lib/virt-p2v/ui/convert.rb, line 47
47: def self.init(ui, converter)
48: # ListStores
49: @profiles = ui.get_object('convert_profile_list')
50: @nics = ui.get_object('convert_network_list')
51: @fixeds = ui.get_object('convert_fixed_list')
52: @removables = ui.get_object('convert_removable_list')
53:
54: # Widgets
55: @profile = ui.get_object('convert_profile')
56: @name = ui.get_object('convert_name')
57: @cpus = ui.get_object('convert_cpus')
58: @memory = ui.get_object('convert_memory')
59: @editable = ui.get_object('convert_editable')
60: @button = ui.get_object('convert_button')
61: @status = ui.get_object('convert_status')
62:
63: # Get initial values from converter
64: @name.text = converter.name
65: @cpus.text = converter.cpus.to_s
66: @memory.text = (converter.memory / 1024 / 1024).to_s
67:
68: # Populate profiles on connection
69: converter.on_connection { |conn|
70: conn.on_connect { |cb|
71: conn.list_profiles { |profiles|
72: cb.call(RuntimeError.new('Remote server does not ' +
73: 'define any profiles in ' +
74: '/etc/virt-v2v.conf')) \
75: if profiles.kind_of?(Exception) or profiles.empty?
76:
77: selected = @profile.active_iter
78: selected = selected[CONVERT_PROFILE_NAME] \
79: unless selected.nil?
80:
81: @profiles.clear
82: profiles.each { |i|
83: profile = @profiles.append
84: profile[CONVERT_PROFILE_NAME] = i
85: @profile.active_iter = profile if i == selected
86: }
87:
88: cb.call(true)
89: }
90: }
91: }
92:
93: VirtP2V::FixedBlockDevice.all_devices.each { |dev|
94: fixed = @fixeds.append
95: fixed[CONVERT_FIXED_CONVERT] = true
96: fixed[CONVERT_FIXED_DEVICE] = dev.device
97: fixed[CONVERT_FIXED_PROGRESS] = 0
98: }
99:
100: VirtP2V::RemovableBlockDevice.all_devices.each { |dev|
101: rem = @removables.append
102: rem[CONVERT_REMOVABLE_CONVERT] = true
103: rem[CONVERT_REMOVABLE_DEVICE] = dev.device
104: rem[CONVERT_REMOVABLE_TYPE] = dev.type
105: }
106:
107: VirtP2V::NetworkDevice.all_devices.each { |dev|
108: nic = @nics.append
109: nic[CONVERT_NETWORK_CONVERT] = dev.connected
110: nic[CONVERT_NETWORK_DEVICE] = dev.name
111: }
112:
113: # Event handlers
114: ui.register_handler('convert_profile_changed',
115: method(:update_values))
116: ui.register_handler('convert_name_changed',
117: method(:update_values))
118: ui.register_handler('convert_cpus_changed',
119: method(:convert_cpus_changed))
120: ui.register_handler('convert_memory_changed',
121: method(:convert_memory_changed))
122: ui.register_handler('convert_fixed_list_row_changed',
123: method(:convert_fixed_list_row_changed))
124: ui.register_handler('convert_removable_list_row_changed',
125: method(:update_values))
126: ui.register_handler('convert_network_list_row_changed',
127: method(:update_values))
128: ui.register_handler('convert_fixed_select_toggled',
129: method(:convert_fixed_select_toggled))
130: ui.register_handler('convert_removable_select_toggled',
131: method(:convert_removable_select_toggled))
132: ui.register_handler('convert_network_select_toggled',
133: method(:convert_network_select_toggled))
134: ui.register_handler('convert_button_clicked',
135: method(:convert_button_clicked))
136:
137: @state = nil
138: set_state(UI_STATE_INVALID)
139: update_values
140:
141: @ui = ui
142: @converter = converter
143: end
# File lib/virt-p2v/ui/convert.rb, line 47
47: def self.init(ui, converter)
48: # ListStores
49: @profiles = ui.get_object('convert_profile_list')
50: @nics = ui.get_object('convert_network_list')
51: @fixeds = ui.get_object('convert_fixed_list')
52: @removables = ui.get_object('convert_removable_list')
53:
54: # Widgets
55: @profile = ui.get_object('convert_profile')
56: @name = ui.get_object('convert_name')
57: @cpus = ui.get_object('convert_cpus')
58: @memory = ui.get_object('convert_memory')
59: @editable = ui.get_object('convert_editable')
60: @button = ui.get_object('convert_button')
61: @status = ui.get_object('convert_status')
62:
63: # Get initial values from converter
64: @name.text = converter.name
65: @cpus.text = converter.cpus.to_s
66: @memory.text = (converter.memory / 1024 / 1024).to_s
67:
68: # Populate profiles on connection
69: converter.on_connection { |conn|
70: conn.on_connect { |cb|
71: conn.list_profiles { |profiles|
72: cb.call(RuntimeError.new('Remote server does not ' +
73: 'define any profiles in ' +
74: '/etc/virt-v2v.conf')) \
75: if profiles.kind_of?(Exception) or profiles.empty?
76:
77: selected = @profile.active_iter
78: selected = selected[CONVERT_PROFILE_NAME] \
79: unless selected.nil?
80:
81: @profiles.clear
82: profiles.each { |i|
83: profile = @profiles.append
84: profile[CONVERT_PROFILE_NAME] = i
85: @profile.active_iter = profile if i == selected
86: }
87:
88: cb.call(true)
89: }
90: }
91: }
92:
93: VirtP2V::FixedBlockDevice.all_devices.each { |dev|
94: fixed = @fixeds.append
95: fixed[CONVERT_FIXED_CONVERT] = true
96: fixed[CONVERT_FIXED_DEVICE] = dev.device
97: fixed[CONVERT_FIXED_PROGRESS] = 0
98: }
99:
100: VirtP2V::RemovableBlockDevice.all_devices.each { |dev|
101: rem = @removables.append
102: rem[CONVERT_REMOVABLE_CONVERT] = true
103: rem[CONVERT_REMOVABLE_DEVICE] = dev.device
104: rem[CONVERT_REMOVABLE_TYPE] = dev.type
105: }
106:
107: VirtP2V::NetworkDevice.all_devices.each { |dev|
108: nic = @nics.append
109: nic[CONVERT_NETWORK_CONVERT] = dev.connected
110: nic[CONVERT_NETWORK_DEVICE] = dev.name
111: }
112:
113: # Event handlers
114: ui.register_handler('convert_profile_changed',
115: method(:update_values))
116: ui.register_handler('convert_name_changed',
117: method(:update_values))
118: ui.register_handler('convert_cpus_changed',
119: method(:convert_cpus_changed))
120: ui.register_handler('convert_memory_changed',
121: method(:convert_memory_changed))
122: ui.register_handler('convert_fixed_list_row_changed',
123: method(:convert_fixed_list_row_changed))
124: ui.register_handler('convert_removable_list_row_changed',
125: method(:update_values))
126: ui.register_handler('convert_network_list_row_changed',
127: method(:update_values))
128: ui.register_handler('convert_fixed_select_toggled',
129: method(:convert_fixed_select_toggled))
130: ui.register_handler('convert_removable_select_toggled',
131: method(:convert_removable_select_toggled))
132: ui.register_handler('convert_network_select_toggled',
133: method(:convert_network_select_toggled))
134: ui.register_handler('convert_button_clicked',
135: method(:convert_button_clicked))
136:
137: @state = nil
138: set_state(UI_STATE_INVALID)
139: update_values
140:
141: @ui = ui
142: @converter = converter
143: end
# File lib/virt-p2v/ui/convert.rb, line 261
261: def self.reconnect
262: @status.text = 'Reconnecting'
263: @converter.connection.connect { |result|
264: if result == true then
265: event(EV_CONNECTION, true)
266: else
267: @status.text =
268: 'Failed to start virt-p2v-server on remote server'
269: event(EV_CONNECTION, false)
270: end
271: }
272: end
# File lib/virt-p2v/ui/convert.rb, line 261
261: def self.reconnect
262: @status.text = 'Reconnecting'
263: @converter.connection.connect { |result|
264: if result == true then
265: event(EV_CONNECTION, true)
266: else
267: @status.text =
268: 'Failed to start virt-p2v-server on remote server'
269: event(EV_CONNECTION, false)
270: end
271: }
272: end
# File lib/virt-p2v/ui/convert.rb, line 204
204: def self.set_state(state)
205: # Don't do anything if state hasn't changed
206: return if state == @state
207: @state = state
208:
209: case @state
210: when UI_STATE_INVALID
211: @editable.sensitive = true
212: @button.sensitive = false
213: when UI_STATE_VALID
214: @editable.sensitive = true
215: @button.sensitive = true
216: when UI_STATE_CONNECTING
217: @status.text = 'Failed to start virt-p2v-server on remote server'
218: @editable.sensitive = false
219: @button.sensitive = false
220: when UI_STATE_CONVERTING
221: @editable.sensitive = false
222: @button.sensitive = false
223: when UI_STATE_COMPLETE
224: @ui.active_page = 'success_win'
225:
226: # ... then leave this one as we hope to find it if we come back here
227: set_state(UI_STATE_VALID)
228: else
229: raise "Attempt to set unexpected UI state: #{@state}"
230: end
231: end
# File lib/virt-p2v/ui/convert.rb, line 204
204: def self.set_state(state)
205: # Don't do anything if state hasn't changed
206: return if state == @state
207: @state = state
208:
209: case @state
210: when UI_STATE_INVALID
211: @editable.sensitive = true
212: @button.sensitive = false
213: when UI_STATE_VALID
214: @editable.sensitive = true
215: @button.sensitive = true
216: when UI_STATE_CONNECTING
217: @status.text = 'Failed to start virt-p2v-server on remote server'
218: @editable.sensitive = false
219: @button.sensitive = false
220: when UI_STATE_CONVERTING
221: @editable.sensitive = false
222: @button.sensitive = false
223: when UI_STATE_COMPLETE
224: @ui.active_page = 'success_win'
225:
226: # ... then leave this one as we hope to find it if we come back here
227: set_state(UI_STATE_VALID)
228: else
229: raise "Attempt to set unexpected UI state: #{@state}"
230: end
231: end
# File lib/virt-p2v/ui/convert.rb, line 280
280: def self.update_values
281: valid = nil
282: begin
283: # Check there's a profile selected
284: profile = @profile.active_iter
285: raise InvalidUIState if profile.nil?
286: @converter.profile = profile[CONVERT_PROFILE_NAME]
287:
288: # Check there's a name set
289: name = @name.text
290: raise InvalidUIState if name.nil? || name.strip.length == 0
291: @converter.name = name
292:
293: # Check cpus and memory are set and numeric
294: cpus = @cpus.text
295: raise InvalidUIState if cpus.nil?
296: cpus = Integer(cpus) rescue nil
297: raise InvalidUIState if cpus.nil?
298: @converter.cpus = cpus
299:
300: memory = @memory.text
301: raise InvalidUIState if memory.nil?
302: memory = Integer(memory) rescue nil
303: raise InvalidUIState if memory.nil?
304: @converter.memory = memory * 1024 * 1024
305:
306: # Check that at least 1 fixed storage device is selected
307: fixed = false
308: @converter.disks.clear
309: @fixeds.each { |model, path, iter|
310: if iter[CONVERT_FIXED_CONVERT] then
311: fixed = true
312: @converter.disks << iter[CONVERT_FIXED_DEVICE]
313: end
314: }
315: raise InvalidUIState unless fixed
316:
317: # Populate removables and nics, although these aren't required to be
318: # selected for the ui state to be valid
319: @converter.removables.clear
320: @removables.each { |model, path, iter|
321: if iter[CONVERT_REMOVABLE_CONVERT] then
322: @converter.removables << iter[CONVERT_REMOVABLE_DEVICE]
323: end
324: }
325: @converter.nics.clear
326: @nics.each { |model, path, iter|
327: if iter[CONVERT_NETWORK_CONVERT] then
328: @converter.nics << iter[CONVERT_NETWORK_DEVICE]
329: end
330: }
331: rescue InvalidUIState
332: valid = false
333: end
334: valid = true if valid.nil?
335:
336: event(EV_VALID, valid)
337: end
# File lib/virt-p2v/ui/convert.rb, line 280
280: def self.update_values
281: valid = nil
282: begin
283: # Check there's a profile selected
284: profile = @profile.active_iter
285: raise InvalidUIState if profile.nil?
286: @converter.profile = profile[CONVERT_PROFILE_NAME]
287:
288: # Check there's a name set
289: name = @name.text
290: raise InvalidUIState if name.nil? || name.strip.length == 0
291: @converter.name = name
292:
293: # Check cpus and memory are set and numeric
294: cpus = @cpus.text
295: raise InvalidUIState if cpus.nil?
296: cpus = Integer(cpus) rescue nil
297: raise InvalidUIState if cpus.nil?
298: @converter.cpus = cpus
299:
300: memory = @memory.text
301: raise InvalidUIState if memory.nil?
302: memory = Integer(memory) rescue nil
303: raise InvalidUIState if memory.nil?
304: @converter.memory = memory * 1024 * 1024
305:
306: # Check that at least 1 fixed storage device is selected
307: fixed = false
308: @converter.disks.clear
309: @fixeds.each { |model, path, iter|
310: if iter[CONVERT_FIXED_CONVERT] then
311: fixed = true
312: @converter.disks << iter[CONVERT_FIXED_DEVICE]
313: end
314: }
315: raise InvalidUIState unless fixed
316:
317: # Populate removables and nics, although these aren't required to be
318: # selected for the ui state to be valid
319: @converter.removables.clear
320: @removables.each { |model, path, iter|
321: if iter[CONVERT_REMOVABLE_CONVERT] then
322: @converter.removables << iter[CONVERT_REMOVABLE_DEVICE]
323: end
324: }
325: @converter.nics.clear
326: @nics.each { |model, path, iter|
327: if iter[CONVERT_NETWORK_CONVERT] then
328: @converter.nics << iter[CONVERT_NETWORK_DEVICE]
329: end
330: }
331: rescue InvalidUIState
332: valid = false
333: end
334: valid = true if valid.nil?
335:
336: event(EV_VALID, valid)
337: end
# File lib/virt-p2v/ui/convert.rb, line 339
339: def self.valid?
340: # Check there's a profile selected
341: profile = @profile.active_iter
342: return false if profile.nil?
343:
344: # Check there's a name set
345: name = @name.text
346: return false if name.nil?
347: return false unless name.strip.length > 0
348:
349: # Check cpus and memory are set and numeric
350: cpus = @cpus.text
351: return false if cpus.nil?
352: cpus = Integer(cpus) rescue nil
353: return false if cpus.nil?
354:
355: memory = @memory.text
356: return false if memory.nil?
357: memory = Integer(memory) rescue nil
358: return false if memory.nil?
359:
360: # Check that at least 1 fixed storage device is selected
361: fixed = false
362: @fixeds.each { |model, path, iter|
363: if iter[CONVERT_FIXED_CONVERT] then
364: fixed = true
365: break
366: end
367: }
368: return false unless fixed
369:
370: return true
371: end
# File lib/virt-p2v/ui/convert.rb, line 339
339: def self.valid?
340: # Check there's a profile selected
341: profile = @profile.active_iter
342: return false if profile.nil?
343:
344: # Check there's a name set
345: name = @name.text
346: return false if name.nil?
347: return false unless name.strip.length > 0
348:
349: # Check cpus and memory are set and numeric
350: cpus = @cpus.text
351: return false if cpus.nil?
352: cpus = Integer(cpus) rescue nil
353: return false if cpus.nil?
354:
355: memory = @memory.text
356: return false if memory.nil?
357: memory = Integer(memory) rescue nil
358: return false if memory.nil?
359:
360: # Check that at least 1 fixed storage device is selected
361: fixed = false
362: @fixeds.each { |model, path, iter|
363: if iter[CONVERT_FIXED_CONVERT] then
364: fixed = true
365: break
366: end
367: }
368: return false unless fixed
369:
370: return true
371: end