| 97 | ) |
| 98 | |
| 99 | def call_maas(self, method, path, data=None, ignore_404=False): |
| 100 | if not path.startswith("/"): |
| 101 | path = "/" + path |
| 102 | url = f"{self.data['endpoint']}:5240/MAAS/api/2.0{path}" |
| 103 | resp = self.session.request(method, url, data=data) |
| 104 | |
| 105 | if resp.status_code == 404 and ignore_404: |
| 106 | return None |
| 107 | |
| 108 | if not resp.ok: |
| 109 | fail(f"MAAS API error: {resp.status_code} {resp.text}") |
| 110 | |
| 111 | try: |
| 112 | return resp.json() if resp.text else {} |
| 113 | except ValueError: |
| 114 | return {} |
| 115 | |
| 116 | def prepare(self): |
| 117 | machines = self.call_maas("GET", "/machines/") |