def prepareBuild(self, name, url, version): if self.__config["status"] != "empty": print( "Error calling prepareBuild: this service is not in 'empty' state" ) return False self.__name = name self.__config["status"] = "preparing" self.__config["actualVersion"] = version # Create service folder fs.filesystem.removeElement(config.servicepath + name) os.makedirs(config.servicepath + name) self.__saveConfiguration() # Download service description self.__desc = description.serviceDescription( True, self.__name, self.__config["actualVersion"], url) self.__localEnv = envman(self.__name) # Check if all required environment variables are set requiredVars = self.__requiredEnvironmentVariables() self.__config["status"] = "installPending" if requiredVars == False: return True else: self.__saveConfiguration() return requiredVars
def __init__(self, exists, id, name): self.__status = 0 self.__localEnv = envman(name) if exists: try: 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.")
def __init__(self, name, firstinstall): # Init vars self.__name = name self.__containers = {"actual": [], "previous": []} self.__volumes = [] self.__description = None self.__errors = 0 self.__installThread = None self.__updateThread = None self.__revertThread = None self.__deleteThread = None self.__rebuildThread = None self.__localEnv = None if not firstinstall: # Read container configuration configFile = open(config.servicepath + name + "/config.json", "r") self.__config = json.loads(configFile.read()) configFile.close() # Create service description object self.__desc = description.serviceDescription( False, self.__name, self.__config["actualVersion"]) self.__localEnv = envman(self.__name) # Create docker references for volumes for storedVolume in self.__config["volumes"]: self.__volumes.append( volume.volume(True, storedVolume["id"], None)) # Create docker references for networks for storedNetwork in self.__config["networks"]: self.networks.append( network.network(True, storedNetwork["id"], None, None)) # Create docker references for containers for storedContainer in self.__config["containers"]["actual"]: self.__containers["actual"].append( container.container(True, storedContainer["id"], self.__name)) for storedContainer in self.__config["containers"]["previous"]: self.__containers["previous"].append( container.container(True, storedContainer["id"], self.__name)) # Check container status and turn containers to wanted status if self.__config["wanted"]: for containerObject in self.__containers["actual"]: if not containerObject.isRunning(): containerObject.start() self.__config["status"] = "running" else: for containerObject in self.__containers["actual"]: if containerObject.isRunning(): containerObject.stop() self.__config["status"] = "paused" else: self.__config = { "networks": [], "volumes": [], "containers": { "actual": [], "previous": [] }, "wanted": True, "status": "empty", "actualVersion": "", "previousVersion": "", }
from subprocess import Popen # Include modules import config import modules.container as container import modules.volume as volume import modules.network as network import modules.prune as prune import modules.servicedescription as description import modules.filesystem as fs import modules.builderThread as bt import modules.repository as repository from modules.envstore import envman # Manager objects env = envman() # Class definition class service: networks = [] def __init__(self, name, firstinstall): # Init vars self.__name = name self.__containers = {"actual": [], "previous": []} self.__volumes = [] self.__description = None self.__errors = 0 self.__installThread = None self.__updateThread = None