-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.gitignore: add *.log
- Loading branch information
Roger
committed
Feb 18, 2023
1 parent
1ef5902
commit 80a9bfc
Showing
3 changed files
with
22 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
.vscode | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
from python_on_whales import docker | ||
from python_on_whales import docker, DockerException | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class Container: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
# Todo: Debug Logger | ||
# def __get_container_info(self): | ||
# container_info = docker.ps(filters={"name": self.name, "status": "running"}) | ||
# for container in container_info: | ||
# print(container.state) | ||
def __get_container_info(self): | ||
for container in docker.ps(all=True, filters={"name": self.name}): | ||
logger.warning(f"Container info for '{self.name}': {container.state}") | ||
|
||
def is_running(self): | ||
if docker.ps(filters={"name": self.name, "status": "running"}): | ||
return True | ||
else: | ||
return False | ||
logger.debug("This is a debug thing") | ||
try: | ||
if docker.ps(filters={"name": self.name, "status": "running"}): | ||
return True | ||
else: | ||
logger.warning(f"Docker Container '{self.name}' not found or is not running") | ||
if logger.isEnabledFor(logging.DEBUG): | ||
self.__get_container_info() | ||
return False | ||
|
||
except DockerException as e: | ||
logger.error(f"{DockerException.__name__}: Exit code {e.return_code}, {e.stderr.strip()}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters