Ejemplo n.º 1
0
 def verify_connectivity(self):
     # Dummy call to verify if connection and authentication token work
     response = requests.get(self.base_url +
                             "/mesos_dns/v1/hosts/master.mesos",
                             auth=get_auth(),
                             verify=False)
     return response.ok
Ejemplo n.º 2
0
 def get_nodes(self):
     response = requests.get(self.base_url + "/system/health/v1/nodes",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         raise Exception("Unknown error occured: %s" % response.text)
     return response.json()["nodes"]
Ejemplo n.º 3
0
 def get_account(self, name):
     response = requests.get(self.base_url + "/users/" + name,
                             auth=get_auth(),
                             verify=False)
     if response.status_code != 200:
         return None
     return response.json()
Ejemplo n.º 4
0
 def remove_user_from_group(self, user_name, group):
     response = requests.delete(self.base_url + "/groups/%s/users/%s" %
                                (group, user_name),
                                auth=get_auth(),
                                verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when adding user to group")
Ejemplo n.º 5
0
 def get_groups_for_user(self, name):
     response = requests.get(self.base_url + "/users/%s/groups" % name,
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when querying groups for user")
     return [g["group"]["gid"] for g in response.json()["array"]]
Ejemplo n.º 6
0
 def get_deployments(self):
     response = requests.get(self.marathon_url + "/deployments",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text, flush=True)
         raise Exception("Failed to get deployments")
     return response.json()
Ejemplo n.º 7
0
 def get_rids(self):
     response = requests.get(self.base_url + "/acls",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when listing permission")
     return [acl["rid"] for acl in response.json()["array"]]
Ejemplo n.º 8
0
 def remove_permission_from_user(self, user_name, rid, action):
     rid = self._encode_rid(rid)
     response = requests.delete(self.base_url + "/acls/%s/users/%s/%s" %
                                (rid, user_name, action),
                                auth=get_auth(),
                                verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when removing permission from user")
Ejemplo n.º 9
0
 def add_permission_to_user(self, user_name, rid, action):
     rid = self._encode_rid(rid)
     response = requests.put(self.base_url + r"/acls/%s/users/%s/%s" %
                             (rid, user_name, action),
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when adding permission to user")
Ejemplo n.º 10
0
 def create_account(self, name, description, public_key):
     data = dict(description=description, public_key=public_key)
     response = requests.put(self.base_url + "/users/" + name,
                             json=data,
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when creating account")
Ejemplo n.º 11
0
 def get_permissions_for_user(self, name):
     response = requests.get(self.base_url+"/users/%s/permissions" % name, auth=get_auth(), verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when querying permissions for user")
     permissions = dict()
     for permission in response.json()["direct"]:
         permissions[permission["rid"]] = [a["name"] for a in permission["actions"]]
     return permissions
Ejemplo n.º 12
0
 def _get_master_state(self):
     response = requests.get(self.mesos_url + "master/state",
                             auth=get_auth(),
                             verify=False)
     if response.ok:
         return response.json()
     else:
         raise Exception("Failed to get mesos master state: %s" %
                         response.text)
Ejemplo n.º 13
0
 def _get_plan_status(self, service_name, plan):
     response = requests.get(get_base_url() + "/service" + service_name +
                             "v1/plans/%s" % plan,
                             auth=get_auth(),
                             verify=False)
     if response.ok:
         return response.json()["status"]
     else:
         return None
Ejemplo n.º 14
0
 def delete_secret(self, name):
     response = requests.delete(self.base_url + "secret/default/%s" % name,
                                auth=get_auth(),
                                verify=False)
     if response.status_code == 404:
         return
     if not response.ok:
         raise Exception("Could not delete secret %s: %s " %
                         (name, response.text))
Ejemplo n.º 15
0
 def create_pool(self, config):
     """Create a new pool"""
     response = requests.post(self.base_url + "v2/pools",
                              json=config,
                              auth=get_auth(),
                              verify=False)
     if not response.ok:
         raise Exception("Could not create pool %s: %s " %
                         (config["name"], response.text))
Ejemplo n.º 16
0
 def sign_csr(self, csr, hosts=list()):
     data = {"certificate_request": csr, "hosts": hosts}
     response = requests.post(self.base_url + "sign",
                              json=data,
                              auth=get_auth(),
                              verify=False)
     if not response.ok:
         raise Exception("Failed to sign cert: %s" % response.text)
     return response.json()["result"]["certificate"]
Ejemplo n.º 17
0
 def update_pool(self, config):
     """Update an existing pool config"""
     response = requests.put(self.base_url + "v2/pools/%s" % config["name"],
                             json=config,
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         raise Exception("Could not update pool %s: %s " %
                         (config["name"], response.text))
Ejemplo n.º 18
0
 def get_cluster_info(self):
     response = requests.get(self.base_url +
                             "/dcos-metadata/dcos-version.json",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         raise Exception("Unknown error occured: %s" % response.text)
     info = response.json()
     return dict(version=info["version"], variant=info["dcos-variant"])
Ejemplo n.º 19
0
 def get_pool(self, name):
     """Get config for a specific pool"""
     response = requests.get(self.base_url + "v2/pools/%s" % name,
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Failed to get pool")
     return response.json()
Ejemplo n.º 20
0
 def delete_pool(self, name):
     response = requests.delete(self.base_url + "v2/pools/%s" % name,
                                auth=get_auth(),
                                verify=False)
     if response.ok:
         return True
     elif response.status_code == 404:
         return False
     else:
         raise Exception("Unknown error occured: %s" % response.text)
Ejemplo n.º 21
0
 def list_secrets(self):
     """Retrive a list of secrets names"""
     response = requests.get(self.base_url + "secret/default/?list=true",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Failed to list secrets")
     data = response.json()["array"]
     return data
Ejemplo n.º 22
0
 def get_jobs(self):
     response = requests.get(self.metronome_url + "v1/jobs",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Unknown error occured")
     data = response.json()
     for job in data:
         yield "/" + job["id"].replace(".", "/")
Ejemplo n.º 23
0
 def create_permission(self, rid):
     rid = self._encode_rid(rid)
     response = requests.put(
         self.base_url + "/acls/%s" % rid,
         json=dict(description="created by dcos-deploy"),
         auth=get_auth(),
         verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Error occured when creating permission")
Ejemplo n.º 24
0
 def has_plans_api(self, service_name):
     if service_name[0] == "/":
         service_name = service_name[1:]
     response = requests.get(get_base_url() + "/service/" + service_name +
                             "/v1/plans/",
                             auth=get_auth(),
                             verify=False)
     if response.ok:
         return True
     else:
         return False
Ejemplo n.º 25
0
 def get_pools(self):
     """Retrive a list of pool names"""
     response = requests.get(self.base_url + "v2/pools",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         print(response.text)
         raise Exception("Failed to list pools")
     data = response.json()
     for pool in data:
         yield pool["name"]
Ejemplo n.º 26
0
 def restart_app(self, app_id, wait_for_deployment=False):
     response = requests.post(self.marathon_url +
                              "/apps/%s/restart" % app_id,
                              auth=get_auth(),
                              verify=False)
     if not response.ok:
         print(response.text, flush=True)
         raise Exception("Failed to restart app %s" % app_id)
     deployment_id = response.json()["deploymentId"]
     if wait_for_deployment:
         self.wait_for_specific_deployment(deployment_id)
Ejemplo n.º 27
0
 def delete_account(self, name):
     response = requests.delete(self.base_url + "/users/" + name,
                                auth=get_auth(),
                                verify=False)
     if response.ok:
         return True
     elif response.status_code == 404:
         return False
     else:
         raise Exception("Error occured when deleting account: %s" %
                         response.text)
Ejemplo n.º 28
0
 def ping(self):
     response = requests.get(self.base_url + "ping",
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         if response.status_code == 503:
             return False
         elif response.status_code == 404:
             return False
         else:
             raise Exception("Could not get ping from edgelb: %s" %
                             response.text)
     return True
Ejemplo n.º 29
0
 def create_job(self, definition):
     response = requests.post(self.metronome_url + "v0/scheduled-jobs",
                              json=definition,
                              auth=get_auth(),
                              verify=False)
     if response.ok:
         return
     if response.status_code == 422:
         print(response.text)
         raise Exception("Invalid job definition")
     else:
         print(response.text)
         raise Exception("Unknown error occured")
Ejemplo n.º 30
0
 def get_app_state(self, app_id):
     if not app_id[0] == "/":
         app_id = "/" + app_id
     response = requests.get(self.marathon_url +
                             "/apps%s/?embed=app.counts" % app_id,
                             auth=get_auth(),
                             verify=False)
     if not response.ok:
         if response.status_code == 404:
             return None
         print(response.text, flush=True)
         raise Exception("Failed to get state for %s" % app_id)
     return response.json()["app"]