mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-20 02:39:02 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -98,12 +98,12 @@ from ansible.module_utils.common.text.converters import to_native
|
|||
|
||||
|
||||
def _load_dist_subclass(cls, *args, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Used for derivative implementations
|
||||
'''
|
||||
"""
|
||||
subclass = None
|
||||
|
||||
distro = kwargs['module'].params['distro']
|
||||
distro = kwargs["module"].params["distro"]
|
||||
|
||||
# get the most specific superclass for this platform
|
||||
if distro is not None:
|
||||
|
|
@ -126,14 +126,14 @@ class Svc:
|
|||
# return _load_dist_subclass(cls, args, kwargs)
|
||||
|
||||
def __init__(self, module):
|
||||
self.extra_paths = ['/command', '/usr/local/bin']
|
||||
self.report_vars = ['state', 'enabled', 'downed', 'svc_full', 'src_full', 'pid', 'duration', 'full_state']
|
||||
self.extra_paths = ["/command", "/usr/local/bin"]
|
||||
self.report_vars = ["state", "enabled", "downed", "svc_full", "src_full", "pid", "duration", "full_state"]
|
||||
|
||||
self.module = module
|
||||
|
||||
self.name = module.params['name']
|
||||
self.service_dir = module.params['service_dir']
|
||||
self.service_src = module.params['service_src']
|
||||
self.name = module.params["name"]
|
||||
self.service_dir = module.params["service_dir"]
|
||||
self.service_src = module.params["service_src"]
|
||||
self.enabled = None
|
||||
self.downed = None
|
||||
self.full_state = None
|
||||
|
|
@ -141,25 +141,25 @@ class Svc:
|
|||
self.pid = None
|
||||
self.duration = None
|
||||
|
||||
self.svc_cmd = module.get_bin_path('svc', opt_dirs=self.extra_paths)
|
||||
self.svstat_cmd = module.get_bin_path('svstat', opt_dirs=self.extra_paths)
|
||||
self.svc_cmd = module.get_bin_path("svc", opt_dirs=self.extra_paths)
|
||||
self.svstat_cmd = module.get_bin_path("svstat", opt_dirs=self.extra_paths)
|
||||
self.svc_full = f"{self.service_dir}/{self.name}"
|
||||
self.src_full = f"{self.service_src}/{self.name}"
|
||||
|
||||
self.enabled = os.path.lexists(self.svc_full)
|
||||
if self.enabled:
|
||||
self.downed = os.path.lexists(f'{self.svc_full}/down')
|
||||
self.downed = os.path.lexists(f"{self.svc_full}/down")
|
||||
self.get_status()
|
||||
else:
|
||||
self.downed = os.path.lexists(f'{self.src_full}/down')
|
||||
self.state = 'stopped'
|
||||
self.downed = os.path.lexists(f"{self.src_full}/down")
|
||||
self.state = "stopped"
|
||||
|
||||
def enable(self):
|
||||
if os.path.exists(self.src_full):
|
||||
try:
|
||||
os.symlink(self.src_full, self.svc_full)
|
||||
except OSError as e:
|
||||
self.module.fail_json(path=self.src_full, msg=f'Error while linking: {to_native(e)}')
|
||||
self.module.fail_json(path=self.src_full, msg=f"Error while linking: {to_native(e)}")
|
||||
else:
|
||||
self.module.fail_json(msg=f"Could not find source for service to enable ({self.src_full}).")
|
||||
|
||||
|
|
@ -167,12 +167,12 @@ class Svc:
|
|||
try:
|
||||
os.unlink(self.svc_full)
|
||||
except OSError as e:
|
||||
self.module.fail_json(path=self.svc_full, msg=f'Error while unlinking: {e}')
|
||||
self.execute_command([self.svc_cmd, '-dx', self.src_full])
|
||||
self.module.fail_json(path=self.svc_full, msg=f"Error while unlinking: {e}")
|
||||
self.execute_command([self.svc_cmd, "-dx", self.src_full])
|
||||
|
||||
src_log = f'{self.src_full}/log'
|
||||
src_log = f"{self.src_full}/log"
|
||||
if os.path.exists(src_log):
|
||||
self.execute_command([self.svc_cmd, '-dx', src_log])
|
||||
self.execute_command([self.svc_cmd, "-dx", src_log])
|
||||
|
||||
def get_status(self):
|
||||
rc, out, err = self.execute_command([self.svstat_cmd, self.svc_full])
|
||||
|
|
@ -182,47 +182,47 @@ class Svc:
|
|||
else:
|
||||
self.full_state = out
|
||||
|
||||
m = re.search(r'\(pid (\d+)\)', out)
|
||||
m = re.search(r"\(pid (\d+)\)", out)
|
||||
if m:
|
||||
self.pid = m.group(1)
|
||||
|
||||
m = re.search(r'(\d+) seconds', out)
|
||||
m = re.search(r"(\d+) seconds", out)
|
||||
if m:
|
||||
self.duration = m.group(1)
|
||||
|
||||
if re.search(' up ', out):
|
||||
self.state = 'start'
|
||||
elif re.search(' down ', out):
|
||||
self.state = 'stopp'
|
||||
if re.search(" up ", out):
|
||||
self.state = "start"
|
||||
elif re.search(" down ", out):
|
||||
self.state = "stopp"
|
||||
else:
|
||||
self.state = 'unknown'
|
||||
self.state = "unknown"
|
||||
return
|
||||
|
||||
if re.search(' want ', out):
|
||||
self.state += 'ing'
|
||||
if re.search(" want ", out):
|
||||
self.state += "ing"
|
||||
else:
|
||||
self.state += 'ed'
|
||||
self.state += "ed"
|
||||
|
||||
def start(self):
|
||||
return self.execute_command([self.svc_cmd, '-u', self.svc_full])
|
||||
return self.execute_command([self.svc_cmd, "-u", self.svc_full])
|
||||
|
||||
def stopp(self):
|
||||
return self.stop()
|
||||
|
||||
def stop(self):
|
||||
return self.execute_command([self.svc_cmd, '-d', self.svc_full])
|
||||
return self.execute_command([self.svc_cmd, "-d", self.svc_full])
|
||||
|
||||
def once(self):
|
||||
return self.execute_command([self.svc_cmd, '-o', self.svc_full])
|
||||
return self.execute_command([self.svc_cmd, "-o", self.svc_full])
|
||||
|
||||
def reload(self):
|
||||
return self.execute_command([self.svc_cmd, '-1', self.svc_full])
|
||||
return self.execute_command([self.svc_cmd, "-1", self.svc_full])
|
||||
|
||||
def restart(self):
|
||||
return self.execute_command([self.svc_cmd, '-t', self.svc_full])
|
||||
return self.execute_command([self.svc_cmd, "-t", self.svc_full])
|
||||
|
||||
def kill(self):
|
||||
return self.execute_command([self.svc_cmd, '-k', self.svc_full])
|
||||
return self.execute_command([self.svc_cmd, "-k", self.svc_full])
|
||||
|
||||
def execute_command(self, cmd):
|
||||
try:
|
||||
|
|
@ -242,24 +242,25 @@ class Svc:
|
|||
# ===========================================
|
||||
# Main control flow
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(type='str', required=True),
|
||||
state=dict(type='str', choices=['killed', 'once', 'reloaded', 'restarted', 'started', 'stopped']),
|
||||
enabled=dict(type='bool'),
|
||||
downed=dict(type='bool'),
|
||||
service_dir=dict(type='str', default='/service'),
|
||||
service_src=dict(type='str', default='/etc/service'),
|
||||
name=dict(type="str", required=True),
|
||||
state=dict(type="str", choices=["killed", "once", "reloaded", "restarted", "started", "stopped"]),
|
||||
enabled=dict(type="bool"),
|
||||
downed=dict(type="bool"),
|
||||
service_dir=dict(type="str", default="/service"),
|
||||
service_src=dict(type="str", default="/etc/service"),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
|
||||
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
|
||||
|
||||
state = module.params['state']
|
||||
enabled = module.params['enabled']
|
||||
downed = module.params['downed']
|
||||
state = module.params["state"]
|
||||
enabled = module.params["enabled"]
|
||||
downed = module.params["downed"]
|
||||
|
||||
svc = Svc(module)
|
||||
changed = False
|
||||
|
|
@ -296,5 +297,5 @@ def main():
|
|||
module.exit_json(changed=changed, svc=svc.report())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue