diff options
author | Dave Eddy <dave@daveeddy.com> | 2015-03-16 22:34:55 -0400 |
---|---|---|
committer | Dave Eddy <dave@daveeddy.com> | 2015-05-05 15:21:17 -0400 |
commit | 9cd0ce0930ced860594189d9a89b1f46ae4c8638 (patch) | |
tree | 1e35bb52f7271f43cdb36538628cc522aa700ba1 | |
parent | 81d3f0a6d3b39c615ca29f8695b8975e783a20f8 (diff) | |
download | ohai-9cd0ce0930ced860594189d9a89b1f46ae4c8638.tar.gz |
cleanup joyent.rb
- condense code
- touch up style
- don't stat(2) before open(2)
-rw-r--r-- | lib/ohai/plugins/joyent.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/ohai/plugins/joyent.rb b/lib/ohai/plugins/joyent.rb index 0b91fdf1..977d8ad2 100644 --- a/lib/ohai/plugins/joyent.rb +++ b/lib/ohai/plugins/joyent.rb @@ -25,21 +25,18 @@ Ohai.plugin(:Joyent) do depends 'os', 'platform', 'virtualization' def collect_product_file - lines = [] - if ::File.exists?("/etc/product") - ::File.open("/etc/product") do |file| - while line = file.gets - lines << line - end - end + data = ::File.read("/etc/product") rescue nil + if data + data.strip.split("\n") + else + nil end - lines end def collect_pkgsrc - if File.exist?('/opt/local/etc/pkg_install.conf') - sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=") - sm_pkgsrc[1].chomp + data = ::File.read("/opt/local/etc/pkg_install.conf") rescue nil + if data + data.strip.split("=", 2).last else nil end @@ -58,14 +55,14 @@ Ohai.plugin(:Joyent) do # get zone id unless globalzone unless joyent[:sm_uuid] == "global" - joyent[:sm_id] = virtualization[:guest_id] + joyent[:sm_id] = virtualization[:guest_id] end # retrieve image name and pkgsrc collect_product_file.each do |line| case line when /^Image/ - sm_image = line.split(" ") + sm_image = line.split(" ") joyent[:sm_image_id] = sm_image[1] joyent[:sm_image_ver] = sm_image[2] when /^Base Image/ |