Debian Codegraph @

cloudapi/machine_firewall.go

raw symbols SCIP
1 package cloudapi
2
3 import (
4 "fmt"
5 "net/http"
6
7 "github.com/joyent/gocommon/client"
8 "github.com/joyent/gocommon/errors"
9 )
10
11 // ListMachineFirewallRules lists all the firewall rules for the specified machine.
12 // See API docs: http://apidocs.joyent.com/cloudapi/#ListMachineFirewallRules
13 func (c *Client) ListMachineFirewallRules(machineID string) ([]FirewallRule, error) {
14 var resp []FirewallRule
15 req := request{
16 method: client.GET,
17 url: makeURL(apiMachines, machineID, apiFirewallRules),
18 resp: &resp,
19 }
20 if _, err := c.sendRequest(req); err != nil {
21 return nil, errors.Newf(err, "failed to get list of firewall rules for machine with id %s", machineID)
22 }
23 return resp, nil
24 }
25
26 // EnableFirewallMachine enables the firewall for the specified machine.
27 // See API docs: http://apidocs.joyent.com/cloudapi/#EnableMachineFirewall
28 func (c *Client) EnableFirewallMachine(machineID string) error {
29 req := request{
30 method: client.POST,
31 url: fmt.Sprintf("%s/%s?action=%s", apiMachines, machineID, actionEnableFw),
32 expectedStatus: http.StatusAccepted,
33 }
34 if _, err := c.sendRequest(req); err != nil {
35 return errors.Newf(err, "failed to enable firewall on machine with id: %s", machineID)
36 }
37 return nil
38 }
39
40 // DisableFirewallMachine disables the firewall for the specified machine.
41 // See API docs: http://apidocs.joyent.com/cloudapi/#DisableMachineFirewall
42 func (c *Client) DisableFirewallMachine(machineID string) error {
43 req := request{
44 method: client.POST,
45 url: fmt.Sprintf("%s/%s?action=%s", apiMachines, machineID, actionDisableFw),
46 expectedStatus: http.StatusAccepted,
47 }
48 if _, err := c.sendRequest(req); err != nil {
49 return errors.Newf(err, "failed to disable firewall on machine with id: %s", machineID)
50 }
51 return nil
52 }