Skip to content

Commit

Permalink
[ignore] Move generic functions from resource_mso_schema_site_anp_epg…
Browse files Browse the repository at this point in the history
…_bulk_staticport to utils file
  • Loading branch information
akinross committed Nov 21, 2024
1 parent cda403b commit 4336f1b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
55 changes: 0 additions & 55 deletions mso/resource_mso_schema_site_anp_epg_bulk_staticport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mso
import (
"fmt"
"log"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -585,57 +584,3 @@ func resourceMSOSchemaSiteAnpEpgBulkStaticPortDelete(d *schema.ResourceData, m i
d.SetId("")
return resourceMSOSchemaSiteAnpEpgBulkStaticPortRead(d, m)
}

func getStaticPortPathValues(pathValue string, re *regexp.Regexp) map[string]string {
match := re.FindStringSubmatch(pathValue) //list of matched strings
result := make(map[string]string)
for i, name := range re.SubexpNames() {
if i != 0 && name != "" {
result[name] = match[i]
}
}

return result
}

func setValuesFromPortPath(staticPortMap map[string]interface{}, pathValue string) {

portFexPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/paths-(?P<leafValue>.*)\/extpaths-(?P<fexValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)
vpcFexPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/protpaths-(?P<leafValue>.*)\/extprotpaths-(?P<fexValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)
vpcPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/protpaths-(?P<leafValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)
// dpcPath also handles the port without FEX defined in the path
dpcPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/paths-(?P<leafValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)

matchedMap := make(map[string]string)

if portFexPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, portFexPath)
} else if vpcFexPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, vpcFexPath)
} else if vpcPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, vpcPath)
} else if dpcPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, dpcPath)
}

staticPortMap["pod"] = matchedMap["podValue"]
staticPortMap["leaf"] = matchedMap["leafValue"]
staticPortMap["path"] = matchedMap["pathValue"]
if fexValue, ok := matchedMap["fexValue"]; ok {
staticPortMap["fex"] = fexValue
}

}

func createPortPath(path_type, static_port_pod, static_port_leaf, static_port_fex, static_port_path string) string {

if path_type == "port" && static_port_fex != "" {
return fmt.Sprintf("topology/%s/paths-%s/extpaths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_fex, static_port_path)
} else if path_type == "vpc" && static_port_fex != "" {
return fmt.Sprintf("topology/%s/protpaths-%s/extprotpaths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_fex, static_port_path)
} else if path_type == "vpc" {
return fmt.Sprintf("topology/%s/protpaths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_path)
} else {
return fmt.Sprintf("topology/%s/paths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_path)
}
}
55 changes: 55 additions & 0 deletions mso/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"regexp"
"strings"

"github.com/ciscoecosystem/mso-go-client/client"
Expand Down Expand Up @@ -240,3 +241,57 @@ func getSchemaIdFromName(msoClient *client.Client, name string) (string, error)

return "", fmt.Errorf("Schema of specified name not found")
}

func getStaticPortPathValues(pathValue string, re *regexp.Regexp) map[string]string {
match := re.FindStringSubmatch(pathValue) //list of matched strings
result := make(map[string]string)
for i, name := range re.SubexpNames() {
if i != 0 && name != "" {
result[name] = match[i]
}
}

return result
}

func setValuesFromPortPath(staticPortMap map[string]interface{}, pathValue string) {

portFexPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/paths-(?P<leafValue>.*)\/extpaths-(?P<fexValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)
vpcFexPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/protpaths-(?P<leafValue>.*)\/extprotpaths-(?P<fexValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)
vpcPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/protpaths-(?P<leafValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)
// dpcPath also handles the port without FEX defined in the path
dpcPath := regexp.MustCompile(`(topology\/(?P<podValue>.*)\/paths-(?P<leafValue>.*)\/pathep-\[(?P<pathValue>.*)\])`)

matchedMap := make(map[string]string)

if portFexPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, portFexPath)
} else if vpcFexPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, vpcFexPath)
} else if vpcPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, vpcPath)
} else if dpcPath.MatchString(pathValue) {
matchedMap = getStaticPortPathValues(pathValue, dpcPath)
}

staticPortMap["pod"] = matchedMap["podValue"]
staticPortMap["leaf"] = matchedMap["leafValue"]
staticPortMap["path"] = matchedMap["pathValue"]
if fexValue, ok := matchedMap["fexValue"]; ok {
staticPortMap["fex"] = fexValue
}

}

func createPortPath(path_type, static_port_pod, static_port_leaf, static_port_fex, static_port_path string) string {

if path_type == "port" && static_port_fex != "" {
return fmt.Sprintf("topology/%s/paths-%s/extpaths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_fex, static_port_path)
} else if path_type == "vpc" && static_port_fex != "" {
return fmt.Sprintf("topology/%s/protpaths-%s/extprotpaths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_fex, static_port_path)
} else if path_type == "vpc" {
return fmt.Sprintf("topology/%s/protpaths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_path)
} else {
return fmt.Sprintf("topology/%s/paths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_path)
}
}

0 comments on commit 4336f1b

Please sign in to comment.