# storage-node05 - Storage Worker Node
#
# Services: PlasmaVMC Agent, LightningStor Data

{ config, lib, pkgs, ... }:

{
  imports = [
    ./common.nix
    ../modules/plasmavmc.nix
    ../modules/coronafs.nix
    ../modules/lightningstor.nix
    ../modules/node-agent.nix
  ];

  photonTestCluster = {
    sshBasePort = 2300;
    vdeSock = "/tmp/ultracloud-test-cluster-vde.sock-storage";
  };

  networking.hostName = "node05";

  virtualisation = {
    cores = lib.mkForce 3;
    memorySize = 5120;
    diskSize = 40960;
  };

  networking.interfaces.eth1.ipv4.addresses = [{
    address = "10.100.0.22";
    prefixLength = 24;
  }];

  services.plasmavmc = {
    enable = true;
    mode = "agent";
    coronafsNodeLocalAttach = true;
    sharedLiveMigration = false;
    port = 50082;
    httpPort = 8084;
    iamAddr = "10.100.0.11:50080";
    chainfireAddr = config.photonTestCluster.chainfireControlPlaneAddrs;
    flaredbAddr = config.photonTestCluster.flaredbControlPlaneAddrs;
    controlPlaneAddr = "10.100.0.11:50082";
    advertiseAddr = "10.100.0.22:50082";
    lightningstorAddr = "10.100.0.11:50086";
    coronafsControllerEndpoint = "http://10.100.0.11:50088";
    coronafsNodeEndpoint = "http://127.0.0.1:50088";
  };

  services.coronafs = {
    enable = true;
    mode = "node";
    port = 50088;
    advertiseHost = "10.100.0.22";
  };

  services.lightningstor = {
    enable = true;
    mode = "data";
    port = 50086;
    distributedRequestTimeoutMs = 300000;
    chainfireAddr = config.photonTestCluster.chainfireControlPlaneAddrs;
    flaredbAddr = config.photonTestCluster.flaredbControlPlaneAddrs;
    iamAddr = "10.100.0.11:50080";
    zone = "zone-c";
    region = "test";
  };

  services.node-agent = {
    enable = true;
    chainfireEndpoint = config.photonTestCluster.chainfireControlPlaneAddrs;
    clusterId = "test-cluster";
    nodeId = "node05";
    intervalSecs = 10;
    apply = true;
    enableContainers = true;
    extraPackages = [ pkgs.python3 ];
  };
}
