@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
*/
15
15
16
- package extContracts
16
+ package objApi
17
17
18
18
import (
19
19
"fmt"
@@ -86,10 +86,12 @@ func extContractsGrpValidateAndRegister(epg *contivModel.EndpointGroup,
86
86
}
87
87
88
88
// Cleanup external contracts from an epg.
89
- func CleanupExternalContracts (endpointGroup * contivModel.EndpointGroup ) error {
89
+ func cleanupExternalContracts (endpointGroup * contivModel.EndpointGroup ) error {
90
90
// Cleanup consumed external contracts
91
+ tenant := endpointGroup .TenantName
91
92
for _ , consExtContractsGrp := range endpointGroup .ConsExtContractsGrps {
92
- contractsGrp := contivModel .FindExtContractsGroup (consExtContractsGrp )
93
+ contractsGrpKey := tenant + ":" + consExtContractsGrp
94
+ contractsGrp := contivModel .FindExtContractsGroup (contractsGrpKey )
93
95
err := extContractsGrpDeregister (endpointGroup , contractsGrp , "consumed" )
94
96
if err != nil {
95
97
if contractsGrp != nil {
@@ -101,7 +103,8 @@ func CleanupExternalContracts(endpointGroup *contivModel.EndpointGroup) error {
101
103
102
104
// Cleanup provided external contracts
103
105
for _ , provExtContractsGrp := range endpointGroup .ProvExtContractsGrps {
104
- contractsGrp := contivModel .FindExtContractsGroup (provExtContractsGrp )
106
+ contractsGrpKey := tenant + ":" + provExtContractsGrp
107
+ contractsGrp := contivModel .FindExtContractsGroup (contractsGrpKey )
105
108
err := extContractsGrpDeregister (endpointGroup , contractsGrp , "provided" )
106
109
if err != nil {
107
110
if contractsGrp != nil {
@@ -115,11 +118,13 @@ func CleanupExternalContracts(endpointGroup *contivModel.EndpointGroup) error {
115
118
}
116
119
117
120
// Setup external contracts for an epg.
118
- func SetupExternalContracts (endpointGroup * contivModel.EndpointGroup ,
121
+ func setupExternalContracts (endpointGroup * contivModel.EndpointGroup ,
119
122
consContractsGrps , provContractsGrps []string ) error {
120
123
// Validate presence and register consumed external contracts
124
+ tenant := endpointGroup .TenantName
121
125
for _ , consExtContractsGrp := range consContractsGrps {
122
- contractsGrp := contivModel .FindExtContractsGroup (consExtContractsGrp )
126
+ contractsGrpKey := tenant + ":" + consExtContractsGrp
127
+ contractsGrp := contivModel .FindExtContractsGroup (contractsGrpKey )
123
128
err := extContractsGrpValidateAndRegister (endpointGroup , contractsGrp , "consumed" )
124
129
if err != nil {
125
130
return err
@@ -128,7 +133,8 @@ func SetupExternalContracts(endpointGroup *contivModel.EndpointGroup,
128
133
129
134
// Validate presence and register provided external contracts
130
135
for _ , provExtContractsGrp := range provContractsGrps {
131
- contractsGrp := contivModel .FindExtContractsGroup (provExtContractsGrp )
136
+ contractsGrpKey := tenant + ":" + provExtContractsGrp
137
+ contractsGrp := contivModel .FindExtContractsGroup (contractsGrpKey )
132
138
err := extContractsGrpValidateAndRegister (endpointGroup , contractsGrp , "provided" )
133
139
if err != nil {
134
140
return err
@@ -139,10 +145,42 @@ func SetupExternalContracts(endpointGroup *contivModel.EndpointGroup,
139
145
}
140
146
141
147
// Check if the external contracts are being used by any of the EPGs.
142
- func IsExtContractsGroupUsed (contractsGroup * contivModel.ExtContractsGroup ) bool {
148
+ func isExtContractsGroupUsed (contractsGroup * contivModel.ExtContractsGroup ) bool {
143
149
if len (contractsGroup .LinkSets .EndpointGroups ) > 0 {
144
150
return true
145
151
}
146
152
147
153
return false
148
154
}
155
+
156
+ // ExtContractsGroupCreate creates a new group of external contracts
157
+ func (ac * APIController ) ExtContractsGroupCreate (contractsGroup * contivModel.ExtContractsGroup ) error {
158
+ log .Infof ("Received ExtContractsGroupCreate: %+v" , contractsGroup )
159
+
160
+ // NOTE: Nothing more needs to be done here. This object
161
+ // need not be created in the masterCfg.
162
+
163
+ return nil
164
+ }
165
+
166
+ // ExtContractsGroupUpdate updates an existing group of contract sets
167
+ func (ac * APIController ) ExtContractsGroupUpdate (contractsGroup , params * contivModel.ExtContractsGroup ) error {
168
+ log .Infof ("Received ExtContractsGroupUpdate: %+v, params: %+v" , contractsGroup , params )
169
+ log .Errorf ("Error: external contracts update not supported: %s" , contractsGroup .ContractsGroupName )
170
+
171
+ return core .Errorf ("external contracts update not supported" )
172
+ }
173
+
174
+ // ExtContractsGroupDelete deletes an existing external contracts group
175
+ func (ac * APIController ) ExtContractsGroupDelete (contractsGroup * contivModel.ExtContractsGroup ) error {
176
+ log .Infof ("Received ExtContractsGroupDelete: %+v" , contractsGroup )
177
+
178
+ // At this moment, we let the external contracts to be deleted only
179
+ // if there are no consumers of this external contracts group
180
+ if isExtContractsGroupUsed (contractsGroup ) == true {
181
+ log .Errorf ("Error: External contracts groups is being used: %s" , contractsGroup .ContractsGroupName )
182
+ return core .Errorf ("External contracts group is in-use" )
183
+ }
184
+
185
+ return nil
186
+ }
0 commit comments