#!/usr/bin/env python # -*- coding: utf-8 -*- __version__ = '0.0.1' __author__ = 'Michael Stangl (mistangl[-a-]syntops.de)' __copyright__ = 'Copyright 2010, Michael Stangl' __license__ = 'BSD' import optparse import os import ConfigParser import jiffys from utils import CSVImport from datetime import datetime from django.utils.encoding import smart_unicode, smart_str def logger_init(logfile): import logging log = logging.getLogger('master') now = datetime.now() timestr = now.strftime("%d-%m-%Y_%H-%M-%S") hdlr = logging.FileHandler(logfile) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) log.addHandler(hdlr) log.setLevel(logging.INFO) log.info('now: '+str(now)) return log #now = datetime.now() #logfile = 'mapsgen_'+ now.strftime("%d-%m-%Y.log") #log_path = os.path.normpath( #os.path.expandvars(os.path.join('$MAPSGEN_LOG', logfile )) #) ##if not os.path.exists(log_path): parser.error('\"'+ log_path +'\" does not exist.') #log = logger_init(log_path) #log.debug('template: '+template) def main( config ): now = datetime.now() ids=[] config_path = os.path.expandvars(os.path.join('$MASTER_CFG', config+'.cfg' )) if not os.path.exists(config_path): parser.error('\"'+ config_path +'\" does not exist. Please give the name to a config file for the rows!') config = ConfigParser.RawConfigParser() config.read(config_path) globalsec = dict(config.items('globals')) # Setup: # gewünschte Box(en) auftauen, wenn noch nicht passiert # Boxen skalieren if options.setup: ids = setup(globalsec) if config.has_section('IDs'): oldids = config.get('IDs', 'Ids') ids = [oldids, ids] else: config.add_section('IDs') # die Ids der neuen in die Config schreiben for i in ids: config.set('IDs', i, 'True') with open(config_path, 'wb') as configfile: config.write(configfile) # # Arbeiten durchführen: # Daten auf Boxen verteilen und Arbeiten anstossen # # Status des Systems anzeigen: # - wieviel Boxen sind am Leben und aktiv? # - welche macht gerade was? # - wieviel % der Aufgaben sind fertig? # - wieviel % der jobs sind erledigt? # - wieviele Packete sind schon ausgeliefert? # wenn alles fertig ist, Teardown: # alle Boxen bis auf den Ursprung löschen # Box(en) einfrieren if options.teardown: ids = dict(config.items('IDs')).keys() teardown(globalsec['token'], ids) def setup( jiffyinfos ): ''' Erstellt aus einem Backup mehrere Jiffy boxen und started diese ''' token = jiffyinfos['token'] boxid = jiffyinfos['boxid'] num_boxes = jiffyinfos['num_boxes'] backupid = jiffyinfos['backupid'] planid = jiffyinfos['planid'] name = jiffyinfos['name'] password = jiffyinfos['password'] ids = jiffys.rebuild_backup(token, boxid, num_boxes, backupid, name, planid, password) jiffys.start_boxes(ids, token, planid) return ids # Ausgabe einer Zeile in der Konsole ##!/bin/python #import sys #for i in xrange(1000000): #print i, "\r", #sys.stdout.flush() # z.B. build image "engine" (3/5) started (1/5) def teardown( token, ids ): ''' killt die Jiffy boxen die angegeben sind ''' jiffys.delete_boxes(ids,token) if __name__ == '__main__': parser = optparse.OptionParser(usage="""%prog [options] Example usage ------------- Full help: $ %prog -h (or --help for possible options) Read Confg, create wakeup and scale this kind of jiffy box $ %prog -c test -i test """, version='%prog ' + __version__) parser.add_option("-c", "--cfg", dest="config", default="test", help="name of the config file with the Name of the rows to be used.", metavar="CONFIG_FILE") parser.add_option("-k", "--check", dest="check", help="check before creation, whether a map of this type exists already", action='store') parser.add_option("-o", "--outdir", dest="outdir", help="path to the directory where the maps will be generated", action='store') parser.add_option("-s", "--setup", dest="setup", help="setup the used boxes", action='store_true') parser.add_option("-t", "--teardown", dest="teardown", help="teardown the used boxes of that project", action='store_true') parser.add_option("-v", "--view-status", dest="view", help="show the status of that project: Boxes, jobs, etc.") parser.add_option("-y", "--dry", dest="dry", help="dont generate images. Just ask the coordinates and fill database.", action='store_true' ) (options, args) = parser.parse_args() main(options.config) else: pass # vim: set tw=75 ft=python ts=4 sw=4: