Skip to content

Commit

Permalink
Add device unreachability warning to anycast_gateway, fabric_l2_hando…
Browse files Browse the repository at this point in the history
…ff, fabric_device, fabric_port_assignment and provision_device resources
  • Loading branch information
kuba-mazurkiewicz committed Dec 2, 2024
1 parent 960ead1 commit 536768d
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 52 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.1.17 (unreleased)

- Add device unreachability warning to `catalystcenter_anycast_gateway`, `catalystcenter_fabric_l2_handoff`, `catalystcenter_fabric_device`, `catalystcenter_fabric_port_assignment` and `catalystcenter_provision_device` resources
- Add `isAuthKeyPSK` and `isAuthKeyPSKPlusFT` attributes to `catalystcenter_wireless_ssid` resource

## 0.1.16
Expand Down
1 change: 1 addition & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description: |-

## 0.1.17 (unreleased)

- Add device unreachability warning to `catalystcenter_anycast_gateway`, `catalystcenter_fabric_l2_handoff`, `catalystcenter_fabric_device`, `catalystcenter_fabric_port_assignment` and `catalystcenter_provision_device` resources
- Add `isAuthKeyPSK` and `isAuthKeyPSKPlusFT` attributes to `catalystcenter_wireless_ssid` resource

## 0.1.16
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/anycast_gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data_source_no_id: true
skip_minimum_test: true
put_id_include_path: "0.id"
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
attributes:
- model_name: fabricId
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ put_id_include_path: 0.id
import_no_id: true
data_source_no_id: true
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_l2_handoff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ id_from_query_path_attribute: id
put_id_include_path: 0.id
get_from_all: true
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_l3_handoff_ip_transit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ id_from_query_path_attribute: id
put_id_include_path: 0.id
get_from_all: true
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_port_assignment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data_source_no_id: true
id_from_attribute: true
root_list: true
skip_minimum_test: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_provision_device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import_no_id: true
data_source_no_id: true
put_id_include_path: "0.id"
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
85 changes: 43 additions & 42 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,49 @@ var templates = []t{
}

type YamlConfig struct {
Name string `yaml:"name"`
NoResource bool `yaml:"no_resource"`
NoDataSource bool `yaml:"no_data_source"`
RestEndpoint string `yaml:"rest_endpoint"`
GetRestEndpoint string `yaml:"get_rest_endpoint"`
PutRestEndpoint string `yaml:"put_rest_endpoint"`
DeleteRestEndpoint string `yaml:"delete_rest_endpoint"`
GetNoId bool `yaml:"get_no_id"`
GetFromAll bool `yaml:"get_from_all"`
GetRequiresId bool `yaml:"get_requires_id"`
GetExtraQueryParams string `yaml:"get_extra_query_params"`
NoDelete bool `yaml:"no_delete"`
DataSourceNoId bool `yaml:"data_source_no_id"`
DeleteNoId bool `yaml:"delete_no_id"`
NoUpdate bool `yaml:"no_update"`
NoRead bool `yaml:"no_read"`
NoImport bool `yaml:"no_import"`
ImportNoId bool `yaml:"import_no_id"`
PostUpdate bool `yaml:"post_update"`
PutCreate bool `yaml:"put_create"`
RootList bool `yaml:"root_list"`
NoReadPrefix bool `yaml:"no_read_prefix"`
IdPath string `yaml:"id_path"`
IdFromQueryPath string `yaml:"id_from_query_path"`
IdFromQueryPathAttribute string `yaml:"id_from_query_path_attribute"`
IdQueryParam string `yaml:"id_query_param"`
IdFromAttribute bool `yaml:"id_from_attribute"`
PutIdIncludePath string `yaml:"put_id_include_path"`
PutIdQueryParam string `yaml:"put_id_query_param"`
PutNoId bool `yaml:"put_no_id"`
PutUpdateId bool `yaml:"put_update_id"`
DeleteIdQueryParam string `yaml:"delete_id_query_param"`
MinimumVersion string `yaml:"minimum_version"`
DsDescription string `yaml:"ds_description"`
ResDescription string `yaml:"res_description"`
DocCategory string `yaml:"doc_category"`
ExcludeTest bool `yaml:"exclude_test"`
SkipMinimumTest bool `yaml:"skip_minimum_test"`
Attributes []YamlConfigAttribute `yaml:"attributes"`
TestTags []string `yaml:"test_tags"`
TestPrerequisites string `yaml:"test_prerequisites"`
MaxAsyncWaitTime int64 `yaml:"max_async_wait_time"`
Name string `yaml:"name"`
NoResource bool `yaml:"no_resource"`
NoDataSource bool `yaml:"no_data_source"`
RestEndpoint string `yaml:"rest_endpoint"`
GetRestEndpoint string `yaml:"get_rest_endpoint"`
PutRestEndpoint string `yaml:"put_rest_endpoint"`
DeleteRestEndpoint string `yaml:"delete_rest_endpoint"`
GetNoId bool `yaml:"get_no_id"`
GetFromAll bool `yaml:"get_from_all"`
GetRequiresId bool `yaml:"get_requires_id"`
GetExtraQueryParams string `yaml:"get_extra_query_params"`
NoDelete bool `yaml:"no_delete"`
DataSourceNoId bool `yaml:"data_source_no_id"`
DeleteNoId bool `yaml:"delete_no_id"`
NoUpdate bool `yaml:"no_update"`
NoRead bool `yaml:"no_read"`
NoImport bool `yaml:"no_import"`
ImportNoId bool `yaml:"import_no_id"`
PostUpdate bool `yaml:"post_update"`
PutCreate bool `yaml:"put_create"`
RootList bool `yaml:"root_list"`
NoReadPrefix bool `yaml:"no_read_prefix"`
IdPath string `yaml:"id_path"`
IdFromQueryPath string `yaml:"id_from_query_path"`
IdFromQueryPathAttribute string `yaml:"id_from_query_path_attribute"`
IdQueryParam string `yaml:"id_query_param"`
IdFromAttribute bool `yaml:"id_from_attribute"`
DeviceUnreachabilityWarning bool `yaml:"device_unreachability_warning"`
PutIdIncludePath string `yaml:"put_id_include_path"`
PutIdQueryParam string `yaml:"put_id_query_param"`
PutNoId bool `yaml:"put_no_id"`
PutUpdateId bool `yaml:"put_update_id"`
DeleteIdQueryParam string `yaml:"delete_id_query_param"`
MinimumVersion string `yaml:"minimum_version"`
DsDescription string `yaml:"ds_description"`
ResDescription string `yaml:"res_description"`
DocCategory string `yaml:"doc_category"`
ExcludeTest bool `yaml:"exclude_test"`
SkipMinimumTest bool `yaml:"skip_minimum_test"`
Attributes []YamlConfigAttribute `yaml:"attributes"`
TestTags []string `yaml:"test_tags"`
TestPrerequisites string `yaml:"test_prerequisites"`
MaxAsyncWaitTime int64 `yaml:"max_async_wait_time"`
}

type YamlConfigAttribute struct {
Expand Down
1 change: 1 addition & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ id_from_query_path: str(required=False) # Specify path to ID container if ID is
id_from_query_path_attribute: str(required=False) # Specify attribute name of ID, only relevant if "id_from_query_path" option used, default is "id"
id_query_param: str(required=False) # Query parameter used to specify the ID
id_from_attribute: bool(required=False) # Set to true if the ID is derived from an attribute
device_unreachability_warning: bool(required=False) # Set to true if a warning should be displayed for device unreachability instead of error
put_id_include_path: str(required=False) # If PUT needs to have specific JSON path where ID should be inserted
put_id_query_param: str(required=False) # If PUT needs to have specific query parameter where ID should be inserted
put_no_id: bool(required=False) # Set to true if the PUT request does not require an ID
Expand Down
12 changes: 12 additions & 0 deletions gen/templates/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,20 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C
res, err := r.client.Post(plan.getPath() + params, body {{- if .MaxAsyncWaitTime }}, func(r *cc.Req) { r.MaxAsyncWaitTime={{.MaxAsyncWaitTime}} }{{end}})
{{- end}}
if err != nil {
{{- if .DeviceUnreachabilityWarning}}
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
{{- else}}
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", {{- if .PutCreate }} "PUT" {{- else }} "POST" {{- end }}, err, res.String()))
return
{{- end}}
}
{{- /* Check if id can be resolved directly from response */}}
{{- if .IdPath}}
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_anycast_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,15 @@ func (r *AnycastGatewayResource) Create(ctx context.Context, req resource.Create
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
params = ""
params += "?fabricId=" + url.QueryEscape(plan.FabricId.ValueString()) + "&virtualNetworkName=" + url.QueryEscape(plan.VirtualNetworkName.ValueString()) + "&ipPoolName=" + url.QueryEscape(plan.IpPoolName.ValueString())
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_fabric_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,15 @@ func (r *FabricDeviceResource) Create(ctx context.Context, req resource.CreateRe
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
params = ""
params += "?networkDeviceId=" + url.QueryEscape(plan.NetworkDeviceId.ValueString()) + "&fabricId=" + url.QueryEscape(plan.FabricId.ValueString())
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_fabric_l2_handoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ func (r *FabricL2HandoffResource) Create(ctx context.Context, req resource.Creat
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
params = ""
params += "?networkDeviceId=" + url.QueryEscape(plan.NetworkDeviceId.ValueString()) + "&fabricId=" + url.QueryEscape(plan.FabricId.ValueString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (r *FabricL3HandoffIPTransitResource) Configure(_ context.Context, req reso

// End of section. //template:end model

// Section below is generated&owned by "gen/generator.go". //template:begin create
func (r *FabricL3HandoffIPTransitResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var plan FabricL3HandoffIPTransit

Expand Down Expand Up @@ -213,6 +214,8 @@ func (r *FabricL3HandoffIPTransitResource) Create(ctx context.Context, req resou
resp.Diagnostics.Append(diags...)
}

// End of section. //template:end create

// Section below is generated&owned by "gen/generator.go". //template:begin read
func (r *FabricL3HandoffIPTransitResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var state FabricL3HandoffIPTransit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ func (r *FabricPortAssignmentResource) Create(ctx context.Context, req resource.
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
plan.Id = types.StringValue(fmt.Sprint(plan.NetworkDeviceId.ValueString()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ func (r *FabricProvisionDeviceResource) Create(ctx context.Context, req resource
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
params = ""
params += "?siteId=" + url.QueryEscape(plan.SiteId.ValueString()) + "&networkDeviceId=" + url.QueryEscape(plan.NetworkDeviceId.ValueString())
Expand Down
1 change: 1 addition & 0 deletions templates/guides/changelog.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description: |-

## 0.1.17 (unreleased)

- Add device unreachability warning to `catalystcenter_anycast_gateway`, `catalystcenter_fabric_l2_handoff`, `catalystcenter_fabric_device`, `catalystcenter_fabric_port_assignment` and `catalystcenter_provision_device` resources
- Add `isAuthKeyPSK` and `isAuthKeyPSKPlusFT` attributes to `catalystcenter_wireless_ssid` resource

## 0.1.16
Expand Down

0 comments on commit 536768d

Please sign in to comment.