コード例 #1
0
 def _get_client(self,
                 pod_id: int,
                 context: dict,
                 project: Optional[str] = None):
     """Connect PyLXD client."""
     if not project:
         project = context.get("project", "default")
     endpoint = self.get_url(context)
     try:
         client = Client(
             endpoint=endpoint,
             project=project,
             cert=get_maas_cert_tuple(),
             verify=False,
         )
         if not client.trusted:
             password = context.get("password")
             if password:
                 client.authenticate(password)
             else:
                 raise LXDPodError(
                     f"Pod {pod_id}: Certificate is not trusted and no password was given."
                 )
     except ClientConnectionFailed:
         raise LXDPodError(
             f"Pod {pod_id}: Failed to connect to the LXD REST API.")
     return client
コード例 #2
0
 def test_get_maas_cert_tuple(self):
     self.assertItemsEqual(
         (
             maas_certificates.MAAS_CERTIFICATE,
             maas_certificates.MAAS_PRIVATE_KEY,
         ),
         maas_certificates.get_maas_cert_tuple(),
     )
     self.assertTrue(os.path.isfile(maas_certificates.MAAS_CERTIFICATE))
     self.assertTrue(os.path.isfile(maas_certificates.MAAS_PRIVATE_KEY))
コード例 #3
0
 def get_client(self, pod_id: str, context: dict):
     """Connect pylxd client."""
     endpoint = self.get_url(context)
     password = context.get("password")
     try:
         client = yield deferToThread(
             Client,
             endpoint=endpoint,
             cert=get_maas_cert_tuple(),
             verify=False,
         )
         if not client.trusted:
             if password:
                 yield deferToThread(client.authenticate, password)
             else:
                 raise LXDPodError(
                     f"Pod {pod_id}: Certificate is not trusted and no password was given."
                 )
     except ClientConnectionFailed:
         raise LXDPodError(
             f"Pod {pod_id}: Failed to connect to the LXD REST API.")
     return client