-
Notifications
You must be signed in to change notification settings - Fork 2
/
floating_ips.go
56 lines (47 loc) · 1.35 KB
/
floating_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
package dbaas
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// FloatingIPsOpts represents create|delete options for creating|deleting
// Floating IP in|from existed cluster.
type FloatingIPsOpts struct {
InstanceID string `json:"instance_id"`
}
const FloatingIPsURI = "/floating-ips"
// CreateFloatingIP creates FloatingIP for provided instance of an existing datastore.
func (api *API) CreateFloatingIP(ctx context.Context, opts FloatingIPsOpts) error {
floatingIPsOpts := struct {
FloatingIP FloatingIPsOpts `json:"floating_ip"`
}{
FloatingIP: opts,
}
requestBody, err := json.Marshal(floatingIPsOpts)
if err != nil {
return fmt.Errorf("Error marshalling params to JSON, %w", err)
}
_, err = api.makeRequest(ctx, http.MethodPost, FloatingIPsURI, requestBody)
if err != nil {
return err
}
return nil
}
// DeleteFloatingIP deletes FloatingIP from provided instance of an existing datastore.
func (api *API) DeleteFloatingIP(ctx context.Context, opts FloatingIPsOpts) error {
floatingIPsOpts := struct {
FloatingIP FloatingIPsOpts `json:"floating_ip"`
}{
FloatingIP: opts,
}
requestBody, err := json.Marshal(floatingIPsOpts)
if err != nil {
return fmt.Errorf("Error marshalling params to JSON, %w", err)
}
_, err = api.makeRequest(ctx, http.MethodDelete, FloatingIPsURI, requestBody)
if err != nil {
return err
}
return nil
}