def main(): parser = argparse.ArgumentParser( epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('address', help='hostname or ip address of target appliance') args = parser.parse_args() ssh_kwargs = { 'username': credentials['ssh']['username'], 'password': credentials['ssh']['password'], 'hostname': args.address } # Init SSH client with SSHClient(**ssh_kwargs) as ssh_client: snmp_path = scripts_data_path.join("snmp") # Copy print("Copying files") ssh_client.put_file( snmp_path.join("snmp_listen.rb").strpath, "/root/snmp_listen.rb") ssh_client.put_file( snmp_path.join("snmp_listen.sh").strpath, "/root/snmp_listen.sh") # Enable after startup print("Enabling after startup") status = ssh_client.run_command( "grep 'snmp_listen[.]sh' /etc/rc.local")[0] if status != 0: ssh_client.run_command( "echo 'cd /root/ && ./snmp_listen.sh start' >> /etc/rc.local") assert ssh_client.run_command("grep 'snmp_listen[.]sh' /etc/rc.local")[0] == 0, \ "Could not enable!" # Run! print("Starting listener") assert ssh_client.run_command("cd /root/ && ./snmp_listen.sh start")[0] == 0, \ "Could not start!" # Open the port if not opened print("Opening the port in iptables") status = ssh_client.run_command( "grep '--dport 8765' /etc/sysconfig/iptables")[0] if status != 0: # append after the 5432 entry ssh_client.run_command( "sed -i '/--dport 5432/a -A INPUT -p tcp -m tcp --dport 8765 -j ACCEPT' " "/etc/sysconfig/iptables") ssh_client.run_command("systemctl restart iptables") # last ssh command, close # Check if accessible try: requests.get("http://{}:8765/".format(args.address)) except requests.exceptions.ConnectionError: print("Could not detect running listener!") exit(2)
def main(): parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('address', help='hostname or ip address of target appliance') args = parser.parse_args() ssh_kwargs = { 'username': credentials['ssh']['username'], 'password': credentials['ssh']['password'], 'hostname': args.address } # Init SSH client with SSHClient(**ssh_kwargs) as ssh_client: snmp_path = scripts_data_path.join("snmp") # Copy print("Copying files") ssh_client.put_file(snmp_path.join("snmp_listen.rb").strpath, "/root/snmp_listen.rb") ssh_client.put_file(snmp_path.join("snmp_listen.sh").strpath, "/root/snmp_listen.sh") # Enable after startup print("Enabling after startup") status = ssh_client.run_command("grep 'snmp_listen[.]sh' /etc/rc.local")[0] if status != 0: ssh_client.run_command("echo 'cd /root/ && ./snmp_listen.sh start' >> /etc/rc.local") assert ssh_client.run_command("grep 'snmp_listen[.]sh' /etc/rc.local")[0] == 0, \ "Could not enable!" # Run! print("Starting listener") assert ssh_client.run_command("cd /root/ && ./snmp_listen.sh start")[0] == 0, \ "Could not start!" # Open the port if not opened print("Opening the port in iptables") status = ssh_client.run_command("grep '--dport 8765' /etc/sysconfig/iptables")[0] if status != 0: # append after the 5432 entry ssh_client.run_command( "sed -i '/--dport 5432/a -A INPUT -p tcp -m tcp --dport 8765 -j ACCEPT' " "/etc/sysconfig/iptables" ) ssh_client.run_command("systemctl restart iptables") # last ssh command, close # Check if accessible try: requests.get("http://{}:8765/".format(args.address)) except requests.exceptions.ConnectionError: print("Could not detect running listener!") exit(2)
from utils import conf, version from utils.log import create_sublogger from utils.path import conf_path, log_path, scripts_data_path from utils.quote import quote from utils.wait import wait_for, TimedOutError # paths to all of the coverage-related files # on the appliance #: Corresponds to Rails.root in the rails env rails_root = local('/var/www/miq/vmdb') #: coverage root, should match what's in the coverage hook and merger scripts appliance_coverage_root = rails_root.join('coverage') # local coverage_data = scripts_data_path.join('coverage') gemfile = coverage_data.join('coverage_gem.rb') bundler_d = rails_root.join('bundler.d') coverage_hook_file_name = 'coverage_hook.rb' coverage_hook = coverage_data.join(coverage_hook_file_name) coverage_merger = coverage_data.join('coverage_merger.rb') thing_toucher = coverage_data.join('thing_toucher.rb') coverage_output_dir = log_path.join('coverage') coverage_results_archive = coverage_output_dir.join('coverage-results.tgz') coverage_appliance_conf = conf_path.join('.ui-coverage') # This is set in sessionfinish, and should be reliably readable # in post-yield sessionfinish hook wrappers and all hooks thereafter ui_coverage_percent = None