Пример #1
0
 def _get_mem_bytes_hv(self):
     if which('virsh'):
         return self._get_mem_bytes_virsh()
     if which('xm'):
         return self._get_mem_bytes_xm()
     else:
         return '0'
Пример #2
0
    def unprovisioner(self):
        if self.vg is None:
            self.log.debug("skip lv unprovision: no vg option")
            return

        if not which('lvdisplay'):
            self.log.debug("skip lv unprovision: lvdisplay command not found")
            return

        dev = self.get_dev()
        if dev is None:
            return
        cmd = ["lvdisplay", dev]
        out, err, ret = justcall(cmd)
        if ret != 0:
            self.log.debug("skip lv unprovision: %s is not a lv" % dev)
            return

        if not which('lvremove'):
            self.log.error("lvcreate command not found")
            raise ex.Error

        if which('wipefs') and os.path.exists(dev):
            self.vcall(["wipefs", "-a", dev])

        cmd = ["lvremove", "-f", dev]
        ret, out, err = self.vcall(cmd)
        self.clear_cache("lvs.attr")
        if ret != 0:
            raise ex.Error
        self.svc.node.unset_lazy("devtree")
Пример #3
0
def listpkg_ips():
    """
    Return a list of ips packages installed.
    """

    #
    #   PKGINST:  SUNWzoneu
    #      NAME:  Solaris Zones (Usr)
    #  CATEGORY:  system
    #      ARCH:  i386
    #   VERSION:  11.11,REV=2009.04.08.17.26
    #    VENDOR:  Sun Microsystems, Inc.
    #      DESC:  Solaris Zones Configuration and Administration
    #   HOTLINE:  Please contact your local service provider
    #    STATUS:  completely installed
    #

    if which('uname') is None:
        return []
    cmd = ['uname', '-p']
    out, _, _ = justcall(cmd)
    arc = out.split('\n')[0]
    if which('pkg') is None:
        return []
    cmd = ['pkg', 'list', '-H']
    out, _, _ = justcall(cmd)
    lines = []
    for line in out.split('\n'):
        elems = line.split()
        if len(elems) != 3:
            continue
        data = [Env.nodename, elems[0], elems[1], arc, "ips", ""]
        lines.append(data)
    return lines
Пример #4
0
 def test_which(non_existing_file):
     """
     which()
     """
     assert which("ls") in ("/bin/ls", "/usr/bin/ls", "/usr/xpg4/bin/ls", "/usr/gnu/bin/ls")
     assert which("/bin/ls") in ("/bin/ls", "/usr/bin/ls")
     assert which(non_existing_file) is None
     assert which(None) is None
Пример #5
0
def driver_capabilities(node=None):
    from utilities.proc import which
    data = []
    if which("docker") or which("docker.io"):
        data += [
            "task.docker",
            "task.docker.registry_creds",
        ]
    return data
Пример #6
0
def driver_capabilities(node=None):
    data = []
    from utilities.proc import which
    if which("docker") or which("docker.io"):
        data += [
            "container.docker",
            "container.docker.registry_creds",
            "container.docker.signal",
        ]
    return data
Пример #7
0
def driver_capabilities(node=None):
    from utilities.proc import which
    data = []
    if which("sg_persist"):
        data.append("disk.scsireserv")
        data.append("disk.scsireserv.sg_persist")
    if which("mpathpersist"):
        out, err, ret = justcall(["multipath", "-h"])
        for line in err.splitlines():
            version = [int(v) for v in line.split()[1].strip("v").split(".")]
            break
        if version > [0, 7, 8]:
            data.append("disk.scsireserv")
            data.append("disk.scsireserv.mpathpersist")
    return data
Пример #8
0
    def zoneadm(self, action, option=None):
        if action in VALID_ACTIONS:
            cmd = [ZONEADM, "-z", self.name, action]
        else:
            self.log.error("unsupported zone action: %s", action)
            return 1
        if option is not None:
            cmd += option

        begin = datetime.now()
        if os.environ.get("OSVC_ACTION_ORIGIN") == "daemon" and which("su"):
            # the zoneadm command gives an error when executed from osvcd.
            # su creates a clean execution context and makes zoneadm succeed.
            cmd = ["su", "root", "-c", " ".join(cmd)]
        self.log.info("%s", " ".join(cmd))
        ret = self.lcall(cmd, env={})
        duration = datetime.now() - begin
        if ret != 0:
            raise ex.Error("%s failed in %s - ret %i" %
                           (" ".join(cmd), duration, ret))
        else:
            self.log.info("%s done in %s - ret %i" %
                          (" ".join(cmd), duration, ret))
        self.zone_refresh()
        return ret
Пример #9
0
    def startip_cmd(self):
        if which("ifconfig") and self.alias:
            if ':' in self.addr:
                cmd = [
                    'ifconfig', self.ipdev, 'inet6', 'add',
                    '/'.join([self.addr, to_cidr(self.netmask)])
                ]
            else:
                cmd = [
                    'ifconfig', self.stacked_dev, self.addr, 'netmask',
                    to_dotted(self.netmask), 'up'
                ]
        else:
            cmd = [
                Env.syspaths.ip, "addr", "add",
                '/'.join([self.addr, to_cidr(self.netmask)]), "dev", self.ipdev
            ]

        ret, out, err = self.vcall(cmd)
        if ret != 0:
            return ret, out, err

        # ip activation may still be incomplete
        # wait for activation, to avoid startapp scripts to fail binding their listeners
        for i in range(5, 0, -1):
            if utilities.ping.check_ping(self.addr, timeout=1, count=1):
                return ret, out, err
        self.log.error("timed out waiting for ip activation")
        raise ex.Error
Пример #10
0
    def load_lv(self, lv):
        if not which("lvdisplay"):
            return
        cmd = ["lvdisplay", "-v", lv]
        p = Popen(cmd, stdout=PIPE, stderr=PIPE)
        out, err = p.communicate()
        if p.returncode:
            return

        vgname = lv.split('/')[2]

        # parser
        h = {}
        for line in out.split('\n'):
            line = line.strip()
            if 'LV Size' in line:
                size = int(line.split()[-1])
            if not line.startswith('/dev'):
                continue
            pv, le, pe = line.split()
            h[pv] = int(pe) * self.pe_size[vgname]

        # use the linux lvm naming convention
        devname = lv.replace('/dev/', '').replace('-', '--').replace('/', '-')
        d = self.add_dev(devname, size, "linear")

        for pv in h:
            d.add_parent(pv.replace('/dev/disk/', ''), size=h[pv])
            d.set_devpath(lv)
            parent_dev = self.get_dev_by_devpath(pv)
            if parent_dev is None:
                continue
            parent_dev.add_child(d.devname)
Пример #11
0
 def fsck(self):
     if self.fs_type in ("", "tmpfs", "shm", "shmfs", "none") or os.path.isdir(self.device):
         # bind mounts are in this case
         return
     self.set_fsck_h()
     if self.fs_type not in self.fsck_h:
         self.log.debug("no fsck method for %s"%self.fs_type)
         return
     bin = self.fsck_h[self.fs_type]['bin']
     if which(bin) is None:
         self.log.warning("%s not found. bypass."%self.fs_type)
         return
     if 'reportcmd' in self.fsck_h[self.fs_type]:
         cmd = self.fsck_h[self.fs_type]['reportcmd']
         (ret, out, err) = self.vcall(cmd, err_to_info=True)
         if ret not in self.fsck_h[self.fs_type]['reportclean']:
             return
     cmd = self.fsck_h[self.fs_type]['cmd']
     (ret, out, err) = self.vcall(cmd)
     if 'allowed_ret' in self.fsck_h[self.fs_type]:
         allowed_ret = self.fsck_h[self.fs_type]['allowed_ret']
     else:
         allowed_ret = [0]
     if ret not in allowed_ret:
         raise ex.Error
Пример #12
0
    def provisioner(self):
        if not which('vxassist'):
            raise ex.Error("vxassist command not found")

        if self.has_it():
            self.log.info("skip vxvol provision: %s already exists" %
                          self.fullname)
            return

        if not self.size:
            raise ex.Error("a size is required")

        size_parm = str(self.size).upper()
        size_parm = [str(convert_size(size_parm, _to="m")) + 'M']
        create_options = self.create_options or self.oget("create_options")

        # strip dev dir in case the alloc vxassist parameter was formatted using sub_devs
        # lazy references
        for idx, option in enumerate(create_options):
            create_options[idx] = option.replace("/dev/vx/dsk/", "")

        # create the logical volume
        cmd = ['vxassist', '-g', self.vg, "make", self.name
               ] + size_parm + create_options
        ret, out, err = self.vcall(cmd)
        if ret != 0:
            raise ex.Error(err)
        self.can_rollback = True
        self.svc.node.unset_lazy("devtree")
Пример #13
0
 def refresh_multipath(self, dev):
     if which(Env.syspaths.multipath) is None:
         return
     cmd = [Env.syspaths.multipath, '-v0', '-r', dev]
     (ret, out, err) = self.vcall(cmd)
     if ret != 0:
         raise ex.Error
Пример #14
0
def listpatch():
    """
    Return a list of patches installed.

    Patch: patchnum-rev Obsoletes: num-rev[,patch-rev]... Requires: .... Incompatibles: ... Packages: ...
    """
    if which('showrev') is None:
        return []
    cmd = ['showrev', '-p']
    out, _, _ = justcall(cmd)
    lines = []
    nodename = Env.nodename
    for line in out.splitlines():
        elems = line.split(' ')
        if len(elems) > 3:
            _elems = elems[1].split('-')
            if len(_elems) != 2:
                continue
            else:
                lines.append([nodename, _elems[0], _elems[1]])

    for idx, line in enumerate(lines):
        # pkg install date
        try:
            mtime = os.stat("/var/sadm/patch/" + line[1])[ST_MTIME]
            mtime = datetime.datetime.fromtimestamp(mtime).strftime(
                "%Y-%m-%d %H:%M:%S")
        except Exception:
            mtime = ""
        lines[idx].append(mtime)

    return lines
Пример #15
0
def listpkg_legacy():
    """
    Return a list of legacy packages installed.
    """
    if which('pkginfo') is None:
        return []
    cmd = ['pkginfo', '-l']
    out, _, _ = justcall(cmd)
    lines = []
    for line in out.splitlines():
        elems = line.split(':', 1)
        if len(elems) != 2:
            continue
        key, val = [elem.strip() for elem in elems]
        if key == "PKGINST":
            data = [Env.nodename, val, "", "", "pkg", ""]
        elif key == "VERSION":
            data[2] = val
        elif key == "ARCH":
            data[3] = val
            lines.append(data)

    for idx, line in enumerate(lines):
        # pkg install date
        try:
            mtime = os.stat("/var/sadm/pkg/" + line[1])[ST_MTIME]
            mtime = datetime.datetime.fromtimestamp(mtime).strftime(
                "%Y-%m-%d %H:%M:%S")
        except Exception:
            mtime = ""
        lines[idx][5] = mtime

    return lines
Пример #16
0
def listpkg_snap():
    """
    Example:

        Name      Version    Rev   Tracking  Publisher   Notes
        core      16-2.35.4  5662  stable    canonical*  core
        inkscape  0.92.3     4274  stable    inkscape*   -
        skype     8.32.0.44  60    stable    skype*      classic

    """
    if not which("snap"):
        return []
    cmd = ["snap", "list", "--unicode=never", "--color=never"]
    out, err, ret = justcall(cmd)
    lines = []
    for line in out.splitlines():
        if line.startswith('Name'):
            header = namedtuple("header", line)
            continue
        _data = header._make(line.split())
        lines.append([
            Env.nodename,
            _data.Name,
            "%s rev %s" % (_data.Version, _data.Rev),
            "",
            "snap",
            "",
        ])
    return lines
Пример #17
0
 def fs_u_zfs():
     if not which(Env.syspaths.zfs):
         return []
     cmd = [
         Env.syspaths.zfs, 'list', '-o', 'name,used,avail,mountpoint', '-H'
     ]
     (out, err, ret) = justcall(cmd)
     if ret != 0:
         return []
     lines = out.split('\n')
     if len(lines) == 0:
         return []
     vals = []
     for line in lines:
         l = line.split()
         if len(l) != 4:
             continue
         if "@" in l[0]:
             # do not report clone usage
             continue
         if "osvc_sync_" in l[0]:
             # do not report osvc sync snapshots fs usage
             continue
         used = convert_size(l[1], _to="KB")
         if l[2] == '0':
             l[2] = '0K'
         avail = convert_size(l[2], _to="KB")
         total = used + avail
         pct = used / total * 100
         vals.append([now, node.nodename, l[0], str(total), str(pct)])
     return vals
Пример #18
0
 def load_mpath(self):
     if hasattr(self, "mpath_h"):
         return self.mpath_h
     self.mpath_h = {}
     if which(Env.syspaths.multipath):
         self.load_mpath_native()
     return self.mpath_h
Пример #19
0
def sssu(cmd, manager, username, password, array=None, sssubin=None):
    if sssubin is None:
        if which("sssu"):
            sssubin = "sssu"
        elif os.path.exists(os.path.join(Env.paths.pathbin, "sssu")):
            sssubin = os.path.join(Env.paths.pathbin, "sssu")
        else:
            raise ex.Error(
                "sssu command not found. set 'array#%s.bin' in the node or cluster configuration."
                % array)
    os.chdir(Env.paths.pathtmp)
    _cmd = [
        sssubin,
        "select manager %s username=%s password=%s" %
        (manager, username, password)
    ]
    if array is not None:
        _cmd += ["select system %s" % array]
    _cmd += [cmd]
    out, err, ret = justcall(_cmd)
    print(" ".join(_cmd))
    if "Error" in out:
        print(_cmd)
        print(out)
        raise ex.Error("sssu command execution error")
    return out, err
Пример #20
0
 def do_check(self):
     if not which('hpacucli'):
         return self.undef
     cmd = ['controller', 'all', 'show', 'status']
     out, err, ret = self.hpacucli(cmd)
     if ret != 0:
         return self.undef
     lines = out.split('\n')
     if len(lines) == 0:
         return self.undef
     r = []
     for line in lines:
         if ' Slot ' in line:
             l = line.split()
             idx = l.index('Slot')
             uslot = l[idx+1]
             slot = 'slot ' + uslot
             _r = []
             _r += self.check_controller(uslot)
             _r += self.check_array(uslot)
             _r += self.check_logicaldrive(uslot)
             _r += self.check_physicaldrive(uslot)
             for inst, value in _r:
                 r.append({
                       "instance": ".".join((slot, inst)),
                       "value": str(value),
                       "path": '',
                      })
     return r
Пример #21
0
 def stopip_cmd(self):
     if not which(Env.syspaths.ipadm):
         raise ex.Error("crossbow ips are not supported on this system")
     ret, out, err = (0, '', '')
     if self.gateway is not None:
         cmd = ['route', '-q', 'delete', 'default', self.gateway]
         r, o, e = self.call(cmd, info=True, outlog=False, errlog=False)
         ret += r
     cmd = [
         Env.syspaths.ipadm, 'delete-addr',
         self.stacked_dev + '/' + self.ipdevext
     ]
     r, o, e = self.vcall(cmd)
     ret += r
     out += o
     err += e
     cmd = [
         Env.syspaths.ipadm, 'show-addr', '-p', '-o', 'state',
         self.stacked_dev
     ]
     _out, _, _ = justcall(cmd)
     _out = _out.strip().split("\n")
     if len(_out) > 0:
         self.log.info("skip delete-ip because addrs still use the ip")
         return ret, out, err
     cmd = [Env.syspaths.ipadm, 'delete-ip', self.stacked_dev]
     r, o, e = self.vcall(cmd)
     ret += r
     out += o
     err += e
     return ret, out, err
Пример #22
0
def file_to_loop(f):
    """Given a file path, returns the loop device associated. For example,
    /path/to/file => /dev/loop0
    """
    if which('mdconfig') is None:
        return []
    if not os.path.isfile(f):
        return []
    (ret, out, err) = call(['mdconfig', '-l', '-v'])
    if ret != 0:
        return []
    """ It's possible multiple loopdev are associated with the same file
    """
    devs = []
    for line in out.split('\n'):
        l = line.split()
        if len(l) < 4:
            continue
        path = ' '.join(l[3:])
        if path != f:
            continue
        if not os.path.exists('/dev/' + l[0]):
            continue
        devs.append(l[0])
    return devs
Пример #23
0
    def scan_mapping(self):
        if len(self.fcluns) > 0:
            return

        if not which('fcinfo'):
            return

        for index, portwwn, host in self._get_fc_hbas():
            cmd = ['fcinfo', '/mapping', '/ai:'+index]
            out, err, ret = justcall(cmd)
            if ret != 0:
                continue
            lines = out.split('\n')
            for i, line in enumerate(lines):
                if line.startswith('(  '):
                    l = line.split()
                    if len(l) < 3:
                        continue
                    bus = int(l[-3].strip(','))
                    target = int(l[-2].strip(','))
                    lun = int(l[-1].strip(')'))
                    _index = (host, bus, target, lun)
                elif line.startswith('(cs:'):
                    l = line.split()
                    if len(l) < 2:
                        continue
                    wwid = l[-1].strip(')')
                    self.fcluns[_index] = dict(wwid=wwid)
Пример #24
0
def listpkg():
    if which('swlist') is None:
        return []
    lines = []
    for t in ('product', 'bundle'):
        lines += listpkg_t(t)
    return lines
Пример #25
0
def listpkg_rpm():
    if not which("rpm"):
        return []
    cmd = [
        'rpm', '-qai',
        '--queryformat=XX%{n} %{v}-%{r} %{arch} rpm %{installtime}\n'
    ]
    out, err, ret = justcall(cmd)
    lines = []
    for line in out.split('\n'):
        if line.startswith('Signature'):
            sig = line.split()[-1].strip()
            continue
        elif not line.startswith('XX'):
            continue
        line = line[2:]
        l = line.split()
        if len(l) < 5:
            continue
        try:
            l[4] = datetime.datetime.fromtimestamp(int(
                l[4])).strftime("%Y-%m-%d %H:%M:%S")
        except:
            l[4] = ""
        x = [Env.nodename] + l + [sig]
        lines.append(x)
    return lines
Пример #26
0
 def find_fmadm(self):
     if which(self.fmadm):
         return self.fmadm
     for prefix in self.prefixes:
         fmadm = os.path.join(prefix, self.fmadm)
         if os.path.exists(fmadm):
             return fmadm
     return
Пример #27
0
 def start_link(self):
     if which(Env.syspaths.ip):
         cmd = [Env.syspaths.ip, 'link', 'set', 'dev', self.ipdev, 'up']
     else:
         cmd = ['ifconfig', self.ipdev, 'up']
     ret, out, err = self.vcall(cmd)
     if ret != 0:
         return ret, out, err
Пример #28
0
 def find_sas2ircu(self):
     if which(self.sas2ircu):
         return self.sas2ircu
     for prefix in self.prefixes:
         sas2ircu = os.path.join(prefix, self.sas2ircu)
         if os.path.exists(sas2ircu):
             return sas2ircu
     return
Пример #29
0
def driver_capabilities(node=None):
    from utilities.proc import which
    from env import Env
    if Env.sysname != "SunOS":
        return []
    if which("share"):
        return ["share.nfs"]
    return []
Пример #30
0
    def unprovisioner(self):
        if not which('vxassist'):
            raise ex.Error("vxassist command not found")

        if not self.has_it():
            self.log.info("skip vxvol unprovision: %s already unprovisioned",
                          self.fullname)
            return

        if which('wipefs') and os.path.exists(self.devpath) and self.is_up():
            self.vcall(["wipefs", "-a", self.devpath])

        cmd = ["vxassist", "-g", self.vg, "remove", "volume", self.name]
        ret, out, err = self.vcall(cmd)
        if ret != 0:
            raise ex.Error
        self.svc.node.unset_lazy("devtree")