예제 #1
0
class Dorados(object):
    arrays = []

    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        self.filtering = len(objects) > 0
        self.timeout = 10
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            try:
                name = self.node.oget(s, 'name')
            except Exception:
                name = None
            if not name:
                name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "dorado":
                continue
            timeout = self.node.oget(s, "timeout")
            try:
                username = self.node.oget(s, "username")
                password = self.node.oget(s, "password")
                api = self.node.oget(s, "api")
            except:
                print("error parsing section", s, file=sys.stderr)
                continue
            try:
                secname, namespace, _ = split_path(password)
                password = factory("sec")(secname,
                                          namespace=namespace,
                                          volatile=True).decode_key("password")
            except Exception as exc:
                print("error decoding password: %s", exc, file=sys.stderr)
                continue
            self.arrays.append(
                Dorado(name, api, username, password, timeout, node=self.node))
            done.append(name)

    def __iter__(self):
        for array in self.arrays:
            yield (array)

    def get_dorado(self, name):
        for array in self.arrays:
            if array.name == name:
                return array
        return None
예제 #2
0
파일: centera.py 프로젝트: sherlant/opensvc
class Centeras(object):
    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        if len(objects) > 0:
            self.filtering = True
        else:
            self.filtering = False
        self.arrays = []
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "centera":
                continue

            try:
                server = self.node.oget(s, "server")
                username = self.node.oget(s, "username")
                password = self.node.oget(s, "password")
                jcass_dir = self.node.oget(s, "jcass_dir")
                java_bin = self.node.oget(s, "java_bin")
            except:
                print("error parsing section", s, file=sys.stderr)

            try:
                secname, namespace, _ = split_path(password)
                password = factory("sec")(secname,
                                          namespace=namespace,
                                          volatile=True).decode_key("password")
            except Exception as exc:
                print("error decoding password: %s", exc, file=sys.stderr)
                continue

            self.arrays.append(
                Centera(name,
                        server=server,
                        username=username,
                        password=password,
                        java_bin=java_bin,
                        jcass_dir=jcass_dir,
                        node=self.node))
            done.append(name)

    def __iter__(self):
        for array in self.arrays:
            yield (array)
예제 #3
0
class IbmDss(object):
    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        self.filtering = len(objects) > 0
        self.arrays = []
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "ibmds":
                continue
            pwfile = os.path.join(Env.paths.pathvar, s + '.pwfile')
            if not os.path.exists(pwfile):
                raise ex.Error(
                    "%s does not exists. create it with 'dscli managepwfile ...'"
                    % pwfile)

            try:
                username = self.node.oget(s, "username")
                hmc1 = self.node.oget(s, "hmc1")
                hmc2 = self.node.oget(s, "hmc2")
            except Exception as exc:
                print("error parsing section %s: %s" % (s, exc),
                      file=sys.stderr)
                continue
            self.arrays.append(
                IbmDs(name, hmc1, hmc2, username, pwfile, node=self.node))
            done.append(name)

    def __iter__(self):
        for array in self.arrays:
            yield (array)

    def get(self, array):
        for o in self.arrays:
            if o.name == array:
                return o
        raise ex.Error(
            "%s not defined in the node/cluster configuration, or is not usable"
            % array)
예제 #4
0
파일: netapp.py 프로젝트: sherlant/opensvc
class Netapps(object):
    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        self.filtering = len(objects) > 0
        self.arrays = []
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "netapp":
                continue

            kwargs = {"node": self.node}

            for key in ("server", "username", "key"):
                try:
                    kwargs[key] = self.node.oget(s, key)
                except:
                    print("missing parameter: %s", s)
            if "server" not in kwargs or "username" not in kwargs or "key" not in kwargs:
                continue
            try:
                secname, namespace, _ = split_path(kwargs["password"])
                kwargs["password"] = factory("sec")(
                    secname, namespace=namespace,
                    volatile=True).decode_key("password")
            except Exception as exc:
                print("error decoding password: %s", exc, file=sys.stderr)
                continue
            self.arrays.append(Netapp(s, **kwargs))

    def __iter__(self):
        for array in self.arrays:
            yield (array)
예제 #5
0
class Brocades(object):
    switchs = []

    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        if len(objects) > 0:
            self.filtering = True
        else:
            self.filtering = False
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="switch"):
            name = self.node.oget(s, "name")
            if not name:
                name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "brocade":
                continue
            key = self.node.oget(s, "key")
            password = self.node.oget(s, "password")
            try:
                username = self.node.oget(s, "username")
            except:
                print("no 'username' parameter in section %s" % s)
                continue
            if key is None and password is None:
                print("no 'key' nor 'password' parameter in section %s" % s)
                continue
            self.switchs.append(
                Brocade(name, username, key, password, node=self.node))
            done.append(name)

    def __iter__(self):
        for switch in self.switchs:
            yield (switch)
예제 #6
0
파일: ibmsvc.py 프로젝트: sherlant/opensvc
class IbmSvcs(object):
    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        self.filtering = len(objects) > 0
        self.arrays = []
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "ibmsvc":
                continue

            try:
                username = self.node.oget(s, 'username')
                key = self.node.oget(s, 'key')
            except:
                print("error parsing section", s, file=sys.stderr)
                continue
            self.arrays.append(IbmSvc(name, username, key, node=self.node))

    def __iter__(self):
        for array in self.arrays:
            yield(array)
예제 #7
0
class EmcVnxs(object):
    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        if len(objects) > 0:
            self.filtering = True
        else:
            self.filtering = False
        self.arrays = []
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "emcvnx":
                continue

            try:
                method = self.node.oget(s, "method")
                scope = self.node.oget(s, "scope")
                spa = self.node.oget(s, "spa")
                spb = self.node.oget(s, "spb")
                username = self.node.oget(s, "username")
                password = self.node.oget(s, "password")
            except Exception as exc:
                print("error parsing section %s: %s" % (s, exc),
                      file=sys.stderr)
                continue

            if method == "credentials":
                if username is None or password is None:
                    print(
                        "error parsing section %s: username and password are mandatory"
                        % s,
                        file=sys.stderr)
                    continue
                try:
                    secname, namespace, _ = split_path(password)
                    password = factory("sec")(
                        secname, namespace=namespace,
                        volatile=True).decode_key("password")
                except Exception as exc:
                    print("error decoding password: %s", exc, file=sys.stderr)
                    continue

            self.arrays.append(
                EmcVnx(name,
                       method,
                       scope,
                       spa,
                       spb,
                       username=username,
                       password=password,
                       node=self.node))
            done.append(name)

    def __iter__(self):
        for array in self.arrays:
            yield (array)
예제 #8
0
파일: hds.py 프로젝트: sherlant/opensvc
class Arrays(object):
    arrays = []

    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        self.filtering = len(objects) > 0
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            try:
                name = self.node.oget(s, "name")
            except Exception:
                name = None
            if not name:
                name = s.split("#", 1)[-1]
            if name in done:
                continue
            if self.filtering and name not in self.objects:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "hds":
                continue
            try:
                bin = self.node.oget(s, 'bin')
                jre_path = self.node.oget(s, 'jre_path')
                url = self.node.oget(s, 'url')
                username = self.node.oget(s, 'username')
                password = self.node.oget(s, 'password')
            except Exception as exc:
                print("error parsing section %s: %s" % (s, exc),
                      file=sys.stderr)
                continue

            try:
                secname, namespace, _ = split_path(password)
                password = factory("sec")(secname,
                                          namespace=namespace,
                                          volatile=True).decode_key("password")
            except Exception as exc:
                print("error decoding password: %s", exc, file=sys.stderr)
                continue

            self.arrays.append(
                Array(name,
                      url,
                      username,
                      password,
                      bin=bin,
                      jre_path=jre_path,
                      node=self.node))
            done.append(name)

    def __iter__(self):
        for array in self.arrays:
            yield (array)

    def get_array(self, name):
        for array in self.arrays:
            if array.name == name:
                return array
        return None
예제 #9
0
파일: eva.py 프로젝트: sherlant/opensvc
class Evas(object):
    arrays = []

    def __init__(self, objects=None, node=None):
        if objects is None:
            objects = []
        self.objects = objects
        self.filtering = len(objects) > 0
        if node:
            self.node = node
        else:
            self.node = Node()
        done = []
        for s in self.node.conf_sections(cat="array"):
            name = s.split("#", 1)[-1]
            if name in done:
                continue
            try:
                stype = self.node.oget(s, "type")
            except:
                continue
            if stype != "eva":
                continue
            try:
                manager = self.node.oget(s, 'manager')
                username = self.node.oget(s, 'username')
                password = self.node.oget(s, 'password')
                sssubin = self.node.oget(s, 'bin')
            except Exception as exc:
                print("error parsing section %s: %s" % (s, exc),
                      file=sys.stderr)
                pass
            try:
                secname, namespace, _ = split_path(password)
                password = factory("sec")(secname,
                                          namespace=namespace,
                                          volatile=True).decode_key("password")
            except Exception as exc:
                print("error decoding password: %s", exc, file=sys.stderr)
                continue
            out, err = sssu('ls system',
                            manager,
                            username,
                            password,
                            sssubin=sssubin)
            _in = False
            for line in out.split('\n'):
                if 'Systems avail' in line:
                    _in = True
                    continue
                if not _in:
                    continue
                name = line.strip()
                if self.filtering and name not in self.objects:
                    continue
                self.arrays.append(
                    Eva(name, manager, username, password, sssubin=sssubin))
                done.append(name)

    def __iter__(self):
        for array in self.arrays:
            yield (array)