2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright: (c) 2018, Emmanouil Kampitakis <info@kampitakis.de>
|
|
|
|
# Copyright: (c) 2018, William Leemans <willie@elaba.net>
|
|
|
|
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
2021-02-27 09:57:55 +01:00
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
__metaclass__ = type
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
DOCUMENTATION = r"""
|
2020-03-09 10:11:07 +01:00
|
|
|
---
|
|
|
|
module: xfs_quota
|
|
|
|
short_description: Manage quotas on XFS filesystems
|
|
|
|
description:
|
|
|
|
- Configure quotas on XFS filesystems.
|
|
|
|
- Before using this module /etc/projects and /etc/projid need to be configured.
|
|
|
|
author:
|
|
|
|
- William Leemans (@bushvin)
|
|
|
|
options:
|
|
|
|
type:
|
|
|
|
description:
|
|
|
|
- The XFS quota type.
|
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
choices:
|
|
|
|
- user
|
|
|
|
- group
|
|
|
|
- project
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of the user, group or project to apply the quota to, if other than default.
|
|
|
|
type: str
|
|
|
|
mountpoint:
|
|
|
|
description:
|
|
|
|
- The mount point on which to apply the quotas.
|
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
bhard:
|
|
|
|
description:
|
|
|
|
- Hard blocks quota limit.
|
|
|
|
- This argument supports human readable sizes.
|
|
|
|
type: str
|
|
|
|
bsoft:
|
|
|
|
description:
|
|
|
|
- Soft blocks quota limit.
|
|
|
|
- This argument supports human readable sizes.
|
|
|
|
type: str
|
|
|
|
ihard:
|
|
|
|
description:
|
|
|
|
- Hard inodes quota limit.
|
|
|
|
type: int
|
|
|
|
isoft:
|
|
|
|
description:
|
|
|
|
- Soft inodes quota limit.
|
|
|
|
type: int
|
|
|
|
rtbhard:
|
|
|
|
description:
|
|
|
|
- Hard realtime blocks quota limit.
|
|
|
|
- This argument supports human readable sizes.
|
|
|
|
type: str
|
|
|
|
rtbsoft:
|
|
|
|
description:
|
|
|
|
- Soft realtime blocks quota limit.
|
|
|
|
- This argument supports human readable sizes.
|
|
|
|
type: str
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Whether to apply the limits or remove them.
|
|
|
|
- When removing limit, they are set to 0, and not quite removed.
|
|
|
|
type: str
|
|
|
|
default: present
|
|
|
|
choices:
|
|
|
|
- present
|
|
|
|
- absent
|
|
|
|
|
|
|
|
requirements:
|
|
|
|
- xfsprogs
|
2021-02-27 09:57:55 +01:00
|
|
|
"""
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
EXAMPLES = r"""
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Set default project soft and hard limit on /opt of 1g
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.xfs_quota:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: project
|
|
|
|
mountpoint: /opt
|
|
|
|
bsoft: 1g
|
|
|
|
bhard: 1g
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Remove the default limits on /opt
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.xfs_quota:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: project
|
|
|
|
mountpoint: /opt
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Set default soft user inode limits on /home of 1024 inodes and hard of 2048
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.xfs_quota:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: user
|
|
|
|
mountpoint: /home
|
|
|
|
isoft: 1024
|
|
|
|
ihard: 2048
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
"""
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
RETURN = r"""
|
2020-03-09 10:11:07 +01:00
|
|
|
bhard:
|
|
|
|
description: the current bhard setting in bytes
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 1024
|
|
|
|
bsoft:
|
|
|
|
description: the current bsoft setting in bytes
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 1024
|
|
|
|
ihard:
|
|
|
|
description: the current ihard setting in bytes
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 100
|
|
|
|
isoft:
|
|
|
|
description: the current isoft setting in bytes
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 100
|
|
|
|
rtbhard:
|
|
|
|
description: the current rtbhard setting in bytes
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 1024
|
|
|
|
rtbsoft:
|
|
|
|
description: the current rtbsoft setting in bytes
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 1024
|
2021-02-27 09:57:55 +01:00
|
|
|
"""
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
import grp
|
|
|
|
import os
|
|
|
|
import pwd
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, human_to_bytes
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
2021-02-27 09:57:55 +01:00
|
|
|
bhard=dict(type="str"),
|
|
|
|
bsoft=dict(type="str"),
|
|
|
|
ihard=dict(type="int"),
|
|
|
|
isoft=dict(type="int"),
|
|
|
|
mountpoint=dict(type="str", required=True),
|
|
|
|
name=dict(type="str"),
|
|
|
|
rtbhard=dict(type="str"),
|
|
|
|
rtbsoft=dict(type="str"),
|
|
|
|
state=dict(type="str", default="present", choices=["absent", "present"]),
|
|
|
|
type=dict(type="str", required=True, choices=["group", "project", "user"]),
|
2020-03-09 10:11:07 +01:00
|
|
|
),
|
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
quota_type = module.params["type"]
|
|
|
|
name = module.params["name"]
|
|
|
|
mountpoint = module.params["mountpoint"]
|
|
|
|
bhard = module.params["bhard"]
|
|
|
|
bsoft = module.params["bsoft"]
|
|
|
|
ihard = module.params["ihard"]
|
|
|
|
isoft = module.params["isoft"]
|
|
|
|
rtbhard = module.params["rtbhard"]
|
|
|
|
rtbsoft = module.params["rtbsoft"]
|
|
|
|
state = module.params["state"]
|
|
|
|
|
|
|
|
xfs_quota_bin = module.get_bin_path("xfs_quota", True)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if bhard is not None:
|
|
|
|
bhard = human_to_bytes(bhard)
|
|
|
|
|
|
|
|
if bsoft is not None:
|
|
|
|
bsoft = human_to_bytes(bsoft)
|
|
|
|
|
|
|
|
if rtbhard is not None:
|
|
|
|
rtbhard = human_to_bytes(rtbhard)
|
|
|
|
|
|
|
|
if rtbsoft is not None:
|
|
|
|
rtbsoft = human_to_bytes(rtbsoft)
|
|
|
|
|
|
|
|
result = dict(
|
|
|
|
changed=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
if not os.path.ismount(mountpoint):
|
|
|
|
module.fail_json(msg="Path '%s' is not a mount point" % mountpoint, **result)
|
|
|
|
|
|
|
|
mp = get_fs_by_mountpoint(mountpoint)
|
|
|
|
if mp is None:
|
2021-02-27 09:57:55 +01:00
|
|
|
module.fail_json(
|
|
|
|
msg="Path '%s' is not a mount point or not located on an xfs file system."
|
|
|
|
% mountpoint,
|
|
|
|
**result
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if quota_type == "user":
|
|
|
|
type_arg = "-u"
|
|
|
|
quota_default = "root"
|
2020-03-09 10:11:07 +01:00
|
|
|
if name is None:
|
|
|
|
name = quota_default
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if (
|
|
|
|
"uquota" not in mp["mntopts"]
|
|
|
|
and "usrquota" not in mp["mntopts"]
|
|
|
|
and "quota" not in mp["mntopts"]
|
|
|
|
and "uqnoenforce" not in mp["mntopts"]
|
|
|
|
and "qnoenforce" not in mp["mntopts"]
|
|
|
|
):
|
2020-03-09 10:11:07 +01:00
|
|
|
module.fail_json(
|
2021-02-27 09:57:55 +01:00
|
|
|
msg="Path '%s' is not mounted with the uquota/usrquota/quota/uqnoenforce/qnoenforce option."
|
|
|
|
% mountpoint,
|
|
|
|
**result
|
2020-03-09 10:11:07 +01:00
|
|
|
)
|
|
|
|
try:
|
|
|
|
pwd.getpwnam(name)
|
|
|
|
except KeyError as e:
|
|
|
|
module.fail_json(msg="User '%s' does not exist." % name, **result)
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
elif quota_type == "group":
|
|
|
|
type_arg = "-g"
|
|
|
|
quota_default = "root"
|
2020-03-09 10:11:07 +01:00
|
|
|
if name is None:
|
|
|
|
name = quota_default
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if (
|
|
|
|
"gquota" not in mp["mntopts"]
|
|
|
|
and "grpquota" not in mp["mntopts"]
|
|
|
|
and "gqnoenforce" not in mp["mntopts"]
|
|
|
|
):
|
2020-03-09 10:11:07 +01:00
|
|
|
module.fail_json(
|
2021-02-27 09:57:55 +01:00
|
|
|
msg="Path '%s' is not mounted with the gquota/grpquota/gqnoenforce option. (current options: %s)"
|
|
|
|
% (mountpoint, mp["mntopts"]),
|
|
|
|
**result
|
2020-03-09 10:11:07 +01:00
|
|
|
)
|
|
|
|
try:
|
|
|
|
grp.getgrnam(name)
|
|
|
|
except KeyError as e:
|
|
|
|
module.fail_json(msg="User '%s' does not exist." % name, **result)
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
elif quota_type == "project":
|
|
|
|
type_arg = "-p"
|
|
|
|
quota_default = "#0"
|
2020-03-09 10:11:07 +01:00
|
|
|
if name is None:
|
|
|
|
name = quota_default
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if (
|
|
|
|
"pquota" not in mp["mntopts"]
|
|
|
|
and "prjquota" not in mp["mntopts"]
|
|
|
|
and "pqnoenforce" not in mp["mntopts"]
|
|
|
|
):
|
|
|
|
module.fail_json(
|
|
|
|
msg="Path '%s' is not mounted with the pquota/prjquota/pqnoenforce option."
|
|
|
|
% mountpoint,
|
|
|
|
**result
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if name != quota_default and not os.path.isfile("/etc/projects"):
|
2020-03-09 10:11:07 +01:00
|
|
|
module.fail_json(msg="Path '/etc/projects' does not exist.", **result)
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if name != quota_default and not os.path.isfile("/etc/projid"):
|
2020-03-09 10:11:07 +01:00
|
|
|
module.fail_json(msg="Path '/etc/projid' does not exist.", **result)
|
|
|
|
|
|
|
|
if name != quota_default and name is not None and get_project_id(name) is None:
|
2021-02-27 09:57:55 +01:00
|
|
|
module.fail_json(
|
|
|
|
msg="Entry '%s' has not been defined in /etc/projid." % name, **result
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
prj_set = True
|
|
|
|
if name != quota_default:
|
2021-02-27 09:57:55 +01:00
|
|
|
cmd = "project %s" % name
|
|
|
|
rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint)
|
2020-03-09 10:11:07 +01:00
|
|
|
if rc != 0:
|
2021-02-27 09:57:55 +01:00
|
|
|
result["cmd"] = cmd
|
|
|
|
result["rc"] = rc
|
|
|
|
result["stdout"] = stdout
|
|
|
|
result["stderr"] = stderr
|
|
|
|
module.fail_json(msg="Could not get project state.", **result)
|
2020-03-09 10:11:07 +01:00
|
|
|
else:
|
2021-02-27 09:57:55 +01:00
|
|
|
for line in stdout.split("\n"):
|
|
|
|
if (
|
|
|
|
"Project Id '%s' - is not set." in line
|
|
|
|
or "project identifier is not set" in line
|
|
|
|
):
|
2020-03-09 10:11:07 +01:00
|
|
|
prj_set = False
|
|
|
|
break
|
|
|
|
|
|
|
|
if not prj_set and not module.check_mode:
|
2021-02-27 09:57:55 +01:00
|
|
|
cmd = "project -s"
|
|
|
|
rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint)
|
2020-03-09 10:11:07 +01:00
|
|
|
if rc != 0:
|
2021-02-27 09:57:55 +01:00
|
|
|
result["cmd"] = cmd
|
|
|
|
result["rc"] = rc
|
|
|
|
result["stdout"] = stdout
|
|
|
|
result["stderr"] = stderr
|
|
|
|
module.fail_json(
|
|
|
|
msg="Could not get quota realtime block report.", **result
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
result["changed"] = True
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
elif not prj_set and module.check_mode:
|
2021-02-27 09:57:55 +01:00
|
|
|
result["changed"] = True
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
# Set limits
|
2021-02-27 09:57:55 +01:00
|
|
|
if state == "absent":
|
2020-03-09 10:11:07 +01:00
|
|
|
bhard = 0
|
|
|
|
bsoft = 0
|
|
|
|
ihard = 0
|
|
|
|
isoft = 0
|
|
|
|
rtbhard = 0
|
|
|
|
rtbsoft = 0
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
current_bsoft, current_bhard = quota_report(
|
|
|
|
module, xfs_quota_bin, mountpoint, name, quota_type, "b"
|
|
|
|
)
|
|
|
|
current_isoft, current_ihard = quota_report(
|
|
|
|
module, xfs_quota_bin, mountpoint, name, quota_type, "i"
|
|
|
|
)
|
|
|
|
current_rtbsoft, current_rtbhard = quota_report(
|
|
|
|
module, xfs_quota_bin, mountpoint, name, quota_type, "rtb"
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
result["xfs_quota"] = dict(
|
2020-03-09 10:11:07 +01:00
|
|
|
bsoft=current_bsoft,
|
|
|
|
bhard=current_bhard,
|
|
|
|
isoft=current_isoft,
|
|
|
|
ihard=current_ihard,
|
|
|
|
rtbsoft=current_rtbsoft,
|
2021-02-27 09:57:55 +01:00
|
|
|
rtbhard=current_rtbhard,
|
2020-03-09 10:11:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
limit = []
|
|
|
|
if bsoft is not None and int(bsoft) != current_bsoft:
|
2021-02-27 09:57:55 +01:00
|
|
|
limit.append("bsoft=%s" % bsoft)
|
|
|
|
result["bsoft"] = int(bsoft)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if bhard is not None and int(bhard) != current_bhard:
|
2021-02-27 09:57:55 +01:00
|
|
|
limit.append("bhard=%s" % bhard)
|
|
|
|
result["bhard"] = int(bhard)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if isoft is not None and isoft != current_isoft:
|
2021-02-27 09:57:55 +01:00
|
|
|
limit.append("isoft=%s" % isoft)
|
|
|
|
result["isoft"] = isoft
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if ihard is not None and ihard != current_ihard:
|
2021-02-27 09:57:55 +01:00
|
|
|
limit.append("ihard=%s" % ihard)
|
|
|
|
result["ihard"] = ihard
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if rtbsoft is not None and int(rtbsoft) != current_rtbsoft:
|
2021-02-27 09:57:55 +01:00
|
|
|
limit.append("rtbsoft=%s" % rtbsoft)
|
|
|
|
result["rtbsoft"] = int(rtbsoft)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if rtbhard is not None and int(rtbhard) != current_rtbhard:
|
2021-02-27 09:57:55 +01:00
|
|
|
limit.append("rtbhard=%s" % rtbhard)
|
|
|
|
result["rtbhard"] = int(rtbhard)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if len(limit) > 0 and not module.check_mode:
|
|
|
|
if name == quota_default:
|
2021-02-27 09:57:55 +01:00
|
|
|
cmd = "limit %s -d %s" % (type_arg, " ".join(limit))
|
2020-03-09 10:11:07 +01:00
|
|
|
else:
|
2021-02-27 09:57:55 +01:00
|
|
|
cmd = "limit %s %s %s" % (type_arg, " ".join(limit), name)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint)
|
2020-03-09 10:11:07 +01:00
|
|
|
if rc != 0:
|
2021-02-27 09:57:55 +01:00
|
|
|
result["cmd"] = cmd
|
|
|
|
result["rc"] = rc
|
|
|
|
result["stdout"] = stdout
|
|
|
|
result["stderr"] = stderr
|
|
|
|
module.fail_json(msg="Could not set limits.", **result)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
result["changed"] = True
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
elif len(limit) > 0 and module.check_mode:
|
2021-02-27 09:57:55 +01:00
|
|
|
result["changed"] = True
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
def quota_report(module, xfs_quota_bin, mountpoint, name, quota_type, used_type):
|
2020-03-09 10:11:07 +01:00
|
|
|
soft = None
|
|
|
|
hard = None
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if quota_type == "project":
|
|
|
|
type_arg = "-p"
|
|
|
|
elif quota_type == "user":
|
|
|
|
type_arg = "-u"
|
|
|
|
elif quota_type == "group":
|
|
|
|
type_arg = "-g"
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if used_type == "b":
|
|
|
|
used_arg = "-b"
|
|
|
|
used_name = "blocks"
|
2020-03-09 10:11:07 +01:00
|
|
|
factor = 1024
|
2021-02-27 09:57:55 +01:00
|
|
|
elif used_type == "i":
|
|
|
|
used_arg = "-i"
|
|
|
|
used_name = "inodes"
|
2020-03-09 10:11:07 +01:00
|
|
|
factor = 1
|
2021-02-27 09:57:55 +01:00
|
|
|
elif used_type == "rtb":
|
|
|
|
used_arg = "-r"
|
|
|
|
used_name = "realtime blocks"
|
2020-03-09 10:11:07 +01:00
|
|
|
factor = 1024
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
rc, stdout, stderr = exec_quota(
|
|
|
|
module, xfs_quota_bin, "report %s %s" % (type_arg, used_arg), mountpoint
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if rc != 0:
|
|
|
|
result = dict(
|
|
|
|
changed=False,
|
|
|
|
rc=rc,
|
|
|
|
stdout=stdout,
|
|
|
|
stderr=stderr,
|
|
|
|
)
|
2021-02-27 09:57:55 +01:00
|
|
|
module.fail_json(msg="Could not get quota report for %s." % used_name, **result)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
for line in stdout.split("\n"):
|
2020-03-09 10:11:07 +01:00
|
|
|
line = line.strip().split()
|
|
|
|
if len(line) > 3 and line[0] == name:
|
|
|
|
soft = int(line[2]) * factor
|
|
|
|
hard = int(line[3]) * factor
|
|
|
|
break
|
|
|
|
|
|
|
|
return soft, hard
|
|
|
|
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
def exec_quota(module, xfs_quota_bin, cmd, mountpoint):
|
|
|
|
cmd = [xfs_quota_bin, "-x", "-c"] + [cmd, mountpoint]
|
2020-03-09 10:11:07 +01:00
|
|
|
(rc, stdout, stderr) = module.run_command(cmd, use_unsafe_shell=True)
|
2021-02-27 09:57:55 +01:00
|
|
|
if (
|
|
|
|
"XFS_GETQUOTA: Operation not permitted" in stderr.split("\n")
|
|
|
|
or rc == 1
|
|
|
|
and "xfs_quota: cannot set limits: Operation not permitted"
|
|
|
|
in stderr.split("\n")
|
|
|
|
):
|
|
|
|
module.fail_json(
|
|
|
|
msg="You need to be root or have CAP_SYS_ADMIN capability to perform this operation"
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
return rc, stdout, stderr
|
|
|
|
|
|
|
|
|
|
|
|
def get_fs_by_mountpoint(mountpoint):
|
|
|
|
mpr = None
|
2021-02-27 09:57:55 +01:00
|
|
|
with open("/proc/mounts", "r") as s:
|
2020-03-09 10:11:07 +01:00
|
|
|
for line in s.readlines():
|
|
|
|
mp = line.strip().split()
|
2021-02-27 09:57:55 +01:00
|
|
|
if len(mp) == 6 and mp[1] == mountpoint and mp[2] == "xfs":
|
|
|
|
mpr = dict(
|
|
|
|
zip(["spec", "file", "vfstype", "mntopts", "freq", "passno"], mp)
|
|
|
|
)
|
|
|
|
mpr["mntopts"] = mpr["mntopts"].split(",")
|
2020-03-09 10:11:07 +01:00
|
|
|
break
|
|
|
|
return mpr
|
|
|
|
|
|
|
|
|
|
|
|
def get_project_id(name):
|
|
|
|
prjid = None
|
2021-02-27 09:57:55 +01:00
|
|
|
with open("/etc/projid", "r") as s:
|
2020-03-09 10:11:07 +01:00
|
|
|
for line in s.readlines():
|
2021-02-27 09:57:55 +01:00
|
|
|
line = line.strip().partition(":")
|
2020-03-09 10:11:07 +01:00
|
|
|
if line[0] == name:
|
|
|
|
prjid = line[2]
|
|
|
|
break
|
|
|
|
|
|
|
|
return prjid
|
|
|
|
|
|
|
|
|
2021-02-27 09:57:55 +01:00
|
|
|
if __name__ == "__main__":
|
2020-03-09 10:11:07 +01:00
|
|
|
main()
|