Browse files

add function SmartMachine::Metadata.from_metadata

  • Loading branch information...
1 parent a068087 commit df3dfb7d1aca1b26730fe6b7f931f10fec8fa96a @sawanoboly sawanoboly committed Apr 5, 2013
Showing with 48 additions and 0 deletions.
  1. +48 −0 libraries/default.rb
View
48 libraries/default.rb
@@ -0,0 +1,48 @@
+#
+# module: SmartMachine
+# Author: Yukihiko Sawanobori
+# Copyright (C) 2013 HiganWorks LLC
+#
+# Licensed under MIT https://github.com/higanworks/LICENSES¬
+#
+
+module SmartMachine
+ def zoneinfo
+ `zoneadm list -p`.split(":")
+ end
+
+ def kstat_zone_cpucaps(id)
+ `kstat -p -c zone_caps -n cpucaps_zone_#{id} -s value`
+ end
+
+ def sm_id
+ zoneinfo[0]
+ end
+
+ def sm_uuid
+ zoneinfo[1]
+ end
+
+ def sm_cpu_cap
+ kstat_zone_cpucaps(sm_id).split("\t")[1].to_i
+ end
+
+ def sm_cpu_counts
+ sm_cpu_cap.div(100)
+ end
+end
+
+
+
+module SmartMachine
+ module Meatadata
+ require 'mixlib/shellout'
+
+ # retieve metadata returns String or nil.
+ def self.from_metadata(key)
+ cmd = Mixlib::ShellOut.new("/usr/sbin/mdata-get #{key}", :returns => [0,1])
+ collect = cmd.run_command
+ collect.stdout if collect.exitstatus == 0
+ end
+ end
+end

0 comments on commit df3dfb7

Please sign in to comment.