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