···
21
21
import proxpose/configuration
22
22
import proxpose/humanise as prox_humanise
23
23
import proxpose/proxmox
24
24
+
import proxpose/proxmox/lxc
24
25
import proxpose/ssh
25
26
import simplifile
26
27
import snag
···
539
540
) -> glint.Command(Result(String, Error)) {
540
541
use <- glint.command_help("Deploy a new machine.")
541
542
543
543
+
use ignore_tls <- glint.flag(ignore_tls_flag())
542
544
use name <- glint.named_arg("name")
543
545
544
544
-
use named, _, _ <- glint.command()
546
546
+
use named, _, flags <- glint.command()
545
547
546
548
use config <- with_configuration(env)
549
549
+
use ignore_tls <- with_flag(ignore_tls(flags))
550
550
+
let verify_tls = !ignore_tls
547
551
548
552
let name = name(named)
549
553
550
550
-
use _ <- result.try(do_new_machine(config, name))
554
554
+
use _ <- result.try(do_new_machine(config, verify_tls, name))
551
555
552
556
Ok(
553
557
"Successfully deployed machine {{name}}"
···
557
561
558
562
fn do_new_machine(
559
563
config: configuration.Configuration,
564
564
+
verify_tls: Bool,
560
565
name: String,
561
561
-
) -> Result(a, Error) {
566
566
+
) -> Result(_, Error) {
567
567
+
use machines <- result.try(all_machines(config, verify_tls))
568
568
+
562
569
// check if machine already exists
570
570
+
case list.find(machines, fn(machine) { machine.name == name }) {
571
571
+
Ok(container) -> Error(MachineExists(container))
572
572
+
Error(_) -> {
573
573
+
// create machine
574
574
+
use vmid <- result.try(next_vmid(config, verify_tls))
563
575
564
564
-
// create machine
576
576
+
default_lxc(vmid, name, storage: todo, filename: todo, memory: todo)
577
577
+
578
578
+
todo as "create machine"
579
579
+
todo as "wait for container to be created"
580
580
+
}
581
581
+
}
582
582
+
}
583
583
+
584
584
+
fn next_vmid(
585
585
+
config: configuration.Configuration,
586
586
+
verify_tls: Bool,
587
587
+
) -> Result(Int, Error) {
588
588
+
let credentials = credentials_from_configuration(config)
589
589
+
590
590
+
do_request(
591
591
+
proxmox.vmid_next(host: config.proxmox_host, credentials:),
592
592
+
verify_tls,
593
593
+
proxmox.vmid_next_response,
594
594
+
)
595
595
+
}
596
596
+
597
597
+
fn default_lxc(
598
598
+
vmid vmid: Int,
599
599
+
name name: String,
600
600
+
storage storage: option.Option(String),
601
601
+
filename filename: option.Option(String),
602
602
+
memory memory: option.Option(Int),
603
603
+
) {
604
604
+
lxc.new(
605
605
+
vmid,
606
606
+
lxc.Template(
607
607
+
storage: option.unwrap(storage, "local"),
608
608
+
filename: option.unwrap(
609
609
+
filename,
610
610
+
"nixos-image-lxc-proxmox-25.11.x86_64.tar.xz",
611
611
+
),
612
612
+
),
613
613
+
)
614
614
+
|> lxc.with_hostname(name)
615
615
+
}
565
616
566
566
-
//
617
617
+
fn all_machines(config: configuration.Configuration, verify_tls: Bool) {
618
618
+
let credentials = credentials_from_configuration(config)
567
619
568
568
-
todo
620
620
+
use nodes <- result.try(do_request(
621
621
+
proxmox.nodes(host: config.proxmox_host, credentials:),
622
622
+
verify_tls,
623
623
+
proxmox.nodes_response,
624
624
+
))
625
625
+
626
626
+
list.map(nodes, fn(node) {
627
627
+
do_request(
628
628
+
proxmox.containers(
629
629
+
host: config.proxmox_host,
630
630
+
credentials:,
631
631
+
node: node.name,
632
632
+
),
633
633
+
verify_tls,
634
634
+
proxmox.containers_response,
635
635
+
)
636
636
+
})
637
637
+
|> result.all()
638
638
+
|> result.map(list.flatten)
569
639
}
570
640
571
641
fn show_config_command(
···
742
812
ApiError(proxmox.ApiError)
743
813
RequestFailed(httpc.HttpError)
744
814
NoMatch
815
815
+
MachineExists(proxmox.Container)
745
816
}
746
817
747
818
type File {
···
781
852
782
853
Ok(
783
854
"Successfully created {{name}}
784
784
-
You can now configure the compose file and .env in {{compose_directory}}/{{name}}.
855
855
+
You can now configure the compose file and .env in {{compose_directory}}{{name}}.
785
856
786
857
Then once you have it configured run the 'deploy' command"
787
858
|> string.replace("{{compose_directory}}", config.compose_directory)