|
@@ -93,20 +93,35 @@ class Podman:
|
|
|
def ps(cls):
|
|
def ps(cls):
|
|
|
out = subprocess.run(["podman", "ps"], capture_output=True, check=True)
|
|
out = subprocess.run(["podman", "ps"], capture_output=True, check=True)
|
|
|
|
|
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def machine_is_running(cls) -> bool:
|
|
|
|
|
+ try:
|
|
|
|
|
+ cls.ps()
|
|
|
|
|
+ except subprocess.CalledProcessError as e:
|
|
|
|
|
+ if "Cannot connect to Podman" in e.stderr.decode():
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def machine_start(cls):
|
|
|
|
|
+ cls._call(["machine", "start"])
|
|
|
|
|
+
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def _call(cls, args: list, **kwargs):
|
|
def _call(cls, args: list, **kwargs):
|
|
|
args = ["podman"] + args
|
|
args = ["podman"] + args
|
|
|
print(f"Executing `{" ".join(args)}`")
|
|
print(f"Executing `{" ".join(args)}`")
|
|
|
- try:
|
|
|
|
|
|
|
+
|
|
|
|
|
+ def run_and_output():
|
|
|
out = subprocess.check_output(args, **kwargs)
|
|
out = subprocess.check_output(args, **kwargs)
|
|
|
print(out.decode())
|
|
print(out.decode())
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ run_and_output()
|
|
|
except subprocess.CalledProcessError as e:
|
|
except subprocess.CalledProcessError as e:
|
|
|
- print(e)
|
|
|
|
|
- try:
|
|
|
|
|
- cls.ps()
|
|
|
|
|
- except subprocess.CalledProcessError as e2:
|
|
|
|
|
- if "Cannot connect to Podman" in e2.stderr.decode():
|
|
|
|
|
- print("podman not running, starting it")
|
|
|
|
|
- subprocess.check_output(["podman", "machine", "start"])
|
|
|
|
|
- out = subprocess.check_output(args, **kwargs)
|
|
|
|
|
- print(out.decode())
|
|
|
|
|
|
|
+ if not cls.machine_is_running:
|
|
|
|
|
+ print("podman not running, starting it")
|
|
|
|
|
+ cls.machine_start()
|
|
|
|
|
+ run_and_output()
|
|
|
|
|
+ else:
|
|
|
|
|
+ raise e
|