def get_hostname_from_marathon(self, environment, roger_env, appTaskId): hostname = '' marathon = Marathon() tasks = marathon.getTasks(roger_env, environment) for task in tasks: if task['id'].startswith(appTaskId): hostname = task['host'] return hostname
def from_json(cls, json_data): participant = Participant(json_data['id']) marathons = [] for marathon_data in json_data['marathons']: marathons.append(Marathon.from_json(marathon_data)) participant.marathons = marathons return participant
def __init__(self, options): self.m = Marathon() if options.empty: self.m.c.empty() if options.fix: self.m.c.fix_config() self.rss = RSS(self.m.c.rssfeeds, self.m.c.showdata[0]['rsslastupdate']) while self.run(): pass self.m.save()
def getFramework(self, request_uri): marathon_pattern = re.compile("^{}$".format("/marathon/.*")) marathon_check = marathon_pattern.match(request_uri) chronos_pattern = re.compile("^{}$".format("/chronos/.*")) chronos_check = chronos_pattern.match(request_uri) if marathon_check: return Marathon() elif chronos_check: return Chronos() else: return None
def __init__(self, cli_args, logger=None): self.args = cli_args self.logger = logger or logging.getLogger(__name__) self.mesos = MesosMaster(cli_args.mesos_uri) self.marathon = Marathon( cli_args.marathon_uri, (cli_args.marathon_user, cli_args.marathon_pass) if cli_args.marathon_user and cli_args.marathon_pass else None) self.auto_scaler = AutoScaler(self.marathon, cli_args=cli_args) self.cpu_fan_out = cli_args.cpu_fan_out self.datadog_client = DatadogClient(cli_args) self.agent_port = cli_args.agent_port
def update(self, switch_state: Callable) -> None: self.input1.update() self.input2.update() if self.entered: if self.position == 0: switch_state(DevicePrompter(Marathon(), 1)) elif self.position == 1: switch_state(DevicePrompter(SplitScreen(), 2)) elif self.position == 2: switch_state(DevicePrompter(Online(), 1)) elif self.position == 3: ctx.running = False
def attach_to_marathon(self, marathon_host): logging.info("Plugins loaded: {}".format(self.plugins_dict)) self.marathon = Marathon(marathon_host) messages = SSEClient("http://" + marathon_host + ":8080/v2/events") msg_json = {} for msg in messages: try: msg_json = json.loads(msg.data) except Exception as e: logging.info("not json message: " + msg.data) if 'eventType' in msg_json: self.handle_message(msg_json)
logging.info('\n\n\n') if __name__ == '__main__': logging.basicConfig( #filename='marathon-autoscale.log', format='[%(asctime)s] %(levelname)s %(message)s', level=logging.DEBUG) logging.info("This application tested with Python3 only") config_file = 'config.properties' if len(sys.argv) > 1: config_file = sys.argv[1] cfg = config.Configuration() try: cfg.load(config_file) except Exception as e: logging.info("Exception %s" % e) sys.exit(1) # Initialize the Marathon object marathon = Marathon(cfg.marathon_endpoint, cfg.auth_id, cfg.auth_password) logging.info("Marathon URI = %s" % marathon.uri) scheduler = BackgroundScheduler() scheduler.add_job(monitor, 'interval', seconds=15, args=[marathon, cfg]) scheduler.start() app.run(host='0.0.0.0', port=5000)
class EventProcessor(object): """Class for processing marathon events for EventProcessor""" def __init__(self): # map from marathon event to array of plugins self.plugins_dict = {} def register_plugin(self, plugin): plugin_instance = plugin() plugin_event = plugin_instance.get_event_to_attach() self.plugins_dict.setdefault(plugin_event, []).append(plugin_instance) return plugin def attach_to_marathon(self, marathon_host): logging.info("Plugins loaded: {}".format(self.plugins_dict)) self.marathon = Marathon(marathon_host) messages = SSEClient("http://" + marathon_host + ":8080/v2/events") msg_json = {} for msg in messages: try: msg_json = json.loads(msg.data) except Exception as e: logging.info("not json message: " + msg.data) if 'eventType' in msg_json: self.handle_message(msg_json) def handle_message(self, msg): logging.info('\n\nEVENT: ' + msg['eventType']) # fetch all marathon apps with specified labels new_feteched_apps = self.get_monitored_apps() event_plugins = self.plugins_dict.get(msg['eventType'], []) logging.info("Plugins triggered: ") logging.info(event_plugins) for plugin in event_plugins: try: monitored_apps_changed = plugin.apps_changed(new_feteched_apps) except Exception as e: logging.error("Plugin exception on apps comparison: {}".format(e)) continue if monitored_apps_changed: logging.info("Apps with changes: {}, plugin {} taking action." .format(monitored_apps_changed, plugin)) try: plugin.action(new_feteched_apps) except Exception as e: logging.error("Plugin exception on action: {}".format(e)) def print_marathon_apps(self, apps): logging.info(" Found Marathon apps: ") for app in apps: logging.info(app.appid) def get_monitored_apps(self): return self.marathon.get_all_apps()
class Menu(Basic): def menu(self, menu, default=None, doprint=True): i = 1 tmp = {} tdefault = None disableds = {} for item in menu: d = "" disableds.update({item[0]: False}) try: if item[2]: d = " (disabled)" disableds.update({item[0]: True}) except IndexError: pass if doprint: print "%s: %s%s" % (i, item[1], d) tmp.update({i : item[0]}) if default == item[0]: tdefault = i i += 1 p = self.ii("Option%s: " % (" (%s)" % tdefault if default!=None else "")) try: w = int(p) if disableds[tmp[w]]: print "Option disabled, try again..." return self.menu(menu, default, False) return tmp[w] except (TypeError, ValueError): if p == None and default != None: if disableds[default]: print "Option disabled, try again..." return self.menu(menu, default, False) return default return p except KeyError: return p def rsscheck(self): if self.rss.check(): print "There are new torrents available." print "Type :rss to see them." def ii(self, msg): self.m.c.autosave() opt = self.i(msg, True) self.rsscheck() print if opt == "SAVE": self.m.save() return None elif opt == "RSS": self.m.check_rss() return None elif opt == "LOAD": self.m.c.config_init() return None elif opt == "QUIT": print "Quit." self.m.save() sys.exit() else: return opt def browser_shows(self): print "Select show:" i = 0 for show in self.m.get_shows(): i += 1 print "%s: %s (%s)" % (i, show, self.m.get_episode_amount(show)) p = self.ii("Option: ") if not p: return False elif p == "RETURN": return True elif p == "TOP": return True else: try: self.m.set_currentshow(p) except (IndexError, ValueError, TypeError): print "Ununderstood option." return True def add_show(self): self.m.add_show() return True def check_rss(self): return True def settings(self): return True def run(self): print "You have %s show(s) in your configuration." % self.m.get_show_count() print "Please select an option:" p = self.menu( [("SHOW", "Select a show to watch", self.m.get_show_count()==0), ("ADD", "Add shows"), ("RSS", "Check RSS feeds"), ("SETTINGS", "Settings")], "SHOW") if p == "SHOW": if len(self.m.shows) == 0: print "No shows available, please add some." else: return self.browser_shows() elif p == "ADD": return self.add_show() elif p == "RSS": return self.check_rss() elif p == "SETTINGS": return self.settings() else: return self.run() def __init__(self, options): self.m = Marathon() if options.empty: self.m.c.empty() if options.fix: self.m.c.fix_config() self.rss = RSS(self.m.c.rssfeeds, self.m.c.showdata[0]['rsslastupdate']) while self.run(): pass self.m.save()
def add_marathon(self, date, name, type, time_finished, category): marathon = Marathon(date, name, type, time_finished, category) self.marathons.append(marathon)