This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vrf.go
68 lines (56 loc) · 1.59 KB
/
vrf.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
package goh4
import (
"encoding/json"
"fmt"
)
// VRF Structure holding a VRF
type VRF struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TenantID int `json:"tenant_id"`
SwitchVRFs []string `json:"switch_vrfs,omitempty"`
ApplyCollectionRules bool `json:"apply_monitoring_rules,string,omitempty"`
Scope *Scope `json:"-"`
}
// AddVRF Create a new VRF
func (h *H4) AddVRF(v *VRF) error {
jsonStr, err := json.Marshal(&v)
if err != nil {
return fmt.Errorf("Error Marshalling VRF: %s", err.Error())
}
postResp, err := h.Post("/vrfs", fmt.Sprintf("%s", jsonStr))
if err != nil {
return fmt.Errorf("POST error: %s / POST: %s", err.Error(), jsonStr)
}
err = json.Unmarshal(postResp, &v)
if err != nil {
return fmt.Errorf("Error unmarshalling JSON: %s / JSON: %s", err.Error(), postResp)
}
scope, err := h.GetRootScope(v.ID)
if err != nil {
return err
}
v.Scope = scope
return nil
}
// GetVRF Get all VRF
func (h *H4) GetVRF() ([]VRF, error) {
getResp, err := h.Get("/vrfs")
if err != nil {
return nil, fmt.Errorf("GET error: %s / GET: %s", err.Error(), getResp)
}
var jsonResp []VRF
err = json.Unmarshal(getResp, &jsonResp)
if err != nil {
return nil, fmt.Errorf("Error unmarshalling JSON: %s / JSON: %s", err.Error(), getResp)
}
return jsonResp, nil
}
// DeleteVRF Delete VRF
func (h *H4) DeleteVRF(vrfID int) error {
err := h.Delete(fmt.Sprintf("/vrfs/%d", vrfID), "")
if err != nil {
return fmt.Errorf("Error deleting vrf %d: %s", vrfID, err)
}
return nil
}