diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> | 2017-04-18 12:27:57 +0200 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2017-04-24 08:23:24 +0000 |
commit | 512b1e00ab9b75e46cc76af40c72cf239fa100e5 (patch) | |
tree | 533eeec1377dd0502725e57bad3225d2e82fd812 /azurelinuxagent/common/event.py | |
parent | c6339c307f36f77a4198d6faf1275acdf371200b (diff) | |
parent | 0f537ddd741bfb333dbc01b994013a2b4e75d26f (diff) | |
download | vyos-walinuxagent-512b1e00ab9b75e46cc76af40c72cf239fa100e5.tar.gz vyos-walinuxagent-512b1e00ab9b75e46cc76af40c72cf239fa100e5.zip |
Import patches-applied version 2.2.9-0ubuntu1 to applied/ubuntu/zesty-proposed
Imported using git-ubuntu import.
Changelog parent: c6339c307f36f77a4198d6faf1275acdf371200b
Unapplied parent: 0f537ddd741bfb333dbc01b994013a2b4e75d26f
New changelog entries:
* New upstream release (LP: #1683521).
Diffstat (limited to 'azurelinuxagent/common/event.py')
-rw-r--r-- | azurelinuxagent/common/event.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/azurelinuxagent/common/event.py b/azurelinuxagent/common/event.py index 9265820..ce79adf 100644 --- a/azurelinuxagent/common/event.py +++ b/azurelinuxagent/common/event.py @@ -46,6 +46,7 @@ class WALAEventOperation: Install = "Install" InitializeHostPlugin = "InitializeHostPlugin" Provision = "Provision" + ReportStatus = "ReportStatus" Restart = "Restart" UnhandledError = "UnhandledError" UnInstall = "UnInstall" @@ -65,8 +66,17 @@ class EventLogger(object): if not os.path.exists(self.event_dir): os.mkdir(self.event_dir) os.chmod(self.event_dir, 0o700) - if len(os.listdir(self.event_dir)) > 1000: - raise EventError("Too many files under: {0}".format(self.event_dir)) + + existing_events = os.listdir(self.event_dir) + if len(existing_events) >= 1000: + existing_events.sort() + oldest_files = existing_events[:-999] + logger.warn("Too many files under: {0}, removing oldest".format(self.event_dir)) + try: + for f in oldest_files: + os.remove(os.path.join(self.event_dir, f)) + except IOError as e: + raise EventError(e) filename = os.path.join(self.event_dir, ustr(int(time.time() * 1000000))) @@ -101,6 +111,15 @@ class EventLogger(object): __event_logger__ = EventLogger() +def report_event(op, is_success=True, message=''): + from azurelinuxagent.common.version import AGENT_NAME, CURRENT_VERSION + add_event(AGENT_NAME, + version=CURRENT_VERSION, + is_success=is_success, + message=message, + op=op) + + def add_event(name, op="", is_success=True, duration=0, version=CURRENT_VERSION, message="", evt_type="", is_internal=False, reporter=__event_logger__): |