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

@@ -107,40 +107,39 @@ from ansible.module_utils.common.network import is_mac
class NicTag:
def __init__(self, module):
self.module = module
self.name = module.params['name']
self.mac = module.params['mac']
self.etherstub = module.params['etherstub']
self.mtu = module.params['mtu']
self.force = module.params['force']
self.state = module.params['state']
self.name = module.params["name"]
self.mac = module.params["mac"]
self.etherstub = module.params["etherstub"]
self.mtu = module.params["mtu"]
self.force = module.params["force"]
self.state = module.params["state"]
self.nictagadm_bin = self.module.get_bin_path('nictagadm', True)
self.nictagadm_bin = self.module.get_bin_path("nictagadm", True)
def is_valid_mac(self):
return is_mac(self.mac.lower())
def nictag_exists(self):
cmd = [self.nictagadm_bin, 'exists', self.name]
cmd = [self.nictagadm_bin, "exists", self.name]
(rc, dummy, dummy) = self.module.run_command(cmd)
return rc == 0
def add_nictag(self):
cmd = [self.nictagadm_bin, '-v', 'add']
cmd = [self.nictagadm_bin, "-v", "add"]
if self.etherstub:
cmd.append('-l')
cmd.append("-l")
if self.mtu:
cmd.append('-p')
cmd.append("-p")
cmd.append(f"mtu={self.mtu}")
if self.mac:
cmd.append('-p')
cmd.append("-p")
cmd.append(f"mac={self.mac}")
cmd.append(self.name)
@@ -148,10 +147,10 @@ class NicTag:
return self.module.run_command(cmd)
def delete_nictag(self):
cmd = [self.nictagadm_bin, '-v', 'delete']
cmd = [self.nictagadm_bin, "-v", "delete"]
if self.force:
cmd.append('-f')
cmd.append("-f")
cmd.append(self.name)
@@ -161,29 +160,29 @@ class NicTag:
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=True),
mac=dict(type='str'),
etherstub=dict(type='bool', default=False),
mtu=dict(type='int'),
force=dict(type='bool', default=False),
state=dict(type='str', default='present', choices=['absent', 'present']),
name=dict(type="str", required=True),
mac=dict(type="str"),
etherstub=dict(type="bool", default=False),
mtu=dict(type="int"),
force=dict(type="bool", default=False),
state=dict(type="str", default="present", choices=["absent", "present"]),
),
mutually_exclusive=[
['etherstub', 'mac'],
['etherstub', 'mtu'],
["etherstub", "mac"],
["etherstub", "mtu"],
],
required_if=[
['etherstub', False, ['name', 'mac']],
['state', 'absent', ['name', 'force']],
["etherstub", False, ["name", "mac"]],
["state", "absent", ["name", "force"]],
],
supports_check_mode=True
supports_check_mode=True,
)
nictag = NicTag(module)
rc = None
out = ''
err = ''
out = ""
err = ""
result = dict(
changed=False,
etherstub=nictag.etherstub,
@@ -195,19 +194,16 @@ def main():
)
if not nictag.is_valid_mac():
module.fail_json(msg='Invalid MAC Address Value',
name=nictag.name,
mac=nictag.mac,
etherstub=nictag.etherstub)
module.fail_json(msg="Invalid MAC Address Value", name=nictag.name, mac=nictag.mac, etherstub=nictag.etherstub)
if nictag.state == 'absent':
if nictag.state == "absent":
if nictag.nictag_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = nictag.delete_nictag()
if rc != 0:
module.fail_json(name=nictag.name, msg=err, rc=rc)
elif nictag.state == 'present':
elif nictag.state == "present":
if not nictag.nictag_exists():
if module.check_mode:
module.exit_json(changed=True)
@@ -216,14 +212,14 @@ def main():
module.fail_json(name=nictag.name, msg=err, rc=rc)
if rc is not None:
result['changed'] = True
result["changed"] = True
if out:
result['stdout'] = out
result["stdout"] = out
if err:
result['stderr'] = err
result["stderr"] = err
module.exit_json(**result)
if __name__ == '__main__':
if __name__ == "__main__":
main()