Vagrant.configure("2") do |config|
    config.vm.box = "backbone"
    config.vm.synced_folder ".", "/vagrant", disabled: true

    # This let's us access all guests with their names from host and other guests
    config.hostmanager.enabled = true
    config.hostmanager.manage_host = true
    config.hostmanager.manage_guest = true

    config.vm.provider :libvirt do |libvirt|
        libvirt.qemu_use_session = false
        # Enable qemu_use_session or set this on macOS
        # Also run **sudo** brew services start
        # libvirt.uri = "qemu:///session"
        libvirt.driver = "kvm"
        libvirt.default_prefix = ""
        # VMs with little disk space may fail to boot
        libvirt.machine_virtual_size = 16
        libvirt.cpus = 1
        libvirt.cpu_mode = "host-passthrough"
        libvirt.memory = 512
    end

    # We will add two static IPs to simulate public and private interfaces
    # Host manager plugin will work only with first interface in this list
    # Public    10.0.x.x
    # Private   10.1.x.x

    # IP Pattern based on server types
    # Proxy     x.x.1.x
    # Jingrow    x.x.2.x
    # Database  x.x.3.x
    # Other     x.x.4.x

    # We'll start IPs from x.x.x.101

    # Default Cluster

    # Reverse Proxy Server
    config.vm.define "n1.local.jingrow.dev" do |n1|
        n1.vm.hostname = "n1.local.jingrow.dev"
        n1.vm.network "private_network", ip: "10.0.1.101", netmask: "255.255.0.0"
        n1.vm.network "private_network", ip: "10.1.1.101", netmask: "255.255.0.0"
        n1.vm.provider :libvirt do |libvirt|
            libvirt.memory = 1024
        end
    end

    # Primary App Server
    config.vm.define "f1.local.jingrow.dev" do |f1|
        f1.vm.hostname = "f1.local.jingrow.dev"
        f1.vm.network "private_network", ip: "10.0.2.101", netmask: "255.255.0.0"
        f1.vm.network "private_network", ip: "10.1.2.101", netmask: "255.255.0.0"
        f1.vm.provider :libvirt do |libvirt|
            libvirt.cpus = 2
            libvirt.memory = 4096
        end
    end

    # Replica of f1
    # config.vm.define "f2.local.jingrow.dev" do |f2|
    #     f2.vm.hostname = "f2.local.jingrow.dev"
    #     f2.vm.network "private_network", ip: "10.0.2.102", netmask: "255.255.0.0"
    #     f2.vm.network "private_network", ip: "10.1.2.102", netmask: "255.255.0.0"
    #     f2.vm.provider :libvirt do |libvirt|
    #         libvirt.cpus = 2
    #         libvirt.memory = 4096
    #     end
    # end

    # Primary DB Server
    config.vm.define "m1.local.jingrow.dev" do |m1|
        m1.vm.hostname = "m1.local.jingrow.dev"
        m1.vm.network "private_network", ip: "10.0.3.101", netmask: "255.255.0.0"
        m1.vm.network "private_network", ip: "10.1.3.101", netmask: "255.255.0.0"
        m1.vm.provider :libvirt do |libvirt|
            libvirt.cpus = 1
            libvirt.memory = 2048
        end
    end

    # Replica of m1
    # config.vm.define "m2.local.jingrow.dev" do |m2|
    #     m2.vm.hostname = "m2.local.jingrow.dev"
    #     m2.vm.network "private_network", ip: "10.0.3.102", netmask: "255.255.0.0"
    #     m2.vm.network "private_network", ip: "10.1.3.102", netmask: "255.255.0.0"
    #     m2.vm.provider :libvirt do |libvirt|
    #         libvirt.cpus = 1
    #         libvirt.memory = 2048
    #     end
    # end

    # # Secondary Cluster
    # config.vm.define "n2.jingrow.dev" do |n2|
    #     n2.vm.hostname = "n2.jingrow.dev"
    #     n2.vm.network "private_network", ip: "10.0.1.102", netmask: "255.255.0.0"
    #     n2.vm.network "private_network", ip: "10.1.1.102", netmask: "255.255.0.0"
    # end

    # Additional Hosts.

    # Docker Registry
    config.vm.define "registry.local.jingrow.dev" do |registry|
        registry.vm.hostname = "registry.local.jingrow.dev"
        registry.vm.network "private_network", ip: "10.0.4.101", netmask: "255.255.0.0"
        registry.vm.network "private_network", ip: "10.1.4.101", netmask: "255.255.0.0"
    end

    # Log Server = ElasticSearch + Logstash + Kibana
    config.vm.define "log.local.jingrow.dev" do |log|
        log.vm.hostname = "log.local.jingrow.dev"
        log.vm.network "private_network", ip: "10.0.4.102", netmask: "255.255.0.0"
        log.vm.network "private_network", ip: "10.1.4.102", netmask: "255.255.0.0"
        log.vm.provider :libvirt do |libvirt|
            libvirt.cpus = 2
            libvirt.memory = 4096
        end
    end

    # Uptime Server = Prometheus + Grafana
    config.vm.define "monitor.local.jingrow.dev" do |monitor|
        monitor.vm.hostname = "monitor.local.jingrow.dev"
        monitor.vm.network "private_network", ip: "10.0.4.103", netmask: "255.255.0.0"
        monitor.vm.network "private_network", ip: "10.1.4.103", netmask: "255.255.0.0"
        monitor.vm.provider :libvirt do |libvirt|
            libvirt.memory = 1024
        end
    end

    # Analytics Server = Plausible
    # config.vm.define "analytics.local.jingrow.dev" do |analytics|
    #     analytics.vm.hostname = "analytics.local.jingrow.dev"
    #     analytics.vm.network "private_network", ip: "10.0.4.104", netmask: "255.255.0.0"
    #     analytics.vm.network "private_network", ip: "10.1.4.104", netmask: "255.255.0.0"
    #     analytics.vm.provider :libvirt do |libvirt|
    #         libvirt.memory = 1024
    #     end
    # end

    # Trace Server = Sentry
    config.vm.define "trace.local.jingrow.dev" do |trace|
        trace.vm.hostname = "trace.local.jingrow.dev"
        trace.vm.network "private_network", ip: "10.0.4.105", netmask: "255.255.0.0"
        trace.vm.network "private_network", ip: "10.1.4.105", netmask: "255.255.0.0"
        trace.vm.provider :libvirt do |libvirt|
            libvirt.cpus = 2
            libvirt.memory = 4096
        end
    end

    # config.vm.define "sn1.local.jingrow.dev" do |sn1|
    #     sn1.vm.box = "scaleway"
    #     sn1.vm.hostname = "sn1.local.jingrow.dev"
    #     sn1.vm.network "private_network", ip: "10.2.0.101", netmask: "255.255.0.0"
    #     sn1.vm.network "private_network", ip: "10.3.0.101", netmask: "255.255.0.0", auto_config: false
    # end

    # config.vm.define "sf1.local.jingrow.dev" do |sf1|
    #     sf1.vm.box = "scaleway"
    #     sf1.vm.hostname = "sf1.local.jingrow.dev"
    #     sf1.vm.network "private_network", ip: "10.2.1.101", netmask: "255.255.0.0"
    #     sf1.vm.network "private_network", ip: "10.3.1.101", netmask: "255.255.0.0", auto_config: false
    #     sf1.vm.provider :libvirt do |libvirt|
    #         libvirt.cpus = 2
    #         libvirt.memory = 4096
    #     end
    # end

end
