def project_lists(self): """ Return the project lists of the user. """ url = get_api_server_url('/api/projects/') response = self.client.get(url) return json.loads(response.text)
def list_hosts(self): """ List all hosts. """ url = get_api_server_url('/api/hosts/') response = self.client.get(url) return json.loads(response.text)
def list_users(self): """ Get user lists only for admin user. """ url = get_api_server_url('/api/users/') response = self.client.get(url) return json.loads(response.text)
def list_projects(self): """ List all projects for admin user. """ url = get_api_server_url('/api/projects/') response = self.client.get(url) return json.loads(response.text)
def get_project(self, project_id): """ Get the detail info of the project. """ url = get_api_server_url('/api/projects/{}/'.format(project_id)) response = self.client.get(url) return json.loads(response.text)
def get_resourcelimits(self): """ Get the resource limits list. """ url = get_api_server_url('/api/resourcelimits/') res = self.client.get(url) return json.loads(res.text)
def get_resourcelimit(self, lid): """ Get the resource limit with id lid. """ url = get_api_server_url('/api/resourcelimits/{}/'.format(lid)) res = self.client.get(url) return json.loads(res.text)
def get_public_images(self): """ Get public images. """ url = get_api_server_url('/api/publics/') response = self.client.get(url) return json.loads(response.text)
def list_resource_modules(self): """ Return resource modules only for admin user. """ url = get_api_server_url('/api/resourcelimits/') response = self.client.get(url) return json.loads(response.text)
def get_volume_username(self, project_id, volume_id): """ Get the username of the volume. """ url = get_api_server_url('/api/projects/{}/volumes/{}/username/'.format( project_id, volume_id)) response = self.client.get(url) return json.loads(response.text)
def download_from_volume(self, project_id, volume_id): """ Download data from volume with id volume_id. """ url = get_api_server_url('/api/projects/{}/volumes/{}/download/' .format(project_id, volume_id)) response = self.client.get(url) return response
def delete_resource_module(self, module_id): url = get_api_server_url('/api/resourcelimits/{}/'.format(module_id)) headers = {'X-CSRFToken': self.client.cookies['csrftoken']} res = self.client.delete(url, headers=headers) # print(res.status_code) if res.status_code == 204: return True return False
def get_pods(self, project_id, application_id): """ Get the pod lists of app with application_id in project project_id. """ url = get_api_server_url('/api/projects/{}/applications/{}/pods/' .format(project_id, application_id)) res = self.client.get(url) return json.loads(res.text)
def get_environments(self, project_id, application_id): """ Get environments of application with id application_id. """ url = get_api_server_url('/api/projects/{}/applications/{}/envs/' .format(project_id, application_id)) response = self.client.get(url) return json.loads(response.text)
def get_application_username(self, project_id, application_id): """ Get the username of the application. """ url = get_api_server_url('/api/projects/{}/applications/{}/username/'.format( project_id, application_id)) response = self.client.get(url) return json.loads(response.text)
def get_pod_logs(self, project_id, pod_name, tail=20): """ Get the tail n lines logs of pod named pod_name in project project_id. """ url = get_api_server_url('/api/projects/{}/pods/{}/logs/'.format( project_id, pod_name)) params = {'tail': tail} res = self.client.get(url, params=params) return json.loads(res.text)
def list_projects_for_user(self, user_id): """ List all projects for user with user_id. """ url = get_api_server_url('/api/list-projects') params = {'user': user_id} response = self.client.get(url, params=params) return json.loads(response.text)
def login(self, data): """ Return cookies. """ url = get_api_server_url('/api/auth/login/') self.client.get(url) data['csrfmiddlewaretoken'] = self.client.cookies['csrftoken'] self.client.post(url, data) return self.client.cookies
def list_pods_for_app(self, app_id): """ List all pods for app with app_id. """ url = get_api_server_url('/api/list-pods') params = {'app': app_id} response = self.client.get(url, params=params) return json.loads(response.text)
def delete_user(self, user_id): """ Admin user delete user with user_id. """ url = get_api_server_url('/api/users/{}/'.format(user_id)) headers = { 'X-CSRFToken': self.client.cookies['csrftoken'], } self.client.delete(url, headers=headers)
def create_project(self, data): """ Create an project for user. """ url = get_api_server_url('/api/projects/') response = self.client.post(url, data) if response.status_code == 201: return True return False
def list_apps_for_project(self, project_id): """ List all apps for project with project_id. """ url = get_api_server_url('/api/list-apps') params = {'project': project_id} response = self.client.get(url, params=params) return json.loads(response.text)
def registry(self, data): """ User registry. """ url = get_api_server_url('/api/registry/') headers = { 'X-CSRFToken': self.client.cookies['csrftoken'], } response = self.client.post(url, data=data, headers=headers)
def delete_project(self, project_id): """ Delete the project with id project_id. """ url = get_api_server_url('/api/projects/{}/'.format(project_id)) headers = {'X-CSRFToken': self.client.cookies['csrftoken']} res = self.client.delete(url, headers=headers) if res.status_code == 204: return True return False
def get_image(self, project_id, image_id): """ Get the detail info of the image. """ url = get_api_server_url('/api/projects/{}/images/{}/'.format( project_id, image_id)) response = self.client.get(url) image = json.loads(response.text) image['user'] = self.get_image_username(project_id=project_id, image_id=image_id) return image
def get_application(self, project_id, application_id): """ Get the detail info of the application. """ url = get_api_server_url('/api/projects/{}/applications/{}/'.format( project_id, application_id)) response = self.client.get(url) application = json.loads(response.text) application['user'] = self.get_application_username( project_id=project_id, application_id=application['id']) return application
def get_autoscaler(self, project_id, application_id): """ Get autoscaler of application with id application_id. """ url = get_api_server_url('/api/projects/{}/applications/{}/scalers/' .format(project_id, application_id)) response = self.client.get(url) scalers = json.loads(response.text) if scalers: return scalers[0] return {}
def get_volume(self, project_id, volume_id): """ Get the detail info of the volume. """ url = get_api_server_url('/api/projects/{}/volumes/{}/'.format( project_id, volume_id)) response = self.client.get(url) volume = json.loads(response.text) volume['user'] = self.get_volume_username(project_id=project_id, volume_id=volume_id) return volume
def clear_volume(self, project_id, volume_id): """ Clear data of volume with id volume_id. """ url = get_api_server_url('/api/projects/{}/volumes/{}/clear/' .format(project_id, volume_id)) response = self.client.get(url) if response.status_code == 200: return True else: return False
def registry(self, data): """ User registry. """ url = get_api_server_url('/api/users/') response = self.client.post(url, data) user_url = json.loads(response.text)['url'] password_url = user_url + 'set_password/' self.client.post(password_url, data) return self.login(data)