Ejemplo n.º 1
0
 def _get_user_number(self):
     """Each user in IPMI has a number associated with that is used on the command line
        when modifying a user. This method will find the number associated with the userid
     """
     _method_ = "PowerNodePlugin._get_user_number"
     user_id = None
     cmd_parms = [
         self.IPMI_TOOL, "-I", "lanplus", "-H", self.host, "-U",
         self.userid, "-P", self.password, "user", "list"
     ]
     (rc, stdout, stderr) = execute_command(" ".join(cmd_parms))
     if rc != 0:
         logging.warning("%s::ipmi query failed with output %s", _method_,
                         stderr)
         raise exceptions.DeviceException(
             "ipmi query failed with output %s" % stderr)
     for line in stdout:
         ids = line.split()[0]
         user = line.split()[1]
         if user == self.userid:
             user_id = ids
             break
     if user_id:
         return user_id
     else:
         raise exceptions.DeviceException(
             "Failed to determine the id for the user: %s" % self.userid)
Ejemplo n.º 2
0
 def change_device_password(self, new_password):
     """Update the password of the ipmi default user on the BMC of the openpower server.
     """
     _method_ = "PowerNodePlugin.change_device_password"
     user_number = self._get_user_number()
     cmd_parms = [
         self.IPMI_TOOL, "-I", "lanplus", "-H", self.host, "-U",
         self.userid, "-P", self.password, "user", "set", "password",
         user_number, new_password
     ]
     (rc, _stdout, stderr) = execute_command(" ".join(cmd_parms))
     if rc != 0:
         logging.error("%s::ipmi password change failed with output %s",
                       _method_, stderr)
         raise exceptions.DeviceException(
             "ipmi password change failed with output %s" % stderr)
Ejemplo n.º 3
0
 def get_version(self):
     _method_ = "PowerNodePlugin.get_version"
     cmd_parms = [
         self.IPMI_TOOL, "-I", "lanplus", "-H", self.host, "-U",
         self.userid, "-P", self.password, "mc", "info"
     ]
     (rc, stdout, stderr) = execute_command(" ".join(cmd_parms))
     if rc != 0:
         logging.warning("%s::ipmi query failed with output %s", _method_,
                         stderr)
         raise exceptions.DeviceException(
             "ipmi query failed with output %s" % stderr)
     for line in stdout:
         if "Firmware Revision" in line:
             self.version = line.split(":")[1].strip()
             break
     return self.version
Ejemplo n.º 4
0
 def change_device_password(self, new_password):
     self._check_connection()
     client_shell = self.client.invoke_shell()
     client_shell.send(self.PASSWORD_CHANGE_COMMAND)
     client_shell.send(self.password + "\n")
     client_shell.send(new_password + "\n")
     client_shell.send(new_password + "\n")
     time.sleep(5)
     output = client_shell.recv(1000).decode()
     client_shell.close()
     if self.PASSWORD_CHANGED_MESSAGE in output:
         logging.info("Password changed for " + self.userid +
                      " successfully")
     else:
         message = "Failed to change password for %s. Console output: %s" % \
                   (self.userid, output)
         logging.warning(message)
         raise exceptions.DeviceException(message)
Ejemplo n.º 5
0
 def connect(self, host, userid, password=None, ssh_key_string=None):
     _method_ = "RackSwitchPlugin.connect"
     self.host = host
     self.userid = userid
     self.password = password
     try:
         self.client = paramiko.SSHClient()
         self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
         if ssh_key_string:
             private_key = paramiko.RSAKey.from_private_key(
                 StringIO(ssh_key_string), password)
             self.client.connect(host,
                                 username=userid,
                                 pkey=private_key,
                                 timeout=30,
                                 allow_agent=False)
         else:
             self.client.connect(host,
                                 username=userid,
                                 password=password,
                                 timeout=30,
                                 allow_agent=False,
                                 look_for_keys=False)
         if not self._is_rack_switch():
             raise exceptions.DeviceException(
                 "Device is not a Lenovo Rack Switch")
     except paramiko.AuthenticationException:
         logging.error(
             "%s::userid/password combination not valid. host=%s userid=%s",
             _method_, host, userid)
         raise exceptions.AuthenticationException(
             "userid/password combination not valid")
     except (paramiko.ssh_exception.SSHException, OSError,
             socket.timeout) as e:
         logging.exception(e)
         logging.error("%s::Connection timed out. host=%s", _method_, host)
         raise exceptions.ConnectionException("Unable to ssh to the device")