Ejemplo n.º 1
0
 def __init__(self):
     # Define the accepted statuses for the ports and drives
     self.valid_port_status_list = ['active', 'error', 'disabled',
                                    'unknown', 'foreign']
     self.valid_drive_status_list = ['active', 'failed', 'missing',
                                     'disabled', 'unknown']
     dbfile = get_config()['sqlite_db']
     self.db = sqlite3.connect(dbfile)
     self.db.row_factory = dict_factory
     self.cur = self.db.cursor()
Ejemplo n.º 2
0
    def __init__(self):
        self.now = int(time())
        # Load the controller module
        try:
            conf_controller = get_config()['controller']
            controller = getattr(__import__('swift_drive.plugins.controller',
                                 fromlist=[conf_controller]), conf_controller)
            self.controller = controller.Controller()
        except:
            raise Exception('Failed to load %s controller module'
                            % conf_controller)

        # Load the ticketing module
        try:
            conf_backend = get_config()['backend']
            backend = getattr(__import__('swift_drive.plugins.backend',
                              fromlist=[conf_backend]), conf_backend)
            self.backend = backend.Backend()
        except:
            raise Exception('Failed to load %s backend module' % conf_backend)
Ejemplo n.º 3
0
    def __init__(self):
        """
        Initialise the binaries for the controller. Prefer those specified in
        the config file to the ones in $PATH. Raise an exception in case at
        least one isn't usable.

        Binaries dictionary format:
        {'omconfig': '/path/to/omconfig', 'omreport': '/path/to/omreport'}

        """
        config = get_config('perc800')
        try:
            binaries = config['controller_binaries']
            self.binaries = dict([(a.split('/')[-1].strip(), a.strip())
                                 for a in binaries.split(', ')])
        except Exception, e:
            self.binaries = get_binaries(COMMANDS)
            if COMMANDS != sorted(self.binaries.keys()):
                msg = 'Error trying to locate the omtools binaries: %s' % e
                raise Exception(msg)
Ejemplo n.º 4
0
def exit(message, subject='', error_code=1, notify=True):
    '''
    Exit with a specific error code (default 1).

    :param msg: Message to be returned.
    :param subject: Subject for the email.
    :param error_code: Exit code.
    :param notify: Should we send out a notification?
    '''
    if notify:
        try:
            notification_types = get_config()['notifications'].split(',')
            for notification in notification_types:
                try:
                    eval(notification).send_notification(subject, message)
                except:
                    raise Exception('Error: notification type not found')
        except:
            # Nothing serious, just no need to notify
            pass
    print message
    sys.exit(error_code)
Ejemplo n.º 5
0
    def send_notification(self, subject, body):
        # Get the list of recipients from the config file.
        # The option is notification_email_recipients
        from swift_drive.common.utils import get_hostname
        hostname = get_hostname()
        config = get_config()
        # Get the recipients from the configuration. We can't go any further
        # without any.
        try:
            recipients = config['notification_email_recipients'].split(',')
        except:
            raise Exception('Error: could not find any recipients in the '
                            'configuration file. Please configure at least one.')

        # Check if there is a specific sender configured.
        try:
            sender = config['notification_email_from']
        except:
            sender = '*****@*****.**'

        for recipient in recipients:
            subject = '[swift-drive] - %s - %s' % (hostname, subject)
            message = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s' % \
                      (sender, recipient, subject, body)
            # Try to send an email for 3 times before raising an exception
            for retries in range(4):
                if retries == 3:
                    msg = 'Failed to send an email to %s. Error: %s' % \
                          (recipient, e)
                    raise Exception(msg)
                try:
                    self.smtp_server.sendmail(sender, recipient, message)
                except Exception, e:
                    pass
                finally:
                    break