def getOs(self):
        """
		Requests the host to get the version of the operating system
		"""
        cmd = {'cmd': "", 'get': GET_OS}
        if self.logEventSent:
            layer_linux = templates.linux(get=GET_OS, event='request')
            self.logSentEvent(shortEvt="%s Request" % GET_OS,
                              tplEvt=self.encapsule(linux_event=layer_linux))
        self.sendNotifyToAgent(data=cmd)
    def getKernel(self):
        """
		Requests the host to get the version of the kernel
		"""
        cmd = {'cmd': "uname -mrs", 'get': GET_KERNEL}
        if self.logEventSent:
            layer_linux = templates.linux(get=GET_KERNEL, event='request')
            self.logSentEvent(shortEvt="%s Request" % GET_KERNEL,
                              tplEvt=self.encapsule(linux_event=layer_linux))
        self.sendNotifyToAgent(data=cmd)
    def getCpuInfo(self):
        """
		Requests the host to get the cpu info
		"""
        cmd = {'cmd': "cat /proc/cpuinfo", 'get': GET_CPU_INFO}
        if self.logEventSent:
            layer_linux = templates.linux(get=GET_CPU_INFO, event='request')
            self.logSentEvent(shortEvt="%s Request" % GET_CPU_INFO,
                              tplEvt=self.encapsule(linux_event=layer_linux))
        self.sendNotifyToAgent(data=cmd)
    def getHostname(self):
        """
		Requests the host to get the hostname
		"""
        cmd = {'cmd': "uname -n", 'get': GET_HOSTNAME}
        if self.logEventSent:
            layer_linux = templates.linux(get=GET_HOSTNAME, event='request')
            self.logSentEvent(shortEvt="%s Request" % GET_HOSTNAME,
                              tplEvt=self.encapsule(linux_event=layer_linux))
        self.sendNotifyToAgent(data=cmd)
    def getMemUsage(self):
        """
		Requests the host to get the memory usage
		"""
        __cmd__ = "cat /proc/meminfo"
        cmd = {'cmd': __cmd__, 'get': GET_MEM_USAGE}
        if self.logEventSent:
            layer_linux = templates.linux(get=GET_MEM_USAGE, event='request')
            self.logSentEvent(shortEvt="%s Request" % GET_MEM_USAGE,
                              tplEvt=self.encapsule(linux_event=layer_linux))
        self.sendNotifyToAgent(data=cmd)
    def execCommand(self, cmd):
        """
		Execute the command passed on argument
	
		@param cmd: command to execute
		@type cmd: string		
		"""
        cmd = {'cmd': cmd, 'get': EXEC_CMD}
        if self.logEventSent:
            layer_linux = templates.linux(get=EXEC_CMD, event='request')
            self.logSentEvent(shortEvt="%s Request" % EXEC_CMD,
                              tplEvt=self.encapsule(linux_event=layer_linux))
        self.sendNotifyToAgent(data=cmd)
    def hasReceivedResponse(self, timeout=1.0):
        """
		Waits to receive "response" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float	

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage		
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        layer_linux = templates.linux(event='response')
        evt = self.received(expected=self.encapsule(linux_event=layer_linux),
                            timeout=timeout)
        return evt
    def receivedNotifyFromAgent(self, data):
        """
		Function to reimplement
		"""
        if 'cmd' in data:
            if data['cmd'] == AGENT_INITIALIZED:
                tpl = TestTemplatesLib.TemplateMessage()
                layer = TestTemplatesLib.TemplateLayer('AGENT')
                layer.addKey("ready", True)
                layer.addKey(name='name', data=self.cfg['agent']['name'])
                layer.addKey(name='type', data=self.cfg['agent']['type'])
                tpl.addLayer(layer=layer)
                self.logRecvEvent(shortEvt="Agent Is Ready", tplEvt=tpl)
        else:
            try:
                raw = data['result']

                tplLin = templates.linux(event='response')
                tplLin.addRaw(raw)

                if data['get'] == EXEC_CMD:
                    Rsp = EXEC_CMD
                    tplLin.addKey(name='get', data=Rsp)
                    tplLin.addKey(name='result', data=raw)

                if data['get'] == GET_HOSTNAME:
                    Rsp = GET_HOSTNAME
                    tplLin.addKey(name='get', data=Rsp)
                    tplLin.addKey(name='hostname', data=raw.splitlines()[0])

                if data['get'] == GET_OS:
                    Rsp = GET_OS
                    tplLin.addKey(name='get', data=Rsp)
                    tplLin.addKey(name='os', data=raw)

                if data['get'] == GET_KERNEL:
                    Rsp = GET_KERNEL
                    tplLin.addKey(name='get', data=Rsp)
                    tplLin.addKey(name='kernel', data=raw)

                if data['get'] == GET_CPU_INFO:
                    Rsp = GET_CPU_INFO
                    tplLin.addKey(name='get', data=Rsp)
                    cpus = self.decodeCpuInfo(cpus=raw)
                    tplLin.addKey(name='cpu-count', data=str(len(cpus)))
                    for cpu, details in cpus.items():
                        tplCpu = TestTemplatesLib.TemplateLayer(name='')
                        for k, v in details.items():
                            tplCpu.addKey(name=k, data=v)
                        tplLin.addKey(name=cpu, data=tplCpu)

                if data['get'] == GET_MEM_USAGE:
                    Rsp = GET_MEM_USAGE
                    tplLin.addKey(name='get', data=Rsp)
                    mem = self.decodeMemUsage(mem=raw)
                    for k, v in mem.items():
                        tplLin.addKey(name=k, data=v)

                if self.logEventReceived:
                    tpl = self.encapsule(linux_event=tplLin)
                    tpl.addRaw(raw)
                    self.logRecvEvent(shortEvt="%s Response" % Rsp, tplEvt=tpl)
            except Exception as e:
                self.error('unable to read response: %s' % str(e))