File: resStonith.py

package info (click to toggle)
opensvc 1.8~20170412-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 6,492 kB
  • ctags: 7,845
  • sloc: python: 77,169; sh: 339; xml: 39; makefile: 7
file content (65 lines) | stat: -rw-r--r-- 2,154 bytes parent folder | download
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
import resources as Res
import rcStatus
import re
import os
from rcGlobalEnv import rcEnv
import rcExceptions as ex

class Stonith(Res.Resource):
    def __init__(self, **kwargs):
        Res.Resource.__init__(self, **kwargs)
        self.name = None
        self.re_login = re.compile("(login\s*: )|(Login Name:  )|(username: )|(User Name :)", re.IGNORECASE)
        self.re_pass  = re.compile("password", re.IGNORECASE)

    def creds(self):
        import ConfigParser
        c = ConfigParser.RawConfigParser()
        c.read(os.path.join(rcEnv.pathetc, 'auth.conf'))

        username = None
        password = None
        key = None

        if not c.has_section(self.name):
            raise ex.excError("No credentials in node.conf for %s"%self.name)

        if c.has_option(self.name, "username"):
            username = c.get(self.name, 'username')
        else:
            raise ex.excError("No username in node.conf for %s"%self.name)

        if c.has_option(self.name, "password"):
            password = c.get(self.name, 'password')
        if c.has_option(self.name, "key"):
            key = c.get(self.name, 'key')
            if not os.path.exists(key):
                raise ex.excError("key in node.conf for %s does not exist"%self.name)

        if password is None and key is None:
            raise ex.excError("No password nor key in node.conf for %s"%self.name)

        return username, password, key

    def start(self):
        if self.sanity():
            self.log.info("sanity checks passed. trigger stonith method")
        else:
            self.log.info("stonith bypassed")
            return
        self._start()

    def _start(self):
        pass

    def _status(self, verbose=False):
        return rcStatus.NA

    def sanity(self):
        for resource in self.svc.get_resources(['hb.ovm', 'hb.openha', 'hb.linuxha']):
            if not resource.disabled and hasattr(resource, 'need_stonith') and resource.need_stonith():
                self.log.info("heartbeat %s asks for stonith" % resource.rid)
                return True
        self.log.debug("no heartbeat asks for stonith")
        return False