Commit f8943191 authored by Simon Redman's avatar Simon Redman

Add simple quagga-user-adding script

parent 30fb722a
#!/usr/bin/env python3
# Copyright (C) 2018 Simon Redman <sredman@cs.utah.edu>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import ssh_helper
import argparse
import getpass
import json
from pexpect import pxssh
import sys
ADDUSER_COMMAND = "touch /tmp/success"
#ADDUSER_COMMAND = "sudo adduser --disabled-password --gecos quagga"
def add_quagga_user_to_network(hostnames, usernames, passwords=None, ssh_options=ssh_helper.DEFAULT_SSH_OPTIONS):
"""
Add the quagga user to every host in the network
:param hostnames: list of hosts on which commands should be run
:param usernames: list of usernames to use to log in to each host
:param passwords: (optional) list of passwords to log in to each host
:param ssh_options: options to pass to ssh, as per pxssh documentation
:return: list of passwords which were used to log in to the servers, where empty string means no password was used
"""
commands = [ADDUSER_COMMAND for i in range(len(hostnames))]
ssh_helper.run_commands_on_network(commands, hostnames, usernames, passwords, ssh_options)
if __name__ == "__main__":
parser = argparse.ArgumentParser("Send a command to create a user named \'quagga\' on every host in the provided NetJSON")
parser.add_argument("--in-file", action='store', type=str, required=True,
help="Path to the NetJSON file to parse")
parser.add_argument("--username", action='store', type=str, default=getpass.getuser())
args = parser.parse_args()
with open(args.in_file, 'r') as netjson_file:
netjson = json.load(netjson_file)
hostnames = [node['properties']['management-ip'] for node in netjson['nodes']]
usernames = [args.username for i in range(len(hostnames))]
passwords = add_quagga_user_to_network(hostnames, usernames)
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment