mostly stable
This commit is contained in:
		| @@ -8,6 +8,12 @@ def c_get_containers(req_obj, host, port, jwt, endpoint): | ||||
|     c_get_containers_response = req_obj.get(url, headers={"Authorization": f"Bearer {jwt}"},verify=False) | ||||
|     return c_get_containers_response.json() | ||||
|  | ||||
| #filters={"name": ["restic","qbittorrent"],"status": ["paused","dead","created","exited","removing","restarting","created"]} | ||||
| def c_get_filtered_containers(req_obj, host, port, jwt, endpoint, containers, statuses): | ||||
|     url = f'https://{host}:{port}/api/endpoints/{endpoint}/docker/containers/json?filters={"name": {containers},"status": {statuses}}' | ||||
|     c_get_containers_response = req_obj.get(url, headers={"Authorization": f"Bearer {jwt}"},verify=False) | ||||
|     return c_get_containers_response.json() | ||||
|  | ||||
| def c_start_container(req_obj, host, port, jwt, endpoint, cid): | ||||
|     url = f'https://{host}:{port}/api/endpoints/{endpoint}/docker/containers/{cid}/start' | ||||
|     c_start_container_response = req_obj.post(url, headers={"Authorization": f"Bearer {jwt}"},verify=False) | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| # TODO add file for containers that need to be started | ||||
|  | ||||
| def build_cont_list(obj, hypercare_containers): | ||||
|     cont_list = [] | ||||
|     for i, c in enumerate(obj): | ||||
|   | ||||
							
								
								
									
										2
									
								
								crane.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								crane.py
									
									
									
									
									
								
							| @@ -50,7 +50,7 @@ class Crn: | ||||
|             self.tl.info('Authenticated successfully.') | ||||
|             self.cont_obj = c_get_containers(self.cc, self.host, self.port, self.jwt, self.endpoint) | ||||
|             self.tl.debug('Collected container data.') | ||||
|             self.cont_list = build_cont_list(self.cont_obj, self.observed_containers) | ||||
|             self.cont_list = build_full_cont_list(self.cont_obj, self.observed_containers) | ||||
|             self.tl.debug('Building container list.') | ||||
|             self.process_cont_list_response = process_cont_list(self.cont_list, c_start_container, self.cc, self.host, self.port, self.jwt, self.endpoint) | ||||
|             if self.process_cont_list_response: | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| import unittest | ||||
| import requests | ||||
| from tomllib import load | ||||
| from cclient import c_auth, c_get_containers, c_start_container, c_stop_container | ||||
| from cclient import c_auth, c_get_containers, c_start_container, c_stop_container, c_get_filtered_containers | ||||
| from cprocess import build_cont_list, process_cont_list, build_full_cont_list, process_cont_status | ||||
| unittest.TestLoader.sortTestMethodsUsing = None | ||||
|  | ||||
| @@ -17,8 +17,10 @@ class TestCrane(unittest.TestCase): | ||||
|         self.cid = 'aa5b217ca6217fd9d268396039da69ea9e4a5aff381b3dceb71edb5a1f4d429d' | ||||
|         self.req_obj = requests | ||||
|         self.hypercare_containers = ['hello-world'] | ||||
|         #self.status_filters = ["paused","dead","created","exited","removing","restarting","created"] | ||||
|         self.jwt = c_auth(self.req_obj, self.host, self.port, self.username, self.password) | ||||
|         self.cont_obj = c_get_containers(self.req_obj, self.host, self.port, self.jwt, self.endpoint) | ||||
|         #self.cont_obj_f = c_get_filtered_containers(self.req_obj, self.host, self.port, self.jwt, self.endpoint,self.hypercare_containers,self.status_filters) | ||||
|  | ||||
|     def test_c_auth(self): | ||||
|         self.assertTrue(self.jwt, "No JWT returned by cauth.") | ||||
| @@ -26,6 +28,9 @@ class TestCrane(unittest.TestCase): | ||||
|     def test_c_get_containers(self): | ||||
|         self.assertTrue(self.cont_obj, "No cont object returned by c_get_containers.") | ||||
|  | ||||
|     def test_c_get_containers_f(self): | ||||
|         self.assertTrue(self.cont_obj_f, "No cont object returned by c_get_containers.") | ||||
|  | ||||
|     def test_a_is_hypercare_container_status(self): | ||||
|         self.cont_full_list = build_full_cont_list(self.cont_obj, self.hypercare_containers) | ||||
|         self.process_cont_status_response = process_cont_status(self.cont_full_list) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user