Unify the template arguments across various template cnfvars
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Thu, 12 May 2022 03:57:33 +0000 (06:57 +0300)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 19 May 2022 09:13:27 +0000 (11:13 +0200)
There are no obligatory fields as whether any of them are used or
required depends entirly on the cnfvar type/mode for each template.
For instance, AD users may not have password field, GWINLAN providers
may not have local IP, DSL and PPTP providers may not have provider IP,
and protocol forwarding might not have source and destination ports.

It is thus better to unify the function signatures entirely and later
provide some extra facilitation for different cnfvar types/modes.

src/cnfvar/templates.py

index 8468c68..e36854b 100644 (file)
@@ -239,12 +239,11 @@ def template(name, value, instance=-1, defaults=None, **kwargs):
     return cnf
 
 
-def user(name, password, instance=-1, **kwargs):
+def user(name, instance=-1, **kwargs):
     """
     Generate a user cnf variable.
 
     :param str name: username for the user
-    :param str password: password for the user
     :param int instance: instance number for the user
     :returns: generated cnf variable
     :rtype: :py:class:`Cnf`
@@ -252,7 +251,6 @@ def user(name, password, instance=-1, **kwargs):
     log.info(f"Generating a user {name} cnfvar")
     user_cnf = template("user", name, instance=instance, defaults=user_defaults, **kwargs)
     user_cnf.children.single_with_name("user_fullname").value = name.capitalize()
-    user_cnf.children.single_with_name("user_password").value = password
     return user_cnf
 
 
@@ -270,16 +268,18 @@ def group(name, instance=-1, **kwargs):
     return group_cnf
 
 
-def nic(instance=-1, **kwargs):
+def nic(name, instance=-1, **kwargs):
     """
     Generate a nic cnf variable.
 
+    :param str name: tag or comment for the nic describing its use
     :param int instance: instance number for the nic
     :returns: generated cnf variable
     :rtype: :py:class:`Cnf`
     """
     log.info(f"Generating a nic cnfvar")
     nic_cnf = template("nic", "", instance=instance, defaults=nic_defaults, **kwargs)
+    nic_cnf.children.single_with_name("nic_comment").value = name
     return nic_cnf
 
 
@@ -298,13 +298,11 @@ def intraclient(name, instance=-1, **kwargs):
     return intraclient_cnf
 
 
-def provider(name, ip, dns, instance=-1, **kwargs):
+def provider(name, instance=-1, **kwargs):
     """
     Generate a provider cnf variable.
 
     :param str name: name for the provider
-    :param str ip: IP address of the provider
-    :param str dns: IP address of the DNS server
     :param int instance: instance number for the provider
     :returns: generated cnf variable
     :rtype: :py:class:`Cnf`
@@ -312,18 +310,14 @@ def provider(name, ip, dns, instance=-1, **kwargs):
     log.info(f"Generating a provider {name} cnfvar")
     provider_cnf = template("provider", name, instance=instance,
                             defaults=provider_defaults, **kwargs)
-    provider_cnf.children.single_with_name("provider_ip").value = ip
-    provider_cnf.children.single_with_name("provider_dns").value = dns
     return provider_cnf
 
 
-def port_forwarding(name, src_port="1234", dst_port="1234", instance=-1, **kwargs):
+def port_forwarding(name, instance=-1, **kwargs):
     """
     Generate a port forwarding cnf variable.
 
     :param str name: name for the port forwarding mapping
-    :param str src_port: forwarded source port
-    :param str dst_port: forwarded destination port
     :param int instance: instance number for the port forwarding mapping
     :returns: generated cnf variable
     :rtype: :py:class:`Cnf`
@@ -331,8 +325,6 @@ def port_forwarding(name, src_port="1234", dst_port="1234", instance=-1, **kwarg
     log.info(f"Generating a port forwarding {name} cnfvar")
     port_forwarding_cnf = template("port_forwarding", name, instance=instance,
                                    defaults=port_forwarding_defaults, **kwargs)
-    port_forwarding_cnf.children.single_with_name("port_forwarding_src_port").value = src_port
-    port_forwarding_cnf.children.single_with_name("port_forwarding_dst_port").value = dst_port
     return port_forwarding_cnf