summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-03 23:37:12 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-03 23:37:12 +0000
commit3327dc809cb645a2e0d81e892c21cf9872f38712 (patch)
treebca91363b534ee61a7efe7c8a4783cbbaba6971b /lib
parent97d5ab656d5d05678eb37800452fb8ac7b615da2 (diff)
downloadpuppet-3327dc809cb645a2e0d81e892c21cf9872f38712.tar.gz
puppet-3327dc809cb645a2e0d81e892c21cf9872f38712.tar.xz
puppet-3327dc809cb645a2e0d81e892c21cf9872f38712.zip
Adding netinfo type and some tests
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1061 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/filetype.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/puppet/filetype.rb b/lib/puppet/filetype.rb
index 6525204ab..c13c740f0 100755
--- a/lib/puppet/filetype.rb
+++ b/lib/puppet/filetype.rb
@@ -205,6 +205,66 @@ module Puppet
}
end
end
+
+ # Treat netinfo tables as a single file, just for simplicity of certain types
+ newfiletype(:netinfo) do
+ def read
+ %x{nidump -r /#{@path} /}
+ end
+
+ # This really only makes sense for cron tabs.
+ def remove
+ raise TypeError, "Cannot remove netinfo tables"
+ end
+
+ # Convert our table to an array of hashes. This only works for handling one
+ # table at a time.
+ def to_array(text = nil)
+ text ||= read
+
+ hash = nil
+
+ # Initialize it with the first record
+ records = []
+ text.split("\n").each do |line|
+ next if line =~ /^[{}]$/ # Skip the wrapping lines
+ next if line =~ /"name" = \( "#{@path}" \)/ # Skip the table name
+ next if line =~ /CHILDREN = \(/ # Skip this header
+ next if line =~ /^ \)/ # and its closer
+
+ # Now we should have nothing but records, wrapped in braces
+
+ case line
+ when /^\s+\{/: hash = {}
+ when /^\s+\}/: records << hash
+ when /\s+"(\w+)" = \( (.+) \)/
+ field = $1
+ values = $2
+
+ # Always use an array
+ hash[field] = []
+
+ values.split(/, /).each do |value|
+ if value =~ /^"(.*)"$/
+ hash[field] << $1
+ else
+ raise ArgumentError, "Could not match value %s" % value
+ end
+ end
+ else
+ raise ArgumentError, "Could not match line %s" % line
+ end
+ end
+
+ records
+ end
+
+ def write(text)
+ IO.popen("niload -d #{@path} .", "w") { |p|
+ p.print text
+ }
+ end
+ end
end
end