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
def build_cli(): config = ConfigParser.SafeConfigParser() config.read(CONFIG_FILE) arch = config.get('DEFAULT','arch') config = ConfigParser.SafeConfigParser() config.read('nodes.conf') broker_url = config.get(arch,'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') buildconf = open(CONFIG_FILE) buildconf_str = json.dumps(buildconf.read()) buildconf.close() config = ConfigParser.RawConfigParser() config.read(CONFIG_FILE) if config.has_section('dvd'): ks = config.get('dvd','config') else: if config.has_section('live'): ks = config.get('live','config') else: ks = None if ks: # if its a remote KS file if ks.startswith(('http','ftp')): # download and then JSON dump import urllib2 ksstr = json.dumps(urllib2.urlopen(ks).read()) head, ks_fname = os.path.split(ks) else: with open(ks) as ks_fp: ksstr = json.dumps(ks_fp.read()) head, ks_fname = os.path.split(ks) #send task to celery woker(s) build.apply_async(args=[buildconf_str,[ks_fname,ksstr]],serializer="json") else: build.apply_async(args=[buildconf_str,None],serializer="json") print 'Build task submitted' return
def build(self): util = Utilities() buildconfig = util.get_dict(self.config) release = buildconfig['default']['release'] 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) isotype = buildconfig['default']['type'] if isotype != 'boot': ksstr = util.get_kickstart(buildconfig) else: ksstr = None # task delegation from tasks import build try: print 'Sending build task to worker' queue_name = 'fedora-{0:s}'.format(release) result_obj = build.apply_async(args = [buildconfig_json, ksstr], queue = queue_name, serializer="json") except Exception as e: sys.exit('Error in communicating with Celery') else: result = result_obj.get() return result
def delegate(): # Read the data/config/imagebuild.conf file # to find the architecture of the image sought config = ConfigParser.SafeConfigParser() config.read('data/config/imagebuild.conf') arch = config.get('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') # task delegation from celery.execute import send_task from tasks import build import json buildconf=open('data/config/imagebuild.conf') buildconf_str=json.dumps(buildconf.read()) buildconf.close() # retrieve the kickstart file name if any config = ConfigParser.RawConfigParser() config.read('data/config/imagebuild.conf') if config.has_section('dvd'): if not config.get('dvd','config').startswith(('http','ftp')): head, ks_fname = os.path.split(config.get('dvd','config')) else: ks_fname = config.get('dvd','config') else: if config.has_section('live'): if not config.get('live','config').startswith(('http','ftp')): head, ks_fname = os.path.split(config.get('live','config')) else: ks_fname = config.get('live','config') else: ks_fname = None if ks_fname: # if its a remote KS file if ks_fname.startswith(('http','ftp')): # download and then JSON dump import urllib2 ksstr = json.dumps(urllib2.urlopen(ks_fname).read()) else: ks = open('data/kickstarts/{0:s}'.format(ks_fname)) ksstr = json.dumps(ks.read()) ks.close() #send task to celery woker(s) if ks_fname: build.apply_async(args=[buildconf_str,[ks_fname,ksstr]],serializer="json") else: build.apply_async(args=[buildconf_str,None],serializer="json") return