Skip to content

Commit

Permalink
modification to mso_rest, site selector and its test file
Browse files Browse the repository at this point in the history
  • Loading branch information
shrsr committed Jul 27, 2021
1 parent 7a7c7b0 commit e3a367e
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 178 deletions.
45 changes: 30 additions & 15 deletions mso/resource_mso_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ func resourceMSORest() *schema.Resource {
Type: schema.TypeString,
Required: true,
},

"ignore_on_destroy": &schema.Schema{
Type: schema.TypeBool,
Required: true,
},

"schema_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
}),
}
}
Expand Down Expand Up @@ -93,22 +104,26 @@ func resourceMSORestUpdate(d *schema.ResourceData, m interface{}) error {
}

func resourceMSORestDelete(d *schema.ResourceData, m interface{}) error {
var method, path, payload string
path = d.Get("path").(string)
payload = d.Get("payload").(string)
if tempVar, ok := d.GetOk("method"); ok {
method = tempVar.(string)
} else {
method = "DELETE"
}
if !contains(HTTP_METHODS, method) {
return fmt.Errorf("Invalid method %s passed", method)
}
msoClient := m.(*client.Client)
_, err := MakeRestRequest(msoClient, path, method, payload)
var ignore_on_destroy = d.Get("ignore_on_destroy").(bool)
if ignore_on_destroy == false {
var method, path, payload string
path = d.Get("path").(string)
payload = d.Get("payload").(string)
if tempVar, ok := d.GetOk("method"); ok {
method = tempVar.(string)
} else {
method = "DELETE"
}
if !contains(HTTP_METHODS, method) {
return fmt.Errorf("Invalid method %s passed", method)
}

if err != nil {
return err
msoClient := m.(*client.Client)
_, err := MakeRestRequest(msoClient, path, method, payload)

if err != nil {
return err
}
}
d.SetId("")
return nil
Expand Down
37 changes: 25 additions & 12 deletions mso/resource_mso_schema_site_anp_epg_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,29 @@ func resourceMSOSchemaSiteAnpEpgSelector() *schema.Resource {
}
}

var importReadSchemaID, importReadSiteID, importReadTemplate, importReadANP, importReadEPG string

func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
log.Printf("[DEBUG] %s: Beginning Import", d.Id())
found := false
msoClient := m.(*client.Client)
get_attribute := strings.Split(d.Id(), "/")
schemaID := get_attribute[0]
siteID := get_attribute[2]
template := get_attribute[4]
anpName := get_attribute[6]
epgName := get_attribute[8]
name := get_attribute[10]

var schemaID, siteID, template, anpName, epgName, name string
if !strings.Contains(d.Id(), "/") {
name = d.Id()
schemaID = importReadSchemaID
siteID = importReadSiteID
template = importReadTemplate
anpName = importReadANP
epgName = importReadEPG
} else {
get_attribute := strings.Split(d.Id(), "/")
schemaID = get_attribute[0]
siteID = get_attribute[2]
template = get_attribute[4]
anpName = get_attribute[6]
epgName = get_attribute[8]
name = get_attribute[10]
}
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
if err != nil {
return nil, err
Expand Down Expand Up @@ -180,7 +191,7 @@ func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{
currentName := models.StripQuotes(selectorCont.S("name").String())
if currentName == name {
found = true
d.SetId(name)
d.SetId(currentName)
d.Set("name", currentName)
exps := selectorCont.S("expressions").Data().([]interface{})

Expand Down Expand Up @@ -357,14 +368,17 @@ func resourceSchemaSiteApnEpgSelectorUpdate(d *schema.ResourceData, m interface{
func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{}) error {
found := false
msoClient := m.(*client.Client)

dn := d.Id()
schemaID := d.Get("schema_id").(string)
siteID := d.Get("site_id").(string)
template := d.Get("template_name").(string)
anpName := d.Get("anp_name").(string)
epgName := d.Get("epg_name").(string)

importReadSchemaID = schemaID
importReadSiteID = siteID
importReadTemplate = template
importReadANP = anpName
importReadEPG = epgName
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
if err != nil {
return err
Expand Down Expand Up @@ -429,7 +443,6 @@ func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{})
currentName := models.StripQuotes(selectorCont.S("name").String())
if currentName == dn {
found = true
d.SetId(dn)
d.Set("name", currentName)
exps := selectorCont.S("expressions").Data().([]interface{})

Expand Down
Loading

0 comments on commit e3a367e

Please sign in to comment.