Skip to content

Commit

Permalink
Merge "Implement checking if agent is up on Windows"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul v3 CI authored and opencontrail-ci-admin committed Aug 2, 2018
2 parents 0d02f8c + 7fed020 commit 9d26794
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/nodemgr/common/windows_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,53 @@
# Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
#

import psutil
import time

from windows_process_mem_cpu import WindowsProcessMemCpuUsageData


def _service_status_to_state(status):
if status == 'running':
return 'PROCESS_STATE_RUNNING'
else:
return 'PROCESS_STATE_STOPPED'

def _get_service_by_name(name):
service = None
try:
service = psutil.win_service_get(name)
except:
pass
return service

def _get_process_by_pid(pid):
process = None
try:
process = psutil.Process(pid)
except:
pass
return process

class WindowsProcessInfoManager(object):
def get_mem_cpu_usage_data(self, pid, last_cpu, last_time):
return WindowsProcessMemCpuUsageData(pid, last_cpu, last_time)

def get_all_processes(self):
return []
agent_service = _get_service_by_name('ContrailAgent')
if agent_service != None:
info = {}
info['name'] = 'contrail-vrouter-agent'
info['group'] = info['name']
info['statename'] = _service_status_to_state(agent_service.status())
if info['statename'] == 'PROCESS_STATE_RUNNING':
info['pid'] = agent_service.pid()
agent_process = _get_process_by_pid(info['pid'])
if agent_process != None:
info['start'] = str(int(agent_process.create_time() * 1000000))
return [info]
else:
return []

def runforever(self):
while True:
Expand Down

0 comments on commit 9d26794

Please sign in to comment.