Exemple #1
0
 def Launch(self):
     if self.flog == None:
         self.flog = open(self.flog_path, 'w')
     dbg.print_info("Launching '%s'" % self.name)
     cmd = self.GetLaunchCmd()
     common.logCmd(self.flog, cmd)
     proc = ex.executeCmd(cmd, self.flog, self.host_machine,
                          self.remote_script_name)
     self.vm_proc = proc
Exemple #2
0
def runContainer(container_cfg, flog):
    rv = removeContainer(container_cfg)
    if rv != 0:
        return 1

    cmd = container_cfg.getRunCmd()
    p = ex.executeCmd(cmd, flog, container_cfg.host_name,
                      container_cfg.sh_script)
    dbg.print_info("%s: container '%s' is running" % \
                  (container_cfg.host_name, container_cfg.name))
    return p
Exemple #3
0
def joinSwarm(h_cfg, join_cmd):
    if leaveSwarm(h_cfg) != 0:
        return 1

    p = ex.executeCmd(join_cmd, subprocess.PIPE, h_cfg.host_name,
                      "docker_client.sh")
    output, error = p.communicate()
    if p.returncode != 0:
        dbg.print_error(error)
        return 1

    return 0
Exemple #4
0
def tryExecute(cmd, hostname, valid_error_str):
    # dbg.print_info("cmd: %s, host: %s, valid error: %s" % \
    # (cmd, hostname, valid_error_str))
    script_name = "%s_cmd.sh" % hostname
    p = ex.executeCmd(cmd, subprocess.PIPE, hostname, script_name)
    output, error = p.communicate()
    if p.returncode != 0:
        if common.isStrInText(valid_error_str, error):
            dbg.print_warning(error)
        else:
            dbg.print_error(error)
            return 1

    return 0
Exemple #5
0
def createOverlayNetwork(h_cfg):
    if removeNetwork(h_cfg) != 0:
        return None

    dbg.print_info("%s: creating overlay network '%s'" % \
                   (h_cfg.host_name, h_cfg.nw_name))
    cmd = "docker network create --driver=overlay --attachable %s" % h_cfg.nw_name
    nw_id = None
    p = ex.executeCmd(cmd, subprocess.PIPE, h_cfg.host_name, "create_nw.sh")
    output, error = p.communicate()
    if p.returncode != 0:
        dbg.print_error("Can not create network '%s' on host '%s'" % \
                        (h_cfg.nw_name, h_cfg.host_name))
        dbg.print_error(error)
        return None
    else:
        nw_id = output

    return nw_id
Exemple #6
0
def removeNetworkOld(h_cfg):
    no_network_str = "No such network"

    # Remove network
    cmd = "docker network rm %s" % h_cfg.nw_name
    p = ex.executeCmd(cmd, subprocess.PIPE, h_cfg.host_name, "remote_nw.sh")
    output, error = p.communicate()
    if p.returncode != 0:
        if common.isStrInText(no_network_str, error):
            dbg.print_warning("%s: '%s' network does not exist!" % \
                              (h_cfg.host_name, h_cfg.nw_name))
        else:
            dbg.print_error("%s: can not remove network '%s'!" % \
                            (h_cfg.nw_name, h_cfg.host_name))
            dbg.print_error(error)
            return 1
    else:
        dbg.print_info("Removed network '%s'" % h_cfg.nw_name)

    return 0
Exemple #7
0
def initSwarm(h_cfg):
    if leaveSwarm(h_cfg) != 0:
        return None

    # Initialize swarm on a host
    cmd = "docker swarm init --advertise-addr %s" % h_cfg.if_name
    p = ex.executeCmd(cmd, subprocess.PIPE, h_cfg.host_name,
                      "docker_server.sh")
    output, error = p.communicate()
    if p.returncode != 0:
        dbg.print_error("Can not initialize swarm on %s" % h_cfg.host_name)
        dbg.print_error(error)
        return None

    # Take only join command from init output
    m = re.search("docker swarm join --token .*", output)
    if m != None:
        join_cmd = m.group(0)
    else:
        join_cmd = None

    return join_cmd