-
Notifications
You must be signed in to change notification settings - Fork 29
/
maintMaintGrp_service.go
171 lines (136 loc) · 5.07 KB
/
maintMaintGrp_service.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package client
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreatePODMaintenanceGroup(name string, description string, maintMaintGrpattr models.PODMaintenanceGroupAttributes) (*models.PODMaintenanceGroup, error) {
rn := fmt.Sprintf("fabric/maintgrp-%s", name)
parentDn := fmt.Sprintf("uni")
maintMaintGrp := models.NewPODMaintenanceGroup(rn, parentDn, description, maintMaintGrpattr)
err := sm.Save(maintMaintGrp)
return maintMaintGrp, err
}
func (sm *ServiceManager) ReadPODMaintenanceGroup(name string) (*models.PODMaintenanceGroup, error) {
dn := fmt.Sprintf("uni/fabric/maintgrp-%s", name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
maintMaintGrp := models.PODMaintenanceGroupFromContainer(cont)
return maintMaintGrp, nil
}
func (sm *ServiceManager) DeletePODMaintenanceGroup(name string) error {
dn := fmt.Sprintf("uni/fabric/maintgrp-%s", name)
return sm.DeleteByDn(dn, models.MaintmaintgrpClassName)
}
func (sm *ServiceManager) UpdatePODMaintenanceGroup(name string, description string, maintMaintGrpattr models.PODMaintenanceGroupAttributes) (*models.PODMaintenanceGroup, error) {
rn := fmt.Sprintf("fabric/maintgrp-%s", name)
parentDn := fmt.Sprintf("uni")
maintMaintGrp := models.NewPODMaintenanceGroup(rn, parentDn, description, maintMaintGrpattr)
maintMaintGrp.Status = "modified"
err := sm.Save(maintMaintGrp)
return maintMaintGrp, err
}
func (sm *ServiceManager) ListPODMaintenanceGroup() ([]*models.PODMaintenanceGroup, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/maintMaintGrp.json", baseurlStr)
cont, err := sm.GetViaURL(dnUrl)
list := models.PODMaintenanceGroupListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationmaintRsMgrppFromPODMaintenanceGroup(parentDn, tnMaintMaintPName string) error {
dn := fmt.Sprintf("%s/rsmgrpp", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tnMaintMaintPName": "%s","annotation":"orchestrator:terraform"
}
}
}`, "maintRsMgrpp", dn, tnMaintMaintPName))
jsonPayload, err := container.ParseJSON(containerJSON)
if err != nil {
return err
}
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true)
if err != nil {
return err
}
_, _, err = sm.client.Do(req)
if err != nil {
return err
}
return nil
}
func (sm *ServiceManager) ReadRelationmaintRsMgrppFromPODMaintenanceGroup(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "maintRsMgrpp")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "maintRsMgrpp")
if len(contList) > 0 {
dat := models.G(contList[0], "tnMaintMaintPName")
return dat, err
} else {
return nil, err
}
}
// START: Variable/Struct/Fuction Naming per ACI SDK Model Definitions
func (sm *ServiceManager) CreateMaintGrp(name string, description string, maintMaintGrpAttr models.MaintGrpAttributes) (*models.MaintGrp, error) {
rn := fmt.Sprintf("maintgrp-%s", name)
parentDn := fmt.Sprintf("uni/fabric")
maintMaintGrp := models.NewMaintGrp(rn, parentDn, description, maintMaintGrpAttr)
err := sm.Save(maintMaintGrp)
return maintMaintGrp, err
}
func (sm *ServiceManager) ReadMaintGrp(name string) (*models.MaintGrp, error) {
dn := fmt.Sprintf("uni/fabric/maintgrp-%s", name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
maintMaintGrp := models.MaintGrpFromContainer(cont)
return maintMaintGrp, nil
}
func (sm *ServiceManager) DeleteMaintGrp(name string) error {
dn := fmt.Sprintf("uni/fabric/maintgrp-%s", name)
return sm.DeleteByDn(dn, models.MaintMaintGrpClassName)
}
func (sm *ServiceManager) UpdateMaintGrp(name string, description string, maintMaintGrpAttr models.MaintGrpAttributes) (*models.MaintGrp, error) {
rn := fmt.Sprintf("maintgrp-%s", name)
parentDn := fmt.Sprintf("uni/fabric")
maintMaintGrp := models.NewMaintGrp(rn, parentDn, description, maintMaintGrpAttr)
maintMaintGrp.Status = "modified"
err := sm.Save(maintMaintGrp)
return maintMaintGrp, err
}
func (sm *ServiceManager) ListMaintGrp() ([]*models.MaintGrp, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/maintMaintGrp.json", baseurlStr)
cont, err := sm.GetViaURL(dnUrl)
list := models.MaintGrpListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationmaintRsMgrppFromMaintGrp(parentDn, tnMaintMaintPName string) error {
dn := fmt.Sprintf("%s/rsmgrpp", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tnMaintMaintPName": "%s","annotation":"orchestrator:terraform"
}
}
}`, "maintRsMgrpp", dn, tnMaintMaintPName))
jsonPayload, err := container.ParseJSON(containerJSON)
if err != nil {
return err
}
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true)
if err != nil {
return err
}
cont, _, err := sm.client.Do(req)
if err != nil {
return err
}
fmt.Printf("%+v", cont)
return nil
}