[Ovirt-devel] [PATCH] Added additional fields to the nic table.

Darryl L. Pierce dpierce at redhat.com
Fri Sep 12 20:52:01 UTC 2008


The new fields are netmask and broadcast.

You will need to run a migration with this patch.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 src/db/migrate/018_add_netmask_to_nics.rb |   11 +++++++++++
 src/host-browser/host-browser.rb          |   18 ++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 src/db/migrate/018_add_netmask_to_nics.rb

diff --git a/src/db/migrate/018_add_netmask_to_nics.rb b/src/db/migrate/018_add_netmask_to_nics.rb
new file mode 100644
index 0000000..a006109
--- /dev/null
+++ b/src/db/migrate/018_add_netmask_to_nics.rb
@@ -0,0 +1,11 @@
+class AddNetmaskToNics < ActiveRecord::Migration
+  def self.up
+    add_column :nics, :netmask,   :string, :limit => 16
+    add_column :nics, :broadcast, :string, :limit => 16
+  end
+
+  def self.down
+    remove_column :nics, :netmask
+    remove_column :nics, :broadcast
+  end
+end
diff --git a/src/host-browser/host-browser.rb b/src/host-browser/host-browser.rb
index a9fc9c7..debd78f 100755
--- a/src/host-browser/host-browser.rb
+++ b/src/host-browser/host-browser.rb
@@ -170,7 +170,7 @@ class HostBrowser
 
             break if info == "ENDNIC"
 
-            raise Exception.new("ERRINFO! Excepted key=value : #{info}\n") unless info =~ /[\w]+[\s]*=[\w]/
+            raise Exception.new("ERRINFO! Excepted key=value : #{info}\n") unless info =~ /[\w]+[\s]*=[\w]*/
 
             key, value = info.split("=")
 
@@ -275,6 +275,17 @@ class HostBrowser
                 # the received data to avoid creating a dupe later
                 if detail['MAC'] == nic.mac
                     nic_info.delete(detail)
+                    
+                    updated_nic = Nic.find_by_id(nic.id)
+            
+                    updated_nic.bandwidth = detail['BANDWIDTH']
+                    updated_nic.ip_addr   = detail['IP_ADDRESS']
+                    updated_nic.netmask   = detail['NETMASK']
+                    updated_nic.broadcast = detail['BROADCAST']
+                  
+                    updated_nic.save!
+                    found=true
+                    nic_info.delete detail
                 end
             end
 
@@ -292,7 +303,10 @@ class HostBrowser
             detail = Nic.new(
                 'mac'        => nic['MAC'],
                 'bandwidth'  => nic['BANDWIDTH'],
-                'usage_type' => 1)
+                'usage_type' => 1,
+                'ip_addr'    => nic['IP_ADDRESS'],
+                'netmask'    => nic['NETMASK'],
+                'broadcast'  => nic['BROADCAST'])
 
             host.nics << detail
         end
-- 
1.5.5.1




More information about the ovirt-devel mailing list