From 94634b8050ca309c06b85d9f9fed71caaca5cde5 Mon Sep 17 00:00:00 2001 From: Pascal Kutscha Date: Mon, 20 May 2024 15:44:53 +0200 Subject: [PATCH 1/2] Implementing creation, listing, and deletion of firewall rules for qemu/{vmid}/firewall --- proxmox/client.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/proxmox/client.go b/proxmox/client.go index 21bdf6b2..4783039c 100644 --- a/proxmox/client.go +++ b/proxmox/client.go @@ -1314,6 +1314,53 @@ func (c *Client) DeleteQemuIPSetNetwork(vmr *VmRef, IPSetName string, network st return } +func (c *Client) ListQemuFirewallRules(vmr *VmRef) (rules map[string]interface{}, err error) { + err = c.CheckVmRef(vmr) + if err != nil { + return nil, err + } + url := fmt.Sprintf("/nodes/%s/qemu/%d/firewall/rules", vmr.node, vmr.vmId) + resp, err := c.session.Get(url, nil, nil) + if err == nil { + rules, err := ResponseJSON(resp) + if err != nil { + return nil, err + } + return rules, nil + } + return +} +func (c *Client) CreateQemuFirewallRules(vmr *VmRef, params map[string]interface{}) (exitStatus *string, err error) { + err = c.CheckVmRef(vmr) + if err != nil { + return nil, err + } + reqbody := ParamsToBody(params) + url := fmt.Sprintf("/nodes/%s/qemu/%d/firewall/rules", vmr.node, vmr.vmId) + resp, err := c.session.Post(url, nil, nil, &reqbody) + if err == nil { + taskResponse, err := ResponseJSON(resp) + if err != nil { + return nil, err + } + exitStatus, err := c.WaitForCompletion(taskResponse) + if err != nil { + return &exitStatus, err + } + } + return +} + +func (c *Client) DeleteQemuFirewallRules(vmr *VmRef, pos int) (err error) { + err = c.CheckVmRef(vmr) + if err != nil { + return err + } + + url := fmt.Sprintf("/nodes/%s/qemu/%d/firewall/rules/%s", vmr.node, vmr.vmId, pos) + return c.Delete(url) +} + func (c *Client) Upload(node string, storage string, contentType string, filename string, file io.Reader) error { var doStreamingIO bool var fileSize int64 From 37911f4d900e4f0c54711fefdf9066f3dcedbc01 Mon Sep 17 00:00:00 2001 From: Pascal Kutscha Date: Tue, 21 May 2024 17:29:14 +0200 Subject: [PATCH 2/2] fixing fmt.Sprintf --- proxmox/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxmox/client.go b/proxmox/client.go index 4783039c..7af3461b 100644 --- a/proxmox/client.go +++ b/proxmox/client.go @@ -1357,7 +1357,7 @@ func (c *Client) DeleteQemuFirewallRules(vmr *VmRef, pos int) (err error) { return err } - url := fmt.Sprintf("/nodes/%s/qemu/%d/firewall/rules/%s", vmr.node, vmr.vmId, pos) + url := fmt.Sprintf("/nodes/%s/qemu/%d/firewall/rules/%d", vmr.node, vmr.vmId, pos) return c.Delete(url) }