Class: Junos::Ez::L1ports::Provider::SWITCH

Inherits:
Junos::Ez::L1ports::Provider show all
Defined in:
lib/junos-ez/l1_ports/switch.rb,
lib/junos-ez/l1_ports/switch.rb

Overview


PRIVATE METHODS


Instance Attribute Summary

Attributes inherited from Provider::Parent

#catalog, #has, #list, #name, #ndev, #parent, #properties, #providers, #should

Instance Method Summary collapse

Methods inherited from Junos::Ez::L1ports::Provider

#build_catalog, #build_list, #status, #xml_change_mtu, #xml_get_has_xml

Methods inherited from Provider::Parent

#[], #[]=, #activate!, #active?, #catalog!, #create, #create!, #create_from_hash!, #create_from_yaml!, #deactivate!, #delete!, #each, #exists?, #init_has, #initialize, #is_new?, #is_provider?, #list!, #name_decorated, #need_write?, #read!, #rename!, #reorder!, #select, #to_h, #to_h_expanded, #to_yaml, #with, #write!, #xml_at_edit, #xml_build_change, #xml_change__active, #xml_change__exist, #xml_change_admin, #xml_change_description, #xml_element_newname, #xml_get_has_xml, #xml_on_create, #xml_on_delete

Constructor Details

This class inherits a constructor from Junos::Ez::Provider::Parent

Instance Method Details

#xml_at_topObject


XML top placement




7
8
9
10
11
12
13
14
15
16
# File 'lib/junos-ez/l1_ports/switch.rb', line 7

def xml_at_top
  xml = Nokogiri::XML::Builder.new {|xml| xml.configuration {
    xml.interfaces {
      xml.interface { 
        xml.name @name
        return xml
      }
    }
  }}
end

#xml_change_duplex(xml) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/junos-ez/l1_ports/switch.rb', line 84

def xml_change_duplex( xml )
  xml.send(:'ether-options') {
    if @should[:duplex] == :auto
      unless @has[:duplex] == :auto
        xml.send( :'link-mode', Netconf::JunosConfig::DELETE )
      end
    else
      xml.send( :'link-mode', case @should[:duplex]
         when :full then 'full-duplex'
         when :half then 'half-duplex'
      end )
    end
  }
end

#xml_change_speed(xml) ⇒ Object


XML property writers




70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/junos-ez/l1_ports/switch.rb', line 70

def xml_change_speed( xml )
  xml.send(:'ether-options') {
    xml.speed {
      if @should[:speed] == :auto
        unless @has[:speed] == :auto
          xml.send( _speed_to_junos_( @has[:speed] ), Netconf::JunosConfig::DELETE )
        end
      else
        xml.send( _speed_to_junos_( @should[:speed] ))
      end
    }
  }
end

#xml_config_read!Object



30
31
32
33
34
# File 'lib/junos-ez/l1_ports/switch.rb', line 30

def xml_config_read!
  xml = xml_at_top
  xml_read_filter( xml )
  @ndev.rpc.get_configuration( xml )      
end

#xml_read_filter(xml) ⇒ Object


XML property readers




22
23
24
25
26
27
28
# File 'lib/junos-ez/l1_ports/switch.rb', line 22

def xml_read_filter( xml )
  xml.description
  xml.disable
  xml.mtu
  xml.send(:'ether-options') 
  xml.unit({:recurse => 'false'})    
end

#xml_read_parser(as_xml, as_hash) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/junos-ez/l1_ports/switch.rb', line 36

def xml_read_parser( as_xml, as_hash )    
  set_has_status( as_xml, as_hash )

  xml_when_item(as_xml.xpath('description')){|i| as_hash[:description] = i.text}        
  as_hash[:admin] = as_xml.xpath('disable').empty? ? :up : :down
  xml_when_item(as_xml.xpath('mtu')){|i| as_hash[:mtu] = i.text.to_i }
      
  phy_options = as_xml.xpath('ether-options')    
  if phy_options.empty?
    as_hash[:speed] = :auto
    as_hash[:duplex] = :auto
  else      
    ## :duplex
    as_hash[:duplex] = case phy_options.xpath('link-mode').text.chomp
      when 'full-duplex' then :full
      when 'half-duplex' then :half
      else :auto
    end
    ## :speed
    if speed = phy_options.xpath('speed')[0]
      as_hash[:speed] = _speed_from_junos_( speed.first_element_child.name )
    else
      as_hash[:speed] = :auto
    end
  end                      
  
  as_hash[:unit_count] = as_xml.xpath('unit').count    
  return true
end