[Ovirt-devel] [PATCH server] fixes to recent vm / nic / pxe validations

Mohammed Morsi mmorsi at redhat.com
Wed Aug 5 17:10:20 UTC 2009


From: Mo <mmorsi at dhcp-100-19-208.bos.redhat.com>

---
 src/app/controllers/vm_controller.rb |    1 +
 src/app/models/vm.rb                 |    2 +-
 src/app/services/vm_service.rb       |   15 ++++++++++-----
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
index eda5798..9860843 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -207,6 +207,7 @@ class VmController < ApplicationController
      # to macs[i] and networks.static_networks_subset[j] corresponds
      # to ip_addresses[j]
      ip_counter = 0
+     params[:vm][:nics] = []
      params[:nics] = []

      unless params[:networks].nil?
diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb
index 9d326ac..88e0aef 100644
--- a/src/app/models/vm.rb
+++ b/src/app/models/vm.rb
@@ -464,7 +464,7 @@ class Vm < ActiveRecord::Base
       self.storage_volumes=@storage_volumes_pending
       @storage_volumes_pending = []
     end
-    errors.add("nics", "must specify at least one network if pxe booting off a network") unless boot_device == BOOT_DEV_NETWORK && nics.size > 0
+    errors.add("nics", "must specify at least one network if pxe booting off a network") unless boot_device != BOOT_DEV_NETWORK || nics.size > 0

   end

diff --git a/src/app/services/vm_service.rb b/src/app/services/vm_service.rb
index 76e4158..e39dbc4 100644
--- a/src/app/services/vm_service.rb
+++ b/src/app/services/vm_service.rb
@@ -98,15 +98,16 @@ module VmService
     vm_hash[:uuid] = Vm::gen_uuid unless vm_hash[:uuid]
     vm_hash[:state] = Vm::STATE_PENDING
     @vm = Vm.new(vm_hash)
+    nics.each{ |nic|
+      nnic = Nic.new(nic)
+      nnic.vm = @vm
+      @vm.nics.push nnic
+    }
     authorized!(Privilege::MODIFY, at vm.vm_resource_pool)

     alert = "VM was successfully created."
     Vm.transaction do
       @vm.save!
-      nics.each{ |nic|
-        nic[:vm_id] = @vm.id
-        Nic.create(nic)
-      }
       vm_provision
       @task = VmTask.new({ :user        => @user,
                            :task_target => @vm,
@@ -158,7 +159,11 @@ module VmService
     alert = "VM was successfully updated."
     Vm.transaction do
       @vm.nics.clear
-      nics.each{ |nic| @vm.nics.push Nic.new(nic) }
+      nics.each{ |nic|
+        nnic = Nic.new(nic)
+        @vm.nics.push nnic
+        vm_hash[:nics].push nnic
+      }

       @vm.update_attributes!(vm_hash)
       vm_provision
--
1.6.2.5




More information about the ovirt-devel mailing list