Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
New workaround for dead container references
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJKM committed Aug 25, 2020
1 parent 6008bcb commit 9b8f9ae
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions modules/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def __init__(self, exists, id):
self.__container = client.containers.get(container_id=id)
self.__status = 1
except docker.errors.NotFound:
self.__container = None
self.__status = 5
except docker.errors.APIError:
self.__container = None
self.__status = 6
print("Container lookup failed. Check inputs.")

Expand Down Expand Up @@ -71,40 +73,50 @@ def create(self, image, object, volumeSource = None):

# Renames this container
def rename(self, newName):
self.__container.rename(name=newName)
self.__container.reload()
if not self.__container == None:
self.__container.rename(name=newName)
self.__container.reload()

# Returns this containers id
def getId(self):
return self.__container.id
if not self.__container == None:
return self.__container.id
else:
return ""

# Returns this containers actual name
def getName(self):
return self.__container.name
if not self.__container == None:
return self.__container.name
else:
return ""

# Starts this container
def start(self):
self.__container.start()
self.__status = 2
if not self.__container == None:
self.__container.start()
self.__status = 2

# Stops this container
def stop(self):
self.__container.stop()
self.__status = 1
if not self.__container == None:
self.__container.stop()
self.__status = 1

# Returns if this container is actually running
def isRunning(self):
if self.__container.status == "running":
return True
if not self.__container == None:
if self.__container.status == "running":
return True
else:
return False
else:
return False

# Deletes this container
def delete(self):
try:
if not self.__container == None:
self.__container.remove(v=False)
except docker.errors.NotFound:
pass

# Returns the container status
def getStatus(self):
Expand Down

0 comments on commit 9b8f9ae

Please sign in to comment.