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

Implementing creation, listing, and deletion of firewall rules for QEMU #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/%d", 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
Expand Down
Loading