Files
opentf/vendor/github.com/joyent/gosdc/cloudapi/machine_firewall.go
James Nugent e70764f64d provider/triton: New provider for Joyent Triton
This brings across the following resources for Triton from the
joyent/triton-terraform repository, and converts them to the canonical
Terraform style, introducing Terraform-style documentation and
acceptance tests which run against the live API rather than the local
APIs:

- triton_firewall_rule
- triton_machine
- triton_key
2016-03-20 20:15:17 +00:00

53 lines
1.8 KiB
Go

package cloudapi
import (
"fmt"
"net/http"
"github.com/joyent/gocommon/client"
"github.com/joyent/gocommon/errors"
)
// ListMachineFirewallRules lists all the firewall rules for the specified machine.
// See API docs: http://apidocs.joyent.com/cloudapi/#ListMachineFirewallRules
func (c *Client) ListMachineFirewallRules(machineID string) ([]FirewallRule, error) {
var resp []FirewallRule
req := request{
method: client.GET,
url: makeURL(apiMachines, machineID, apiFirewallRules),
resp: &resp,
}
if _, err := c.sendRequest(req); err != nil {
return nil, errors.Newf(err, "failed to get list of firewall rules for machine with id %s", machineID)
}
return resp, nil
}
// EnableFirewallMachine enables the firewall for the specified machine.
// See API docs: http://apidocs.joyent.com/cloudapi/#EnableMachineFirewall
func (c *Client) EnableFirewallMachine(machineID string) error {
req := request{
method: client.POST,
url: fmt.Sprintf("%s/%s?action=%s", apiMachines, machineID, actionEnableFw),
expectedStatus: http.StatusAccepted,
}
if _, err := c.sendRequest(req); err != nil {
return errors.Newf(err, "failed to enable firewall on machine with id: %s", machineID)
}
return nil
}
// DisableFirewallMachine disables the firewall for the specified machine.
// See API docs: http://apidocs.joyent.com/cloudapi/#DisableMachineFirewall
func (c *Client) DisableFirewallMachine(machineID string) error {
req := request{
method: client.POST,
url: fmt.Sprintf("%s/%s?action=%s", apiMachines, machineID, actionDisableFw),
expectedStatus: http.StatusAccepted,
}
if _, err := c.sendRequest(req); err != nil {
return errors.Newf(err, "failed to disable firewall on machine with id: %s", machineID)
}
return nil
}