-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoc.go
More file actions
114 lines (113 loc) · 3.37 KB
/
Copy pathdoc.go
File metadata and controls
114 lines (113 loc) · 3.37 KB
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
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2025 Daniel Schmidt
// Package netconf provides a simple, fluent API for interacting with network devices
// using the NETCONF protocol (RFC 6241).
//
// The library provides a high-level client interface that handles session management,
// XML manipulation, error handling with automatic retry logic, and thread-safe operations.
//
// # Quick Start
//
// Create a client and perform basic operations:
//
// client, err := netconf.NewClient(
// "192.168.1.1",
// netconf.Username("admin"),
// netconf.Password("secret"),
// netconf.Port(830),
// )
// if err != nil {
// log.Fatal(err)
// }
// defer client.Close()
//
// // Get configuration with filter
// ctx := context.Background()
// filter := netconf.SubtreeFilter("<interfaces/>")
// res, err := client.GetConfig(ctx, "running", filter)
// if err != nil {
// log.Fatal(err)
// }
//
// // Parse response using xmldot
// ifName := res.Res.Get("data.interfaces.interface.name").String()
// fmt.Println("Interface:", ifName)
//
// # XML Manipulation
//
// Use the Body builder for constructing XML configurations:
//
// config := netconf.Body{}.
// Set("interfaces.interface.name", "GigabitEthernet1").
// Set("interfaces.interface.description", "WAN Interface").
// Set("interfaces.interface.enabled", true).String()
//
// ctx := context.Background()
// res, err := client.EditConfig(ctx, "candidate", config)
//
// # Transaction Management
//
// Use the candidate datastore workflow for safe configuration changes:
//
// ctx := context.Background()
//
// // Lock candidate datastore
// if _, err := client.Lock(ctx, "candidate"); err != nil {
// log.Fatal(err)
// }
// defer client.Unlock(ctx, "candidate")
//
// // Edit configuration
// _, err = client.EditConfig(ctx, "candidate", config)
// if err != nil {
// client.Discard(ctx)
// log.Fatal(err)
// }
//
// // Validate and commit
// if _, err := client.Validate(ctx, "candidate"); err != nil {
// client.Discard(ctx)
// log.Fatal(err)
// }
// if _, err := client.Commit(ctx); err != nil {
// log.Fatal(err)
// }
//
// # Error Handling
//
// The library automatically retries transient errors with exponential backoff:
//
// client, err := netconf.NewClient(
// "192.168.1.1",
// netconf.Username("admin"),
// netconf.Password("secret"),
// netconf.MaxRetries(5),
// netconf.BackoffMinDelay(1*time.Second),
// netconf.BackoffMaxDelay(60*time.Second),
// )
//
// # Thread Safety
//
// Read operations (Get, GetConfig) are thread-safe and can be called concurrently.
// Write operations (EditConfig, CopyConfig, DeleteConfig) are synchronized with a mutex.
//
// # Supported Operations
//
// - Get: Retrieve configuration and state data
// - GetConfig: Retrieve configuration from datastore
// - EditConfig: Modify configuration
// - CopyConfig: Copy configuration between datastores
// - DeleteConfig: Delete configuration datastore
// - Lock/Unlock: Lock and unlock datastores
// - Commit: Commit candidate to running
// - Discard: Discard candidate changes
// - Validate: Validate configuration
// - RPC: Send custom RPC operations
//
// # References
//
// - RFC 6241: Network Configuration Protocol (NETCONF)
// - RFC 6242: Using the NETCONF Protocol over SSH
// - xmldot: https://github.com/netascode/xmldot
// - scrapligo: https://github.com/scrapli/scrapligo
package netconf