1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
Quick start
===========
Importing the library
---------------------
After you successfully installed the **python-ipmi** library, import it in your python environment:
.. code:: python
import pyipmi
import pyipmi.interfaces
Creating the session
--------------------
Authenticated :abbr:`IPMI (Intelligent Platform Management Interface)` communication to the :abbr:`BMC (Board Management Controller)` is accomplished by establishing a session. Once established, a session is identified by a Session ID. The Session ID identifies a connection between a given remote user and :abbr:`BMC (Board Management Controller)`, using either the :abbr:`LAN (Local Area Network)` or Serial/Modem connection.
Before establishing the session the interface type shall be defined. There are 4 interface types included in this library:
* **'rmcp'** - using native :abbr:`RMCP (Remote Management Control Protocol)` encapsulation over :abbr:`LAN (Local Area Network)` (so called :abbr:`IPMI (Intelligent Platform Management Interface)` over :abbr:`LAN (Local Area Network)`). This interface requires only common python libraries.
* **'ipmitool'** - so called legacy :abbr:`RMCP (Remote Management Control Protocol)`, still an :abbr:`IPMI (Intelligent Platform Management Interface)` over :abbr:`LAN (Local Area Network)`, but requires IPMITOOL as backend. This interface requires `ipmitool`_ compiled and installed, and each time an ipmitool command is issued a new session is established with the Target (left for legacy purpuses; used before native rmcp was not implemented yet).
* **'aardvark'** - :abbr:`IPMB (Intelligent Platform Management Bus)` interface (using the `Total Phase`_ Aardvark)
* **'mock'** - This interface uses the ipmitool raw command to "emulate" an :abbr:`RMCP (Remote Management Control Protocol)` session. It uses the session information to assemble the correct ipmitool parameters. Therefore, a session must be established before any request can be sent.
Then you create an instance of the ``pyipmi.Ipmi`` object using the ``interface`` instance just created, and set also the required parameteres of the interface type. You should also set the :abbr:`IPMI (Intelligent Platform Management Interface)` **Target**, otherwise different runtime errors shall be expected later on when invoking methods of this library. Finally, you can try to establish a session. If there is a connection problem (no response), then you get the following error during session establishment:
.. error::
timeout: timed out
This runtime error occurs anytime with any method in case of no response.
Native RMCP interface
*********************
Here is an example to create a native :abbr:`RMCP (Remote Management Control Protocol)` interface:
.. code:: python
interface = pyipmi.interfaces.create_interface(interface='rmcp',
slave_address=0x81,
host_target_address=0x20,
keep_alive_interval=1)
ipmi = pyipmi.create_connection(interface)
ipmi.session.set_session_type_rmcp(host='10.0.114.199', port=623)
ipmi.session.set_auth_type_user(username='admin', password='admin')
ipmi.target = pyipmi.Target(ipmb_address=0x20)
ipmi.session.establish()
device_id = ipmi.get_device_id()
# Below code used only to print out the device ID information
print('''
Device ID: %(device_id)s
Device Revision: %(revision)s
Firmware Revision: %(fw_revision)s
IPMI Version: %(ipmi_version)s
Manufacturer ID: %(manufacturer_id)d (0x%(manufacturer_id)04x)
Product ID: %(product_id)d (0x%(product_id)04x)
Device Available: %(available)d
Provides SDRs: %(provides_sdrs)d
Additional Device Support:
'''[1:-1] % device_id.__dict__)
functions = (
('SENSOR', 'Sensor Device'),
('SDR_REPOSITORY', 'SDR Repository Device'),
('SEL', 'SEL Device'),
('FRU_INVENTORY', 'FRU Inventory Device'),
('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver'),
('IPMB_EVENT_GENERATOR', 'IPMB Event Generator'),
('BRIDGE', 'Bridge'),
('CHASSIS', 'Chassis Device')
)
for n, s in functions:
if device_id.supports_function(n):
print(' %s' % s)
if device_id.aux is not None:
print('Aux Firmware Rev Info: [%s]' % (
' '.join('0x%02x' % d for d in device_id.aux)))
For ``create_interface`` method the first argument tells that a native RMCP interface shall be created, while for the rest of the arguments the default values are shown. After creating an instance of the ``interface`` object the interface parameters shall be set with ``set_session_type_rmcp`` and ``set_auth_type_user`` methods of the session as shown above. If authentication fails during session establishment an error of the following form shall be expected:
.. error::
CompletionCodeError: CompletionCodeError cc=0x81 desc=Unknown error description
Legacy RMCP interface with IPMITOOL as backend
**********************************************
An example showing how to setup the interface and the connection using the ipmitool as backend with network interface:
.. code:: python
interface = pyipmi.interfaces.create_interface(interface='ipmitool',
interface_type='lan')
ipmi = pyipmi.create_connection(interface)
ipmi.session.set_session_type_rmcp('10.0.0.1', port=623)
ipmi.session.set_auth_type_user('admin', 'admin')
ipmi.target = pyipmi.Target(ipmb_address=0x82, routing=[(0x81,0x20,0),(0x20,0x82,7)])
ipmi.session.establish()
ipmi.get_device_id()
where in the ``create_interface`` method the supported interface types for ipmitool are **'lan'** , **'lanplus'**, and **'serial-terminal'**. When setting the **Target**, the ``ipmb_address`` argument represents the :abbr:`IPMI (Intelligent Platform Management Interface)` target address, and ``routing`` argument represents the bridging information over which a target is reachable. The path is given as a list of tuples in the form (address, bridge_channel). Here are three examples to have a better understanding about the format of the routing:
* **Example #1**: access to an :abbr:`ATCA (Advanced Telecommunication Computing Architecture)` blade in a chassis
- slave = 0x81, target = 0x82
- routing = [(0x81,0x20,0),(0x20,0x82,None)]
.. graphviz::
digraph g{
rankdir=LR;
nd1 [label="0x81"]
nd2 [label="0x20"]
nd3 [label="0x82"]
nd4 [label="0x20"]
nd1 -> nd2 [label="channel=0"]
nd2 -> nd3 -> nd4
subgraph cluster0 {
label="Slave"
nd1;
}
subgraph cluster3 {
label="Chassis"
subgraph cluster1 {
label="ATCA Blade (Target)"
nd3;
nd4;
}
nd2;
}
}
}
* **Example #2**: access to an :abbr:`MMC (Module Management Controller)` of an :abbr:`AMC (Advanced Mezzanine Card)` plugged into a :abbr:`CM (Carrier Module)` in a :abbr:`uTCA (Micro Telecommunication Computing Architecture)`-:abbr:`MCH (MicroTCA Carrier Hub)` chassis with :abbr:`ShMC (Shelf Management Controller)`
- slave = 0x81, target = 0x72
- routing = [(0x81,0x20,0),(0x20,0x82,7),(0x20,0x72,None)]
.. graphviz::
digraph g{
rankdir=LR;
nd1 [label="0x81"]
nd2 [label="0x20"]
nd3 [label="0x82"]
nd4 [label="0x20"]
nd5 [label="0x72"]
nd1 -> nd2 [label="channel=0"]
nd2 -> nd3 -> nd4
nd4 -> nd5 [label="channel=7"]
subgraph cluster0 {
label="Slave"
nd1;
}
subgraph cluster3 {
label="uTCA - MCH"
subgraph cluster1 {
label="CM"
nd3;
nd4;
}
subgraph cluster2 {
label="ShMC"
nd2;
}
}
subgraph cluster5 {
label="AMC (Target)"
subgraph cluster4 {
label="MMC"
nd5;
}
}
}
* **Example #3**: access to an :abbr:`MMC (Module Management Controller)` of an :abbr:`AMC (Advanced Mezzanine Card)` plugged into :abbr:`ATCA (Advanced Telecommunication Computing Architecture)` :abbr:`AMC (Advanced Mezzanine Card)` carrier
- slave = 0x81, target = 0x72
- routing = [(0x81,0x20,0),(0x20,0x8e,7),(0x20,0x80,None)]
.. graphviz::
digraph g{
rankdir=LR;
nd1 [label="0x81"]
nd2 [label="0x20"]
nd3 [label="0x8E"]
nd4 [label="0x20"]
nd5 [label="0x80"]
nd1 -> nd2 [label="channel=0"]
nd2 -> nd3 -> nd4
nd4 -> nd5 [label="channel=7"]
subgraph cluster0 {
label="Slave"
nd1;
}
subgraph cluster3 {
label="ATCA"
subgraph cluster1 {
label="AMC Carrier"
nd3;
nd4;
}
nd2;
}
subgraph cluster5 {
label="AMC (Target)"
subgraph cluster4 {
label="MMC"
nd5;
}
}
}
ipmitool command:
.. code:: shell
ipmitool -I lan -H 10.0.0.1 -p 623 -U "admin" -P "admin" -t 0x82 -b 0 -l 0 raw 0x06 0x01
An example that shows how to setup the interface and the connection using the ipmitool as backend with serial interfaces:
.. code:: python
interface = pyipmi.interfaces.create_interface(interface='ipmitool',
interface_type='serial-terminal')
ipmi = pyipmi.create_connection(interface)
ipmi.session.set_session_type_serial('/dev/tty2', 115200)
ipmi.target = pyipmi.Target(0xb2)
ipmi.session.establish()
ipmi.get_device_id()
ipmitool command:
.. code:: shell
ipmitool -I serial-terminal -D /dev/tty2:115200 -t 0xb2 -l 0 raw 0x06 0x01
IPMB with Aardvark
******************
For :abbr:`IPMB (Intelligent Platform Management Bus)` interface with Aardvark tool you should use the followig code:
.. code:: python
interface = pyipmi.interfaces.create_interface('aardvark',
slave_address=0x20,
serial_number='2237-523145')
ipmi = pyipmi.create_connection(interface)
ipmi.target = pyipmi.Target(ipmb_address=0xb4)
device_id = ipmi.get_device_id()
# Below code used only to print out the device ID information
print('''
Device ID: %(device_id)s
Device Revision: %(revision)s
Firmware Revision: %(fw_revision)s
IPMI Version: %(ipmi_version)s
Manufacturer ID: %(manufacturer_id)d (0x%(manufacturer_id)04x)
Product ID: %(product_id)d (0x%(product_id)04x)
Device Available: %(available)d
Provides SDRs: %(provides_sdrs)d
Additional Device Support:
'''[1:-1] % device_id.__dict__)
functions = (
('SENSOR', 'Sensor Device'),
('SDR_REPOSITORY', 'SDR Repository Device'),
('SEL', 'SEL Device'),
('FRU_INVENTORY', 'FRU Inventory Device'),
('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver'),
('IPMB_EVENT_GENERATOR', 'IPMB Event Generator'),
('BRIDGE', 'Bridge'),
('CHASSIS', 'Chassis Device')
)
for n, s in functions:
if device_id.supports_function(n):
print(' %s' % s)
if device_id.aux is not None:
print('Aux Firmware Rev Info: [%s]' % (
' '.join('0x%02x' % d for d in device_id.aux)))
Sending IPMI commands
---------------------
You can send an :abbr:`IPMI (Intelligent Platform Management Interface)` message using the predefined command name
+------------------------------------------------------------+
| **send_message_with_name(name, *args, **kwargs)** |
+------------------------------------------------------------+
where the ``name`` argument represents the string name of the command as listed in the last column of table from `commands`_. For commands which do not require data to be sent name is the only argument to be passed.
The returned value is on object which types depend on the name of the issued command.
The following example requests the device ID:
.. code:: python
ipmi.send_message_with_name('GetDeviceId')
.. note::
The returned object in this case is different from the one shown for the native :abbr:`RMCP (Remote Management Control Protocol)` example shown above.
Closing the session
-------------------
When you finish, close your session with ``session_close`` method.
.. code:: python
ipmi.session.close()
As a beginner, you might find useful the debugging capabilities of this library. You can use the logging of the **python-ipmi** library by setting the following lines:
.. code:: python
import logging
logging.basicConfig(filename='ipmi_debug.log', filemode='w', level=logging.DEBUG)
in which case debug, info and warning messages are all recorded in the **'ipmi_debug.log'** file.
.. note::
It is assumed in all code examples that the instantiation of the ``pyipmi.Ipmi`` object is called **ipmi**, thus **ipmi** will preceed all the methods and attributes of the ``pyipmi.Ipmi`` object.
.. _Total Phase: http://www.totalphase.com
.. _ipmitool: http://sourceforge.net/projects/ipmitool/
.. _commands: https://github.com/kontron/python-ipmi/blob/master/docs/commands.rst
|