def unreserve_resource(agent, role): """ Unreserves all the resources for the role on the agent. """ resources = [] agent_id = agent['id'] reserved_resources_full = agent.get('reserved_resources_full', None) if not reserved_resources_full: # doesn't exist return True reserved_resources = reserved_resources_full.get(role, None) if not reserved_resources: # doesn't exist return True for reserved_resource in reserved_resources: resources.append(reserved_resource) req_url = urljoin(master_url(), 'unreserve') data = { 'slaveId': agent_id, 'resources': json.dumps(resources) } success = False try: response = http.post(req_url, data=data) success = 200 <= response.status_code < 300 except DCOSHTTPException as e: print("HTTP {}: Unabled to unreserve resources based on: {}".format( e.response.status_code, e.response.text)) return success
def mesos_available_predicate(): url = master_url() try: response = http.get(url) return response.status_code == 200 except Exception as e: return False
def destroy_volume(agent, role): """ Deletes the volumes on the specific agent for the role """ volumes = [] agent_id = agent['id'] reserved_resources_full = agent.get('reserved_resources_full', None) if not reserved_resources_full: # doesn't exist return True reserved_resources = reserved_resources_full.get(role, None) if not reserved_resources: # doesn't exist return True for reserved_resource in reserved_resources: name = reserved_resource.get('name', None) disk = reserved_resource.get('disk', None) if name == 'disk' and disk is not None and 'persistence' in disk: volumes.append(reserved_resource) req_url = urljoin(master_url(), 'destroy-volumes') data = { 'slaveId': agent_id, 'volumes': json.dumps(volumes) } success = False try: response = http.post(req_url, data=data) success = 200 <= response.status_code < 300 if response.status_code == 409: # thoughts on what to do here? throw exception # i would rather not print print('''###\nIs a framework using these resources still installed?\n###''') except DCOSHTTPException as e: print("HTTP {}: Unabled to delete volume based on: {}".format( e.response.status_code, e.response.text)) return success