-
Notifications
You must be signed in to change notification settings - Fork 29
/
fileRemotePath_service.go
140 lines (123 loc) · 4.35 KB
/
fileRemotePath_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
package client
import (
"fmt"
"log"
"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
)
func (sm *ServiceManager) CreateRemotePathofaFile(name string, description string, nameAlias string, fileRemotePathAttr models.RemotePathofaFileAttributes) (*models.RemotePathofaFile, error) {
rn := fmt.Sprintf(models.RnfileRemotePath, name)
parentDn := fmt.Sprintf(models.ParentDnfileRemotePath)
fileRemotePath := models.NewRemotePathofaFile(rn, parentDn, description, nameAlias, fileRemotePathAttr)
err := sm.Save(fileRemotePath)
return fileRemotePath, err
}
func (sm *ServiceManager) ReadRemotePathofaFile(name string) (*models.RemotePathofaFile, error) {
dn := fmt.Sprintf(models.DnfileRemotePath, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
fileRemotePath := models.RemotePathofaFileFromContainer(cont)
return fileRemotePath, nil
}
func (sm *ServiceManager) DeleteRemotePathofaFile(name string) error {
dn := fmt.Sprintf(models.DnfileRemotePath, name)
return sm.DeleteByDn(dn, models.FileremotepathClassName)
}
func (sm *ServiceManager) UpdateRemotePathofaFile(name string, description string, nameAlias string, fileRemotePathAttr models.RemotePathofaFileAttributes) (*models.RemotePathofaFile, error) {
rn := fmt.Sprintf(models.RnfileRemotePath, name)
parentDn := fmt.Sprintf(models.ParentDnfileRemotePath)
fileRemotePath := models.NewRemotePathofaFile(rn, parentDn, description, nameAlias, fileRemotePathAttr)
fileRemotePath.Status = "modified"
err := sm.Save(fileRemotePath)
return fileRemotePath, err
}
func (sm *ServiceManager) ListRemotePathofaFile() ([]*models.RemotePathofaFile, error) {
dnUrl := fmt.Sprintf("%s/uni/fabric/fileRemotePath.json", models.BaseurlStr)
cont, err := sm.GetViaURL(dnUrl)
list := models.RemotePathofaFileListFromContainer(cont)
return list, err
}
func (sm *ServiceManager) CreateRelationfileRsARemoteHostToEpg(parentDn, annotation, tDn string) error {
dn := fmt.Sprintf("%s/rsARemoteHostToEpg", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tDn": "%s"
}
}
}`, "fileRsARemoteHostToEpg", dn, annotation, tDn))
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
}
log.Printf("%+v", cont)
return nil
}
func (sm *ServiceManager) DeleteRelationfileRsARemoteHostToEpg(parentDn string) error {
dn := fmt.Sprintf("%s/rsARemoteHostToEpg", parentDn)
return sm.DeleteByDn(dn, "fileRsARemoteHostToEpg")
}
func (sm *ServiceManager) ReadRelationfileRsARemoteHostToEpg(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fileRsARemoteHostToEpg")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "fileRsARemoteHostToEpg")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}
func (sm *ServiceManager) CreateRelationfileRsARemoteHostToEpp(parentDn, annotation, tDn string) error {
dn := fmt.Sprintf("%s/rsARemoteHostToEpp", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tDn": "%s"
}
}
}`, "fileRsARemoteHostToEpp", dn, annotation, tDn))
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
}
log.Printf("%+v", cont)
return nil
}
func (sm *ServiceManager) DeleteRelationfileRsARemoteHostToEpp(parentDn string) error {
dn := fmt.Sprintf("%s/rsARemoteHostToEpp", parentDn)
return sm.DeleteByDn(dn, "fileRsARemoteHostToEpp")
}
func (sm *ServiceManager) ReadRelationfileRsARemoteHostToEpp(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fileRsARemoteHostToEpp")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "fileRsARemoteHostToEpp")
if len(contList) > 0 {
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
}
}