Skip to content

Commit

Permalink
BareosFdPluginOvirt.py: Job error when oVirt SDK is not installed
Browse files Browse the repository at this point in the history
When the Python SDK for oVirt Engine API is not installed, the
plugin now terminates the job with an appropriate job error
message instead of throwing an exception.
  • Loading branch information
sduehr committed Dec 9, 2020
1 parent 60fac79 commit 5916b25
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py
Expand Up @@ -38,9 +38,6 @@
import xml.etree


import ovirtsdk4 as sdk
import ovirtsdk4.types as types

import ssl

from sys import version_info
Expand All @@ -59,6 +56,13 @@

import logging

SDK_IMPORT_ERROR = False
try:
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
except ImportError:
SDK_IMPORT_ERROR = True

# The name of the application, to be used as the 'origin' of events
# sent to the audit log:
APPLICATION_NAME = "Bareos oVirt plugin"
Expand Down Expand Up @@ -114,11 +118,20 @@ def check_options(self, mandatory_options=None):
"""
Check Plugin options
Note: this is called by parent class parse_plugin_definition().
This plugin does not yet implement any checks.
This plugin does not yet implement any checks for plugin options,
but it's used to report if the Python oVirt SDK is not installed.
If it is required to know if it is a backup or a restore, it
may make more sense to invoke the options checking from
start_backup_job() and start_restore_job()
"""

if SDK_IMPORT_ERROR:
bareosfd.JobMessage(
bareosfd.M_FATAL,
"Please install the Python SDK for oVirt Engine API.\n",
)
return bareosfd.bRC_Error

return bareosfd.bRC_OK

def start_backup_job(self):
Expand Down Expand Up @@ -342,6 +355,12 @@ def start_restore_job(self):
Overload this to handle restore objects, if applicable
"""
bareosfd.DebugMessage(100, "BareosFdPluginOvirt:start_restore_job() called\n")

bareosfd.JobMessage(
bareosfd.M_INFO,
"Using oVirt SDK Version %s\n" % sdk.version.VERSION,
)

if self.options.get("local") == "yes":
bareosfd.DebugMessage(
100,
Expand Down

0 comments on commit 5916b25

Please sign in to comment.