/
resource_debug_isis.go
127 lines (121 loc) · 3.92 KB
/
resource_debug_isis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceDebugIsis() *schema.Resource {
return &schema.Resource{
Description: "`thunder_debug_isis`: Intermediate System - Intermediate System (IS-IS)\n\n__PLACEHOLDER__",
CreateContext: resourceDebugIsisCreate,
UpdateContext: resourceDebugIsisUpdate,
ReadContext: resourceDebugIsisRead,
DeleteContext: resourceDebugIsisDelete,
Schema: map[string]*schema.Schema{
"all": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable all debugging",
},
"bfd": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Bidirectional Forwarding Detection (BFD)",
},
"events": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS Events",
},
"ifsm": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS Interface Finite State Machine",
},
"lsp": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS Link State PDU",
},
"nfsm": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS Neighbor Finite State Machine",
},
"nsm": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS NSM information",
},
"pdu": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS Protocol Data Unit",
},
"spf": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "IS-IS SPF Calculation",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
}
}
func resourceDebugIsisCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDebugIsisCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDebugIsis(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDebugIsisRead(ctx, d, meta)
}
return diags
}
func resourceDebugIsisUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDebugIsisUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDebugIsis(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceDebugIsisRead(ctx, d, meta)
}
return diags
}
func resourceDebugIsisDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDebugIsisDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDebugIsis(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceDebugIsisRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDebugIsisRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDebugIsis(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func dataToEndpointDebugIsis(d *schema.ResourceData) edpt.DebugIsis {
var ret edpt.DebugIsis
ret.Inst.All = d.Get("all").(int)
ret.Inst.Bfd = d.Get("bfd").(int)
ret.Inst.Events = d.Get("events").(int)
ret.Inst.Ifsm = d.Get("ifsm").(int)
ret.Inst.Lsp = d.Get("lsp").(int)
ret.Inst.Nfsm = d.Get("nfsm").(int)
ret.Inst.Nsm = d.Get("nsm").(int)
ret.Inst.Pdu = d.Get("pdu").(int)
ret.Inst.Spf = d.Get("spf").(int)
//omit uuid
return ret
}