Skip to content

Commit e3a367e

Browse files
committed
modification to mso_rest, site selector and its test file
1 parent 7a7c7b0 commit e3a367e

5 files changed

+199
-178
lines changed

mso/resource_mso_rest.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ func resourceMSORest() *schema.Resource {
3737
Type: schema.TypeString,
3838
Required: true,
3939
},
40+
41+
"ignore_on_destroy": &schema.Schema{
42+
Type: schema.TypeBool,
43+
Required: true,
44+
},
45+
46+
"schema_id": &schema.Schema{
47+
Type: schema.TypeString,
48+
Optional: true,
49+
ForceNew: true,
50+
},
4051
}),
4152
}
4253
}
@@ -93,22 +104,26 @@ func resourceMSORestUpdate(d *schema.ResourceData, m interface{}) error {
93104
}
94105

95106
func resourceMSORestDelete(d *schema.ResourceData, m interface{}) error {
96-
var method, path, payload string
97-
path = d.Get("path").(string)
98-
payload = d.Get("payload").(string)
99-
if tempVar, ok := d.GetOk("method"); ok {
100-
method = tempVar.(string)
101-
} else {
102-
method = "DELETE"
103-
}
104-
if !contains(HTTP_METHODS, method) {
105-
return fmt.Errorf("Invalid method %s passed", method)
106-
}
107-
msoClient := m.(*client.Client)
108-
_, err := MakeRestRequest(msoClient, path, method, payload)
107+
var ignore_on_destroy = d.Get("ignore_on_destroy").(bool)
108+
if ignore_on_destroy == false {
109+
var method, path, payload string
110+
path = d.Get("path").(string)
111+
payload = d.Get("payload").(string)
112+
if tempVar, ok := d.GetOk("method"); ok {
113+
method = tempVar.(string)
114+
} else {
115+
method = "DELETE"
116+
}
117+
if !contains(HTTP_METHODS, method) {
118+
return fmt.Errorf("Invalid method %s passed", method)
119+
}
109120

110-
if err != nil {
111-
return err
121+
msoClient := m.(*client.Client)
122+
_, err := MakeRestRequest(msoClient, path, method, payload)
123+
124+
if err != nil {
125+
return err
126+
}
112127
}
113128
d.SetId("")
114129
return nil

mso/resource_mso_schema_site_anp_epg_selector.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,29 @@ func resourceMSOSchemaSiteAnpEpgSelector() *schema.Resource {
104104
}
105105
}
106106

107+
var importReadSchemaID, importReadSiteID, importReadTemplate, importReadANP, importReadEPG string
108+
107109
func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
108110
log.Printf("[DEBUG] %s: Beginning Import", d.Id())
109111
found := false
110112
msoClient := m.(*client.Client)
111-
get_attribute := strings.Split(d.Id(), "/")
112-
schemaID := get_attribute[0]
113-
siteID := get_attribute[2]
114-
template := get_attribute[4]
115-
anpName := get_attribute[6]
116-
epgName := get_attribute[8]
117-
name := get_attribute[10]
118-
113+
var schemaID, siteID, template, anpName, epgName, name string
114+
if !strings.Contains(d.Id(), "/") {
115+
name = d.Id()
116+
schemaID = importReadSchemaID
117+
siteID = importReadSiteID
118+
template = importReadTemplate
119+
anpName = importReadANP
120+
epgName = importReadEPG
121+
} else {
122+
get_attribute := strings.Split(d.Id(), "/")
123+
schemaID = get_attribute[0]
124+
siteID = get_attribute[2]
125+
template = get_attribute[4]
126+
anpName = get_attribute[6]
127+
epgName = get_attribute[8]
128+
name = get_attribute[10]
129+
}
119130
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
120131
if err != nil {
121132
return nil, err
@@ -180,7 +191,7 @@ func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{
180191
currentName := models.StripQuotes(selectorCont.S("name").String())
181192
if currentName == name {
182193
found = true
183-
d.SetId(name)
194+
d.SetId(currentName)
184195
d.Set("name", currentName)
185196
exps := selectorCont.S("expressions").Data().([]interface{})
186197

@@ -357,14 +368,17 @@ func resourceSchemaSiteApnEpgSelectorUpdate(d *schema.ResourceData, m interface{
357368
func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{}) error {
358369
found := false
359370
msoClient := m.(*client.Client)
360-
361371
dn := d.Id()
362372
schemaID := d.Get("schema_id").(string)
363373
siteID := d.Get("site_id").(string)
364374
template := d.Get("template_name").(string)
365375
anpName := d.Get("anp_name").(string)
366376
epgName := d.Get("epg_name").(string)
367-
377+
importReadSchemaID = schemaID
378+
importReadSiteID = siteID
379+
importReadTemplate = template
380+
importReadANP = anpName
381+
importReadEPG = epgName
368382
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
369383
if err != nil {
370384
return err
@@ -429,7 +443,6 @@ func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{})
429443
currentName := models.StripQuotes(selectorCont.S("name").String())
430444
if currentName == dn {
431445
found = true
432-
d.SetId(dn)
433446
d.Set("name", currentName)
434447
exps := selectorCont.S("expressions").Data().([]interface{})
435448

0 commit comments

Comments
 (0)