Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/fabric_policies_ptp_policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
terraform {
required_providers {
mso = {
source = "CiscoDevNet/mso"
}
}
}

provider "mso" {
username = "" # <MSO username>
password = "" # <MSO pwd>
url = "" # <MSO URL>
insecure = true
}

# fabric policy template example

resource "mso_template" "fabric_policy_template" {
template_name = "fabric_policy_template"
template_type = "fabric_policy"
}

# fabric policies ptp policy example

resource "mso_fabric_policies_ptp_policy" "ptp_policy" {
template_id = mso_template.fabric_policy_template.id
name = "ptp_policy"
description = "Example description"
admin_state = "enabled"
global_priority1 = 250
global_priority2 = 100
global_domain = 99
fabric_profile_template = "aes67"
fabric_announce_interval = 1
fabric_sync_interval = -3
fabric_delay_interval = -2
fabric_announce_timeout = 3
}
53 changes: 53 additions & 0 deletions examples/fabric_policies_ptp_policy_profile/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
terraform {
required_providers {
mso = {
source = "CiscoDevNet/mso"
}
}
}

provider "mso" {
username = "" # <MSO username>
password = "" # <MSO pwd>
url = "" # <MSO URL>
insecure = true
}

# fabric policy template example

resource "mso_template" "fabric_policy_template" {
template_name = "fabric_policy_template"
template_type = "fabric_policy"
}

# fabric policies ptp policy example

resource "mso_fabric_policies_ptp_policy" "ptp_policy" {
template_id = mso_template.fabric_policy_template.id
name = "ptp_policy"
description = "Example description"
admin_state = "enabled"
global_priority1 = 250
global_priority2 = 100
global domain = 99
fabric_profile_template = "aes67"
fabric_announce_interval = 1
fabric_sync_interval = -3
fabric_delay_interval = -2
fabric_announce_timeout = 3
}

# fabric policies ptp policy profile example

resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" {
template_id = mso_template.fabric_policy_template.id
ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid
name = "ptp_policy_profile"
description = "Example description"
delay_interval = -2
sync_interval = -3
announce_timeout = 3
announce_interval = 1
profile_template = "aes67"
override_node_profile = false
}
22 changes: 22 additions & 0 deletions mso/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,25 @@ var loadBalanceHashingMap = map[string]string{
"layer_4_source_ip": "l4-src-port",
"source_ip": "src-ip",
}

var ptpProfileTemplateMap = map[string]string{
"aes67": "aes67",
"default": "default",
"smpte": "smpte",
"telecom": "telecomFullPath",
"telecomFullPath": "telecom",
}

var ptpDestinationMacMap = map[string]string{
"forwardable": "forwardable",
"non_forwardable": "nonForwardable",
"nonForwardable": "non_forwardable",
}

var ptpMismatchedMacHandlingMap = map[string]string{
"drop": "drop",
"reply_with_config_mac": "replyWithCfgMac",
"replyWithCfgMac": "reply_with_config_mac",
"reply_with_received_mac": "replyWithRxMac",
"replyWithRxMac": "reply_with_received_mac",
}
81 changes: 81 additions & 0 deletions mso/datasource_mso_fabric_policies_ptp_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package mso

import (
"log"

"github.com/ciscoecosystem/mso-go-client/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func datasourceMSOPtpPolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourcePtpPolicyRead,

Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
"admin_state": {
Type: schema.TypeString,
Computed: true,
},
"global_priority1": {
Type: schema.TypeInt,
Computed: true,
},
"global_priority2": {
Type: schema.TypeInt,
Computed: true,
},
"global_domain": {
Type: schema.TypeInt,
Computed: true,
},
"fabric_profile_template": {
Type: schema.TypeString,
Computed: true,
},
"fabric_announce_interval": {
Type: schema.TypeInt,
Computed: true,
},
"fabric_sync_interval": {
Type: schema.TypeInt,
Computed: true,
},
"fabric_delay_interval": {
Type: schema.TypeInt,
Computed: true,
},
"fabric_announce_timeout": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}

func dataSourcePtpPolicyRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] MSO PTP Policy Data Source - Beginning Read")
msoClient := m.(*client.Client)

templateId := d.Get("template_id").(string)
policyName := d.Get("name").(string)

setPtpPolicyData(d, msoClient, templateId, policyName)
log.Printf("[DEBUG] MSO PTP Policy Data Source - Read Complete : %v", d.Id())
return nil
}
81 changes: 81 additions & 0 deletions mso/datasource_mso_fabric_policies_ptp_policy_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package mso

import (
"log"

"github.com/ciscoecosystem/mso-go-client/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func datasourceMSOPtpPolicyProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourcePtpPolicyProfileRead,

Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"ptp_policy_uuid": {
Type: schema.TypeString,
Computed: true,
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
"profile_template": {
Type: schema.TypeString,
Computed: true,
},
"delay_interval": {
Type: schema.TypeInt,
Computed: true,
},
"sync_interval": {
Type: schema.TypeInt,
Computed: true,
},
"announce_interval": {
Type: schema.TypeInt,
Computed: true,
},
"announce_timeout": {
Type: schema.TypeInt,
Computed: true,
},
"override_node_profile": {
Type: schema.TypeBool,
Computed: true,
},
"local_priority": {
Type: schema.TypeInt,
Computed: true,
},
"destination_mac_type": {
Type: schema.TypeString,
Computed: true,
},
"mismatched_mac_handling": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourcePtpPolicyProfileRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[DEBUG] MSO PTP Policy Profile Data Source - Beginning Read")
msoClient := m.(*client.Client)

templateId := d.Get("template_id").(string)
policyName := d.Get("name").(string)

setPtpPolicyProfileData(d, msoClient, templateId, policyName)
log.Printf("[DEBUG] MSO PTP Policy Profile Data Source - Read Complete : %v", d.Id())
return nil
}
61 changes: 61 additions & 0 deletions mso/datasource_mso_fabric_policies_ptp_policy_profile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package mso

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccMSOPtpPolicyProfileDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: PTP Policy Profile Data Source") },
Config: testAccMSOPtpPolicyProfileDataSource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "name", "tf_ptp_profile"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "profile_template", "telecom"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "delay_interval", "-4"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "sync_interval", "-4"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_interval", "-3"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "announce_timeout", "3"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "local_priority", "120"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "destination_mac_type", "forwardable"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "mismatched_mac_handling", "reply_with_config_mac"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "override_node_profile", "false"),
resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "uuid"),
resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy_profile.ptp_policy_profile", "ptp_policy_uuid"),
),
},
},
})
}

func testAccMSOPtpPolicyProfileConfig() string {
return fmt.Sprintf(`%s
resource "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" {
template_id = mso_template.template_fabric_policy.id
ptp_policy_uuid = mso_fabric_policies_ptp_policy.ptp_policy.uuid
name = "tf_ptp_profile"
profile_template = "telecom"
announce_interval = -3
delay_interval = -4
sync_interval = -4
announce_timeout = 3
local_priority = 120
destination_mac_type = "forwardable"
mismatched_mac_handling = "reply_with_config_mac"
override_node_profile = "false"
}`, testAccMSOPtpPolicyConfigCreate())
}

func testAccMSOPtpPolicyProfileDataSource() string {
return fmt.Sprintf(`%s
data "mso_fabric_policies_ptp_policy_profile" "ptp_policy_profile" {
template_id = mso_fabric_policies_ptp_policy_profile.ptp_policy_profile.template_id
name = "tf_ptp_profile"
}`, testAccMSOPtpPolicyProfileConfig())
}
43 changes: 43 additions & 0 deletions mso/datasource_mso_fabric_policies_ptp_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package mso

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccMSOPtpPolicyDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: PTP Policy Data Source") },
Config: testAccMSOPtpPolicyDataSource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "name", "tf_test_ptp_policy"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "description", "Terraform test PTP Policy"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "admin_state", "enabled"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_profile_template", "default"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority1", "255"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_priority2", "254"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "global_domain", "100"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_interval", "1"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_sync_interval", "-1"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_delay_interval", "1"),
resource.TestCheckResourceAttr("mso_fabric_policies_ptp_policy.ptp_policy", "fabric_announce_timeout", "3"),
resource.TestCheckResourceAttrSet("mso_fabric_policies_ptp_policy.ptp_policy", "uuid"),
),
},
},
})
}

func testAccMSOPtpPolicyDataSource() string {
return fmt.Sprintf(`%s
data "mso_fabric_policies_ptp_policy" "ptp_policy" {
template_id = mso_fabric_policies_ptp_policy.ptp_policy.template_id
name = "tf_test_ptp_policy"
}`, testAccMSOPtpPolicyConfigCreate())
}
Loading
Loading