1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-27 14:08:53 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -55,60 +55,60 @@ from ansible.module_utils.common.text.converters import to_text
class Namespace:
"""Interface to network namespaces. """
"""Interface to network namespaces."""
def __init__(self, module):
self.module = module
self.name = module.params['name']
self.state = module.params['state']
self.name = module.params["name"]
self.state = module.params["state"]
def _netns(self, command):
'''Run ip nents command'''
return self.module.run_command(['ip', 'netns'] + command)
"""Run ip nents command"""
return self.module.run_command(["ip", "netns"] + command)
def exists(self):
'''Check if the namespace already exists'''
rc, out, err = self.module.run_command(['ip', 'netns', 'list'])
"""Check if the namespace already exists"""
rc, out, err = self.module.run_command(["ip", "netns", "list"])
if rc != 0:
self.module.fail_json(msg=to_text(err))
return self.name in out
def add(self):
'''Create network namespace'''
rtc, out, err = self._netns(['add', self.name])
"""Create network namespace"""
rtc, out, err = self._netns(["add", self.name])
if rtc != 0:
self.module.fail_json(msg=err)
def delete(self):
'''Delete network namespace'''
rtc, out, err = self._netns(['del', self.name])
"""Delete network namespace"""
rtc, out, err = self._netns(["del", self.name])
if rtc != 0:
self.module.fail_json(msg=err)
def check(self):
'''Run check mode'''
"""Run check mode"""
changed = False
if self.state == 'present' and self.exists():
if self.state == "present" and self.exists():
changed = True
elif self.state == 'absent' and self.exists():
elif self.state == "absent" and self.exists():
changed = True
elif self.state == 'present' and not self.exists():
elif self.state == "present" and not self.exists():
changed = True
self.module.exit_json(changed=changed)
def run(self):
'''Make the necessary changes'''
"""Make the necessary changes"""
changed = False
if self.state == 'absent':
if self.state == "absent":
if self.exists():
self.delete()
changed = True
elif self.state == 'present':
elif self.state == "present":
if not self.exists():
self.add()
changed = True
@ -120,8 +120,8 @@ def main():
"""Entry point."""
module = AnsibleModule(
argument_spec={
'name': {'default': None},
'state': {'default': 'present', 'choices': ['present', 'absent']},
"name": {"default": None},
"state": {"default": "present", "choices": ["present", "absent"]},
},
supports_check_mode=True,
)
@ -133,5 +133,5 @@ def main():
network_namespace.run()
if __name__ == '__main__':
if __name__ == "__main__":
main()