-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloud_ips.go
81 lines (72 loc) · 2.72 KB
/
cloud_ips.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package brightbox
import (
"context"
"path"
"github.com/brightbox/gobrightbox/v2/enums/cloudipstatus"
"github.com/brightbox/gobrightbox/v2/enums/mode"
"github.com/brightbox/gobrightbox/v2/enums/transportprotocol"
)
//go:generate ./generate_enum cloudipstatus mapped unmapped
//go:generate ./generate_enum mode nat route
//go:generate ./generate_enum transportprotocol tcp udp
// CloudIP represents a Cloud IP
// https://api.gb1.brightbox.com/1.0/#cloud_ip
type CloudIP struct {
ResourceRef
ID string
Name string
PublicIP string `json:"public_ip"`
PublicIPv4 string `json:"public_ipv4"`
PublicIPv6 string `json:"public_ipv6"`
Status cloudipstatus.Enum `json:"status"`
ReverseDNS string `json:"reverse_dns"`
Fqdn string
Mode mode.Enum
Account *Account
Interface *Interface
Server *Server
ServerGroup *ServerGroup `json:"server_group"`
PortTranslators []PortTranslator `json:"port_translators"`
LoadBalancer *LoadBalancer `json:"load_balancer"`
DatabaseServer *DatabaseServer `json:"database_server"`
}
// PortTranslator represents a port translator on a Cloud IP
type PortTranslator struct {
Incoming uint16 `json:"incoming"`
Outgoing uint16 `json:"outgoing"`
Protocol transportprotocol.Enum `json:"protocol,omitempty"`
}
// CloudIPOptions is used in conjunction with CreateCloudIP and UpdateCloudIP to
// create and update cloud IPs.
type CloudIPOptions struct {
ID string `json:"-"`
ReverseDNS *string `json:"reverse_dns,omitempty"`
Mode mode.Enum `json:"mode,omitempty"`
Name *string `json:"name,omitempty"`
PortTranslators []PortTranslator `json:"port_translators,omitempty"`
}
// CloudIPAttachment is used in conjunction with MapCloudIP to specify
// the destination the CloudIP should be mapped to
type CloudIPAttachment struct {
Destination string `json:"destination"`
}
// MapCloudIP issues a request to map the cloud ip to the destination. The
// destination can be an identifier of any resource capable of receiving a Cloud
// IP, such as a server interface, a load balancer, or a cloud sql instace.
func (c *Client) MapCloudIP(ctx context.Context, identifier string, attachment CloudIPAttachment) (*CloudIP, error) {
return apiPost[CloudIP](
ctx,
c,
path.Join(cloudipAPIPath, identifier, "map"),
attachment,
)
}
// UnMapCloudIP issues a request to unmap the cloud ip.
func (c *Client) UnMapCloudIP(ctx context.Context, identifier string) (*CloudIP, error) {
return apiPost[CloudIP](
ctx,
c,
path.Join(cloudipAPIPath, identifier, "unmap"),
nil,
)
}