from diagrams import Cluster, Diagram, Edge

from diagrams.azure.database import DatabaseForMariadbServers
from diagrams.onprem.network import Internet
from diagrams.onprem.groupware import Nextcloud
from diagrams.onprem.monitoring import Grafana, Prometheus
from diagrams.onprem.network import Haproxy
import diagrams.generic.storage as storage_1
from diagrams.azure.identity import Groups
from diagrams.onprem.storage import Ceph, CephOsd

from diagrams.custom import Custom

mypath="/home/pbarriat/Documents/Boulot/UCL/Brevet/report/assets/"

with Diagram(filename="../assets/dia_nc_test_improved", show=True, direction="TB"):
    out = Internet("Intranet")    
    ldap = Groups("LDAP")

    with Cluster("SSL proxy + PHP Caching"):
        openstack_lb = Custom("", mypath+"openstack.png")
        lb = [Haproxy("Load Balancing")]

    with Cluster("Web server"):
        openstack_web = Custom("", mypath+"openstack.png")
        with Cluster("Node 1"):
            caching_1 = Custom("PHP Caching", mypath+"keydb.png")
            nc_frontend_1 = [ Nextcloud(), caching_1]
        with Cluster("Node 2"):
            caching_2 = Custom("PHP Caching", mypath+"keydb.png")
            nc_frontend_2 = [ Nextcloud(), caching_2]
        caching_1 - Edge(label="Master-Master", style="dashed") - caching_2

    with Cluster("Database"):
        openstack_db = Custom("", mypath+"openstack.png")
        nc_db = DatabaseForMariadbServers("Backup writer")
 
    with Cluster("Ceph Storage Cluster"):
        ceph_cluster = Ceph()
        ceph_object = CephOsd("Object Gateway")
        
    #with Cluster("Control / Monitor"):
    #    openstack_ctrl = Custom("", mypath+"openstack.png")
    #    ctrl = [Prometheus(), Grafana()]        
 
    openstack_lb >> openstack_web << openstack_db
    ceph_cluster >> openstack_web << ldap
    #openstack_ctrl >> openstack_web
    out >> lb