コード例 #1
0
def main(inventory, verbose):
    parsed_inventory = helpers.parse_yaml(inventory)
    password = getpass.getpass('Please enter a password: '******'password'] = password
        config = helpers.run_show(params, COMMAND, verbose=verbose)
        configs[device] = config

    parsed_vrrp_dict = parse_vrrp(configs, VRRP_REGEX)

    for device, params in parsed_inventory.items():
        generated_config = generate_config(parsed_vrrp_dict[device])
        connection = helpers.connect(address=params['address'],
                                     username=params['username'],
                                     password=params['password'],
                                     port=params['port'])
        connection.login()
        connection.configure()
        print(device)
        print(generated_config)
        actions = helpers.run_commands(connection,
                                       generated_config,
                                       verbose=verbose)
        helpers.commit_and_save(connection, actions, verbose=True)
        connection.exit()
        connection.logout()
コード例 #2
0
ファイル: sip_net_finish.py プロジェクト: bkoblenz/Irricloud
def start_daemons():
    shutil.copy2('/etc/dhcpcd.conf.yeswlan0', '/etc/dhcpcd.conf') # make sure dhcp can serve addresses from wlan0
    cmds = [['./dnsmasq', 'start', '/etc/dnsmasq.conf'],
            ['./hostapd', 'start', '/etc/hostapd/hostapd.conf'],
           ]
    run_commands(logger, cmds)
コード例 #3
0
ファイル: sip_net_finish.py プロジェクト: bkoblenz/Irricloud
def stop_daemons():
    cmds = [['./hostapd', 'stop'],
            ['./dnsmasq', 'stop'],
           ]
    run_commands(logger, cmds)
コード例 #4
0
ファイル: sip_monitor.py プロジェクト: bkoblenz/Irricloud
        config_mode = False

    logger.info('sip_monitor config_mode: ' + str(config_mode))
    cmds = [['rm', 'data/substation_proxy_pause'],
            ['rm', 'data/hostapd.conf'],
            ['rm', 'data/dnsmasq.conf'],
            ['chattr', '-i', '/etc/resolv.conf'], # allow overwriting resolv.conf
            ['/etc/init.d/bind9', 'stop'], # only run with master radio
            ['./dnsmasq', 'stop'],
            ['./hostapd', 'stop'],
            ['update-rc.d', 'sip', 'remove'],
            ['update-rc.d', 'sip_net_finish', 'remove'],
            ['update-rc.d', 'sip_monitor', 'defaults'],
            ['sysctl', '/net/ipv4/ip_forward=1'],
           ]
    run_commands(logger, cmds)

    time.sleep(15) # give time for network to come up
    light_ip(get_ip())

    if not config_mode:
        cmds = [
                ['sysctl', 'net.ipv4.tcp_thin_linear_timeouts=1'], # not proven necessary (or problematic)
                ['iw', 'dev', 'wlan0', 'interface', 'add', 'uap0', 'type', '__ap'],
                ['ifup', 'uap0'],
                ['/etc/init.d/bind9', 'start'],
               ]
        run_commands(logger, cmds)

    pi = pigpio.pi()
    button_pin = 21
コード例 #5
0
ファイル: main.py プロジェクト: abelhOrihuela/tasks-spark
from helpers import print_color_text, print_log, print_table, run_commands

with open("hosts.yml") as file:
    data = yaml.load(file, Loader=yaml.FullLoader)

hosts = data["hosts"]
print_table(hosts)

selected_host = None
while selected_host is None:
    id_host = int(input("Selecciona el host: "))
    if id_host < len(hosts):
        selected_host = hosts[id_host]
    else:
        print("Host no valido")
password = getpass.getpass("Ingresa la contraseña: ")

try:
    with Connection(
            host=selected_host["host"],
            user=selected_host["user"],
            connect_kwargs={
                "password": password,
            },
    ) as c:
        run_commands(c, selected_host)
        print(print_color_text("Done!", 'green'))

except Exception as exception:
    print(TRED + "Error de conexión: ", exception, ENDC)