def notify_email_final(self):
        ''' Send a final notification email upon build completion '''

        if os.environ.has_key('LOCAL_MODE'):
            if os.environ['LOCAL_MODE'] == '1':
                return

        message = 'Your Image Building Request have been completed.'
        ipaddr = self.getip()
        message = '<p>The build was completed by worker:: {0:s}. Detailed log: '.format(ipaddr)

        with open(self.logfile) as f:
            for line in f:
                message = message + '<p>' + line

        recipient = self.email
        subject = 'Your Image Build Request'

        headers = ["From: " + 'Fedora Build Service',
                   "Subject: " + subject,
                   "To: " + recipient,
                   "MIME-Version: 1.0",
                   "Content-Type: text/html"]
        headers = "\r\n".join(headers)
            
        notify = Notification()
        notify.send_email(recipient, headers, message)

        return
    def notify_email_init(self):
        ''' Send a notification email upon build initiation with
        the monitor access URL: <ip>:/log/tmp/imagebuild_xxx.log
        '''
        if os.environ.has_key('LOCAL_MODE'):
            if os.environ['LOCAL_MODE'] == '1':
                return

        message = 'Your Image Building Request have been submitted. '
        ipaddr = self.getip()

        if self.monitor:
            message = message + 'You may monitor the progress by going to '
            message = message + 'http://' + ipaddr + ':5100/log{0:s}. '.format(self.logfile)
            message = message + 'You will also recieve an email upon completion.'
        else:
            message = message + 'You will recieve an email upon completion.'
        
        recipient = self.email
        subject = 'Your Image Build Request'

        headers = ["From: " + 'Fedora Build Service',
                   "Subject: " + subject,
                   "To: " + recipient,
                   "MIME-Version: 1.0",
                   "Content-Type: text/html"]
        headers = "\r\n".join(headers)
            
        
        notify = Notification()
        notify.send_email(recipient, headers, message)

        return
Exemple #3
0
def delegate():
    # Read the data/config/imagebuild.conf file
    # to find the architecture of the image sought

    util = Utilities()
    buildconfig = util.get_dict('data/config/imagebuild.conf')

    arch = buildconfig['default']['arch']
    #find an appropriate build node from nodes.conf
    #based on the arch
    config = ConfigParser.SafeConfigParser()
    config.read('nodes.conf')
    broker_url = config.get(arch,'broker_url')

    #now create the celeryconfig.py using this broker_url
    with open('celeryconfig.py','w') as f:
        f.write('BROKER_URL = {0:s}\n'.format(broker_url))
        f.write('CELERY_RESULT_BACKEND = "amqp"\n')
        f.write('\n')
    
    buildconfig_json = json.dumps(buildconfig)

    if not buildconfig['default']['type'] == 'boot':
        ksstr = util.get_kickstart(buildconfig)
    else:
        ksstr = None

    # celery task delegation
    from tasks import build

    try:
        release = buildconfig['default']['release']
        queue_name = 'fedora-{0:s}'.format(release)
        build.apply_async(args = [buildconfig_json, ksstr], queue = queue_name, serializer="json")
    except Exception as e:
        # if there is an error in submitting job to celery
        # we save this somewhere and retry (TODO)
        # for now, we just have an email error message
        # using config in smtp.py
        recipient = buildconfig['default']['email']
        subject = 'Your Image Build Request'
        message = 'Uh Oh. The image builders are having a bad day. Retry again in sometime.'

        headers = ["From: " + 'Fedora Build Service',
                   "Subject: " + subject,
                   "To: " + recipient,
                   "MIME-Version: 1.0",
                   "Content-Type: text/html"]
        headers = "\r\n".join(headers)

        notify = Notification()
        notify.send_email(recipient, headers, message)
        return 
    else:
        return