Exemple #1
0
def check(password):
    command = "uptime"

    for host in ssh.gethostnames():

        print(t.translate("checking").format(host), end="")
        try:
            ssh.run(host, 22, "rc3-admin", password,
                    ssh.suwrap(password, command))
            print(bcolors.OKGREEN + "ON" + bcolors.ENDC)
        except:
            print(bcolors.FAIL + "OFF" + bcolors.ENDC)

    print("--------")
Exemple #2
0
def vncconnect(tty, user, host, password):
    command = 'nohup x11vnc -noxdamage -display {} -rfbport 5566 -auth /run/user/`id -u {}`/gdm/Xauthority &'.format(
        tty, user)
    _ = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, command))
    time.sleep(1)
    os.system(
        "nohup vncviewer -ViewOnly {}:5566 >/dev/null 2>&1 &".format(host))
Exemple #3
0
def vncall(password, hosts, skipRemmina):
    user = input(t.translate("vncuser"))

    for host in hosts:
        print("VNC start: '{}:5566'... ".format(host), end="")
        try:
            who = ssh.run(host, 22, "rc3-admin", password,
                          ssh.suwrap(password,
                                     "'who | grep -v rc3-admin'"))[33:]

            tty = ":0"
            for str in who.split("\n"):
                if user in str:
                    tty = str.split()[4].strip().replace("(",
                                                         "").replace(")", "")
                    break

            vncstart(tty, user, host, password)

            print(bcolors.OKGREEN + "OK" + bcolors.ENDC)
        except:
            print(bcolors.FAIL + t.translate("off") + bcolors.ENDC)
    if not skipRemmina:
        print("rc3-admin login:"******"loginpromptremind"))
        os.system("su - rc3-admin -c 'remmina'")
Exemple #4
0
def cmdrun(command, password):
    for host in ssh.gethostnames():
        print(t.translate("executing").format(command, host), end="")
        try:
            output = ssh.run(host, 22, "rc3-admin", password,
                             ssh.suwrap(password, command))
            print(bcolors.OKGREEN + "OK" + bcolors.ENDC)
            print("Output: {}".format(output[31:]))
        except:
            print(bcolors.FAIL + t.translate("off") + bcolors.ENDC)

    print(t.translate("finished"))
Exemple #5
0
def provision_task(host, phases):
    """
    Executes the provisioning in a given host.
    """
    logging.info(f"[{host}] <- Provision launching...")

    #
    # Execute provisioning
    #
    for dir, option, phase in phases:
        res = ssh.run(
            "root", "linux", host,
            f"sh /{dir}/salt/provision.sh -{option} -l /var/log/provision.log")
        if tasks.has_failed(res):
            logging.info(f"[{host}] <- phase {phase} failed")
            break
        else:
            logging.info(f"[{host}] <- phase {phase} executed")

    #
    # Independently of success of provisioning process, cat logs
    #
    destiny = f"./{host}.tmp"
    rcopy = ssh.copy_from_host("root", "linux", host, "/var/log/provision.log",
                               destiny)
    if tasks.has_succeeded(rcopy):
        with open(destiny, "r") as f:
            logging.debug(f"[{host}] provision logs =\n{f.read()}")
    rcopy = ssh.copy_from_host("root", "linux", host, "/var/log/salt/minion",
                               destiny)
    if tasks.has_succeeded(rcopy):
        with open(destiny, "r") as f:
            logging.debug(f"[{host}] provision minion logs =\n{f.read()}")
    tasks.run(f"rm -f {destiny}")

    #
    # Log global result
    #
    if tasks.has_succeeded(res):
        logging.info(f"[{host}] <- provisioning success")
    else:
        logging.error(
            f"[{host}] <- provisioning FAILED, continue provisioning with => deploy.py provision {host} --from={phase}"
        )

    return res
Exemple #6
0
def vnc(password):

    host = "rc3-" + input(t.translate("vnchost")).replace("rc3-", "")
    print(t.translate("loggedin"))

    who = ssh.run(host, 22, "rc3-admin", password,
                  ssh.suwrap(password, "'who | grep -v rc3-admin'"))[33:]

    if len(who.split("\n")) > 1:
        print(who)
        user = input(t.translate("vncuser"))

        tty = ":0"
        for str in who.split("\n"):
            if user in str:
                tty = str.split()[4].strip().replace("(", "").replace(")", "")
                break
    else:
        user = who.split()[0].strip()
        tty = who.split()[4].strip().replace("(", "").replace(")", "")

    vncconnect(tty, user, host, password)

    print(t.translate("finished"))
Exemple #7
0
parser = argparse.ArgumentParser(description='Run recipe')
parser.add_argument('name',   action='store', help="Virtual Machine's name")
parser.add_argument('recipe', action='store', help="Recipe name")
args,vargs = parser.parse_known_args()

# Recipe
recipe_dir = os.path.join (os.path.dirname(__file__), "recipes")

# Make sure the VM is shut down
cmd.run("qvm stop %s"%(args.name))

# Copy recipes
g = util.get_guestfs_vm_handler (args.name)
g.mkdir_p (REMOTE_TMP)

for filename in os.listdir(recipe_dir):
	if filename.endswith(".py"):
		fp_local = os.path.join (recipe_dir, filename)
		fp_vm    = os.path.join (REMOTE_TMP, filename)
		print "+ cp %s %s:%s" % (fp_local, args.name, fp_vm)
		g.upload (fp_local, fp_vm)
		g.chmod (stat.S_IMODE(os.stat(fp_local).st_mode), fp_vm)

util.close_guestfs_vm_handler(g)

# Execute recipe
cmd.run("qvm start %s"%(args.name))
network.wait_vm_net_service (args.name, 22)
ssh.run (args.name, os.path.join(REMOTE_TMP, '%s.py'%(args.recipe)), ' '.join(vargs))
cmd.run("qvm stop %s"%(args.name))
	def ssh_command(self, command):
		""" Send ssh command to node """
		result, error = ssh.run(self.nodeName, command)
		if error:
			self.logger.log_error("Failed to send command %s to %s: %s" % (command, self.nodeName, str(sys.exc_info()[1])))
		return result, error
Exemple #9
0
 def cmd(self, bind_host):
     ssh.run(bind_host, self.user, self.service)
Exemple #10
0
def vncstart(tty, user, host, password):
    command = 'nohup x11vnc -noxdamage -display {} -rfbport 5566 -auth /run/user/`id -u {}`/gdm/Xauthority &'.format(
        tty, user)
    _ = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, command))