This fixes the check class stop() interface so it allows subclass check to override the default

behavior and adds the stop implementation in vcenter check so it logs out from vcenter session
when the collector is stopped.

Change-Id: I83fac9995dbeabfa082cc241a1ee3f7940032ed6
This commit is contained in:
James Gu 2017-01-25 22:07:15 -08:00
parent 9599bb4912
commit e9e3275040
2 changed files with 11 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
"""Base class for Checks.
If you are writing your own checks you should subclass the AgentCheck class.
@ -214,8 +214,7 @@ class AgentCheck(util.Dimensions):
"""
raise NotImplementedError()
@staticmethod
def stop():
def stop(self):
"""To be executed when the agent is being stopped to clean resources.
"""
pass

View File

@ -1,4 +1,4 @@
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
"""VCenter Only.
Generic VCenter check. This check allows you to specify particular metrics that
@ -62,6 +62,14 @@ class VCenterCheck(AgentCheck):
self.is_new_session = True
self._resource_moid_dict = {}
def stop(self):
"""To be executed when the agent is being stopped to clean resources.
"""
if self.session is not None:
self.session.logout()
self.session = None
self.is_new_session = True
def _propset_dict(self, propset):
"""Turns a propset list into a dictionary