Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos in Nodes endpoint response #156

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions sdn_vnets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package proxmox

import (
"context"
"fmt"
)

type Vnet struct {
client *Client
Vnet string
Zone string
Alias string
Tag int
VlanAware bool
}

type VnetStatus struct {
client *Client
Vnet string
Pending bool
Running bool
}

type VnetOptions []*VnetOption
type VnetOption struct {
Name string
Value interface{}
}

func (c *Client) Vnets(ctx context.Context, pending bool, running bool) (vnets []VnetStatus, err error) {
return vnets, c.Get(ctx, fmt.Sprintf("/cluster/sdn/vnets?pending=%s&running=%s", pending, running), &vnets)

Check failure on line 31 in sdn_vnets.go

View workflow job for this annotation

GitHub Actions / ci

fmt.Sprintf format %s has arg pending of wrong type bool

Check failure on line 31 in sdn_vnets.go

View workflow job for this annotation

GitHub Actions / ci

printf: fmt.Sprintf format %s has arg pending of wrong type bool, see also https://pkg.go.dev/fmt#hdr-Printing (govet)
}

func (c *Client) Vnet(ctx context.Context, name string) (vnet *VnetStatus, err error) {

if err = c.Get(ctx, fmt.Sprintf("/cluster/sdn/vnets/%s", name), &vnet); err != nil {
return nil, err
}

vnet.client = c

return
}

func (c *Client) NewVnet(ctx context.Context, vnet string, zone string, options ...VnetOption) (ret string, err error) {
data := make(map[string]interface{})
data["vnet"] = vnet
data["zone"] = zone

for _, option := range options {
data[option.Name] = option.Value
}

err = c.Post(ctx, "/cluster/sdn/vnets", data, &ret)
return ret, err
}

func (z *Vnet) Update(ctx context.Context, options ...VnetOption) error {
return z.client.Put(ctx, fmt.Sprintf("/cluster/sdn/vnets/%s", z.Vnet), nil, nil)
}

func (z *Vnet) Delete(ctx context.Context) error {
return z.client.Delete(ctx, fmt.Sprintf("/cluster/sdn/vnets/%s", z.Vnet), nil)
}
111 changes: 111 additions & 0 deletions sdn_zones.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package proxmox

import (
"context"
"fmt"
"strconv"
)

type Zone struct {
client *Client
Zone string `json:"zone"`
Type string `json:"type,omitempty"`
AdvertiseSubnets bool `json:"advertise-subnets,omitempty"`
Bridge string `json:"bridge,omitempty"`
BridgeDisableMacLearning bool `json:"bridge-disable-mac-learning,omitempty"`
Controller string `json:"controller,omitempty"`
Dhcp string `json:"dhcp,omitempty"`
DisableArpNdSuppression bool `json:"disable-arp-nd-suppression,omitempty"`
Dns string `json:"dns,omitempty"`

Check failure on line 19 in sdn_zones.go

View workflow job for this annotation

GitHub Actions / ci

var-naming: struct field Dns should be DNS (revive)
DnsZone string `json:"dnszone,omitempty"`

Check failure on line 20 in sdn_zones.go

View workflow job for this annotation

GitHub Actions / ci

var-naming: struct field DnsZone should be DNSZone (revive)
DpId int `json:"dp-id,omitempty"`

Check failure on line 21 in sdn_zones.go

View workflow job for this annotation

GitHub Actions / ci

var-naming: struct field DpId should be DpID (revive)
Exitnodes string `json:"exitnodes,omitempty"`
ExitnodesLocalRouting bool `json:"exitnodes-local-routing,omitempty"`
ExitnodesPrimary string `json:"exitnodes-primary,omitempty"`
Ipam string `json:"ipam,omitempty"`
Mac string `json:"mac,omitempty"`
Mtu int `json:"mtu,omitempty"`
Nodes string `json:"nodes,omitempty"`
Peers string `json:"peers,omitempty"`
Reversedns string `json:"reversedns,omitempty"`
RtImport string `json:"rt-import,omitempty"`
Tag int `json:"tag,omitempty"`
VlanProtocol string `json:"vlan-protocol,omitempty"`
VrfVxlan int `json:"vrf-vxlan,omitempty"`
VxlanPort int `json:"vxlan-port,omitempty"`
Digest string `json:"digest,omitempty"`
}

type ZoneStatus struct {
Zone string
Pending bool
Running bool
}

type ZoneOptions []*ZoneOption
type ZoneOption struct {
Name string
Value interface{}
}

type ZoneConfig struct {
Zone string `json:"zone"`
Type string `json:"type,omitempty"`
AdvertiseSubnets bool `json:"advertise-subnets,omitempty"`
Bridge string `json:"bridge,omitempty"`
BridgeDisableMacLearning bool `json:"bridge-disable-mac-learning,omitempty"`
Controller string `json:"controller,omitempty"`
Dhcp string `json:"dhcp,omitempty"`
DisableArpNdSuppression bool `json:"disable-arp-nd-suppression,omitempty"`
Dns string `json:"dns,omitempty"`

Check failure on line 60 in sdn_zones.go

View workflow job for this annotation

GitHub Actions / ci

var-naming: struct field Dns should be DNS (revive)
DnsZone string `json:"dnszone,omitempty"`

Check failure on line 61 in sdn_zones.go

View workflow job for this annotation

GitHub Actions / ci

var-naming: struct field DnsZone should be DNSZone (revive)
DpId int `json:"dp-id,omitempty"`

Check failure on line 62 in sdn_zones.go

View workflow job for this annotation

GitHub Actions / ci

var-naming: struct field DpId should be DpID (revive)
Exitnodes string `json:"exitnodes,omitempty"`
ExitnodesLocalRouting bool `json:"exitnodes-local-routing,omitempty"`
ExitnodesPrimary string `json:"exitnodes-primary,omitempty"`
Ipam string `json:"ipam,omitempty"`
Mac string `json:"mac,omitempty"`
Mtu int `json:"mtu,omitempty"`
Nodes string `json:"nodes,omitempty"`
Peers string `json:"peers,omitempty"`
Reversedns string `json:"reversedns,omitempty"`
RtImport string `json:"rt-import,omitempty"`
Tag int `json:"tag,omitempty"`
VlanProtocol string `json:"vlan-protocol,omitempty"`
VrfVxlan int `json:"vrf-vxlan,omitempty"`
VxlanPort int `json:"vxlan-port,omitempty"`
}

func (c *Client) Zones(ctx context.Context, pending bool, running bool) (zones []ZoneStatus, err error) {
pendingStr := strconv.FormatBool(pending)
runningStr := strconv.FormatBool(running)
return zones, c.Get(ctx, fmt.Sprintf("/cluster/sdn/zones?pending=%v&running=%v", pendingStr, runningStr), &zones)
}

func (c *Client) Zone(ctx context.Context, name string) (zone *Zone, err error) {

if err = c.Get(ctx, fmt.Sprintf("/cluster/sdn/zones/%s", name), &zone); err != nil {
return nil, err
}

zone.client = c

return
}

func (c *Client) NewZone(ctx context.Context, config ZoneConfig) (zone *Zone, err error) {

if err = c.Post(ctx, "/cluster/sdn/zones", config, nil); err != nil {
return nil, err
}

return c.Zone(ctx, config.Zone)
}

func (z *Zone) Update(ctx context.Context, config ZoneConfig) error {
return z.client.Put(ctx, fmt.Sprintf("/cluster/sdn/zones/%s", z.Zone), config, nil)
}

func (z *Zone) Delete(ctx context.Context) error {
return z.client.Delete(ctx, fmt.Sprintf("/cluster/sdn/zones/%s", z.Zone), nil)
}
17 changes: 16 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ type Node struct {
Ksm Ksm
Uptime uint64
Wait float64

CurrentKernel CurrentKernel `json:"current-kernel"`
BootInfo BootInfo `json:"boot-info"`
}

type VirtualMachines []*VirtualMachine
Expand Down Expand Up @@ -249,7 +252,7 @@ type RootFS struct {
type CPUInfo struct {
UserHz int `json:"user_hz"`
MHZ StringOrInt
Mode string
Model string
luthermonson marked this conversation as resolved.
Show resolved Hide resolved
Cores int
Sockets int
Flags string
Expand All @@ -267,6 +270,18 @@ type Ksm struct {
Shared int64
}

type CurrentKernel struct {
Release string
SysName string
Version string
Machine string
}

type BootInfo struct {
Mode string
SecureBoot int
}

type Time struct {
Timezone string
Time uint64
Expand Down
Loading