def deletesnapshot(dClusterId, tag=None): images = docker.images() for image in images: if image.repository.startswith(dClusterId) and tag is None: cmdutil.execute(["docker", "rmi", image.repository + ":" + image.tag]) elif image.repository.startswith(dClusterId + "/") and tag == image.tag: cmdutil.execute(["docker", "rmi", image.repository + ":" + image.tag])
def _flattenDockerfile(conf): for node in conf["nodes"]: if "Dockerfile" in node: tempImageName = conf["id"] + "/" + node["hostname"].replace("[", "_").replace("]", "_") cmdutil.execute(["docker", "build", "-t", tempImageName, node["Dockerfile"]]) node["imageName"] = tempImageName return conf
def getContainer(containerName): result = Container() result.name = containerName _retcode, stdout = cmdutil.execute(["docker", "inspect", '--format="{{.NetworkSettings.IPAddress}}"', containerName]) result.ip = stdout.strip("\n").strip('"') _retcode, stdout = cmdutil.execute(["docker", "inspect", '--format="{{.Config.Hostname}}"', containerName]) result.hostname = stdout.strip("\n").strip('"') _retcode, stdout = cmdutil.execute(["docker", "inspect", '--format="{{.Config.Domainname}}"', containerName]) result.fqdn = result.hostname + "." + stdout.strip("\n").strip('"') return result
def getContainer(containerName): result = Container() result.name = containerName _retcode, stdout = cmdutil.execute([ "docker", "inspect", '--format="{{.NetworkSettings.IPAddress}}"', containerName ]) result.ip = stdout.strip("\n").strip('"') _retcode, stdout = cmdutil.execute([ "docker", "inspect", '--format="{{.Config.Hostname}}"', containerName ]) result.hostname = stdout.strip("\n").strip('"') _retcode, stdout = cmdutil.execute([ "docker", "inspect", '--format="{{.Config.Domainname}}"', containerName ]) result.fqdn = result.hostname + "." + stdout.strip("\n").strip('"') return result
def ps(): ''' root@jaoki-ubuntu:/home/jaoki/coding/phd-docker# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f61811577af2 phd:base bash -c cp /tmp/phd- 9 minutes ago Up 9 minutes mycluster2-node3 079ed8874604 phd:base bash -c cp /tmp/phd- 9 minutes ago Up 9 minutes mycluster2-node2 845fda0ffb74 phd:installed bash -c /tmp/phd-doc 9 minutes ago Up 9 minutes mycluster2-node1 5f7434e4b690 phd:base bash -c cp /tmp/phd- 9 minutes ago Up 9 minutes mycluster1-node3 e677692a7022 phd:base bash -c cp /tmp/phd- 9 minutes ago Up 9 minutes mycluster1-node2 e2481e18d7a8 phd:installed bash -c /tmp/phd-doc 9 minutes ago Up 9 minutes mycluster1-node1 ''' # lines = subprocess.check_output(["docker", "ps", "-a"]).split("\n") _retcode, stdout = cmdutil.execute(["docker", "ps", "-a"]) return _parsePsResult(stdout.split("\n"))
def getLatestDockerConatinerId(): _retcode, stdout = cmdutil.execute(["docker", "ps", "-l", "-q"]) # return subprocess.check_output(["docker", "ps", "-l", "-q"]).strip("\n") return stdout.strip("\n")
def images(): _retcode, stdout = cmdutil.execute(["docker", "images"]) return _parseImageResult(stdout.split("\n"))
def installed(): retcode, _stdout = cmdutil.execute(["which", "docker"]) if retcode == 0: return True return False
def getContainerIpAddress(containerName): _retcode, stdout = cmdutil.execute([ "docker", "inspect", '--format="{{.NetworkSettings.IPAddress}}"', containerName ]) return stdout.strip("\n").strip('"')