Beispiel #1
0
def getParsedDockerImages(noTrunc=False):
  """ Parse `docker images` related output for easier access: return a dictionary of Columns Lists
  no-trunc: if False: truncate output 
  """
  dockerImageMatrix = {'REPOSITORY' : [], 'TAG' : [], 'ID' : [], 'CREATED' : [], 'SIZE' : []}
  if noTrunc:
    roughImagesList = docker.getDockerOutput(["images", "--no-trunc=true"])
  else:
    roughImagesList = docker.getDockerOutput(["images", "--no-trunc=false"])

  #solve the problem with white space allowed in RepoNames and Tags
  #Columns: REPOSITORY   TAG   IMAGE ID   CREATED   VIRTUAL SIZE
  splitPoints = {'REPOSITORY' : -1, 'TAG' : -1, 'IMAGE ID' : -1, 'CREATED' : -1, 'VIRTUAL SIZE' : -1}
  imagesLinesList = [line for line in roughImagesList.split("\n") if line.strip()]
  topRowNames = imagesLinesList[0]

  for name in splitPoints.keys():
    splitPoints[name] = topRowNames.find(name)
    if splitPoints[name] == -1:
      sys.exit("ERROR: could not parse 'docker images' output")
      
  for line in imagesLinesList[1:]:
    dockerImageMatrix['REPOSITORY'].append(line[splitPoints['REPOSITORY']:splitPoints['TAG']].strip())
    dockerImageMatrix['TAG'].append(line[splitPoints['TAG']:splitPoints['IMAGE ID']].strip())
    dockerImageMatrix['ID'].append(line[splitPoints['IMAGE ID']:splitPoints['CREATED']].strip())
    dockerImageMatrix['CREATED'].append(line[splitPoints['CREATED']:splitPoints['VIRTUAL SIZE']].strip())
    dockerImageMatrix['SIZE'].append(line[splitPoints['VIRTUAL SIZE']:len(line)].strip())
  return dockerImageMatrix
Beispiel #2
0
def getParsedDockerImages(noTrunc=False):
    """ Parse `docker images` related output for easier access: return a dictionary of Columns Lists
  no-trunc: if False: truncate output 
  """
    dockerImageMatrix = {
        'REPOSITORY': [],
        'TAG': [],
        'ID': [],
        'CREATED': [],
        'SIZE': []
    }
    if noTrunc:
        roughImagesList = docker.getDockerOutput(["images", "--no-trunc=true"])
    else:
        roughImagesList = docker.getDockerOutput(
            ["images", "--no-trunc=false"])

    #solve the problem with white space allowed in RepoNames and Tags
    #Columns: REPOSITORY   TAG   IMAGE ID   CREATED   VIRTUAL SIZE
    splitPoints = {
        'REPOSITORY': -1,
        'TAG': -1,
        'IMAGE ID': -1,
        'CREATED': -1,
        'VIRTUAL SIZE': -1
    }
    imagesLinesList = [
        line for line in roughImagesList.split("\n") if line.strip()
    ]
    topRowNames = imagesLinesList[0]

    for name in splitPoints.keys():
        splitPoints[name] = topRowNames.find(name)
        if splitPoints[name] == -1:
            sys.exit("ERROR: could not parse 'docker images' output")

    for line in imagesLinesList[1:]:
        dockerImageMatrix['REPOSITORY'].append(
            line[splitPoints['REPOSITORY']:splitPoints['TAG']].strip())
        dockerImageMatrix['TAG'].append(
            line[splitPoints['TAG']:splitPoints['IMAGE ID']].strip())
        dockerImageMatrix['ID'].append(
            line[splitPoints['IMAGE ID']:splitPoints['CREATED']].strip())
        dockerImageMatrix['CREATED'].append(
            line[splitPoints['CREATED']:splitPoints['VIRTUAL SIZE']].strip())
        dockerImageMatrix['SIZE'].append(
            line[splitPoints['VIRTUAL SIZE']:len(line)].strip())
    return dockerImageMatrix
Beispiel #3
0
def inspectImage(imageTag):
  """ Returns a dictionary coresponding to the json outputed by docker inspect. """
  try:
    dockerInspectOutput = docker.getDockerOutput(["inspect",imageTag])
  except subprocess.CalledProcessError:
    return None
  imageInfo = json.loads(dockerInspectOutput)
  return imageInfo[0]
Beispiel #4
0
def inspectImage(imageTag):
    """ Returns a dictionary coresponding to the json outputed by docker inspect. """
    try:
        dockerInspectOutput = docker.getDockerOutput(["inspect", imageTag])
    except subprocess.CalledProcessError:
        return None
    imageInfo = json.loads(dockerInspectOutput)
    return imageInfo[0]
Beispiel #5
0
def getRunningSubuserPrograms():
  """ Returns a list of the currently running subuser programs. """
  psOutput = docker.getDockerOutput(["ps","-q"])
  runningContainerIDs = filter(len,psOutput.split("\n")) #We filter out emty strings
  runningSubuserPrograms = set()
  for container in runningContainerIDs:
    containerImageTag = dockerImages.getContainerImageTag(container)
    subuserPrefix = "subuser-"
    if containerImageTag.startswith(subuserPrefix):
      runningSubuserPrograms.add(containerImageTag[len(subuserPrefix):])
  return list(runningSubuserPrograms)
Beispiel #6
0
def getRunningProgramsWithNames(names):
  """ Returns a very crude listing from docker ps. Not a real list of the names of running programs or anything. """
  psOutput = docker.getDockerOutput(["ps"])
  psOutput = psOutput.split("\n")
  psOutput = psOutput[1:]
  def amongProgramsToBeWaitedOn(psOutputLine):
    tags = ["subuser-"+name for name in names]
    if psOutputLine == '': return False
    outputLineWords = psOutputLine.split()
    tagName = outputLineWords[1].split(':')[0]
    return tagName in tags
  return [psOutputLine for psOutputLine in psOutput if amongProgramsToBeWaitedOn(psOutputLine) ]
Beispiel #7
0
def getRunningProgramsWithNames(names):
    """ Returns a very crude listing from docker ps. Not a real list of the names of running programs or anything. """
    psOutput = docker.getDockerOutput(["ps"])
    psOutput = psOutput.split("\n")
    psOutput = psOutput[1:]

    def amongProgramsToBeWaitedOn(psOutputLine):
        tags = ["subuser-" + name for name in names]
        if psOutputLine == '': return False
        outputLineWords = psOutputLine.split()
        tagName = outputLineWords[1].split(':')[0]
        return tagName in tags

    return [
        psOutputLine for psOutputLine in psOutput
        if amongProgramsToBeWaitedOn(psOutputLine)
    ]
Beispiel #8
0
def getContainerImageTag(containerID):
  inspectOutput = docker.getDockerOutput(["inspect",containerID])
  containerInfo = json.loads(inspectOutput)
  return containerInfo[0]["Config"]["Image"]
Beispiel #9
0
def getContainerImageTag(containerID):
    inspectOutput = docker.getDockerOutput(["inspect", containerID])
    containerInfo = json.loads(inspectOutput)
    return containerInfo[0]["Config"]["Image"]
Beispiel #10
0
def inspectImage(imageTag):
    """ Returns a dictionary coresponding to the json outputed by docker inspect. """
    dockerInspectOutput = docker.getDockerOutput(["inspect", imageTag])
    imageInfo = json.loads(dockerInspectOutput)
    return imageInfo[0]
Beispiel #11
0
def getContainerInfo(containerID):
  inspectOutput = docker.getDockerOutput(["inspect",containerID])
  return json.loads(inspectOutput)
Beispiel #12
0
def getContainerInfo(containerID):
    inspectOutput = docker.getDockerOutput(["inspect", containerID])
    return json.loads(inspectOutput)
Beispiel #13
0
def inspectImage(imageTag):
  """ Returns a dictionary coresponding to the json outputed by docker inspect. """
  dockerInspectOutput = docker.getDockerOutput(["inspect",imageTag])
  imageInfo = json.loads(dockerInspectOutput)
  return imageInfo[0]