From a2bf608a54b1098dbe9225375cf3280dda237000 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Sun, 19 Apr 2026 00:09:29 +0000 Subject: [PATCH] add initial types --- access-types.go | 88 +++++++++++++++++++++++++++++++++++++++++++++++ resource-types.go | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 access-types.go create mode 100644 resource-types.go diff --git a/access-types.go b/access-types.go new file mode 100644 index 0000000..e10681b --- /dev/null +++ b/access-types.go @@ -0,0 +1,88 @@ +package paas_common_lib + +type Pool struct { + PoolID string `json:"poolid"` + Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally + Groups []Group `json:"groups"` + Resources map[string]any `json:"resources"` + Templates Templates `json:"templates"` + AllowedNodes map[string]bool `json:"nodes-allowed"` + VMIDRange VMID `json:"vmid-allowed"` + Backups Backups `json:"backups-allowed"` // measured in numbers +} + +// proxmox typically formats as gid-realm for non pve realms +// proxmox realms are formatted without realm values +// I assume that backends store groups by ID only and only proxmox will append the realm string +type Groupname struct { + GroupID string `json:"gid"` + Realm string `json:"realm"` +} + +type Group struct { + Groupname Groupname `json:"groupname"` + Role string `json:"role"` // role in owner pool + Users []User `json:"users"` +} + +type Username struct { // ie userid@realm + UserID string `json:"uid"` + Realm string `json:"realm"` +} + +type User struct { + Username Username `json:"username"` + CN string `json:"cn"` // aka first name + SN string `json:"sn"` // aka last name + Mail string `json:"mail"` + Password string `json:"password"` // only used for POST requests +} + +type VMID struct { + Min int `json:"min"` + MAx int `json:"max"` +} + +type Backups struct { + Max int `json:"max"` +} + +type Templates struct { + Instances struct { + LXC map[string]ResourceTemplate `json:"lxc"` + QEMU map[string]ResourceTemplate `json:"qemu"` + } `json:"instances"` +} + +type SimpleResource struct { + Limits struct { + Global SimpleLimit `json:"global"` + Nodes map[string]SimpleLimit `json:"nodes"` + } `json:"limits"` +} + +type SimpleLimit struct { + Max int `json:"max"` +} + +type MatchResource struct { + Limits struct { + Global []MatchLimit `json:"global"` + Nodes map[string][]MatchLimit `json:"nodes"` + } `json:"limits"` +} + +type MatchLimit struct { + Match string `json:"match"` + Name string `json:"name"` + Max int `json:"max"` +} + +type ResourceTemplate struct { + Value string `json:"value"` + Resource struct { + Enabled bool `json:"enabled"` + Name string `json:"name"` + Amount int `json:"amount"` + } `json:"resource"` +} diff --git a/resource-types.go b/resource-types.go new file mode 100644 index 0000000..0b6e7f8 --- /dev/null +++ b/resource-types.go @@ -0,0 +1,88 @@ +package paas_common_lib + +type Cluster struct { + Nodes map[string]*Node `json:"nodes"` +} + +type Node struct { + Name string `json:"name"` + Cores uint64 `json:"cores"` + Memory uint64 `json:"memory"` + Swap uint64 `json:"swap"` + Devices map[DeviceBus]*Device `json:"devices"` + Instances map[InstanceID]*Instance `json:"instances"` + Proctypes []string `json:"cpus"` +} + +type InstanceID uint64 +type InstanceType string + +const ( + VM InstanceType = "VM" + CT InstanceType = "CT" +) + +type Instance struct { + Type InstanceType `json:"type"` + Name string `json:"name"` + Proctype string `json:"cpu"` + Cores uint64 `json:"cores"` + Memory uint64 `json:"memory"` + Swap uint64 `json:"swap"` + Volumes map[VolumeID]*Volume `json:"volumes"` + Nets map[NetID]*Net `json:"nets"` + Devices map[DeviceID]*Device `json:"devices"` + Boot BootOrder `json:"boot"` +} + +var VolumeTypes = []string{ + "sata", + "scsi", + "ide", + "rootfs", + "mp", + "unused", +} + +type VolumeID string +type Volume struct { + Volume_ID VolumeID `json:"volume_id"` + Type string `json:"type"` + Storage string `json:"storage"` + Format string `json:"format"` + Size uint64 `json:"size"` + File string `json:"file"` + MP string `json:"mp"` +} + +type NetID string +type Net struct { + Net_ID NetID `json:"net_id"` + Value string `json:"value"` + Rate uint64 `json:"rate"` + VLAN uint64 `json:"vlan"` +} + +type DeviceID string +type DeviceBus string +type Device struct { + Device_ID DeviceID `json:"device_id"` + Device_Bus DeviceBus `json:"device_bus"` + Device_Name string `json:"device_name"` + Vendor_Name string `json:"vendor_name"` + Functions map[FunctionID]*Function `json:"functions"` + Reserved bool `json:"reserved"` +} + +type FunctionID string +type Function struct { + Function_ID FunctionID `json:"function_id"` + Function_Name string `json:"subsystem_device_name"` + Vendor_Name string `json:"subsystem_vendor_name"` + Reserved bool `json:"reserved"` +} + +type BootOrder struct { + Enabled []any `json:"enabled"` + Disabled []any `json:"disabled"` +}