Example #1
0
 def inspect_instance(self, name):
     try:
         container = self.client.containers.get(name)
         return new_operator_instance(
             container.short_id, container.name, container.status,
             container.attrs["NetworkSettings"]["IPAddress"],
             container.ports)
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)
Example #2
0
 def inspect_instance(self, name):
     try:
         container = self.client.containers.get(name)
         return new_operator_instance(container.short_id, container.name,
                                      container.status,
                                      self.get_container_ip(container),
                                      container.ports)
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)
Example #3
0
 def delete_instance(self, name):
     try:
         container = self.client.containers.get(name)
         container.remove(force=True)
         return new_operator_instance(
             container.short_id, container.name, "deleted",
             container.attrs["NetworkSettings"]["IPAddress"],
             container.ports)
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)
Example #4
0
 def delete_instance(self, name):
     try:
         container = self.client.containers.get(name)
         container.remove(force=True)
         return new_operator_instance(container.short_id, container.name,
                                      "deleted",
                                      self.get_container_ip(container),
                                      container.ports)
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)
Example #5
0
 def create_instance(self, name, image, ports, args=None):
     try:
         container = self.client.containers.run(image=image,
                                                name=name,
                                                detach=True,
                                                ports=ports,
                                                labels=self.labels)
         return new_operator_instance(
             container.short_id, container.name, container.status,
             container.attrs["NetworkSettings"]["IPAddress"],
             container.ports)
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)
Example #6
0
 def create_instance(self, name, image, ports, args=None):
     try:
         self.client.containers.run(image=image,
                                    name=name,
                                    detach=True,
                                    ports=ports,
                                    labels=self.labels,
                                    network=self.network)
         containers = self.client.containers.list(all=False,
                                                  filters={"name": name})
         container = containers[0]
         return new_operator_instance(container.short_id, container.name,
                                      container.status,
                                      self.get_container_ip(container),
                                      container.ports)
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)
Example #7
0
 def list_instances(self, name):
     try:
         res = []
         containers = self.client.containers.list(all=True,
                                                  filters={
                                                      "name":
                                                      f"phantoscope_{name}",
                                                      "label": self.labels
                                                  })
         for container in containers:
             res.append(
                 new_operator_instance(
                     container.short_id, container.name, container.status,
                     container.attrs["NetworkSettings"]["IPAddress"],
                     container.ports))
         return res
     except APIError as e:
         raise DockerRuntimeError(e.explanation, e)