# Info: KCL Local provider server schemas for provisioning (Provisioning)
# Author: JesusPerezLorenzo 
# Release: 0.0.4
# Date: 15-12-2023
import regex
import provisioning

schema Server_local(ServerDefaults_local):
    """
    Local server settings
    """
    # Hostname as reference for resource if is changed later inside server, change will not be updated in resource inventory
    hostname: str
    title: str
    # IP will be assign here
    network_private_ip?: str
    # extra hostnames for server local resolution 
    extra_hostnames?: [str]
    taskservs?: [provisioning.TaskServDef]
    clusters?: [provisioning.ClusterDef]

    check:
        len(hostname) > 0, "Check hostname value"
        len(title) > 0, "Check titlevalue"
        network_private_ip == Undefined or regex.match(network_private_ip, "^\$.*$") or regex.match(network_private_ip, "^((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])$"), "'network_private_ip = ${network_private_ip}' check value definition (use $vaule or xx.xx.xx.xx)"
        storages != Undefined, "🛑 Storages is not defined"

