def launch_docker(self): my_offers = self.conn.offers.get('offers') for i in range(0, len(my_offers)): print("Starting offer ", i + 1, " of ", len(my_offers)) offer = my_offers[i] container_launch_info = get_json(DOCKER_JSON) # Need to update the fields that reflect the offer ID / agent ID and a random, unique task ID: task_id = str(random.randint(1, 100)) agent_id = offer['agent_id']['value'] offer_id = offer['id'] container_launch_info["accept"]["offer_ids"].append(offer["id"]) container_launch_info["framework_id"]["value"] = self.conn.framework_id task_infos = container_launch_info["accept"]["operations"][0]["launch"]["task_infos"][0] task_infos["agent_id"]["value"] = agent_id task_infos["task_id"]["value"] = task_id task_infos["resources"].append(get_json(TASK_RESOURCES_JSON)) print("Sending ACCEPT message, launching a DOCKER container:") pretty.pprint(container_launch_info) try: r = self.conn.post(self.api_url, container_launch_info) print("Result: {}".format(r.status_code)) if r.text: print(r.text) except ValueError, err: print("Request failed: {}".format(err))
def launch(self): my_offers = self.conn.offers.get('offers') for i in range(0, len(my_offers)): print("Starting offer ", i + 1, " of ", len(my_offers)) offer = my_offers[i] launch_json = get_json(LAUNCH_JSON) task_id = str(random.randint(100, 1000)) launch_json["accept"]["offer_ids"].append(offer["id"]) launch_json["framework_id"]["value"] = self.conn.framework_id task_infos = launch_json["accept"]["operations"][0]["launch"]["task_infos"][0] task_infos["task_id"]["value"] = task_id task_infos["command"]["value"] = "/usr/bin/python -m SimpleHTTPServer 9000" task_infos["agent_id"]["value"] = offer["agent_id"]["value"] task_infos["resources"] = get_json(TASK_RESOURCES_JSON) try: r = self.conn.post(self.api_url, launch_json) print("Result: {}".format(r.status_code)) if r.text: print(r.text) if 200 <= r.status_code < 300: print("Successfully launched task {} on Agent [{}]".format(task_id, self.conn.offers.get('offers')[0]["agent_id"]["value"])) except ValueError, err: print("Request failed: {}".format(err))
def launch(self): for i in range(0, len(self.conn.offers)): print("Starting offer ", i) offer = self.conn.offers.get('offers')[i] launch_json = get_json(LAUNCH_JSON) task_id = str(random.randint(100, 1000)) launch_json["accept"]["offer_ids"].append(offer["id"]) launch_json["framework_id"]["value"] = self.conn.framework_id task_infos = launch_json["accept"]["operations"][0]["launch"][ "task_infos"][0] task_infos["task_id"]["value"] = task_id task_infos["command"][ "value"] = "cd /var/local/www && /usr/bin/python -m SimpleHTTPServer 9000" task_infos["agent_id"]["value"] = self.conn.offers.get( 'offers')[0]["agent_id"]["value"] task_infos["resources"] = get_json(TASK_RESOURCES_JSON) q = Queue(1) self.framework.request("launch", launch_json, q) r = q.get() print("reply: {}".format(r))
def launch(self): for i in range(0, len(self.conn.offers)): print("Starting offer ", i) offer = self.conn.offers.get('offers')[i] launch_json = get_json(LAUNCH_JSON) task_id = str(random.randint(100, 1000)) launch_json["accept"]["offer_ids"].append(offer["id"]) launch_json["framework_id"]["value"] = self.conn.framework_id task_infos = launch_json["accept"]["operations"][0]["launch"]["task_infos"][0] task_infos["task_id"]["value"] = task_id task_infos["command"]["value"] = "cd /var/local/www && /usr/bin/python -m SimpleHTTPServer 9000" task_infos["agent_id"]["value"] = self.conn.offers.get('offers')[0]["agent_id"]["value"] task_infos["resources"] = get_json(TASK_RESOURCES_JSON) q = Queue(1) self.framework.request("launch", launch_json, q) r = q.get() print("reply: {}".format(r))