~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/drivers/modules/snmp.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
"""
29
29
 
30
30
import abc
31
 
import six
32
31
 
33
32
from oslo.config import cfg
34
33
from oslo.utils import importutils
 
34
import six
35
35
 
36
36
from ironic.common import exception
37
37
from ironic.common.i18n import _
75
75
    'snmp_outlet': _("PDU power outlet index (1-based).  Required."),
76
76
}
77
77
OPTIONAL_PROPERTIES = {
78
 
    'snmp_version': _("SNMP protocol version: %(v1)s, %(v2c)s, %(v3)s  "
79
 
                      "(optional, default %(v1)s)")
80
 
                    % {"v1": SNMP_V1, "v2c": SNMP_V2C, "v3": SNMP_V3},
81
 
    'snmp_port': _("SNMP port, default %(port)d") % {"port": SNMP_PORT},
82
 
    'snmp_community': _("SNMP community.  Required for versions %(v1)s, "
83
 
                        "%(v2c)s")
84
 
                      % {"v1": SNMP_V1, "v2c": SNMP_V2C},
85
 
    'snmp_security': _("SNMP security name.  Required for version %(v3)s")
86
 
                      % {"v3": SNMP_V3},
 
78
    'snmp_version':
 
79
        _("SNMP protocol version: %(v1)s, %(v2c)s, %(v3)s  "
 
80
          "(optional, default %(v1)s)")
 
81
        % {"v1": SNMP_V1, "v2c": SNMP_V2C, "v3": SNMP_V3},
 
82
    'snmp_port':
 
83
        _("SNMP port, default %(port)d") % {"port": SNMP_PORT},
 
84
    'snmp_community':
 
85
        _("SNMP community.  Required for versions %(v1)s, %(v2c)s")
 
86
        % {"v1": SNMP_V1, "v2c": SNMP_V2C},
 
87
    'snmp_security':
 
88
        _("SNMP security name.  Required for version %(v3)s")
 
89
        % {"v3": SNMP_V3},
87
90
}
88
91
COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy()
89
92
COMMON_PROPERTIES.update(OPTIONAL_PROPERTIES)
220
223
 
221
224
    @abc.abstractmethod
222
225
    def _snmp_power_state(self):
223
 
        """Perform the SNMP request required to retrieve the current power
224
 
        state.
 
226
        """Perform the SNMP request required to get the current power state.
225
227
 
226
228
        :raises: SNMPFailure if an SNMP request fails.
227
229
        :returns: power state. One of :class:`ironic.common.states`.
376
378
        self.client.set(self.oid, value)
377
379
 
378
380
 
 
381
class SNMPDriverAten(SNMPDriverSimple):
 
382
    """SNMP driver class for Aten PDU devices.
 
383
 
 
384
    SNMP objects for Aten PDU:
 
385
    1.3.6.1.4.1.21317.1.3.2.2.2.2 Outlet Power
 
386
    Values: 1=Off, 2=On, 3=Pending, 4=Reset
 
387
    """
 
388
    oid_device = (21317, 1, 3, 2, 2, 2, 2)
 
389
    value_power_on = 2
 
390
    value_power_off = 1
 
391
 
 
392
    def _snmp_oid(self):
 
393
        """Return the OID of the power state object.
 
394
 
 
395
        :returns: Power state object OID as a tuple of integers.
 
396
        """
 
397
        outlet = int(self.snmp_info['outlet'])
 
398
        return self.oid_enterprise + self.oid_device + (outlet, 0,)
 
399
 
 
400
 
379
401
class SNMPDriverAPC(SNMPDriverSimple):
380
402
    """SNMP driver class for APC PDU devices.
381
403
 
501
523
# A dictionary of supported drivers keyed by snmp_driver attribute
502
524
DRIVER_CLASSES = {
503
525
        'apc': SNMPDriverAPC,
 
526
        'aten': SNMPDriverAten,
504
527
        'cyberpower': SNMPDriverCyberPower,
505
528
        'eatonpower': SNMPDriverEatonPower,
506
529
        'teltronix': SNMPDriverTeltronix
508
531
 
509
532
 
510
533
def _parse_driver_info(node):
511
 
    """Return a dictionary of validated driver information, usable for
 
534
    """Parse a node's driver_info values.
 
535
 
 
536
    Return a dictionary of validated driver information, usable for
512
537
    SNMPDriver object creation.
513
538
 
514
539
    :param node: An Ironic node object.
520
545
    missing_info = [key for key in REQUIRED_PROPERTIES if not info.get(key)]
521
546
    if missing_info:
522
547
        raise exception.MissingParameterValue(_(
523
 
            "SNMP driver requires the following to be set: %s.")
524
 
            % missing_info)
 
548
            "SNMP driver requires the following parameters to be set in "
 
549
            "node's driver_info: %s.") % missing_info)
525
550
 
526
551
    snmp_info = {}
527
552