[Ovirt-devel] [PATCH] Cleanup vnc port setting in task_vm
Hugh O. Brock
hbrock at redhat.com
Mon Jun 16 19:09:25 UTC 2008
On Mon, Jun 16, 2008 at 11:55:17AM -0700, Ian Main wrote:
> Make a method to implement setting the vnc port instead of duplicating
> the calls.
>
> Signed-off-by: Ian Main <imain at redhat.com>
> ---
> wui/src/task-omatic/task_vm.rb | 23 ++++++++++++-----------
> 1 files changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/wui/src/task-omatic/task_vm.rb b/wui/src/task-omatic/task_vm.rb
> index 4157668..34749e0 100644
> --- a/wui/src/task-omatic/task_vm.rb
> +++ b/wui/src/task-omatic/task_vm.rb
> @@ -88,6 +88,16 @@ def setVmState(vm, state)
> vm.save
> end
>
> +def setVmVncPort(vm, domain)
> + doc = REXML::Document.new(domain.xml_desc)
> + attrib = REXML::XPath.match(doc, "//graphics/@port")
> + if not attrib.empty?:
> + vm.vnc_port = attrib.to_s.to_i
> + end
> + vm.save
> +end
> +
> +
> def findVM(task, fail_on_nil_host_id = true)
> # find the matching VM in the vms table
> vm = Vm.find(:first, :conditions => [ "id = ?", task.vm_id ])
> @@ -321,11 +331,7 @@ def start_vm(task)
> dom = conn.define_domain_xml(xml.to_s)
> dom.create
>
> - doc = REXML::Document.new(dom.xml_desc)
> - attrib = REXML::XPath.match(doc, "//graphics/@port")
> - if not attrib.empty?:
> - vm.vnc_port = attrib.to_s.to_i
> - end
> + setVmVncPort(vm, dom)
>
> conn.close
> rescue => ex
> @@ -414,12 +420,7 @@ def restore_vm(task)
> dom = conn.lookup_domain_by_uuid(vm.uuid)
> dom.restore
>
> - doc = REXML::Document.new(dom.xml_desc)
> - attrib = REXML::XPath.match(doc, "//graphics/@port")
> - if not attrib.empty?:
> - vm.vnc_port = attrib.to_s.to_i
> - vm.save
> - end
> + setVmVncPort(vm, dom)
>
> conn.close
> rescue => ex
> --
Looks lurvly to me...
ACK
--H
More information about the ovirt-devel
mailing list