-
Notifications
You must be signed in to change notification settings - Fork 1
/
fw_firewall_v1.go
66 lines (52 loc) · 1.82 KB
/
fw_firewall_v1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package viettelidc
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion"
)
// Firewall is an OpenStack firewall.
type Firewall struct {
firewalls.Firewall
routerinsertion.FirewallExt
}
// FirewallCreateOpts represents the attributes used when creating a new firewall.
type FirewallCreateOpts struct {
firewalls.CreateOpts
ValueSpecs map[string]string `json:"value_specs,omitempty"`
}
// ToFirewallCreateMap casts a CreateOptsExt struct to a map.
// It overrides firewalls.ToFirewallCreateMap to add the ValueSpecs field.
func (opts FirewallCreateOpts) ToFirewallCreateMap() (map[string]interface{}, error) {
return BuildRequest(opts, "firewall")
}
// FirewallUpdateOpts.
type FirewallUpdateOpts struct {
firewalls.UpdateOptsBuilder
}
func (opts FirewallUpdateOpts) ToFirewallUpdateMap() (map[string]interface{}, error) {
return BuildRequest(opts, "firewall")
}
func fwFirewallV1RefreshFunc(networkingClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
var fw Firewall
err := firewalls.Get(networkingClient, id).ExtractInto(&fw)
if err != nil {
return nil, "", err
}
return fw, fw.Status, nil
}
}
func fwFirewallV1DeleteFunc(networkingClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
fw, err := firewalls.Get(networkingClient, id).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return "", "DELETED", nil
}
return nil, "", fmt.Errorf("Unexpected error: %s", err)
}
return fw, "DELETING", nil
}
}