<?xml version="1.0" encoding="utf-8"?>
<creole>
    <files>
        <!-- System configuration -->
        <file filelist='redis' name='/etc/sysctl.d/100-redis-tuning.conf' source='redis_sysctl.conf' mkdir='True' rm='True'/>
        <file filelist='redis' name='/etc/redis/redis.conf' mkdir='True' rm='True'/>
        <file filelist='redisSlave' name='/etc/redis/redis-slave.conf' mkdir='True' rm='True'/>
        <file filelist='redisCl' name='/etc/redis/cluster.conf' source='redis-cluster.conf' mkdir='True' rm='True'/>
        <file filelist='redisSSL' name='/etc/stunnel/redis-ssl.conf' mkdir='True' rm='True'/>
        <service servicelist="svredis">redis-server</service>
        <service servicelist="svredisSlave">redis2-server</service>
        <service_access service='redis-server'>
            <port service_accesslist='saRedis' protocol='tcp' port_type='SymLinkOption'>redisPort</port>
            <port service_accesslist='saSSLRedis' protocol='tcp' port_type='SymLinkOption'>redisSSLPort</port>
            <port service_accesslist='saRedis' protocol='tcp' port_type='SymLinkOption'>redisClPort</port>
            <port service_accesslist='saRedisSlave' protocol='tcp' port_type='SymLinkOption'>redisPortSlave</port>
            <port service_accesslist='saRedisSlave' protocol='tcp' port_type='SymLinkOption'>redisClPortSlave</port>
            <tcpwrapper>redis-server</tcpwrapper>
        </service_access>
        <service_restriction service='redis-server'>
            <ip interface='auto' netmask='rdClmask' netmask_type='SymLinkOption' ip_type='SymLinkOption'>rdClIP</ip>
        </service_restriction>
    </files>
    <variables>
        <family name='Services'>
            <variable name='activer_redis' type='oui/non' description="Activer le service de cache Redis ?">
                <value>oui</value>
            </variable>
        </family>
        <family name="Redis" icon='redis'>
            <variable name='redisMode' type='string' description="Mode d'utilisation de Redis">
                <value>Local</value>
            </variable>
            <variable name='redisSSL' type='oui/non' description="Activer le support SSL pour redis">
                <value>non</value>
            </variable>
            <variable name='redisSlaveInstance' type='oui/non' description="Voulez-vous lancer une instance esclave Redis sur ce serveur ?">
                <value>non</value>
            </variable>

            <!-- Instance Principale-->
            <variable name='redisInstanceName' type='string' description="Nom de l'instance principale"/>
            <variable name='redisPort' type='number' description="Port d'écoute du service Redis">
                <value>6379</value>
            </variable>
            <variable name='redisSSLPort' type='port' description="Port d'écoute SSL du service Redis">
                <value>6380</value>
            </variable>
            <variable name='redisSSLVersion' type='string' description="Version du protocole SSL">
                <value>TLSv1</value>
            </variable>
            <variable name='redisClPort' type='number' description="Port d'écoute du service Cluster Redis"/>
            <variable name='redisMaxMemory' type='number' description="Quantité de mémoire utilisable par Redis en Mo">
                <value>512</value>
            </variable>
            <variable name='redisMemoryPolicy' type='string' description='Méthode de libération de mémoire lorsque le maximum est atteint '>
                <value>noeviction</value>
            </variable>
            <variable name='redisTCPKeepAlive' type='number' description="Intervalle entre le dernier envoi de paquet TCP et la réponse ACK (en secondes)">
                <value>60</value>
            </variable>
            <!-- Instance Secondaire -->
            <variable name='redisSlaveInstanceName' type='string' description="Nom de l'instance secondaire"/>
            <variable name='redisSlaveInstanceMaster' type='string' description="Nom du noeud a répliquer sur l'instance secondaire"/>
            <variable name='redisMasterIPSlave' type='domain' description="Nom de domaine du service Redis master" mandatory="True"/>
            <variable name='redisMasterPortSlave' type='number' description="Port d'écoute du service Redis master">
                <value>6379</value>
            </variable>
            <variable name='redisPortSlave' type='number' description="Port d'écoute du service Redis slave">
                <value>8379</value>
            </variable>
            <variable name='redisClPortSlave' type='number' description="Port d'écoute du service Cluster Redis"/>
            <variable name='redisMaxMemorySlave' type='number' description="Quantité de mémoire utilisable par Redis en Mo">
                <value>512</value>
            </variable>
            <variable name='redisMemoryPolicySlave' type='string' description='Méthode de libération de mémoire lorsque le maximum est atteint '>
                <value>noeviction</value>
            </variable>
            <variable name='redisTCPKeepAliveSlave' type='number' description="Intervalle entre le dernier envoi de paquet TCP et la réponse ACK (en secondes)">
                <value>60</value>
            </variable>
            <!-- Autorisations d'accès -->
            <variable name='rdClIP' type='ip' description="Adresse IP réseau autorisée a utiliser le service Redis" multi='True'/>
            <variable name='rdClmask' type='ip' description="Masque de sous réseau"/>

            <!-- Cluster configration Part -->
            <variable name='redisRole' type='string' description="Role du serveur Redis">
                <value>Leader</value>
            </variable>
            <variable name='rdClMember' type='string' description="Nom du noeud" multi='True'/>
            <variable name='rdClMemberIP' type='ip' description="Adresse IP du noeud" multi='True'/>
            <variable name='rdClMemberPort' type='number' description="Port d'écoute du noeud" multi='True'>
                <value>6379</value>
            </variable>
            <variable name='rdClMemberRole' type='ip' description="Rôle du membre"/>
            <variable name='rdClMemberMaster' type='string' description="Nom du neoud a répliquer sur ce membre"/>
            <variable name='rdClMemberAsSlave' type='oui/non' description="Ce noeud dispose de 2 instances ?">
                <value>non</value>
            </variable>
            <variable name='rdClMemberSlaveName' type='string' description="Nom de l'instance secondaire"/>
            <variable name='rdClMemberSlaveIP' type='ip' description="IP de l'instance secondaire"/>
            <variable name='rdClMemberSlavePort' type='number' description="Port de l'instance secondaire"/>
            <variable name='rdClMemberSlaveRole' type='string' description="Rôle de l'instance secondaire" hidden='True'/>
            <variable name='rdClMemberSlaveMaster' type='string' description="Noeud du noeud répliquer sur cette instance secondaire"/>
        </family>
        <family name='Redis tunning' icon='redis' mode='expert'>
            <variable name='redisMaxClients' type='number' description="Maximum allowed clients">
                <value>10000</value>
            </variable>
            <variable name='rdCliOutBuffHardLimit' type='number' description="Client output buffer hard limit (for slave)">
                <value>512</value>
            </variable>
            <variable name='rdCliOutBuffSoftLimit' type='number' description="Client output buffer soft limit (for slave)">
                <value>256</value>
            </variable>
            <variable name='rdSaveDisable' type='oui/non' description="Désactiver la persistence des données sur les maitres et esclaves">
                <value>non</value>
            </variable>
            <variable name='rdAOFDisable' type='oui/non' description="Désactiver la sauvegarde AOF sur les maitres et esclaves">
                <value>non</value>
            </variable>
        </family>
        <separators>
            <separator name='redisInstanceName'>Instance Principale</separator>
            <separator name='redisSlaveInstanceName'>Instance Secondaire</separator>
            <separator name='rdClIP'>Autorisation d'accès au service Redis</separator>
            <separator name='redisRole'>Grappe Redis</separator>
            <separator name='rdClMemberIP'>Serveurs membres de la grappe Redis</separator>
        </separators>
    </variables>
    <constraints>
        <condition name='disabled_if_in' source='activer_redis'>
            <param>non</param>
            <target type='filelist'>redis</target>
            <target type='family'>Redis</target>
            <target type='service_accesslist'>saRedis</target>
            <target type='service_accesslist'>saRedisSlave</target>
            <target type='servicelist'>svredis</target>
            <target type='filelist'>redisCl</target>
        </condition>

        <condition name='disabled_if_in' source="redisSSL">
            <param>non</param>
            <target type='variable'>redisSSLPort</target>
            <target type='service_accesslist'>saSSLRedis</target>
            <target type='filelist'>redisSSL</target>
        </condition>

        <condition name='disabled_if_in' source='redisSlaveInstance'>
            <param>non</param>
            <target type='filelist'>redisSlave</target>
            <target type='servicelist'>svredisSlave</target>
            <target type='service_accesslist'>saRedisSlave</target>
            <target type='variable'>redisSlaveInstanceName</target>
            <target type='variable'>redisSlaveInstanceMaster</target>
            <target type='variable'>redisPortSlave</target>
            <target type='variable'>redisClPortSlave</target>
            <target type='variable'>redisMemoryPolicySlave</target>
            <target type='variable'>redisTCPKeepAliveSlave</target>
            <target type='variable'>redisMaxMemorySlave</target>
        </condition>

        <condition name='disabled_if_in' source='rdClMemberAsSlave'>
            <param>non</param>
            <target type='variable'>rdClMemberSlaveName</target>
            <target type='variable'>rdClMemberSlaveIP</target>
            <target type='variable'>rdClMemberSlavePort</target>
            <target type='variable'>rdClMemberSlaveRole</target>
            <target type='variable'>rdClMemberSlaveMaster</target>
        </condition>

        <condition name='disabled_if_in' source='redisMode'>
            <param>Local</param>
            <target type='variable'>redisRole</target>
            <target type='variable'>redisInstanceName</target>
            <target type='variable'>redisSlaveInstance</target>
            <target type='filelist'>redisCl</target>
            <target type='variable'>redisClPort</target>
        </condition>

        <condition name='disabled_if_in' source='redisMode'>
            <param>Local avec slave distant</param>
            <target type='variable'>redisRole</target>
            <target type='variable'>redisInstanceName</target>
            <target type='variable'>redisSlaveInstanceName</target>
            <target type='variable'>redisSlaveInstanceMaster</target>
            <target type='variable'>redisClPortSlave</target>
            <target type='variable'>redisClPort</target>
        </condition>

        <condition name='disabled_if_not_in' source='redisMode'>
            <param>Local avec slave distant</param>
            <target type='variable'>redisMasterIPSlave</target>
            <target type='variable'>redisMasterPortSlave</target>
        </condition>

        <condition name='disabled_if_in' source='redisRole'>
            <param>Node</param>
            <target type='filelist'>redisCl</target>
            <target type='variable'>redisInstanceName</target>
            <target type='variable'>rdClMember</target>
            <target type='variable'>rdClMemberIP</target>
            <target type='variable'>rdClMemberPort</target>
            <target type='variable'>rdClMemberRole</target>
            <target type='variable'>rdClMemberMaster</target>
            <target type='variable'>rdClMemberAsSlave</target>
            <target type='variable'>rdClMemberSlaveName</target>
            <target type='variable'>rdClMemberSlaveIP</target>
            <target type='variable'>rdClMemberSlavePort</target>
            <target type='variable'>rdClMemberSlaveRole</target>
            <target type='variable'>rdClMemberSlaveMaster</target>
            <target type='variable'>redisSlaveInstanceMaster</target>
        </condition>

        <condition name='disabled_if_in' source='rdClMemberRole'>
            <param>master</param>
            <target type='variable'>rdClMemberMaster</target>
        </condition>

        <group master='rdClIP'>
            <slave>rdClmask</slave>
        </group>

        <group master='rdClMember'>
            <slave>rdClMemberIP</slave>
            <slave>rdClMemberPort</slave>
            <slave>rdClMemberRole</slave>
            <slave>rdClMemberMaster</slave>
            <slave>rdClMemberAsSlave</slave>
            <slave>rdClMemberSlaveName</slave>
            <slave>rdClMemberSlaveIP</slave>
            <slave>rdClMemberSlavePort</slave>
            <slave>rdClMemberSlaveRole</slave>
            <slave>rdClMemberSlaveMaster</slave>
        </group>
        <check name="valid_enum" target="redisRole">
            <param>['Leader','Node']</param>
        </check>
        <check name="valid_enum" target="redisMode">
            <param>['Local', 'Local avec slave distant', 'Cluster']</param>
        </check>
        <check name="valid_enum" target="rdClMemberRole">
            <param>['master','slave']</param>
        </check>
        <check name="valid_enum" target="redisMemoryPolicy">
            <param>['noeviction', 'allkeys-lru','volatile-lru','volatile-random', 'allkeys-random','volatile-ttl']</param>
        </check>

        <fill name='concat' target="redisSlaveInstanceName">
            <param type='eole' name='valeur1'>redisInstanceName</param>
            <param name='valeur2'>Second</param>
        </fill>

        <fill name='concat' target="rdClMemberSlaveName">
            <param type='eole' name='valeur1'>rdClMember</param>
            <param name='valeur2'>Second</param>
        </fill>

        <fill name='calc_val' target="rdClMemberSlaveIP">
            <param type='eole' name='valeur'>rdClMemberIP</param>
        </fill>
        <auto name='calc_val' target='rdClMemberSlaveRole'>
            <param>slave</param>
        </auto>

        <fill name='calc_val' target='redisInstanceName'>
            <param type='eole' name='valeur'>nom_machine</param>
        </fill>

        <fill name='calc_val' target='redisMaxMemorySlave'>
            <param type='eole' name='valeur'>redisMaxMemory</param>
        </fill>

        <fill name='calc_val' target='redisMemoryPolicySlave'>
            <param type='eole' name='valeur'>redisMemoryPolicy</param>
        </fill>

        <fill name='calc_val' target='redisTCPKeepAliveSlave'>
            <param type='eole' name='valeur'>redisTCPKeepAlive</param>
        </fill>

    </constraints>

    <help>
        <variable name='activer_redis'>Redis est un système de gestion de base de données clé-valeur</variable>
        <family name="Redis">Configuration du service de cache Redis</family>
        <family name='Redis tunning'>Paramétrage avancé du service de cache Redis</family>
    </help>

</creole>
