Пример #1
0
def create_services(app_name):
    cmd="docker stack deploy --with-registry-auth --compose-file=" + docker_compose_file + " " + app_name
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline,''):
        line = line.decode("utf-8").replace("\n","")
        print(line)
        if line is "":
            break
def get_drain_node():
    cmd = "docker node ls | grep Drain | awk '{print $1}'"
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    nodes=[]
    for line in iter(proc.stdout.readline,''):
        line = line.decode("utf-8").replace("\n","")
        if line == '':
            break
        else:
            nodes.append(line)
    return nodes
Пример #3
0
def get_swarm_node_list(status):
    node_list=[]
    cmd="docker node ls | grep " + status + " | awk '{print $2}'"
    #cmd="docker node ls | awk '{print $2}'"
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline,''):
        line = line.decode("utf-8")
        if line == '' :
            break
        elif (line != '*\n'): #not consider this node (cloud-leader-manager) and the columns title
            node_list.append(line.rstrip())
    return node_list
Пример #4
0
def get_node_labels(node):
    cmd = "docker node inspect --format '{{ .Spec.Labels }}' " + node
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    labels = {}
    for line in iter(proc.stdout.readline,''):
        line = line.decode("utf-8").replace("map[","").replace("]\n","")
        if line != "":
            for label in line.split(" "):
                element = label.split(":")
                labels[element[0]] = element[1]
        break
    return labels
Пример #5
0
def ip_from_id(host_id):
    cmd = "docker node inspect " + host_id + " | grep Addr"
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline,''):
        line = line.decode("utf-8").replace("\n","").replace("\"","").split("Addr:")[1]
        return line.strip()
Пример #6
0
def id_from_hostname(hostname):
    cmd = "docker node ls | grep " + hostname + "| awk '{print $1}'"
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline,''):
        return line.decode("utf-8").replace("\n","").strip()
Пример #7
0
def get_token():
    cmd = "docker swarm join-token -q worker"
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline,''):
        return line.decode("utf-8").replace("\n","")