Esempio n. 1
0
 def _detect(self):
     """Set self.available True if the process and config file are detected
     """
     # Detect Agent's OS username by getting the group owner of confg file
     try:
         gid = os.stat('/etc/monasca/agent/agent.yaml').st_gid
         self.agent_user = grp.getgrgid(gid)[0]
     except OSError:
         self.agent_user = None
     # Try to detect the location of the Nova configuration file.
     # Walk through the list of processes, searching for 'nova-compute'
     # process with 'nova.conf' inside one of the parameters
     nova_conf = None
     for proc in psutil.process_iter():
         try:
             cmd = proc.as_dict(['cmdline'])['cmdline']
             if len(cmd) > 2 and 'python' in cmd[0] and 'nova-compute' in cmd[1]:
                 conf_indexes = [cmd.index(y) for y in cmd if 'nova.conf' in y]
                 if not conf_indexes:
                     continue
                 param = conf_indexes[0]
                 if '=' in cmd[param]:
                     nova_conf = cmd[param].split('=')[1]
                 else:
                     nova_conf = cmd[param]
         except (IOError, psutil.NoSuchProcess):
             # Process has already terminated, ignore
             continue
     if (nova_conf is not None and os.path.isfile(nova_conf)):
         self.available = True
         self.nova_conf = nova_conf
Esempio n. 2
0
 def _detect(self):
     """Run detection, set self.available True if the service is
        detected.
     """
     self.available = False
     # Start with plugin-specific configuration parameters
     # Try to detect the location of the Nova configuration file.
     # Walk through the list of processes, searching for 'nova-compute'
     # process with 'nova.conf' inside one of the parameters
     nova_conf = None
     for proc in psutil.process_iter():
         try:
             cmd = proc.as_dict(['cmdline'])['cmdline']
             if (len(cmd) > 2 and 'python' in cmd[0]
                     and 'nova-compute' in cmd[1]):
                 conf_indexes = [
                     cmd.index(y) for y in cmd if 'nova.conf' in y
                 ]
                 if not conf_indexes:
                     continue
                 param = conf_indexes[0]
                 if '=' in cmd[param]:
                     nova_conf = cmd[param].split('=')[1]
                 else:
                     nova_conf = cmd[param]
         except (IOError, psutil.NoSuchProcess):
             # Process has already terminated, ignore
             continue
     if (nova_conf is not None and os.path.isfile(nova_conf)):
         self.available = True
         self.nova_conf = nova_conf
Esempio n. 3
0
 def _detect(self):
     """Run detection, set self.available True if the service is
        detected.
     """
     self.available = False
     # Start with plugin-specific configuration parameters
     # Try to detect the location of the Nova configuration file.
     # Walk through the list of processes, searching for 'nova-compute'
     # process with 'nova.conf' inside one of the parameters
     nova_conf = None
     for proc in psutil.process_iter():
         try:
             cmd = proc.as_dict(['cmdline'])['cmdline']
             if (len(cmd) > 2 and 'python' in cmd[0] and
                     'nova-compute' in cmd[1]):
                 conf_indexes = [cmd.index(y)
                                 for y in cmd if 'nova.conf' in y]
                 if not conf_indexes:
                     continue
                 param = conf_indexes[0]
                 if '=' in cmd[param]:
                     nova_conf = cmd[param].split('=')[1]
                 else:
                     nova_conf = cmd[param]
         except (IOError, psutil.NoSuchProcess):
             # Process has already terminated, ignore
             continue
     if (nova_conf is not None and os.path.isfile(nova_conf)):
         self.available = True
         self.nova_conf = nova_conf
Esempio n. 4
0
 def _detect(self):
     """Set self.available True if the process and config file are detected
     """
     # Detect Agent's OS username by getting the group owner of confg file
     try:
         gid = os.stat('/etc/monasca/agent/agent.yaml').st_gid
         self.agent_user = grp.getgrgid(gid)[0]
     except OSError:
         self.agent_user = None
     # Try to detect the location of the Nova configuration file.
     # Walk through the list of processes, searching for 'nova-compute'
     # process with 'nova.conf' inside one of the parameters
     nova_conf = None
     for proc in psutil.process_iter():
         try:
             cmd = proc.as_dict(['cmdline'])['cmdline']
             if len(cmd) > 2 and 'python' in cmd[0] and 'nova-compute' in cmd[1]:
                 conf_indexes = [cmd.index(y) for y in cmd if 'nova.conf' in y]
                 if not conf_indexes:
                     if os.path.exists('/etc/nova/nova.conf'):
                         nova_conf = "/etc/nova/nova.conf"
                     continue
                 param = conf_indexes[0]
                 if '=' in cmd[param]:
                     nova_conf = cmd[param].split('=')[1]
                 else:
                     nova_conf = cmd[param]
         except (IOError, psutil.NoSuchProcess):
             # Process has already terminated, ignore
             continue
     if (nova_conf is not None and os.path.isfile(nova_conf)):
         self.available = True
         self.nova_conf = nova_conf
Esempio n. 5
0
def find_process_name(pname):
    """Simple function to search running process for one with pname.
    """
    for process in psutil.process_iter():
        try:
            if pname == process.as_dict()['name']:
                return process
        except psutil.NoSuchProcess:
            continue

    return None
Esempio n. 6
0
def find_process_name(pname):
    """Simple function to search running process for one with pname.
    """
    for process in psutil.process_iter():
        try:
            if pname == process.as_dict()['name']:
                return process
        except psutil.NoSuchProcess:
            continue

    return None
Esempio n. 7
0
    def is_running(self):
        """Returns True if monasca-agent is running, false otherwise.

        """
        # Looking for the supervisor process not the individual components
        for process in psutil.process_iter():
            if ('{0}/supervisor.conf'.format(self.config_dir)
                    in process.as_dict(['cmdline'])['cmdline']):
                return True

        return False
Esempio n. 8
0
    def is_running(self):
        """Returns True if monasca-agent is running, false otherwise.

        """
        # Looking for the supervisor process not the individual components
        for process in psutil.process_iter():
            if ('{0}/supervisor.conf'.format(self.config_dir)
                    in process.as_dict(['cmdline'])['cmdline']):
                return True

        return False
Esempio n. 9
0
def find_process_cmdline(search_string):
    """Simple function to search running process for one with cmdline
    containing search_string.
    """
    for process in psutil.process_iter():
        try:
            process_cmdline = ' '.join(process.as_dict()['cmdline'])
            if (search_string in process_cmdline and
               'monasca-setup' not in process_cmdline):
                return process
        except psutil.NoSuchProcess:
            continue

    return None
Esempio n. 10
0
def find_process_cmdline(search_string):
    """Simple function to search running process for one with cmdline
    containing search_string.
    """
    for process in psutil.process_iter():
        try:
            process_cmdline = ' '.join(process.as_dict()['cmdline'])
            if (search_string in process_cmdline
                    and 'monasca-setup' not in process_cmdline):
                return process
        except psutil.NoSuchProcess:
            continue

    return None
Esempio n. 11
0
 def get_nova_config_file(self):
     nova_conf = None
     for proc in psutil.process_iter():
         try:
             cmd = proc.as_dict(['cmdline'])['cmdline']
             if len(cmd) > 2 and 'python' in cmd[0] and 'nova-compute' in cmd[1]:
                 params = [cmd.index(y) for y in cmd if 'hypervisor.conf' in y]
                 if not params:
                     # The configuration file is not found, skip
                     continue
                 else:
                     param = params[0]
                 if '=' in cmd[param]:
                     nova_conf = cmd[param].split('=')[1]
                 else:
                     nova_conf = cmd[param]
         except IOError:
             # Process has already terminated, ignore
             continue
     return nova_conf
Esempio n. 12
0
 def get_nova_config_file(self):
     nova_conf = None
     for proc in psutil.process_iter():
         try:
             cmd = proc.as_dict(['cmdline'])['cmdline']
             if len(cmd) > 2 and 'python' in cmd[0] and 'nova-compute' in cmd[1]:
                 params = [cmd.index(y) for y in cmd if 'hypervisor.conf' in y]
                 if not params:
                     # The configuration file is not found, skip
                     continue
                 else:
                     param = params[0]
                 if '=' in cmd[param]:
                     nova_conf = cmd[param].split('=')[1]
                 else:
                     nova_conf = cmd[param]
         except IOError:
             # Process has already terminated, ignore
             continue
     return nova_conf
Esempio n. 13
0
    def prepare_run(self):
        """Collect the list of processes once before each run"""

        self._current_process_list = []

        for process in psutil.process_iter():
            try:
                process_dict = process.as_dict(
                    attrs=['name', 'pid', 'username', 'cmdline'])
                p = ProcessStruct(name=process_dict['name'],
                                  pid=process_dict['pid'],
                                  username=process_dict['username'],
                                  cmdline=' '.join(process_dict['cmdline']))
                self._current_process_list.append(p)
            except psutil.NoSuchProcess:
                # No way to log useful information here so just move on
                pass
            except psutil.AccessDenied as e:
                process_dict = process.as_dict(attrs=['name'])
                self.log.info('Access denied to process {0}: {1}'.format(
                    process_dict['name'], e))
Esempio n. 14
0
    def prepare_run(self):
        """Collect the list of processes once before each run"""

        self._current_process_list = []

        for process in psutil.process_iter():
            try:
                process_dict = process.as_dict(
                    attrs=['name', 'pid', 'username', 'cmdline'])
                p = ProcessStruct(name=process_dict['name'],
                                  pid=process_dict['pid'],
                                  username=process_dict['username'],
                                  cmdline=' '.join(process_dict['cmdline']))
                self._current_process_list.append(p)
            except psutil.NoSuchProcess:
                # No way to log useful information here so just move on
                pass
            except psutil.AccessDenied as e:
                process_dict = process.as_dict(attrs=['name'])
                self.log.info('Access denied to process {0}: {1}'.format(
                    process_dict['name'], e))