def create(): targets = [] vm_manager = None for vm in request.json.get('vms'): if vm['role'] == 'manager': vm_manager = vm break server = Server(_id=vm_manager['_id']) server.swarm_init() targets.append(server.ips[server.networks[0]][0]['addr'] + ':' + cfg.prometheus['PROMETHEUS_PORT']) for vm in request.json.get('vms'): if vm['_id'] != vm_manager['_id']: if vm['role'] == 'manager': manager = Server(_id=vm['_id']) manager.swarm_join_manager(server) targets.append(manager.ips[manager.networks[0]][0]['addr'] + ':' + cfg.prometheus['PROMETHEUS_PORT']) elif vm['role'] == 'worker': worker = Server(_id=vm['_id']) worker.swarm_join_worker(server) targets.append(worker.ips[worker.networks[0]][0]['addr'] + ':' + cfg.prometheus['PROMETHEUS_PORT']) cluster = db.clusters.insert({'vms': request.json.get('vms')}) add_cluster_id.delay(targets, str(cluster)) return 'created'
def create(): targets = [] vm_manager = None for vm in request.json.get('vms'): if vm['role'] == 'manager': vm_manager = vm break server = Server(_id=vm_manager['_id']) server.swarm_init() targets.append(server.ips[server.networks[0]][0]['addr'] + ':' + cfg.prometheus['PROMETHEUS_PORT']) for vm in request.json.get('vms'): if vm['_id'] != vm_manager['_id']: if vm['role'] == 'manager': manager = Server(_id=vm['_id']) manager.swarm_join_manager(server) targets.append(manager.ips[manager.networks[0]][0]['addr'] + ':' + cfg.prometheus['PROMETHEUS_PORT']) elif vm['role'] == 'worker': worker = Server(_id=vm['_id']) worker.swarm_join_worker(server) targets.append(worker.ips[worker.networks[0]][0]['addr'] + ':' + cfg.prometheus['PROMETHEUS_PORT']) cluster = db.clusters.insert({'vms': request.json.get('vms')}) if 'up' in request.get_json(): rule = request.json.get('up') direction = 'up' db.clusters.update_one({'_id': cluster}, { '$set': {'up': request.json.get('up')} }) if 'down' in request.get_json(): rule = request.json.get('down') direction = 'down' db.clusters.update_one({'_id': cluster}, { '$set': {'down': request.json.get('down')} }) add_cluster_id.delay(targets, str(cluster)) return 'created'