class Junos::Ez::Group::Provider


Provider collection methods



_PRIVATE methods


Public Instance Methods

_apply_group() click to toggle source
# File lib/junos-ez/group.rb, line 182
def _apply_group
  cfg = Netconf::JunosConfig.new(:TOP)
  xml = cfg.doc
  Nokogiri::XML::Builder.with( xml.at_xpath( 'configuration' )) do |dot|
    if @config and @should[:_active] == :true  
      dot.send :'apply-groups', @name
    else 
      dot.send :'apply-groups', @name, Netconf::JunosConfig::DELETE
    end
  end
  begin
    attr = {}
    attr[:action] = 'replace'
    attr[:format] = 'xml'
    result = @ndev.rpc.load_configuration( xml, attr  )
  rescue Netconf::RpcError => e      
    errs = e.rsp.xpath('//rpc-error[error-severity = "error"]')
    raise e unless errs.empty?
    e.rsp
  else
    result
  end
end
_load( xml ) click to toggle source
# File lib/junos-ez/group.rb, line 158
def _load ( xml )
  return @config = nil if ( @should[:_exist] == false )
  admin = '' 
  if @should[:format].to_s == 'set'
    @config =  "\ndelete groups #{@name}\n" +
                 "edit groups #{@name}\n" + 
                  File.read( @should[:path] ) 
    admin = @should[:_active] == :false ? 'deactivate' : 'activate'
    @config += "\nquit\n"
    @config += "\n#{admin} groups #{@name}"

  elsif @should[:format].to_s == 'text'
    admin = @should[:_active] == :false ? 'inactive' : 'active'
    admin += ": " unless admin.empty? 
    @config = "groups {\n#{admin} replace: #{@name} {\n" + 
              File.read( @should[:path] ) + "\n}\n}"

  elsif @should[:format].to_s == 'xml'
    xml.at_xpath('groups') << File.read( @should[:path])
    @config = xml
  end
  return @config
end
build_catalog() click to toggle source
# File lib/junos-ez/group.rb, line 136
def build_catalog
  return @catalog if list!.empty?
  list.each do |grp_name|
    @ndev.rpc.get_configuration{ |xml|
      xml.groups {
          xml.name grp_name
        }
    }.xpath('groups').each do |as_xml|
      @catalog[grp_name] = {}
      xml_read_parser( as_xml, @catalog[grp_name] )
    end
  end    
  @catalog
  end
build_list() click to toggle source
# File lib/junos-ez/group.rb, line 127
def build_list
  grp_cfgs = @ndev.rpc.get_configuration{|xml| 
    xml.send(:'groups')
  }.xpath('groups/name').collect do |item|
    item.text
  end 
  return grp_cfgs
end
write!() click to toggle source
# File lib/junos-ez/group.rb, line 100
def write!
   return nil if @should.empty?
   
   @should[:_exist] ||= true
   @should[:_active] ||= :true
   # load the conifguration from file and apply under group
   # hirerachy
   rsp = write_xml_config!( xml_at_top.doc.root )    
   
   # copy the 'should' values into the 'has' values now that
   # they've been written back to Junos
       
   @has.merge! @should 
   @should.clear
   
   return true
 end
write_xml_config!( xml, opts = {} ) click to toggle source
# File lib/junos-ez/group.rb, line 78
def write_xml_config!( xml, opts = {} )
  if (@should[:_exist] == true)
    _load ( xml )
    @should[:format] = 'xml' unless @should[:format]
    begin
      attr = {}
      attr[:action] = 'replace'
      attr[:format] = @should[:format].to_s
      result = @ndev.rpc.load_configuration( @config.to_s, attr  )
    rescue Netconf::RpcError => e      
      errs = e.rsp.xpath('//rpc-error[error-severity = "error"]')
      raise e unless errs.empty?
      e.rsp
    else
      result
    end
  else
    super(xml) 
  end
  _apply_group
end
xml_at_top() click to toggle source

XML top placement


# File lib/junos-ez/group.rb, line 29
def xml_at_top
  xml = Nokogiri::XML::Builder.new {|xml| xml.configuration {
    xml.groups {
      xml.name @name
      return xml
    }
  }}
end
xml_change_format( xml ) click to toggle source
# File lib/junos-ez/group.rb, line 62
def xml_change_format( xml )
end
xml_change_path( xml ) click to toggle source

XML property writers


# File lib/junos-ez/group.rb, line 59
def xml_change_path( xml )
end
xml_get_has_xml( xml ) click to toggle source

XML property readers


# File lib/junos-ez/group.rb, line 42
def xml_get_has_xml( xml ) 
  xml.xpath('//groups')[0]
end
xml_on_create( xml ) click to toggle source

XML on-create


# File lib/junos-ez/group.rb, line 69
def xml_on_create( xml )
end
xml_on_delete( xml ) click to toggle source

XML on-delete


# File lib/junos-ez/group.rb, line 75
def xml_on_delete( xml )
end
xml_read_parser( as_xml, as_hash ) click to toggle source
# File lib/junos-ez/group.rb, line 46
def xml_read_parser( as_xml, as_hash )    
  set_has_status( as_xml, as_hash )  
  
  grp = as_xml.xpath('name').text
  as_hash[:name] = grp unless grp.empty?

end