summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-25 19:59:46 -0400
committerPatrick Williams <patrick@stwcx.xyz>2017-08-02 20:18:19 +0000
commitfcbedca0d847c27fdeab59cda9c6659d8640b6dd (patch)
tree165fe3c760f9896979eefc0f0732551abd75a2ea
parent00b520827e5d16fc8262783e1ccf8de89a213006 (diff)
downloadphosphor-fan-presence-fcbedca0d847c27fdeab59cda9c6659d8640b6dd.zip
phosphor-fan-presence-fcbedca0d847c27fdeab59cda9c6659d8640b6dd.tar.gz
presence: Add parser support for any of
Add support for the anyof yaml keyword. Change-Id: Ib28ca8ef9959cec29cb2d15a0bf758668375895f Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--presence/example/example.yaml17
-rwxr-xr-xpresence/pfpgen.py23
-rw-r--r--presence/templates/anyof.mako.hpp7
-rw-r--r--presence/templates/generated.mako.hpp1
4 files changed, 46 insertions, 2 deletions
diff --git a/presence/example/example.yaml b/presence/example/example.yaml
index aea0139..140e1ec 100644
--- a/presence/example/example.yaml
+++ b/presence/example/example.yaml
@@ -64,3 +64,20 @@
rpolicy:
type: fallback
+- name: Example Fan3
+ description: >
+ 'Example fan with anyof redundancy policy.
+
+ The anyof algorithm reports true if any redundancy set
+ component sensors report true.'
+ path: /system/chassis/motherboard/fan3
+ methods:
+ - type: gpio
+ key: 125
+ physpath: /sys/devices/foo/bar
+ - type: tach
+ sensors:
+ - fan3
+ rpolicy:
+ type: anyof
+
diff --git a/presence/pfpgen.py b/presence/pfpgen.py
index 1e22ac7..00ba900 100755
--- a/presence/pfpgen.py
+++ b/presence/pfpgen.py
@@ -194,8 +194,26 @@ class Rpolicy(ConfigEntry):
self.fan = get_index(objs, 'fan', self.fan)
+class AnyOf(Rpolicy, Renderer):
+ '''Default policy handler (policy:type:anyof).'''
+
+ def __init__(self, *a, **kw):
+ kw['name'] = 'anyof-{}'.format(kw['fan'])
+ super(AnyOf, self).__init__(**kw)
+
+ def setup(self, objs):
+ super(AnyOf, self).setup(objs)
+
+ def construct(self, loader, indent):
+ return self.render(
+ loader,
+ 'anyof.mako.hpp',
+ f=self,
+ indent=indent)
+
+
class Fallback(Rpolicy, Renderer):
- '''Default policy handler (policy:type:fallback).'''
+ '''Fallback policy handler (policy:type:fallback).'''
def __init__(self, *a, **kw):
kw['name'] = 'fallback-{}'.format(kw['fan'])
@@ -230,7 +248,7 @@ class Fan(ConfigEntry):
factory = Everything.classmap(self.rpolicy['type'])
rpolicy = factory(**self.rpolicy)
else:
- rpolicy = Fallback(fan=self.name)
+ rpolicy = AnyOf(fan=self.name)
for m in self.methods:
m['policy'] = rpolicy.name
@@ -252,6 +270,7 @@ class Everything(Renderer):
handler methods.'''
class_map = {
+ 'anyof': AnyOf,
'fan': Fan,
'fallback': Fallback,
'gpio': Gpio,
diff --git a/presence/templates/anyof.mako.hpp b/presence/templates/anyof.mako.hpp
new file mode 100644
index 0000000..cc0ca09
--- /dev/null
+++ b/presence/templates/anyof.mako.hpp
@@ -0,0 +1,7 @@
+std::make_unique<AnyOf>(
+${indent(1)}ConfigFans::get()[${f.fan}],
+${indent(1)}std::vector<std::reference_wrapper<PresenceSensor>>{
+% for s in f.sensors:
+${indent(2)}*ConfigSensors::get()[${s}],
+% endfor
+${indent(1)}})\
diff --git a/presence/templates/generated.mako.hpp b/presence/templates/generated.mako.hpp
index 3afd29f..6ba18dc 100644
--- a/presence/templates/generated.mako.hpp
+++ b/presence/templates/generated.mako.hpp
@@ -5,6 +5,7 @@
#include <array>
#include <memory>
#include <string>
+#include "anyof.hpp"
#include "fallback.hpp"
#include "fan.hpp"
#include "gpio.hpp"
OpenPOWER on IntegriCloud