Skip to content

Commit 5965b96

Browse files
Ap subnet (#181)
* fvap, l3extsubnet and docs update * fvcep datasource and l3extsubnet updated
1 parent 94a6b8d commit 5965b96

13 files changed

+138
-79
lines changed

aci/data_source_aci_fvcep.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ func dataSourceAciClientEndPoint() *schema.Resource {
107107
Optional: true,
108108
Computed: true,
109109
},
110+
111+
"endpoint_path": &schema.Schema{
112+
Type: schema.TypeList,
113+
Optional: true,
114+
Computed: true,
115+
Elem: &schema.Schema{
116+
Type: schema.TypeString,
117+
},
118+
},
110119
},
111120
},
112121
},
@@ -162,6 +171,27 @@ func extractInfo(con *container.Container) (obj map[string]interface{}, dn strin
162171
return infoMap, dnString
163172
}
164173

174+
func extractEndpointPaths(cont *container.Container) ([]string, error) {
175+
paths := make([]string, 0, 1)
176+
177+
count, err := cont.ArrayCount("imdata")
178+
if err != nil {
179+
return paths, err
180+
}
181+
182+
for i := 0; i < count; i++ {
183+
pathEpCont, err := cont.ArrayElement(i, "imdata")
184+
if err != nil {
185+
return paths, err
186+
}
187+
188+
tDN := models.StripQuotes(pathEpCont.S("fvRsCEpToPathEp", "attributes", "tDn").String())
189+
190+
paths = append(paths, tDN)
191+
}
192+
return paths, nil
193+
}
194+
165195
func getRemoteClientEndPoint(client *client.Client, query string) (objMap []interface{}, objdns []string, err error) {
166196
baseURL := "/api/node/class"
167197

@@ -193,6 +223,15 @@ func getRemoteClientEndPoint(client *client.Client, query string) (objMap []inte
193223

194224
objMap, dn := extractInfo(clientEndPointCont.S("fvCEp", "attributes"))
195225
if dn != "" {
226+
durl := fmt.Sprintf("%s/%s/fvRsCEpToPathEp.json", baseURL, dn)
227+
cepToPathEpCont, err := client.GetViaURL(durl)
228+
if err == nil {
229+
endpointPaths, err := extractEndpointPaths(cepToPathEpCont)
230+
if err == nil {
231+
objMap["endpoint_path"] = endpointPaths
232+
}
233+
}
234+
196235
objects = append(objects, objMap)
197236
dns = append(dns, dn)
198237
}

aci/data_source_aci_fvnsencapblk.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func dataSourceAciRanges() *schema.Resource {
2020
Required: true,
2121
},
2222

23-
"_from": &schema.Schema{
23+
"from": &schema.Schema{
2424
Type: schema.TypeString,
2525
Required: true,
2626
},
@@ -36,12 +36,6 @@ func dataSourceAciRanges() *schema.Resource {
3636
Computed: true,
3737
},
3838

39-
"from": &schema.Schema{
40-
Type: schema.TypeString,
41-
Optional: true,
42-
Computed: true,
43-
},
44-
4539
"name_alias": &schema.Schema{
4640
Type: schema.TypeString,
4741
Optional: true,
@@ -60,11 +54,11 @@ func dataSourceAciRanges() *schema.Resource {
6054
func dataSourceAciRangesRead(d *schema.ResourceData, m interface{}) error {
6155
aciClient := m.(*client.Client)
6256

63-
_from := d.Get("_from").(string)
57+
from := d.Get("from").(string)
6458

6559
to := d.Get("to").(string)
6660

67-
rn := fmt.Sprintf("from-[%s]-to-[%s]", _from, to)
61+
rn := fmt.Sprintf("from-[%s]-to-[%s]", from, to)
6862
VLANPoolDn := d.Get("vlan_pool_dn").(string)
6963

7064
dn := fmt.Sprintf("%s/%s", VLANPoolDn, rn)

aci/data_source_aci_l3extsubnet.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ func dataSourceAciL3ExtSubnet() *schema.Resource {
3838
},
3939

4040
"scope": &schema.Schema{
41-
Type: schema.TypeString,
41+
Type: schema.TypeList,
4242
Optional: true,
4343
Computed: true,
44+
Elem: &schema.Schema{
45+
Type: schema.TypeString,
46+
},
4447
},
4548
}),
4649
}
@@ -56,12 +59,12 @@ func dataSourceAciL3ExtSubnetRead(d *schema.ResourceData, m interface{}) error {
5659

5760
dn := fmt.Sprintf("%s/%s", ExternalNetworkInstanceProfileDn, rn)
5861

59-
l3extSubnet, err := getRemoteSubnet(aciClient, dn)
62+
l3extSubnet, err := getRemoteL3ExtSubnet(aciClient, dn)
6063

6164
if err != nil {
6265
return err
6366
}
6467
d.SetId(dn)
65-
setSubnetAttributes(l3extSubnet, d)
68+
setL3ExtSubnetAttributes(l3extSubnet, d)
6669
return nil
6770
}

aci/resource_aci_fvap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func resourceAciApplicationProfile() *schema.Resource {
5151
"level3",
5252
"level2",
5353
"level1",
54+
"level4",
55+
"level5",
56+
"level6",
5457
}, false),
5558
},
5659

aci/resource_aci_fvnsencapblk.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func resourceAciRanges() *schema.Resource {
3030
ForceNew: true,
3131
},
3232

33-
"_from": &schema.Schema{
33+
"from": &schema.Schema{
3434
Type: schema.TypeString,
3535
Required: true,
3636
ForceNew: true,
@@ -53,12 +53,6 @@ func resourceAciRanges() *schema.Resource {
5353
}, false),
5454
},
5555

56-
"from": &schema.Schema{
57-
Type: schema.TypeString,
58-
Optional: true,
59-
Computed: true,
60-
},
61-
6256
"name_alias": &schema.Schema{
6357
Type: schema.TypeString,
6458
Optional: true,
@@ -102,10 +96,6 @@ func setRangesAttributes(fvnsEncapBlk *models.Ranges, d *schema.ResourceData) *s
10296
}
10397
fvnsEncapBlkMap, _ := fvnsEncapBlk.ToMap()
10498

105-
d.Set("_from", fvnsEncapBlkMap["from"])
106-
107-
d.Set("to", fvnsEncapBlkMap["to"])
108-
10999
d.Set("alloc_mode", fvnsEncapBlkMap["allocMode"])
110100
d.Set("annotation", fvnsEncapBlkMap["annotation"])
111101
d.Set("from", fvnsEncapBlkMap["from"])
@@ -143,7 +133,7 @@ func resourceAciRangesCreate(d *schema.ResourceData, m interface{}) error {
143133
aciClient := m.(*client.Client)
144134
desc := d.Get("description").(string)
145135

146-
_from := d.Get("_from").(string)
136+
from := d.Get("from").(string)
147137

148138
to := d.Get("to").(string)
149139

@@ -170,15 +160,15 @@ func resourceAciRangesCreate(d *schema.ResourceData, m interface{}) error {
170160
if To, ok := d.GetOk("to"); ok {
171161
fvnsEncapBlkAttr.To = To.(string)
172162
}
173-
fvnsEncapBlk := models.NewRanges(fmt.Sprintf("from-[%s]-to-[%s]", _from, to), VLANPoolDn, desc, fvnsEncapBlkAttr)
163+
fvnsEncapBlk := models.NewRanges(fmt.Sprintf("from-[%s]-to-[%s]", from, to), VLANPoolDn, desc, fvnsEncapBlkAttr)
174164

175165
err := aciClient.Save(fvnsEncapBlk)
176166
if err != nil {
177167
return err
178168
}
179169
d.Partial(true)
180170

181-
d.SetPartial("_from")
171+
d.SetPartial("from")
182172

183173
d.SetPartial("to")
184174

@@ -196,7 +186,7 @@ func resourceAciRangesUpdate(d *schema.ResourceData, m interface{}) error {
196186
aciClient := m.(*client.Client)
197187
desc := d.Get("description").(string)
198188

199-
_from := d.Get("_from").(string)
189+
from := d.Get("from").(string)
200190

201191
to := d.Get("to").(string)
202192

@@ -223,7 +213,7 @@ func resourceAciRangesUpdate(d *schema.ResourceData, m interface{}) error {
223213
if To, ok := d.GetOk("to"); ok {
224214
fvnsEncapBlkAttr.To = To.(string)
225215
}
226-
fvnsEncapBlk := models.NewRanges(fmt.Sprintf("from-[%s]-to-[%s]", _from, to), VLANPoolDn, desc, fvnsEncapBlkAttr)
216+
fvnsEncapBlk := models.NewRanges(fmt.Sprintf("from-[%s]-to-[%s]", from, to), VLANPoolDn, desc, fvnsEncapBlkAttr)
227217

228218
fvnsEncapBlk.Status = "modified"
229219

@@ -234,7 +224,7 @@ func resourceAciRangesUpdate(d *schema.ResourceData, m interface{}) error {
234224
}
235225
d.Partial(true)
236226

237-
d.SetPartial("_from")
227+
d.SetPartial("from")
238228

239229
d.SetPartial("to")
240230

aci/resource_aci_fvnsencapblk_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,15 @@ func testAccCheckAciRangesConfig_basic(description string) string {
6666
return fmt.Sprintf(`
6767
6868
resource "aci_ranges" "fooranges" {
69-
vlan_pool_dn = "${aci_vlan_pool.example.id}"
69+
vlan_pool_dn = "${aci_vlan_pool.example.id}"
7070
description = "%s"
71-
72-
_from = "example"
73-
71+
from = "example"
7472
to = "example"
75-
alloc_mode = "static"
76-
annotation = "example"
77-
from = "example"
78-
name_alias = "example"
79-
role = "external"
80-
}
73+
alloc_mode = "static"
74+
annotation = "example"
75+
name_alias = "example"
76+
role = "external"
77+
}
8178
`, description)
8279
}
8380

@@ -137,7 +134,7 @@ func testAccCheckAciRangesAttributes(description string, ranges *models.Ranges)
137134
}
138135

139136
if "example" != ranges.From {
140-
return fmt.Errorf("Bad ranges _from %s", ranges.From)
137+
return fmt.Errorf("Bad ranges from %s", ranges.From)
141138
}
142139

143140
if "example" != ranges.To {
@@ -152,10 +149,6 @@ func testAccCheckAciRangesAttributes(description string, ranges *models.Ranges)
152149
return fmt.Errorf("Bad ranges annotation %s", ranges.Annotation)
153150
}
154151

155-
if "example" != ranges.From {
156-
return fmt.Errorf("Bad ranges from %s", ranges.From)
157-
}
158-
159152
if "example" != ranges.NameAlias {
160153
return fmt.Errorf("Bad ranges name_alias %s", ranges.NameAlias)
161154
}

aci/resource_aci_l3extsubnet.go

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package aci
33
import (
44
"fmt"
55
"log"
6+
"reflect"
7+
"sort"
8+
"strings"
69

710
"github.com/ciscoecosystem/aci-go-client/client"
811
"github.com/ciscoecosystem/aci-go-client/models"
@@ -54,16 +57,19 @@ func resourceAciL3ExtSubnet() *schema.Resource {
5457
},
5558

5659
"scope": &schema.Schema{
57-
Type: schema.TypeString,
60+
Type: schema.TypeList,
5861
Optional: true,
5962
Computed: true,
60-
ValidateFunc: validation.StringInSlice([]string{
61-
"import-rtctrl",
62-
"export-rtctrl",
63-
"shared-rtctrl",
64-
"import-security",
65-
"shared-security",
66-
}, false),
63+
Elem: &schema.Schema{
64+
Type: schema.TypeString,
65+
ValidateFunc: validation.StringInSlice([]string{
66+
"import-rtctrl",
67+
"export-rtctrl",
68+
"shared-rtctrl",
69+
"import-security",
70+
"shared-security",
71+
}, false),
72+
},
6773
},
6874

6975
"relation_l3ext_rs_subnet_to_profile": &schema.Schema{
@@ -121,7 +127,27 @@ func setL3ExtSubnetAttributes(l3extSubnet *models.L3ExtSubnet, d *schema.Resourc
121127
d.Set("annotation", l3extSubnetMap["annotation"])
122128
d.Set("ip", l3extSubnetMap["ip"])
123129
d.Set("name_alias", l3extSubnetMap["nameAlias"])
124-
d.Set("scope", l3extSubnetMap["scope"])
130+
131+
scpGet := make([]string, 0, 1)
132+
for _, val := range strings.Split(l3extSubnetMap["scope"], ",") {
133+
scpGet = append(scpGet, strings.Trim(val, " "))
134+
}
135+
sort.Strings(scpGet)
136+
if scpInp, ok := d.GetOk("scope"); ok {
137+
scpAct := make([]string, 0, 1)
138+
for _, val := range scpInp.([]interface{}) {
139+
scpAct = append(scpAct, val.(string))
140+
}
141+
sort.Strings(scpAct)
142+
if reflect.DeepEqual(scpAct, scpGet) {
143+
d.Set("scope", d.Get("scope").([]interface{}))
144+
} else {
145+
d.Set("scope", scpGet)
146+
}
147+
} else {
148+
d.Set("scope", scpGet)
149+
}
150+
125151
return d
126152
}
127153

@@ -172,7 +198,12 @@ func resourceAciL3ExtSubnetCreate(d *schema.ResourceData, m interface{}) error {
172198
l3extSubnetAttr.NameAlias = NameAlias.(string)
173199
}
174200
if Scope, ok := d.GetOk("scope"); ok {
175-
l3extSubnetAttr.Scope = Scope.(string)
201+
scpList := make([]string, 0, 1)
202+
for _, val := range Scope.([]interface{}) {
203+
scpList = append(scpList, val.(string))
204+
}
205+
scp := strings.Join(scpList, ",")
206+
l3extSubnetAttr.Scope = scp
176207
}
177208
l3extSubnet := models.NewL3ExtSubnet(fmt.Sprintf("extsubnet-[%s]", ip), ExternalNetworkInstanceProfileDn, desc, l3extSubnetAttr)
178209

@@ -259,7 +290,12 @@ func resourceAciL3ExtSubnetUpdate(d *schema.ResourceData, m interface{}) error {
259290
l3extSubnetAttr.NameAlias = NameAlias.(string)
260291
}
261292
if Scope, ok := d.GetOk("scope"); ok {
262-
l3extSubnetAttr.Scope = Scope.(string)
293+
scpList := make([]string, 0, 1)
294+
for _, val := range Scope.([]interface{}) {
295+
scpList = append(scpList, val.(string))
296+
}
297+
scp := strings.Join(scpList, ",")
298+
l3extSubnetAttr.Scope = scp
263299
}
264300
l3extSubnet := models.NewL3ExtSubnet(fmt.Sprintf("extsubnet-[%s]", ip), ExternalNetworkInstanceProfileDn, desc, l3extSubnetAttr)
265301

aci/resource_aci_l3extsubnet_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func testAccCheckAciL3ExtSubnetConfig_basic(description, aggregate string) strin
7272
aggregate = "%s"
7373
annotation = "tag_ext_subnet"
7474
name_alias = "alias_ext_subnet"
75-
scope = "import-security"
75+
scope = ["import-security"]
7676
}
7777
`, description, aggregate)
7878
}
@@ -148,10 +148,6 @@ func testAccCheckAciL3ExtSubnetAttributes(description, aggregate string, subnet
148148
return fmt.Errorf("Bad subnet name_alias %s", subnet.NameAlias)
149149
}
150150

151-
if "import-security" != subnet.Scope {
152-
return fmt.Errorf("Bad subnet scope %s", subnet.Scope)
153-
}
154-
155151
return nil
156152
}
157153
}

website/docs/d/client_end_point.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ data "aci_client_end_point" "check" {
4646
* `fvcep_objects.epg_name` - parent epg name for matched client end point.
4747
* `fvcep_objects.l2out_name` - parent l2out name for matched client end point.
4848
* `fvcep_objects.instance_profile_name` - parent instance profile name for matched client end point.
49+
* `fvcep_objects.endpoint_path` - list of endpoint paths associated with client end point.

0 commit comments

Comments
 (0)