You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2012/09/09 08:42:00 UTC
svn commit: r1382412 - in /incubator/ambari/branches/AMBARI-666:
AMBARI-666-CHANGES.txt
ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
ambari-agent/src/main/python/ambari_agent/Hardware.py
Author: mahadev
Date: Sun Sep 9 06:42:00 2012
New Revision: 1382412
URL: http://svn.apache.org/viewvc?rev=1382412&view=rev
Log:
AMBARI-709. Getting hardware info on disks/cpu/others using facter and using it during registeration. (mahadev)it during registeration. (mahadev)
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/Hardware.py
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1382412&r1=1382411&r2=1382412&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Sun Sep 9 06:42:00 2012
@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-709. Getting hardware info on disks/cpu/others using facter and using
+ it during registeration. (mahadev)
+
AMBARI-707. More work on Node FSM and additional tests/cleanup. (hitesh)
AMBARI-706. Basic tests for Node FSM. (hitesh)
Modified: incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py?rev=1382412&r1=1382411&r2=1382412&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py Sun Sep 9 06:42:00 2012
@@ -35,8 +35,8 @@ prefix=/tmp/ambari
installprefix=/var/ambari/
[puppet]
-puppet_home=/usr/local/bin
-facter_home=/usr/local/bin
+puppet_home=/root/workspace/puppet-install/puppet-2.7.9
+facter_home=/root/workspace/puppet-install/facter-1.6.10
[command]
maxretries=2
Modified: incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/Hardware.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/Hardware.py?rev=1382412&r1=1382411&r2=1382412&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/Hardware.py (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/ambari_agent/Hardware.py Sun Sep 9 06:42:00 2012
@@ -18,27 +18,102 @@ See the License for the specific languag
limitations under the License.
'''
-from shell import shellRunner
import multiprocessing
import platform
import AmbariConfig
+import os.path
+import shell
+import logging
+import subprocess
+
+logger = logging.getLogger()
class Hardware:
def __init__(self):
- facterHome = AmbariConfig.config.get('puppet', 'facter_home')
+ self.hardware = {}
+ osdisks = self.osdisks()
+ self.hardware['mounts'] = osdisks
+ otherInfo = self.facterInfo()
+ self.hardware.update(otherInfo)
+ pass
+
+ def osdisks(self):
+ """ Run df to find out the disks on the host. Only works on linux
+ platforms. Note that this parser ignores any filesystems with spaces
+ and any mounts with spaces. """
+ mounts = {}
+ df = subprocess.Popen(["df", "-kP"], stdout=subprocess.PIPE)
+ dfdata = df.communicate()[0]
+ lines = dfdata.splitlines()
+ for l in lines:
+ split = l.split()
+ """ this ignores any spaces in the filesystemname and mounts """
+ if (len(split)) == 6:
+ device, size, used, available, percent, mountpoint = split
+ mountinfo = { 'size' : size,
+ 'used' : used,
+ 'available' : available,
+ 'percent' : percent,
+ 'mountpoint' : mountpoint}
+
+ mounts[device ] = mountinfo
+ pass
+ pass
+ return mounts
- self.hardware = { 'coreCount' : 4,
- 'cpuSpeed' : 4,
- 'cpuFlag' : 4,
- 'diskCount' : 3,
- 'netSpeed' : 3,
- 'ramSize' : 2
- }
-
+ def facterBin(self, facterHome):
+ return facterHome + "/bin/facter"
+ pass
+
+ def facterLib(self, facterHome):
+ return facterHome + "/lib/"
+ pass
+
+ def parseFacterOutput(self, facterOutput):
+ retDict = {}
+ allLines = facterOutput.splitlines()
+ for line in allLines:
+ keyValue = line.split("=>")
+ if (len(keyValue) == 2):
+ """Ignoring values that are just spaces or do not confirm to the
+ format"""
+ retDict[keyValue[0].strip()] = keyValue[1].strip()
+ pass
+ pass
+ return retDict
+
+ def facterInfo(self):
+ facterHome = AmbariConfig.config.get("puppet", "facter_home")
+ facterEnv = os.environ
+ logger.info("Using facter home as: " + facterHome)
+ facterInfo = {}
+ if os.path.exists(facterHome):
+ rubyLib = ""
+ if os.environ.has_key("RUBYLIB"):
+ rubyLib = os.environ["RUBYLIB"]
+ logger.info("Ruby Lib env from Env " + rubyLib)
+ rubyLib = rubyLib + ":" + self.facterLib(facterHome)
+ facterEnv["RUBYLIB"] = rubyLib
+ logger.info("Setting RUBYLIB as: " + rubyLib)
+ facter = subprocess.Popen([self.facterBin(facterHome)],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ env=facterEnv)
+ stderr_out = facter.communicate()
+ if facter.returncode != 0:
+ logging.error("Error getting facter info: " + stderr_out[1])
+ pass
+ facterOutput = stderr_out[0]
+ infoDict = self.parseFacterOutput(facterOutput)
+ facterInfo = infoDict
+ else:
+ pass
+ return facterInfo
+
def get(self):
+ logger.info("Hardware Info for the agent: " + str(self.hardware))
return self.hardware
-
def main(argv=None):
hardware = Hardware()
print hardware.get()