summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schwarz <david.schwarz@calxeda.com>2012-02-28 13:52:44 -0600
committerDavid Schwarz <david.schwarz@calxeda.com>2012-02-28 13:52:44 -0600
commit0b083a38da9ff89684abdc69c0efad4ea84b88f0 (patch)
tree25387eff63c20ac24271cafb37ddde80a1530d75
parent1ecaac7748fe8967a8898d8959ea528e06d00975 (diff)
downloadpyipmi-0b083a38da9ff89684abdc69c0efad4ea84b88f0.tar.gz
Add user commands (get/set access, set password, enable/disable)
-rw-r--r--pyipmi/bmc.py20
-rw-r--r--pyipmi/commands/__init__.py2
-rw-r--r--pyipmi/commands/user.py131
3 files changed, 153 insertions, 0 deletions
diff --git a/pyipmi/bmc.py b/pyipmi/bmc.py
index cd8bc7f..5dbd33b 100644
--- a/pyipmi/bmc.py
+++ b/pyipmi/bmc.py
@@ -284,6 +284,26 @@ class BMC(object):
callin=callin, ipmi=ipmi,
link=link, priv_level=priv_level)
+ def user_list(self, channel=None):
+ return self.handle.user_list(channel=channel)
+
+ def user_set_name(self, userid, name):
+ return self.handle.user_set_name(userid=userid, name=name)
+
+ def user_set_password(self, userid, password=None):
+ return self.handle.user_set_password(userid=userid, password=password)
+
+ def user_enable(self, userid):
+ return self.handle.user_enable(userid=userid)
+
+ def user_disable(self, userid):
+ return self.handle.user_disable(userid=userid)
+
+ def user_priv(self, userid, priv_level, channel=None):
+ return self.handle.user_priv(userid=userid, priv_level=priv_level,
+ channel=channel)
+
+
class LanBMC(BMC):
"""A BMC that's accessed over the LAN"""
def __init__(self,
diff --git a/pyipmi/commands/__init__.py b/pyipmi/commands/__init__.py
index bdd0269..91f8ff3 100644
--- a/pyipmi/commands/__init__.py
+++ b/pyipmi/commands/__init__.py
@@ -22,6 +22,7 @@ from watchdog import watchdog_commands
from fru import fru_commands
from lan import lan_commands
from channel import channel_commands
+from user import user_commands
ipmi_commands = {}
@@ -41,3 +42,4 @@ ipmi_commands.update(watchdog_commands)
ipmi_commands.update(fru_commands)
ipmi_commands.update(lan_commands)
ipmi_commands.update(channel_commands)
+ipmi_commands.update(user_commands)
diff --git a/pyipmi/commands/user.py b/pyipmi/commands/user.py
new file mode 100644
index 0000000..18e89a7
--- /dev/null
+++ b/pyipmi/commands/user.py
@@ -0,0 +1,131 @@
+#Copyright 2012 Calxeda, Inc. All Rights Reserved.
+"""user management IPMI commands"""
+
+from .. import Command
+from pyipmi.user import *
+from pyipmi.tools.responseparser import (ResponseParserMixIn,
+ str_to_list,
+ str_to_dict)
+
+
+class UserListCommand(Command, ResponseParserMixIn):
+ """Describes the user list ipmitool command
+ """
+ name = "User List"
+ result_type = UserListResults
+
+ def parse_response(self, out, err):
+ """ Output is a table with a header row:
+ ID Name Callin Link Auth IPMI Msg Channel Priv Limit
+ 1 anonymous true false false NO ACCESS
+ """
+ result = []
+ for line in out.strip().split('\n')[1:]:
+ user_info = self.result_type()
+
+ user_info_list = line.strip().split()
+ print str(user_info_list)
+ user_info.user_id = user_info_list[0].strip()
+ user_info.name = user_info_list[1].strip()
+ user_info.callin = user_info_list[2].strip()
+ user_info.link_auth = user_info_list[3].strip()
+ user_info.ipmi_msg = user_info_list[4].strip()
+ user_info.channel_priv_limit = ' '.join(user_info_list[5:]).strip()
+
+ result.append(user_info)
+
+ return result
+
+ @property
+ def ipmitool_args(self):
+ channel = self._params.get('channel', '')
+ return ["user", "list", channel]
+
+
+class UserSetNameCommand(Command, ResponseParserMixIn):
+ """Describes the user set name ipmitool command
+ """
+ name = "User Set Name"
+ result_type = UserSetNameResults
+
+ response_fields = {
+ 'Field Name' : {}
+ }
+
+ @property
+ def ipmitool_args(self):
+ return ["user", "set", "name", self._params['userid'],
+ self._params['name']]
+
+
+class UserSetPasswordCommand(Command, ResponseParserMixIn):
+ """Describes the user set password ipmitool command
+ """
+ name = "User Set Password"
+ result_type = UserSetPasswordResults
+
+ response_fields = {
+ 'Field Name' : {}
+ }
+
+ @property
+ def ipmitool_args(self):
+ password = self._params.get('password', '')
+ return ["user", "set", "password", self._params['userid'], password]
+
+
+class UserDisableCommand(Command, ResponseParserMixIn):
+ """Describes the user disable ipmitool command
+ """
+ name = "User Disable"
+ result_type = UserDisableResults
+
+ response_fields = {
+ 'Field Name' : {}
+ }
+
+ @property
+ def ipmitool_args(self):
+ return ["user", "disable", self._params['userid']]
+
+
+class UserEnableCommand(Command, ResponseParserMixIn):
+ """Describes the user enable ipmitool command
+ """
+ name = "User Enable"
+ result_type = UserEnableResults
+
+ response_fields = {
+ 'Field Name' : {}
+ }
+
+ @property
+ def ipmitool_args(self):
+ return ["user", "enable", self._params['userid']]
+
+
+class UserPrivCommand(Command, ResponseParserMixIn):
+ """Describes the user priv ipmitool command
+ """
+ name = "User Set Privileges"
+ result_type = UserPrivResults
+
+ response_fields = {
+ 'Field Name' : {}
+ }
+
+ @property
+ def ipmitool_args(self):
+ channel = self._params.get('channel', '')
+ return ["user", "priv", self._params['userid'],
+ self._params['priv_level'], channel]
+
+
+user_commands = {
+ 'user_list' : UserListCommand,
+ 'user_set_name' : UserSetNameCommand,
+ 'user_set_password' : UserSetPasswordCommand,
+ 'user_enable' : UserEnableCommand,
+ 'user_disable' : UserDisableCommand,
+ 'user_priv' : UserPrivCommand
+}