Class: Junos::Ez::L1ports::Provider
- Inherits:
-
Provider::Parent
- Object
- Provider::Parent
- Junos::Ez::L1ports::Provider
- Defined in:
- lib/junos-ez/l1_ports.rb
Instance Attribute Summary
Attributes inherited from Provider::Parent
#catalog, #has, #list, #name, #ndev, #parent, #properties, #providers, #should
Instance Method Summary collapse
- #build_catalog ⇒ Object
-
#build_list ⇒ Object
————————————————————— Collection methods —————————————————————.
-
#status {|phy| ... } ⇒ Object
returns a Hash of status information, from “show interface …” basic information, not absolutely everything.
- #xml_change_mtu(xml) ⇒ Object
-
#xml_get_has_xml(xml) ⇒ Object
————————————————————— XML readers —————————————————————.
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_at_top, #xml_build_change, #xml_change__active, #xml_change__exist, #xml_change_admin, #xml_change_description, #xml_config_read!, #xml_element_newname, #xml_on_create, #xml_on_delete
Constructor Details
This class inherits a constructor from Junos::Ez::Provider::Parent
Instance Method Details
#build_catalog ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/junos-ez/l1_ports.rb', line 58 def build_catalog @catalog = {} # we could have a large list of interfaces, so # we need to break this up into individual "gets" list!.each do |ifs_name| @ndev.rpc.get_configuration{ |xml| xml.interfaces { xml.interface { xml.name ifs_name xml_read_filter( xml ) } } }.xpath('interfaces/interface').each do |ifs_xml| @catalog[ifs_name] = {} xml_read_parser( ifs_xml, @catalog[ifs_name] ) end end return @catalog end |
#build_list ⇒ Object
Collection methods
48 49 50 51 52 53 54 55 56 |
# File 'lib/junos-ez/l1_ports.rb', line 48 def build_list @ndev.rpc.get_interface_information({ :media => true, :terse => true, :interface_name => Junos::Ez::L1ports::IFS_NAME_FILTER }).xpath('physical-interface/name').collect do |ifs| ifs.text.strip end end |
#status {|phy| ... } ⇒ Object
returns a Hash of status information, from “show interface …” basic information, not absolutely everything. but if a block is given, then pass the XML to the block.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/junos-ez/l1_ports.rb', line 89 def status got = @ndev.rpc.get_interface_information(:interface_name => @name, :media => true ) phy = got.xpath('physical-interface')[0] return nil unless phy ret_h = {} ret_h[:macaddr] = phy.xpath('current-physical-address').text.strip xml_when_item(phy.xpath('description')){|i| ret_h[:description] = i.text.strip } ret_h[:oper_status] = phy.xpath('oper-status').text.strip ret_h[:admin_status] = phy.xpath('admin-status').text.strip ret_h[:mtu] = phy.xpath('mtu').text.to_i ret_h[:speed] = {:admin => phy.xpath('speed').text.strip } ret_h[:duplex] = {:admin => phy.xpath('duplex').text.strip } ret_h[:autoneg] = phy.xpath('if-auto-negotiation').text.strip if ret_h[:autoneg] == "enabled" autoneg = phy.xpath('ethernet-autonegotiation')[0] ret_h[:speed][:oper] = autoneg.xpath('link-partner-speed').text.strip ret_h[:duplex][:oper] = autoneg.xpath('link-partner-duplexity').text.strip end # if a block is given, then it means the caller wants to process the XML data. yield( phy ) if block_given? ret_h end |
#xml_change_mtu(xml) ⇒ Object
40 41 42 |
# File 'lib/junos-ez/l1_ports.rb', line 40 def xml_change_mtu( xml ) xml_set_or_delete( xml, 'mtu', @should[:mtu] ) end |
#xml_get_has_xml(xml) ⇒ Object
XML readers
36 37 38 |
# File 'lib/junos-ez/l1_ports.rb', line 36 def xml_get_has_xml( xml ) xml.xpath('//interface')[0] end |