예제 #1
0
    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])
예제 #2
0
    def __init__(self):
        self.ssh = ssh.Ssh()

        host = self.host()

        for h in host:
            comentario = re.compile('[#]+')

            if len(h[0]) > 1 and not comentario.search(h[0]):
                try:
                    ip = h[0]
                    username = h[1]
                    password = h[2]

                    if 3 == len(h):
                        port = 22
                    else:
                        port = int(h[3])

                    print
                    print 'Conectando em %s na porta %s' % (ip, port)
                    if self.ssh.connect(
                            host=ip, usuario=username, senha=password,
                            porta=port) is True:
                        self.clone_mac_detect()
                except Exception as e:
                    print 'Não foi possível conectar. Algo errado com as informações para conexão.'
예제 #3
0
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
예제 #4
0
 def login(self, ioLoop, data):
     termId = data['termId']
     oSsh = ssh.Ssh(None, self, data)
     ret = oSsh.login()
     if ret:
         return self.encoder.encode('loginResponse', {'code': -1, 'termId': termId, 'msg': ret})
     ioLoop.addEvent(oSsh, ioLoop.E_READ)
     self.sshs[termId] = oSsh
     return self.encoder.encode('loginResponse', {'code': 0, 'termId': termId})
예제 #5
0
 def downloadCerts(self):
    # if tlsoption == 1 or tlsoption == 2:
     logging.info('Downloading certs from '+self.ip)
     myssh = ssh.Ssh(self.ip)
     try:
         self.downloaddir = myssh.download('/usr/local/sip/.security/xmpp-s2s/certs/cup-xmpp-s2s.der')
         logging.info('Downloaded certs to '+self.downloaddir)
         myssh.download('/usr/local/sip/.security/xmpp-s2s-ECDSA/certs/cup-xmpp-s2s-ECDSA.der')
     except:
         logging.info('Certificate download failed')
         return 0
     logging.info('Downloaded certificates')
     return 1
예제 #6
0
파일: vir.py 프로젝트: ysoldak/syco
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)
예제 #7
0
    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)
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
    def run(self, ip, purpose, plat_tuple,fromdir):
        browser = webdriver.Firefox()
        browser.get('http://'+ip+'/cmplatform/certificateUpload.do')
        un = browser.find_element_by_name('j_username')
        un.send_keys(plat_tuple[0])
        pw = browser.find_element_by_name('j_password')
        pw.send_keys(plat_tuple[1])
        login_btn = browser.find_element_by_css_selector('button.cuesLoginButton:nth-child(1)')
        login_btn.click()
        dropdown_list = Select(browser.find_element_by_xpath("id('NAME')"))
       # dropdown_list.click()
        if purpose == 'xmpp':
            dropdown_list.select_by_value('cup-xmpp-trust')
       # browse_btn = browser.find_element_by_css_selector('#FILE')
       # browse_btn.send_keys('test.txt')
        file =browser.find_element_by_id('FILE')
        full_path = os.path.join(fromdir,'cup-xmpp-s2s.der')
        full_path_EC = os.path.join(fromdir,'cup-xmpp-s2s-ECDSA.der')
        logging.info('Upload dir is '+full_path)
        file.send_keys(full_path)
       # browser.execute_script('document.getElementById("FILE").setAttribute("value", "C:\\cup-xmpp-s2s.der")')
        submit_btn = browser.find_element_by_css_selector('input.cuesButton:nth-child(1)')
        submit_btn.click()
        logging.info('Upload dir is ' + full_path_EC)
        file2 = browser.find_element_by_id('FILE')
        #time.sleep(7)
        try:
            file2.send_keys(full_path_EC)
            upload2 = browser.find_element_by_css_selector('input.cuesButton:nth-child(1)')
            upload2.click()
        except:
            logging.exception('')
        browser.close()

        logging.info("Restarting XCP Router")
        myssh = ssh.Ssh(ip)
        myssh.restartService('Cisco XCP Router')
        logging.info('Done')