Example #1
0
def cleanup():
    print("Stopping processes..")
    for f in os.listdir(config.run_dir):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(config.run_dir, f))

    create_dir(config.run_dir, True)
    # create_dir(env.cmd, True)

    print("Reseting NAT..")
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(config.subnet, get_default_route()[1], config.bridge)
    runcmd(cmd)

    print("Deleting bridge %s.." % config.bridge)
    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(config.bridge, config.gateway, config.net.prefixlen)
    runcmd(cmd)
Example #2
0
def cleanup():
    print("Stopping processes..")
    for f in os.listdir(config.run_dir):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(config.run_dir, f))

    create_dir(config.run_dir, True)
    # create_dir(env.cmd, True)

    print("Reseting NAT..")
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(config.subnet,
               get_default_route()[1], config.bridge)
    runcmd(cmd)

    print("Deleting bridge %s.." % config.bridge)
    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(config.bridge, config.gateway, config.net.prefixlen)
    runcmd(cmd)
Example #3
0
def cleanup(args, env):
    print("Cleaning up bridge, NAT, resolv.conf...")

    for f in os.listdir(env.run):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(env.run, f))

    create_dir(env.run, True)
    # create_dir(env.cmd, True)
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(env.subnet, get_default_route()[1], env.bridge)
    os.system(cmd)

    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(env.bridge, env.gateway, env.net.prefixlen)
    os.system(cmd)
Example #4
0
def cleanup(args, env):
    print("Cleaning up bridge, NAT, resolv.conf...")

    for f in os.listdir(env.run):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(env.run, f))

    create_dir(env.run, True)
    # create_dir(env.cmd, True)
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(env.subnet,
               get_default_route()[1], env.bridge)
    os.system(cmd)

    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(env.bridge, env.gateway, env.net.prefixlen)
    os.system(cmd)
Example #5
0
def image():
    disk0 = os.path.join(config.vcluster_dir, "disk0")
    disk1 = os.path.join(config.vcluster_dir, "disk1")

    create_dir(config.vcluster_dir, False)

    env = os.environ.copy()
    env.update({
        "DISK0": disk0,
        "DISK0_SIZE": config.disk0_size,
        "DISK1": disk1,
        "DISK1_SIZE": config.disk1_size,
    })
    cmd = os.path.join(config.lib_dir, "mkimage.sh")

    subprocess.Popen([cmd], env=env)
Example #6
0
def image():
    disk0 = os.path.join(config.vcluster_dir, "disk0")
    disk1 = os.path.join(config.vcluster_dir, "disk1")

    create_dir(config.vcluster_dir, False)

    env = os.environ.copy()
    env.update({
        "DISK0": disk0,
        "DISK0_SIZE": config.disk0_size,
        "DISK1": disk1,
        "DISK1_SIZE": config.disk1_size,
        })
    cmd = os.path.join(config.lib_dir, "mkimage.sh")

    subprocess.Popen([cmd], env=env)
Example #7
0
def main():
    args = parse_options()

    config.init(args)
    status.init()
    context.init(args)

    create_dir(config.run_dir, False)
    create_dir(config.dns_dir, False)

    # Check if there are keys to use
    if args.command == "keygen":
        if must_create_keys() or args.force:
            do_create_keys()
        else:
            print "ssh keys found. To re-create them use --force"
        if must_create_ddns_keys() or args.force:
            do_create_ddns_keys()
        else:
            print "ddns keys found. To re-create them use --force"
        return 0
    else:
        if ((args.key_inject and not args.ssh_key and
             must_create_keys()) or must_create_ddns_keys()):
            print "No ssh/ddns keys to use. Run `snf-deploy keygen' first."
            return 1
        config.ddns_keys = find_ddns_key_files()
        config.ddns_private_key = "/root/ddns/" + config.ddns_keys[0]

    if args.command == "test":
        config.print_config()
        return 0

    if args.command == "image":
        vcluster.image()
        return 0

    if args.command == "cleanup":
        vcluster.cleanup()
        return 0

    if args.command == "packages":
        create_dir(config.package_dir, True)
        get_packages()
        return 0

    if args.command == "vcluster":
        status.reset()
        vcluster.cleanup()
        vcluster.launch()
        return 0

    if args.command == "help":
        print_help_msg(args.cmds)
        return 0

    actions = get_actions(args.command)
    fabcommand(args, actions)

    return 0
Example #8
0
def main():
    args = parse_options()

    config.init(args)
    status.init()
    context.init(args)

    create_dir(config.run_dir, False)
    create_dir(config.dns_dir, False)

    # Check if there are keys to use
    if args.command == "keygen":
        if must_create_keys() or args.force:
            do_create_keys()
        else:
            print "ssh keys found. To re-create them use --force"
        if must_create_ddns_keys() or args.force:
            do_create_ddns_keys()
        else:
            print "ddns keys found. To re-create them use --force"
        return 0
    else:
        if ((args.key_inject and not args.ssh_key and must_create_keys())
                or must_create_ddns_keys()):
            print "No ssh/ddns keys to use. Run `snf-deploy keygen' first."
            return 1
        config.ddns_keys = find_ddns_key_files()
        config.ddns_private_key = "/root/ddns/" + config.ddns_keys[0]

    if args.command == "test":
        config.print_config()
        return 0

    if args.command == "image":
        vcluster.image()
        return 0

    if args.command == "cleanup":
        vcluster.cleanup()
        return 0

    if args.command == "packages":
        create_dir(config.package_dir, True)
        get_packages()
        return 0

    if args.command == "vcluster":
        status.reset()
        vcluster.cleanup()
        vcluster.launch()
        return 0

    if args.command == "help":
        print_help_msg(args.cmds)
        return 0

    actions = get_actions(args.command)
    fabcommand(args, actions)

    return 0
Example #9
0
def main():
    args = parse_options()

    conf = Conf(args)
    env = Env(conf)

    create_dir(env.run, False)
    create_dir(env.dns, False)

    # Check if there are keys to use
    if args.command == "keygen":
        if must_create_keys(args.force, env):
            do_create_keys(args, env)
            return 0
        else:
            print "Keys already existed.. aborting"
            return 1
    else:
        if (args.key_inject and (args.ssh_key is None)
                and must_create_keys(False, env)):
            print "No ssh keys to use. Run `snf-deploy keygen' first."
            return 1

    if args.command == "test":
        conf.print_config()

    if args.command == "cleanup":
        cleanup(args, env)

    if args.command == "packages":
        create_dir(env.packages, True)
        get_packages(args, env)

    if args.command == "vcluster":
        image(args, env)
        network(args, env)
        create_dnsmasq_files(args, env)
        dnsmasq(args, env)
        cluster(args, env)

    if args.command == "prepare":
        actions = get_actions("prepare")
        fabcommand(args, env, actions)

    if args.command == "synnefo":
        actions = get_actions("synnefo")
        fabcommand(args, env, actions)

    if args.command == "backend":
        actions = get_actions("backend")
        fabcommand(args, env, actions)

    if args.command == "ganeti":
        actions = get_actions("ganeti")
        fabcommand(args, env, actions)

    if args.command == "all":
        actions = get_actions("prepare", "synnefo", "backend")
        fabcommand(args, env, actions)

    if args.command == "add":
        if args.cluster_node:
            add_node(args, env)
        else:
            actions = get_actions("backend")
            fabcommand(args, env, actions)

    if args.command == "run":
        if not args.actions:
            print_available_actions(args.command)
        else:
            fabcommand(args, env, args.actions)
Example #10
0
def main():
    args = parse_options()

    conf = Conf(args)
    env = Env(conf)

    create_dir(env.run, False)
    create_dir(env.dns, False)

    # Check if there are keys to use
    if args.command == "keygen":
        if must_create_keys(args.force, env):
            do_create_keys(args, env)
            return 0
        else:
            print "Keys already existed.. aborting"
            return 1
    else:
        if (args.key_inject and (args.ssh_key is None)
                and must_create_keys(False, env)):
            print "No ssh keys to use. Run `snf-deploy keygen' first."
            return 1

    if args.command == "test":
        conf.print_config()

    if args.command == "cleanup":
        cleanup(args, env)

    if args.command == "packages":
        create_dir(env.packages, True)
        get_packages(args, env)

    if args.command == "vcluster":
        image(args, env)
        network(args, env)
        create_dnsmasq_files(args, env)
        dnsmasq(args, env)
        cluster(args, env)

    if args.command == "prepare":
        actions = get_actions("prepare")
        fabcommand(args, env, actions)

    if args.command == "synnefo":
        actions = get_actions("synnefo")
        fabcommand(args, env, actions)

    if args.command == "backend":
        actions = get_actions("backend")
        fabcommand(args, env, actions)

    if args.command == "ganeti":
        actions = get_actions("ganeti")
        fabcommand(args, env, actions)

    if args.command == "all":
        actions = get_actions("prepare", "synnefo", "backend")
        fabcommand(args, env, actions)

    if args.command == "add":
        if args.cluster_node:
            add_node(args, env)
        else:
            actions = get_actions("backend")
            fabcommand(args, env, actions)

    if args.command == "run":
        if not args.actions:
            print_available_actions(args.command)
        else:
            fabcommand(args, env, args.actions)