| 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 |
|
| 12 |
|
| 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 |
|
| 27 |
|
| 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 |
|
| 41 |
|
| 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 |
} |