def run_remote_command(host, command): shell_run("ssh root@{0} {1}".format(host, command), events={ 'Are you su1re you want to continue connecting \(yes\/no\)\?': "YES\n", host + "\'s password\:": app.get_root_password() + "\n" } )
def _install_host(self, hostname): ''' Execute the commands on the remote host. Create one process for each remote host. ''' try: server = config.host(hostname).get_front_ip() app.print_verbose("Try to install " + hostname + " (" + server + ")", 2) obj = ssh.Ssh(server, app.get_root_password()) self._validate_alive(obj, hostname) app.print_verbose("========================================================================================") app.print_verbose("=== Update " + hostname + " (" + server + ")") app.print_verbose("========================================================================================") obj.install_ssh_key() self._install_syco_on_remote_host(obj) self._execute_commands(obj, hostname) except pexpect.EOF, e: app.print_error(e, 2) # Remove progress state. if hostname in self._installed: del(self._installed[hostname])
def _scp_from(server, src, dst): shell_run("scp -r " + server + ":" + src + " " + dst, events={ 'Are you sure you want to continue connecting \(yes\/no\)\?': "YES\n", server + "\'s password\:": app.get_root_password() + "\n" })
def _install_host(self, hostname): ''' Execute the commands on the remote host. Create one process for each remote host. ''' try: server = config.host(hostname).get_back_ip() app.print_verbose("Try to install " + hostname + " (" + server + ")", 2) obj = ssh.Ssh(server, app.get_root_password()) self._validate_alive(obj, hostname) app.print_verbose("========================================================================================") app.print_verbose("=== Update " + hostname + " (" + server + ")") app.print_verbose("========================================================================================") obj.install_ssh_key() self._install_syco_on_remote_host(obj) self._execute_commands(obj, hostname) except pexpect.EOF, e: app.print_error(e, 2) # Remove progress state. if hostname in self.installed: del(self.installed[hostname])
def scp_from(server, src, dst): general.shell_run("scp -r " + server + ":" + src + " " + dst, events={ 'Are you sure you want to continue connecting \(yes\/no\)\?': "YES\n", server + "\'s password\:": app.get_root_password() + "\n" } )
def is_server_root_open(server): """Check if root account is accessible.""" ssh_con = ssh.Ssh(server, app.get_root_password()) try: ssh_con.ssh_exec('whoami', silent = True) return True except Exception: return False
def run_remote_command(host, command): shell_run( "ssh root@{0} {1}".format(host, command), events={ 'Are you su1re you want to continue connecting \(yes\/no\)\?': "YES\n", host + "\'s password\:": app.get_root_password() + "\n" })
def is_server_root_open(server): """Check if root account is accessible.""" ssh_con = ssh.Ssh(server, app.get_root_password()) try: ssh_con.ssh_exec('whoami', silent=True) return True except Exception: return False
def umount_syco(args): ''' SSH Umount all syco servers on ~/mount/XX Tested on Ubuntu and os x. ''' app.print_verbose("Umount syco servers.") # Cache master password. app.get_root_password() user_name = pwd.getpwuid(os.getuid()).pw_name for hostname in config.get_servers(): ip = config.host(hostname).get_back_ip() mount_dir = os.environ['HOME'] + "/mount/" + hostname if os.access(mount_dir, os.W_OK): shell_run("umount " + mount_dir)
def mount_syco(args): ''' SSH Mount all syco servers to ~/mount/XX Tested on Ubuntu and os x. ''' app.print_verbose("Mount syco servers.") # Cache master password. app.get_root_password() user_name = pwd.getpwuid(os.getuid()).pw_name # What servers to install remote_host = [] if args[1] == "": remote_host = config.get_servers() else: remote_host.append(args[1]) for hostname in remote_host: ip = config.host(hostname).get_back_ip() app.print_verbose("Mount ~/mount/" + hostname + " from " + ip) obj = ssh.Ssh(ip, app.get_root_password()) if (obj.is_alive()): obj.install_ssh_key() # ssh_mount_server mount_dir = os.environ['HOME'] + "/mount/" + hostname if not os.access(mount_dir, os.W_OK): os.makedirs(mount_dir) shell_run("umount " + mount_dir, user=user_name) sshopt = "-o StrictHostKeychecking=no -o BatchMode=yes -o PasswordAuthentication=no -o GSSAPIAuthentication=no" shell_run("sshfs root@" + ip + ":/opt/ " + mount_dir + " -oauto_cache,reconnect " + sshopt, user=user_name)
def install_haproxy(args): app.print_verbose("Install HA Proxy version: %d" % script_version) version_obj = version.Version("InstallHaproxy", script_version) version_obj.check_executed() # Prompt for syco pw early, certificate copy requires root pw app.get_root_password() setup_global_vars() # Validate all command line parameters. if len(args) != 3: print_killmessage() env = haproxy_env(args) state = haproxy_state(args) install_packages("tcl haproxy") iptables.add_haproxy_chain() iptables.save() _copy_certificate_files(env) _configure_haproxy(env, state) version_obj.mark_executed()
def passwords(args): app.print_verbose("Set all passwords used by syco") app.init_all_passwords() print "root: ", app.get_root_password() print "svn: ", app.get_svn_password() print "ldap_admin: ", app.get_ldap_admin_password() print "ldap_sssd: ", app.get_ldap_sssd_password() print "glassfish_master: ", app.get_glassfish_master_password() print "glassfish_admin: ", app.get_glassfish_admin_password() print "glassfish_user: "******"glassfish") print "mysql_root: ", app.get_mysql_root_password() print "mysql_int: ", app.get_mysql_integration_password() print "mysql_stable: ", app.get_mysql_stable_password() print "mysql_uat: ", app.get_mysql_uat_password() print "mysql_prod: ", app.get_mysql_production_password()
def vir_list(args): old_verbose = app.options.verbose app.options.verbose = 2 try: for hostname in config.get_hosts(): server = config.host(hostname).get_back_ip() obj = ssh.Ssh(server, app.get_root_password()) app.print_verbose("List KVM guests on host " + hostname + " (" + server + ")") if (obj.is_alive()): obj.install_ssh_key() obj.ssh_exec("virsh list --all") else: app.print_verbose(" Not online.") except SettingsError, e: app.print_error(e, 2)
def vir_list(args): old_verbose = app.options.verbose app.options.verbose = 2 try: for hostname in config.get_hosts(): server = config.host(hostname).get_front_ip() obj = ssh.Ssh(server, app.get_root_password()) app.print_verbose("List KVM guests on host " + hostname + " (" + server + ")") if (obj.is_alive()): obj.install_ssh_key() obj.ssh_exec("virsh list --all") else: app.print_verbose(" Not online.") except SettingsError, e: app.print_error(e, 2)
def remote_install_syco(self, hostname): ''' Execute the commands on the remote host. Create one process for each remote host. ''' try: server = config.host(hostname).get_back_ip() app.print_verbose("Install syco on " + hostname + " (" + server + ")", 2) obj = ssh.Ssh(server, app.get_root_password()) self._validate_alive(obj, hostname) obj.install_ssh_key() self._install_syco_on_remote_host(obj) except pexpect.EOF, e: app.print_error(e, 2)
def passwords(args): app.print_verbose("Set all passwords used by syco") app.init_all_passwords() print "root: ", app.get_root_password() print "svn: ", app.get_svn_password() print "ldap_admin: ", app.get_ldap_admin_password() print "ldap_sssd: ", app.get_ldap_sssd_password() print "glassfish_master: ", app.get_glassfish_master_password() print "glassfish_admin: ", app.get_glassfish_admin_password() print "glassfish_user: "******"glassfish") print "mysql_root: ", app.get_mysql_root_password() print "mysql_int: ", app.get_mysql_integration_password() print "mysql_stable: ", app.get_mysql_stable_password() print "mysql_uat: ", app.get_mysql_uat_password() print "mysql_prod: ", app.get_mysql_production_password() print "mysql_backup: ", app.get_mysql_backup_password() print "mysql_monitor: ", app.get_mysql_monitor_password() print "switch_icmp: ", app.get_switch_icmp_password()
def download_cert(filename): ''' Get certificate from ldap server. This is not needed to be done on the server. ''' #Creating certs folder x("mkdir -p /etc/openldap/cacerts") ip = config.general.get_ldap_server_ip() fullpath = '/etc/openldap/cacerts/' + filename shell_run("scp root@%s:%s %s" % (ip, fullpath, fullpath), events={ 'Are you sure you want to continue connecting \(yes\/no\)\?': "YES\n", "root@" + ip + "\'s password\:": app.get_root_password() + "\n" } )
def download_cert(filename): """ Get certificate from ldap server. This is not needed to be done on the server. """ # Creating certs folder x("mkdir -p /etc/openldap/cacerts") ip = config.general.get_ldap_server_ip() fullpath = '/etc/openldap/cacerts/' + filename shell_run("scp root@%s:%s %s" % (ip, fullpath, fullpath), events={ 'Are you sure you want to continue connecting \(yes\/no\)\?': "YES\n", "root@" + ip + "\'s password\:": app.get_root_password() + "\n" })
def remote_install_syco(self, hostname): ''' Execute the commands on the remote host. Create one process for each remote host. ''' try: server = config.host(hostname).get_back_ip() app.print_verbose( "Install syco on " + hostname + " (" + server + ")", 2) obj = ssh.Ssh(server, app.get_root_password()) self._validate_alive(obj, hostname) obj.install_ssh_key() self._install_syco_on_remote_host(obj) except pexpect.EOF, e: app.print_error(e, 2)
def _setup_backup_for_all_servers(): servers = config.get_servers() total_servers = len(servers) checked_servers = 0 while (len(servers)): checked_servers += 1 hostname = servers.pop() ip = config.host(hostname).get_back_ip() remote_server = ssh.Ssh(ip, app.get_root_password()) if (remote_server.is_alive()): remote_server.install_ssh_key() _configure_backup_pathes(remote_server, ip, hostname) else: servers.insert(0, hostname) app.print_error("Server " + hostname + " is not alive.") if (checked_servers > total_servers): total_servers = len(servers) checked_servers = 0 time.sleep(60)
def _setup_backup_for_all_servers(): servers = config.get_servers() total_servers = len(servers) checked_servers = 0 while(len(servers)): checked_servers += 1 hostname = servers.pop() ip = config.host(hostname).get_back_ip() remote_server = ssh.Ssh(ip, app.get_root_password()) if (remote_server.is_alive()): remote_server.install_ssh_key() _configure_backup_pathes(remote_server, ip, hostname) else: servers.insert(0, hostname) app.print_error("Server " + hostname + " is not alive.") if (checked_servers > total_servers): total_servers = len(servers) checked_servers = 0 time.sleep(60)