Changeset 287

Show
Ignore:
Timestamp:
10/25/08 10:09:41 (2 months ago)
Author:
pwh
Message:

Created parse_bridge_id to convert a Bridge ID in to MAC address and priority

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nethorus/app/controllers/device_admin_controller.rb

    r184 r287  
    3535    @subtitle = "Device Administration" 
    3636 
    37     @all_devices = Device.all 
     37    @all_devices = Device.paginate :page => params[:page] 
    3838 
    3939  end 
     
    101101    if params[:device] 
    102102 
    103  
    104       # Compare the submitted data to the recorded data and log any changes 
     103      logger.debug "Form submitted, processing any changes" 
    105104 
    106105      params[:device].each do |param| 
    107106 
     107        # Only update the record if the attribute's value has actually 
     108        # changed. 
     109 
    108110        if @device.send(param[0]) != param[1] 
    109111 
    110           @device.send("#{param[0]}=", "#{param[1]}") 
    111           logger.debug "Column #{param[0]} changed from value='#{@device.send(param[0])}' to value='#{param[1]}'" 
    112  
    113         else 
    114  
    115           logger.debug "Column #{param[0]} unchanged from value='#{@device.send(param[0])}'" 
    116  
     112          old_value = @device.send(param[0]) 
     113 
     114          @device.send("#{param[0]}=", param[1]) 
     115           
    117116        end 
    118  
    119       end 
    120  
    121  
    122       # Always check if the device is valid, in case we have a now-invalid 
    123       # record in the database. 
     117           
     118      end 
     119 
     120      # Find out if anything has actually changed, and if so, report on it 
     121           
     122      if @device.changed? 
     123 
     124        @device.changes.keys.each do |change| 
     125 
     126          logger.debug "Column #{change} changed from #{@device.changes[change][0]} to #{@device.changes[change][1]}" 
     127    
     128        end 
     129 
     130      end 
     131       
    124132 
    125133      if @device.valid? 
    126134 
    127         if @device.changed? 
    128  
    129           # If the object has changed, save it and respond with a suitable flash message. 
    130  
    131           logger.debug "Device id=#{@device.id} changed - saving record" 
    132           @device.save 
    133           flash[:info] = "Updated <strong>#{@device.hostname}</strong>" 
    134  
    135         else 
     135        # If the object is valid, save it and respond with a suitable flash message. 
     136 
     137        logger.debug "Device id=#{@device.id} changed - saving record" 
     138        @device.save 
     139        flash[:info] = "Updated <strong>#{@device.hostname}</strong>" 
     140 
     141        # Redirect to the index page since the device has been changed 
    136142         
    137           # If the object hasn't changed, log it for debugging purposes but 
    138           # don't show any feedback. 
    139          
    140           logger.debug "Device id=#{@device.id} not changed" 
    141  
    142         end 
    143  
    144  
    145         # Since the object is valid, we can return to the index. 
    146  
    147143        redirect_to :action => 'index' 
    148  
     144       
    149145      else 
    150        
     146 
    151147        # The object isn't valid - log it, and go back to the edit page 
    152148        # which will then show the errors 
    153149 
    154150        logger.debug "Device id=#{@device.id} is invalid" 
    155  
    156       end 
    157  
    158     end 
    159  
     151       
     152      end 
     153 
     154    else 
     155     
     156      logger.debug "Form not submitted, continuing to load data" 
     157     
     158    end 
     159         
    160160  end 
    161161 
  • nethorus/app/controllers/search_controller.rb

    r174 r287  
    3535 
    3636      @devices = Device.find(:all, :conditions => [ "hostname LIKE :hostname", { :hostname => params[:for] } ]) 
    37       @l2_interfaces_short = L2Interface.find(:all, :conditions => [ "ifdescr_short LIKE :description", { :description => "%#params[:for]}%" } ]) 
     37      @l2_interfaces_short = L2Interface.find(:all, :conditions => [ "ifdescr_short LIKE :description", { :description => "%#{params[:for]}%" } ]) 
    3838      @l2_interfaces_long = L2Interface.find(:all, :conditions => [ "ifdescr_long LIKE :description", { :description => "%#{params[:for]}%" } ]) 
    3939      @l2_interfaces_address = L2Interface.find(:all, :conditions => [ "address LIKE :address", { :address => "%#{params[:for]}%" } ]) 
  • nethorus/app/helpers/bridges_helper.rb

    r230 r287  
    3737    return nil if bridge_id.blank? 
    3838   
    39     bridge_info = bridge_id.match(/(.{4})(.+)/
     39    bridge_data = parse_bridge_id(bridge_id
    4040 
    41     bridge = Bridge.find(:first, :conditions => { :dot1d_base_bridge_address => bridge_info[2].upcase }) 
     41    bridge = Bridge.find(:first, :conditions => { :dot1d_base_bridge_address => bridge_data['mac_address'] }) 
    4242     
    4343    if bridge.nil? 
     
    5353  end 
    5454 
     55 
     56  # Return the bridge priority and the bridge MAC address from a bridge ID. 
     57 
     58  def parse_bridge_id(bridge_id) 
     59   
     60    bridge_info = Hash.new 
     61   
     62    bridge_elements = bridge_id.match(/(.{4})(.+)/) 
     63 
     64    bridge_info['priority'] = bridge_elements[1].upcase 
     65    bridge_info['mac_address'] = bridge_elements[2].upcase 
     66 
     67    return bridge_info 
     68 
     69  end 
     70 
    5571end 
  • nethorus/app/models/device.rb

    r217 r287  
    8484 
    8585class Device < ActiveRecord::Base 
     86 
     87  cattr_reader :per_page 
     88  @@per_page = 15 
    8689 
    8790  has_many :l2_interfaces 
  • nethorus/app/models/ipv4_network.rb

    r195 r287  
    5858 
    5959  belongs_to :site 
     60  belongs_to :ipvpn 
    6061 
    6162  validates_presence_of :network_address, :network_mask 
  • nethorus/app/views/common/_all_devices.html.erb

    r242 r287  
    1 <table class="vert"> 
    2  <tr> 
    3   <th>Hostname</th> 
    4   <th>IP Address</th> 
    5   <th>Site</th> 
    6   <th>Description</th> 
    7  </tr> 
    8  <%- for device in @devices -%> 
    9   <tr class="<%= cycle('even_row', 'odd_row', :name => 'row_class') %>"> 
    10   <td> 
    11    <% if device.is_manageable? %> 
    12    <%= render :partial => 'common/device_information_box', :locals => { :device => device } %> 
    13    <% else %> 
    14    <%=h device.hostname %> 
    15    <% end %> 
    16   </td> 
    17   <td> 
    18    <%= device.ipv4_address %> 
    19   </td> 
    20   <td> 
    21    <%=h format_site(device.site) %> 
    22   </td> 
    23   <td> 
    24    <%=h device.description %> 
    25   </td> 
    26  </tr> 
    27  <%- end -%> 
    28 </table> 
     1<% if @devices.count > 0 %> 
     2 <table class="vert"> 
     3  <tr> 
     4   <th>Hostname</th> 
     5   <th>IP Address</th> 
     6   <th>Site</th> 
     7   <th>Description</th> 
     8  </tr> 
     9  <%- for device in @devices -%> 
     10   <tr class="<%= cycle('even_row', 'odd_row', :name => 'row_class') %>"> 
     11   <td> 
     12    <% if device.is_manageable? %> 
     13    <%= render :partial => 'common/device_information_box', :locals => { :device => device } %> 
     14    <% else %> 
     15    <%=h device.hostname %> 
     16    <% end %> 
     17   </td> 
     18   <td> 
     19    <%= device.ipv4_address %> 
     20   </td> 
     21   <td> 
     22    <%=h format_site(device.site) %> 
     23   </td> 
     24   <td> 
     25    <%=h device.description %> 
     26   </td> 
     27  </tr> 
     28  <%- end -%> 
     29 </table> 
     30<% else %> 
     31 <p>No devices found.</p> 
     32<% end %> 
  • nethorus/app/views/common/_device_hardware_inventory.html.erb

    r145 r287  
     1<% if !@device.ent_physical_elements.empty? %> 
    12<p> 
    23 <%= link_to('Update hardware inventory', { :controller => 'manage', :action => 'update_physical_entity_table_and_return' } ) %> |  
    3  <%= link_to_if(!@device.ent_physical_elements.empty?, 'Draw diagram', { :controller => 'diagram', :action => 'draw_hardware' } ) %> 
     4 <%= link_to('Draw diagram', { :controller => 'diagram', :action => 'draw_hardware' } ) %> 
    45</p> 
    56 
    6 <% unless @device.ent_physical_elements.empty? %> 
    7  <table class="vert"> 
    8   <tr> 
    9    <th>Description</th> 
    10    <th>Class</th> 
    11    <th>Revisions</th> 
    12    <th>Serial No.</th> 
    13    <th>Manufacturer</th> 
    14    <th>Model</th> 
    15    <th>FRU?</th> 
    16   </tr> 
     7<table class="vert"> 
     8 <tr> 
     9  <th>Description</th> 
     10  <th>Class</th> 
     11  <th>Revisions</th> 
     12  <th>Serial No.</th> 
     13  <th>Manufacturer</th> 
     14  <th>Model</th> 
     15  <th>FRU?</th> 
     16 </tr> 
    1717 <% @device.ent_physical_elements.each do |element| %> 
    18   <tr class="<%= cycle('even_row', 'odd_row', :name => 'row_class') %>"> 
    19    <td><%=h element.phys_description %></td> 
    20    <td><%=h element.phys_class %></td> 
    21    <td> 
    22     <% unless element.phys_hardware_rev.blank? %>H/W: <tt><%=h element.phys_hardware_rev %></tt><br /><% end %> 
    23     <% unless element.phys_firmware_rev.blank? %>F/W: <tt><%=h element.phys_firmware_rev %></tt><br /><% end %> 
    24     <% unless element.phys_software_rev.blank? %>S/W: <tt><%=h element.phys_software_rev %></tt><% end %> 
    25    </td> 
    26    <td><%=h element.phys_serial_number %></td> 
    27    <td><%=h element.phys_mfg_name %></td> 
    28    <td><%=h element.phys_model_name %></td> 
    29    <td><%=h display_yn(element.is_fru) %></td> 
    30   </tr> 
     18 <tr class="<%= cycle('even_row', 'odd_row', :name => 'row_class') %>"> 
     19  <td><%=h element.phys_description %></td> 
     20  <td><%=h element.phys_class %></td> 
     21  <td> 
     22   <% unless element.phys_hardware_rev.blank? %>H/W: <tt><%=h element.phys_hardware_rev %></tt><br /><% end %> 
     23   <% unless element.phys_firmware_rev.blank? %>F/W: <tt><%=h element.phys_firmware_rev %></tt><br /><% end %> 
     24   <% unless element.phys_software_rev.blank? %>S/W: <tt><%=h element.phys_software_rev %></tt><% end %> 
     25  </td> 
     26  <td><%=h element.phys_serial_number %></td> 
     27  <td><%=h element.phys_mfg_name %></td> 
     28  <td><%=h element.phys_model_name %></td> 
     29  <td><%=h display_yn(element.is_fru) %></td> 
     30 </tr> 
     31</table> 
    3132 <% end %> 
    32  </table> 
     33<% else %> 
     34 <p>This device has no hardware inventory recorded.  Please <%= link_to('poll the device', { :controller => 'manage', :action => 'update_physical_entity_table_and_return'} ) %> to build up a list of hardware components.</p> 
    3335<% end %> 
  • nethorus/app/views/device_admin/edit.html.erb

    r209 r287  
    2626  <legend>Management</legend> 
    2727  <label for="ipv4_address" accesskey="a">IP Address</label><%= form.text_field :ipv4_address %><br /> 
    28   <%= form.radio_button("snmp_version", "1", { :onchange => "Element.show('snmpv1_data'); Element.hide('snmpv2_data'); Element.hide('snmpv3_data');" } ) %>SNMPv1<br /> 
    29   <%= form.radio_button("snmp_version", "2", { :onchange => "Element.hide('snmpv1_data'); Element.show('snmpv2_data'); Element.hide('snmpv3_data');" } ) %>SNMPv2<br /> 
    30   <%= form.radio_button("snmp_version", "3", { :onchange => "Element.hide('snmpv1_data'); Element.hide('snmpv2_data'); Element.show('snmpv3_data');" } ) %>SNMPv3<br /> 
     28  <%= form.radio_button("snmp_version", "1", { :onchange => "Element.show('snmpv1v2_data'); Element.show('snmpv1_warning'); Element.hide('snmpv3_data');" } ) %>SNMPv1<br /> 
     29  <%= form.radio_button("snmp_version", "2", { :onchange => "Element.show('snmpv1v2_data'); Element.hide('snmpv1_warning'); Element.hide('snmpv3_data');" } ) %>SNMPv2<br /> 
     30  <%= form.radio_button("snmp_version", "3", { :onchange => "Element.hide('snmpv1v2_data'); Element.hide('snmpv1_warning'); Element.show('snmpv3_data');" } ) %>SNMPv3<br /> 
    3131 </fieldset> 
    3232 
    33  <fieldset id="snmpv1_data"> 
    34   <legend>SNMPv1 Settings</legend> 
    35   <p><strong>Select SNMPv1 only when you are certain this device does not support SNMPv2.  Although SNMPv1 is backward compatible, it will not use GETBULK, which may delay gathering data.</strong></p> 
     33 <fieldset id="snmpv1v2_data"> 
     34  <legend>SNMPv1/v2 Settings</legend> 
    3635  <label for="snmp_community" accesskey="c">Community string</label><%= form.text_field :snmp_community %><br /> 
    37  </fieldset> 
    38  
    39  <fieldset id="snmpv2_data"> 
    40   <legend>SNMPv2 Settings</legend> 
    41   <label for="snmp_community" accesskey="c">Community string</label><%= form.text_field :snmp_community %><br /> 
     36  <p id="snmpv1_warning"><strong>Select SNMPv1 only when you are certain this device does not support SNMPv2.  Although SNMPv1 is backward compatible, it will not use GETBULK, which may delay gathering data.</strong></p> 
    4237 </fieldset> 
    4338 
     
    5146 
    5247 <% if @device.snmp_version == 1 %> 
    53   <%= javascript_tag "Element.hide('snmpv2_data'); Element.hide('snmpv3_data');" %> 
     48  <%= javascript_tag "Element.show('snmpv1v2_data'); Element.show('snmpv1_warning'); Element.hide('snmpv3_data');" %> 
    5449 <% elsif @device.snmp_version == 3 %> 
    55   <%= javascript_tag "Element.hide('snmpv1_data'); Element.hide('snmpv2_data');" %> 
     50  <%= javascript_tag "Element.hide('snmpv1v2_data'); Element.show('snmpv3_data');" %> 
    5651 <% else %> 
    57   <%= javascript_tag "Element.hide('snmpv1_data'); Element.hide('snmpv3_data');" %> 
     52  <%= javascript_tag "Element.show('snmpv1v2_data'); Element.hide('snmpv1_warning'); Element.hide('snmpv3_data');" %> 
    5853 <% end %> 
    5954 
  • nethorus/app/views/device_admin/index.html.erb

    r209 r287  
    22 
    33<p><%= link_to "New device", { :controller => 'device_admin', :action => 'new' } %></p> 
     4 
     5<div class="paginator"><%= will_paginate @all_devices %></div> 
    46 
    57<table class="vert"> 
     
    1517<% end %> 
    1618</table> 
     19 
     20<div class="paginator"><%= will_paginate @all_devices %></div> 
  • nethorus/app/views/ip_network_admin/edit.html.erb

    r192 r287  
    2626 <fieldset> 
    2727  <legend>Location</legend> 
    28   <label for="ipvpn_id" accesskey="v">IP VPN</label><%= collection_select(:ip_network, :ipvpn_id, Ipvpn.find(:all), :id, :ipvpn_name) %><br /> 
     28  <label for="ipvpn_id" accesskey="v">IP VPN</label><%= collection_select(:ip_network, :ipvpn_id, Ipvpn.find(:all), :id, :ipvpn_name, { :prompt => :true }) %><br /> 
    2929  <label for="country" accesskey="c">Country</label><%= form.text_field :country, :size => 2 %> 
    3030 </fieldset> 
  • nethorus/app/views/ip_network_admin/index.html.erb

    r192 r287  
    1717  <td><%= ip_network.network_description %></td> 
    1818  <td><%= ip_network.country %></td> 
    19   <td><%= ip_network.ipvpn_id.nil? ? 'Global' : '#{ip_network.ipvpn_id.ipvpn_name} (#{ip_network.ipvpn_id.ipvpn_rd})' %></td> 
     19  <td><%= ip_network.ipvpn_id.nil? ? 'Global' : ipvpn_name_and_rd_or_nil(ip_network.ipvpn) %></td> 
    2020 </tr> 
    2121<% end %> 
  • nethorus/app/views/manage_bridge/show_bridge.html.erb

    r215 r287  
    3232      This is a root bridge and has no root port. 
    3333    <% else %> 
    34       <%= link_to @bridge.stp_ports.find(:first, :conditions => { :dot1d_base_port => @bridge.dot1d_stp_root_port }).l2_interface.ifdescr_short, { :controller => 'manage', :action => 'interface', :device_id => @bridge.device_id, :interface_id => @bridge.stp_ports.find(:first, :conditions => { :dot1d_base_port => @bridge.dot1d_stp_root_port }).l2_interface.id } %> 
     34      <%= link_to @bridge.stp_ports.find(:first, :conditions => { :dot1d_base_port => @bridge.dot1d_stp_root_port }).l2_interface.ifdescr_short, { :controller => 'manage_interface', :action => 'interface', :device_id => @bridge.device_id, :interface_id => @bridge.stp_ports.find(:first, :conditions => { :dot1d_base_port => @bridge.dot1d_stp_root_port }).l2_interface.id } %> 
    3535    <% end %> 
    3636  </td> 
  • nethorus/app/views/search/index.html.erb

    r254 r287  
    33<p>You may search by hostname, interface name, interface description, Layer 2 or Layer 3 address.</p> 
    44 
    5 <form method="get"> 
     5<form method="post" action=""> 
    66 <input name="for" /> 
    77 <input type="submit" value="Search" /> 
     
    1010<% unless params[:for].nil? || @results.nil? %> 
    1111 
    12  <p>You searched for <strong><%=h params[:for] %></strong>: 
    13   <ul> 
    14    <li><%=h @devices.size %> matches on hostname</li> 
    15    <li><%=h @l2_interfaces_short.size + @l2_interfaces_long.size %> matches on interface name and description</li> 
    16    <li><%=h @l3_interfaces_exact.size %> matches on IPv4 address</li> 
    17    <li><%=h @l2_interfaces_address.size %> matches on Layer 2 address</li> 
    18    <li><%=h @element_serial.size %> matches on serial number</li> 
    19   </ul> 
    20  </p> 
     12 <p>You searched for <strong><%=h params[:for] %></strong>:</p> 
     13 <ul> 
     14  <li><%=h @devices.size %> matches on hostname</li> 
     15  <li><%=h @l2_interfaces_short.size + @l2_interfaces_long.size %> matches on interface name and description</li> 
     16  <li><%=h @l3_interfaces_exact.size %> matches on IPv4 address</li> 
     17  <li><%=h @l2_interfaces_address.size %> matches on Layer 2 address</li> 
     18  <li><%=h @element_serial.size %> matches on serial number</li> 
     19 </ul> 
    2120 
    2221 <% unless @devices.nil? && @l2_interfaces.nil? && @l3_interfaces_exact.nil? %> 
     
    2827    </tr> 
    2928 
    30  
    3129   <% for device in @devices %> 
    3230    <tr class="<%= cycle('even_row', 'odd_row', :name => 'row_class') %>"> 
     
    3634    </tr> 
    3735   <% end %> 
    38  
    3936 
    4037   <% for l2_interface in @l2_interfaces_long %> 
     
    4643   <% end %> 
    4744 
    48  
    4945   <% for l2_interface in @l2_interfaces_short %> 
    5046    <tr class="<%= cycle('even_row', 'odd_row', :name => 'row_class') %>"> 
     
    5450    </tr> 
    5551   <% end %> 
    56  
    5752 
    5853   <% for l3_interface in @l3_interfaces_exact %> 
     
    8075   <% end %> 
    8176 
    82  
    83  
    8477  </table> 
    8578 <% end %> 
  • nethorus/config/environment.rb

    r236 r287  
    9090  require 'nethorus_functions' 
    9191 
     92  config.gem "mislav-will_paginate", :version => '~> 2.3.4', :lib => 'will_paginate', :source => 'http://gems.github.com' 
     93 
    9294end 
  • nethorus/db/schema.rb

    r207 r287  
    1010# It's strongly recommended to check this file into your version control system. 
    1111 
    12 ActiveRecord::Schema.define(:version => 39) do 
     12ActiveRecord::Schema.define(:version => 42) do 
     13 
     14  create_table "bridge_forwarding", :force => true do |t| 
     15    t.integer "vlan_id",      :limit => 11 
     16    t.text    "address" 
     17    t.integer "stp_port",     :limit => 11 
     18    t.text    "entry_status" 
     19  end 
    1320 
    1421  create_table "bridges", :force => true do |t| 
     
    124131 
    125132  create_table "ipvpns", :force => true do |t| 
    126     t.integer  "ipvpn_rd",         :limit => 11 
     133    t.text     "ipvpn_rd" 
    127134    t.text     "ipvpn_name" 
    128135    t.datetime "created_at" 
    129136    t.datetime "updated_at" 
    130     t.integer  "ipvpn_rd_integer", :limit => 16 
     137    t.integer  "ipvpn_rd_integer", :limit => 11 
    131138  end 
    132139 
     
    146153    t.text     "connector_present" 
    147154    t.integer  "parent_id",          :limit => 11 
     155  end 
     156 
     157  create_table "l2_vlans", :force => true do |t| 
     158    t.integer "vlan_id",      :limit => 11 
     159    t.integer "device_id",    :limit => 11 
     160    t.text    "vlan_state" 
     161    t.text    "vlan_name" 
     162    t.integer "vlan_mtu",     :limit => 11 
     163    t.integer "vlan_ifindex", :limit => 11 
    148164  end 
    149165 
  • nethorus/public/stylesheets/stylesheet.css

    r170 r287  
    354354        margin: 5px 0 0 10px; 
    355355} 
     356 
     357.paginator { 
     358        padding: 0.5em 0em 0.5em 0em; 
     359        text-align: center; 
     360        font-weight: bold; 
     361} 
  • nethorus/spec/spec.opts

    r256 r287  
    11--colour 
    2 --format specdoc 
     2--format progress 
    33--loadby mtime 
    44--reverse