Skip to content

Commit

Permalink
Merge pull request #108 from upmaru/feature/endpoint-for-getting-list…
Browse files Browse the repository at this point in the history
…-of-nodes

Setup endpoint and test case for node listing
  • Loading branch information
zacksiri authored Jan 8, 2025
2 parents 20c9328 + 8ed6a39 commit b9ddbb6
Show file tree
Hide file tree
Showing 5 changed files with 386 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/uplink/clients/lxd/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule Uplink.Clients.LXD.Node do
use Ecto.Schema
import Ecto.Changeset

@derive Jason.Encoder

@primary_key false
embedded_schema do
field :name, :string
Expand Down
28 changes: 28 additions & 0 deletions lib/uplink/nodes/router.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Uplink.Nodes.Router do
use Plug.Router
use Uplink.Web

alias Uplink.Secret
alias Uplink.Clients.LXD

plug :match

plug Plug.Parsers,
parsers: [:urlencoded, :json],
body_reader: {Uplink.Web.CacheBodyReader, :read_body, []},
json_decoder: Jason

plug Secret.VerificationPlug

plug :dispatch

post "/" do
nodes =
LXD.list_cluster_members()
|> Enum.map(fn member ->
LXD.get_node(member.server_name)
end)

json(conn, :ok, nodes)
end
end
2 changes: 2 additions & 0 deletions lib/uplink/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Uplink.Router do
alias Uplink.Installations
alias Uplink.Cache
alias Uplink.Monitors
alias Uplink.Nodes

alias Uplink.Packages.{
Instance,
Expand All @@ -27,6 +28,7 @@ defmodule Uplink.Router do
forward "/components", to: Components.Router
forward "/cache", to: Cache.Router
forward "/monitors", to: Monitors.Router
forward "/nodes", to: Nodes.Router

match _ do
send_resp(conn, 404, "not found")
Expand Down
263 changes: 263 additions & 0 deletions test/fixtures/lxd/resources/show.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
{
"cpu": {
"architecture": "x86_64",
"sockets": [
{
"cache": [
{
"level": 1,
"size": 32768,
"type": "Data"
},
{
"level": 1,
"size": 65536,
"type": "Instruction"
},
{
"level": 2,
"size": 524288,
"type": "Unified"
},
{
"level": 3,
"size": 8388608,
"type": "Unified"
}
],
"cores": [
{
"core": 0,
"die": 0,
"threads": [
{
"id": 0,
"isolated": false,
"numa_node": 0,
"online": true,
"thread": 0
},
{
"id": 1,
"isolated": false,
"numa_node": 0,
"online": true,
"thread": 1
}
]
}
],
"name": "AMD EPYC 7571",
"socket": 0,
"vendor": "AuthenticAMD"
}
],
"total": 2
},
"gpu": {
"cards": [
{
"numa_node": 0,
"pci_address": "0000:00:03.0",
"product_id": "1111",
"vendor": "Amazon.com, Inc.",
"vendor_id": "1d0f"
}
],
"total": 1
},
"memory": {
"hugepages_size": 2097152,
"hugepages_total": 0,
"hugepages_used": 0,
"nodes": [
{
"hugepages_total": 0,
"hugepages_used": 0,
"numa_node": 0,
"total": 4294967296,
"used": 3809120256
}
],
"total": 4294967296,
"used": 2107842560
},
"network": {
"cards": [
{
"driver": "ena",
"driver_version": "6.5.0-1023-aws",
"numa_node": 0,
"pci_address": "0000:00:05.0",
"ports": [
{
"address": "06:b1:cc:28:99:2d",
"auto_negotiation": false,
"id": "ens5",
"link_detected": true,
"port": 0,
"protocol": "ethernet"
}
],
"product": "Elastic Network Adapter (ENA)",
"product_id": "ec20",
"vendor": "Amazon.com, Inc.",
"vendor_id": "1d0f"
}
],
"total": 1
},
"pci": {
"devices": [
{
"driver": "",
"driver_version": "",
"iommu_group": 0,
"numa_node": 0,
"pci_address": "0000:00:00.0",
"product": "440FX - 82441FX PMC [Natoma]",
"product_id": "1237",
"vendor": "Intel Corporation",
"vendor_id": "8086",
"vpd": {}
},
{
"driver": "",
"driver_version": "",
"iommu_group": 0,
"numa_node": 0,
"pci_address": "0000:00:01.0",
"product": "82371SB PIIX3 ISA [Natoma/Triton II]",
"product_id": "7000",
"vendor": "Intel Corporation",
"vendor_id": "8086",
"vpd": {}
},
{
"driver": "",
"driver_version": "",
"iommu_group": 0,
"numa_node": 0,
"pci_address": "0000:00:01.3",
"product": "82371AB/EB/MB PIIX4 ACPI",
"product_id": "7113",
"vendor": "Intel Corporation",
"vendor_id": "8086",
"vpd": {}
},
{
"driver": "",
"driver_version": "",
"iommu_group": 0,
"numa_node": 0,
"pci_address": "0000:00:03.0",
"product": "",
"product_id": "1111",
"vendor": "Amazon.com, Inc.",
"vendor_id": "1d0f",
"vpd": {}
},
{
"driver": "nvme",
"driver_version": "6.5.0-1023-aws",
"iommu_group": 0,
"numa_node": 0,
"pci_address": "0000:00:04.0",
"product": "",
"product_id": "8061",
"vendor": "Amazon.com, Inc.",
"vendor_id": "1d0f",
"vpd": {}
},
{
"driver": "ena",
"driver_version": "6.5.0-1023-aws",
"iommu_group": 0,
"numa_node": 0,
"pci_address": "0000:00:05.0",
"product": "Elastic Network Adapter (ENA)",
"product_id": "ec20",
"vendor": "Amazon.com, Inc.",
"vendor_id": "1d0f",
"vpd": {}
}
],
"total": 6
},
"storage": {
"disks": [
{
"block_size": 512,
"device": "259:0",
"device_id": "nvme-nvme.1d0f-766f6c3038346564376336353263323933646366-416d617a6f6e20456c617374696320426c6f636b2053746f7265-00000001",
"device_path": "pci-0000:00:04.0-nvme-1",
"firmware_version": "1.0",
"id": "nvme0n1",
"model": "Amazon Elastic Block Store",
"numa_node": 0,
"partitions": [
{
"device": "259:1",
"id": "nvme0n1p1",
"partition": 1,
"read_only": false,
"size": 42833264128
},
{
"device": "259:2",
"id": "nvme0n1p14",
"partition": 14,
"read_only": false,
"size": 4194304
},
{
"device": "259:3",
"id": "nvme0n1p15",
"partition": 15,
"read_only": false,
"size": 111149056
}
],
"read_only": false,
"removable": false,
"rpm": 0,
"serial": "vol084ed7c652c293dcf",
"size": 42949672960,
"type": "nvme",
"wwn": "nvme.1d0f-766f6c3038346564376336353263323933646366-416d617a6f6e20456c617374696320426c6f636b2053746f7265-00000001"
}
],
"total": 4
},
"system": {
"chassis": {
"serial": "",
"type": "Other",
"vendor": "Amazon EC2",
"version": ""
},
"family": "",
"firmware": {
"date": "10/16/2017",
"vendor": "Amazon EC2",
"version": "1.0"
},
"motherboard": {
"product": "",
"serial": "",
"vendor": "Amazon EC2",
"version": ""
},
"product": "t3a.medium",
"serial": "ec20b7a9-497a-9279-cba6-7417800214a3",
"sku": "",
"type": "virtual-machine",
"uuid": "ec20b7a9-497a-9279-cba6-7417800214a3",
"vendor": "Amazon EC2",
"version": ""
},
"usb": {
"devices": [],
"total": 0
}
}
Loading

0 comments on commit b9ddbb6

Please sign in to comment.