Ejemplo n.º 1
0
def disSunOS(host_obj, client, Framework = None, langBund = None, packageToCmdLine = None, pid2Process = None):
	hostId = Framework.getDestinationAttribute('hostId')
	discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses'))

	myVec = ObjectStateHolderVector()
	
	# Note: Using /usr/ucb/ps instead of /usr/bin/ps can produce
	# output without the 80 character/line limit, but can not
	# also accept formating identifiers the way /usr/bin/ps can.

	SOLARIS_ZONE_SUPPORTED_OS_VERSION = ('5.10') 	#version of solaris taht supports zone

	processList = []
	
	# list of process ids which belong to global zone
	globalZonePids = []
	lines = [] # init ps command results vector
	os_ver = client.execCmd('uname -r')#V@@CMD_PERMISION tty protocol execution
	if (os_ver.strip() == SOLARIS_ZONE_SUPPORTED_OS_VERSION):
		# discover only supported platform version
		buff = client.execCmd('zonename')#V@@CMD_PERMISION tty protocol execution
		if (buff == None or buff.lower().find('not found')):
			buff = client.execCmd('/usr/bin/zonename')#V@@CMD_PERMISION tty protocol execution
		if (buff != None):
			if (buff.strip() == 'global'):
				# this is a global zone - since ps command return all running processes including zones process
				#  on global zone we need to issue a special command so we can parse only the global zone procesess
				# discovering non zone processes only
				
				# get processes ids and Solaris Zones they belong to:
				r = client.execCmd('ps -e -o pid -o zone')#V@@CMD_PERMISION tty protocol execution
				if (r == None):
					return myVec
				if(re.search('\r\n',r)):
					lines = r.split('\r\n')
				elif (re.search('\n',r)):
					lines = r.split('\n')
				else:
					return myVec
				# keep only processes that belong to the global zone
				for line in lines:
					m = re.match('\s*(\d+)\s*global$',line)
					if m != None:
						globalZonePids.append(m.group(1))
	pdu = None
	try:
		pdu = processdbutils.ProcessDbUtils(Framework)
		hostOSH = modeling.createOshByCmdbIdString('host', hostId)
		# retrieve a map with pids as keys and commands as values. The map
		# is filtered according to globalZonePids (if applicable - meaning 
		# that if globalZonePids is not None or empty, then processesHash will 
		# contain only pids from globalZonePids).
		processesHash = getProcessesHash(client, globalZonePids)
		
		if (processesHash and len(processesHash) > 0):
			for pid in processesHash.keys():
				[owner,command] = processesHash[pid]
				spaceIndex = command.find(' ')
				commAndPath = ''
				cleanArgs = ''
	
				if spaceIndex > -1:
					commAndPath = command[:spaceIndex]
					try:
						cleanArgs = command[spaceIndex+1:]
					except:
						cleanArgs = ''
				else:
					commAndPath = command
					cleanArgs = ''
	
				cleanCommand = ''
				if (commAndPath.find('/') == -1) or (commAndPath[0] == '['):
					cleanCommand = commAndPath
				else:
					res2 = re.search('(.*/)([^/]+)',commAndPath)
					if (res2):
						cleanCommand = res2.group(2)
					else:
						continue
				
				if packageToCmdLine != None and commAndPath:
					pkgName = file_ver_lib.getSunPackageName(client, commAndPath)
					if pkgName:
						packageToCmdLine[pkgName] = commAndPath
				
				commandLine = cleanCommand + ' ' + cleanArgs
				addProcess(pdu, hostId, cleanCommand, pid, commandLine, commAndPath, cleanArgs, processList, discoverProcesses, myVec, hostOSH, None, owner)

		pdu.flushHostProcesses(hostId)
		if pid2Process is not None:
			pid2Process.putAll(pdu.getProcessCmdMap())
	finally:
		if pdu != None:
			pdu.close()
	return myVec
Ejemplo n.º 2
0
 def getPackageNameByProcess(self, process):
     if process and process.executablePath:
         return file_ver_lib.getSunPackageName(self._getShell(),
                                               process.executablePath)
 def getPackageNameByProcess(self, process):
     if process and process.executablePath:
         return file_ver_lib.getSunPackageName(self._getShell(), process.executablePath)