-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of SSH Key-Based Authentication
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/shiftky/go-tmsh" | ||
) | ||
|
||
// SSH Key-Based Authentication | ||
func main() { | ||
// Read private key file | ||
key, err := ioutil.ReadFile("/Users/user/.ssh/id_rsa") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Connect to BIG-IP | ||
// Create New SSH Session using SSH key | ||
bigip, err := tmsh.NewKeySession("lb01.example.com", "22", "admin", key) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer bigip.Close() | ||
|
||
// Create nodes. | ||
bigip.CreateNode("web01.example.com", "192.0.2.1") | ||
bigip.CreateNode("web02.example.com", "192.0.2.2") | ||
|
||
// Disable Node | ||
bigip.DisableNode("web02.example.com") | ||
|
||
// Get node. | ||
node1, _ := bigip.GetNode("web01.example.com") | ||
fmt.Println("Name: " + node1.Name) | ||
fmt.Println("Addr: " + node1.Addr) | ||
fmt.Println("State: " + node1.EnabledState) | ||
|
||
node2, _ := bigip.GetNode("web02.example.com") | ||
fmt.Println("Name: " + node2.Name) | ||
fmt.Println("Addr: " + node2.Addr) | ||
fmt.Println("State: " + node2.EnabledState) | ||
|
||
// Delete nodes. | ||
bigip.DeleteNode("web01.example.com") | ||
bigip.DeleteNode("web02.example.com") | ||
} |