From 4336f1b7a5b5672607471fe2362f4ed4a28ec06a Mon Sep 17 00:00:00 2001
From: akinross <akinross@cisco.com>
Date: Thu, 21 Nov 2024 16:31:06 +0100
Subject: [PATCH] [ignore] Move generic functions from
 resource_mso_schema_site_anp_epg_bulk_staticport to utils file

---
 ...mso_schema_site_anp_epg_bulk_staticport.go | 55 -------------------
 mso/utils.go                                  | 55 +++++++++++++++++++
 2 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/mso/resource_mso_schema_site_anp_epg_bulk_staticport.go b/mso/resource_mso_schema_site_anp_epg_bulk_staticport.go
index a6ebc1b7..02589bf9 100644
--- a/mso/resource_mso_schema_site_anp_epg_bulk_staticport.go
+++ b/mso/resource_mso_schema_site_anp_epg_bulk_staticport.go
@@ -3,7 +3,6 @@ package mso
 import (
 	"fmt"
 	"log"
-	"regexp"
 	"strconv"
 	"strings"
 
@@ -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)
-	}
-}
diff --git a/mso/utils.go b/mso/utils.go
index 03df6217..9b23d793 100644
--- a/mso/utils.go
+++ b/mso/utils.go
@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
+	"regexp"
 	"strings"
 
 	"github.com/ciscoecosystem/mso-go-client/client"
@@ -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)
+	}
+}