Beispiel #1
0
 def command(self, command, subcommand, *args):
     command = [
         'ipmitool',
         '-H',
         self.host,
         '-U',
         self.user,
         '-P',
         self.password,
         command,
         subcommand,
     ]
     if args:
         command.extend(args)
     proc = subprocess.Popen(
         command,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
     )
     out, err = proc.communicate()
     if proc.returncode and err:
         if err.lower().startswith('invalid user name'):
             raise AuthError('Invalid user name.')
         raise Error('Error calling ipmitool: %s' % err)
     return force_unicode(out)
Beispiel #2
0
def _get_session_id(ip_address, user, password):
    login_url = "http://%s/session/create" % ip_address
    login_data = "%s,%s" % (user, password)
    opener = urllib2.build_opener()
    request = urllib2.Request(login_url, login_data)
    response = opener.open(request, timeout=15)
    response_data = response.readlines()
    if response_data and response_data[0][:2] == 'ok':
        return response_data[0][3:]
    raise AuthError('Session error.')
Beispiel #3
0
 def _auth(self, username, password, pkey, key_filenames, allow_agent,
           look_for_keys):
     self._transport.auth_password(username, password)
     self._cisco_chan = self._transport.open_session()
     self._cisco_chan.invoke_shell()
     self._cisco_chan.sendall('\r\n')
     self._cisco_chan.settimeout(15.0)
     time.sleep(4)
     try:
         chunk = self._cisco_chan.recv(1024)
     except socket.timeout:
         raise AuthError('Authentication failed.')
     else:
         if not chunk.endswith(('#', '>')):
             raise ConsoleError('Expected system prompt, got %r.' % chunk)
Beispiel #4
0
def _get_session(base_url, user, password):
    s = requests.Session()
    data = {'username': '******'.format(user), 'password': password}
    try:
        r = requests.post('{}/access/ticket'.format(base_url),
                          verify=False, data=data)
    except requests.ConnectionError:
        raise ConnectionError("Can't connect through API.")
    try:
        ticket = r.json()['data']['ticket']
    except (KeyError, TypeError):
        raise AuthError("Can't get access ticket through API.")
    s.headers = {
        'content-type': 'application/x-www-form-urlencoded',
        'Connection': 'keep-alive',
    }
    s.cookies = requests.cookies.cookiejar_from_dict({'PVEAuthCookie': ticket})
    s.verify = False
    return s
Beispiel #5
0
 def _auth(
     self,
     username,
     password,
     pkey,
     key_filenames,
     allow_agent,
     look_for_keys,
 ):
     self._transport.auth_password(username, password)
     self._asa_chan = self._transport.open_session()
     self._asa_chan.invoke_shell()
     self._asa_chan.sendall('\r\n')
     self._asa_chan.settimeout(15.0)
     time.sleep(0.125)
     try:
         chunk = self._asa_chan.recv(1024)
     except socket.timeout:
         raise AuthError('Authentication failed.')
     else:
         if '> ' not in chunk and not chunk.strip().startswith('asa'):
             raise ConsoleError('Expected system prompt, got %r.' % chunk)