init now will work
parent
0f212782d5
commit
643602e5b7
@ -1,10 +1,60 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
from string import Template
|
||||||
from .common import (
|
from .common import (
|
||||||
Validateable,
|
Validateable,
|
||||||
DnsRecord,
|
DnsRecord,
|
||||||
Devops,
|
Devops,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CONFIG_BASE = """
|
||||||
|
fqdn: $fqdn
|
||||||
|
"""
|
||||||
|
CONFIG_IPV4 = """node:
|
||||||
|
ipv4: $ipv4
|
||||||
|
"""
|
||||||
|
CONFIG_IPV6 = """ ipv6: $ipv6
|
||||||
|
"""
|
||||||
|
CONFIG_CERTMANAGER = """certmanager:
|
||||||
|
email: $letsencrypt_email
|
||||||
|
letsencryptEndpoint: $letsencrypt_endpoint
|
||||||
|
"""
|
||||||
|
CONFIG_ECHO = """echo: $echo
|
||||||
|
"""
|
||||||
|
|
||||||
class K3s(Validateable):
|
class K3s(Validateable):
|
||||||
def __init__(self, inp: dict):
|
def __init__(self, inp: dict):
|
||||||
pass
|
self.k3s_provision_user = inp.get("k3s_provision_user")
|
||||||
|
self.k3s_letsencrypt_email = inp.get("k3s_letsencrypt_email")
|
||||||
|
self.k3s_letsencrypt_endpoint = inp.get("k3s_letsencrypt_endpoint")
|
||||||
|
self.k3s_app_filename_to_provision = inp.get("k3s_app_filename_to_provision", "provs")
|
||||||
|
fqdn = inp.get("k3_fqdn")
|
||||||
|
ipv4 = inp.get("k3_ipv4")
|
||||||
|
ipv6 = inp.get("k3_ipv6")
|
||||||
|
self.provision_dns = DnsRecord(fqdn, ipv4=ipv4, ipv6=ipv6)
|
||||||
|
self.k3s_enable_echo = inp.get("k3s_enable_echo", False)
|
||||||
|
self.k3s_provs_template = inp.get("k3s_provs_template", None)
|
||||||
|
|
||||||
|
def validate(self) -> List[str]:
|
||||||
|
result = []
|
||||||
|
result += self.__validate_is_not_empty__("k3s_provision_user")
|
||||||
|
result += self.__validate_is_not_empty__("k3s_letsencrypt_email")
|
||||||
|
result += self.__validate_is_not_empty__("k3s_letsencrypt_endpoint")
|
||||||
|
result += self.__validate_is_not_empty__("k3s_app_filename_to_provision")
|
||||||
|
if self.provision_dns:
|
||||||
|
result += self.provision_dns.validate()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def config_template(self) -> str:
|
||||||
|
template_text = self.k3s_provs_template
|
||||||
|
if template_text is None:
|
||||||
|
template_text = CONFIG_BASE
|
||||||
|
if self.k3s_letsencrypt_endpoint is not None:
|
||||||
|
template_text += CONFIG_CERTMANAGER
|
||||||
|
if self.k3s_enable_echo is not None:
|
||||||
|
template_text += CONFIG_ECHO
|
||||||
|
if self.provision_dns.ipv4 is not None:
|
||||||
|
template_text += CONFIG_IPV4
|
||||||
|
if self.provision_dns.ipv6 is not None:
|
||||||
|
template_text += CONFIG_IPV6
|
||||||
|
return template_text
|
||||||
|
|
Loading…
Reference in New Issue