summaryrefslogtreecommitdiffstats
path: root/doc/admin/power/usage.rst
blob: 67a7f2e8bb7a90b2acf9d0254f3811cdb254dca8 (plain)
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
.. _usage:

OpenLMI Power Management usage
==============================

All example scripts are for ``lmishell``. See it's documentation_ on OpenLMI_
page.

.. _documentation: https://fedorahosted.org/openlmi/wiki/shell
.. _OpenLMI: https://fedorahosted.org/openlmi/

We also assume that ``lmishell`` is connected to the CIMOM and the
connection is stored in ``connection`` variable::

    connection = connect("server", "username", "password")
    ns = connection.root.cimv2

Enumeration of available power states
-------------------------------------

To see the available power states on given managed system, use following::

    capabilities = ns.LMI_PowerManagementCapabilities.first_instance()
    for state in capabilities.PowerStatesSupported:
        print ns.LMI_PowerManagementCapabilities.PowerStatesSupportedValues.value_name(state)

Setting the power state
-----------------------

Let's say we want to power off the system gracefully::

    # Check if the power state is available first
    capabilities = ns.LMI_PowerManagementCapabilities.first_instance()
    if not ns.LMI_PowerManagementCapabilities.PowerStatesSupportedValues.OffSoftGraceful in capabilities.PowerStatesSupported:
        print "OffSoftGraceful state is not supported"
        return
    # Get the PowerManagement service
    service = ns.LMI_PowerManagementService.first_instance()
    # Invoke the state change
    service.RequestPowerStateChange(PowerState=ns.LMI_PowerManagementCapabilities.PowerStatesSupportedValues.OffSoftGraceful)

Note that the job returned from this function is not much usable because
when system is shutting down, the CIMOM is terminated as well.