Created
March 27, 2018 09:46
-
-
Save ljjjustin/21f6f8cbf38f292cbbcffc39c6ee5ff9 to your computer and use it in GitHub Desktop.
go demo: IPMI poweroff
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "strconv" | |
| ipmi "github.com/vmware/goipmi" | |
| ) | |
| func main() { | |
| if len(os.Args) < 3 { | |
| fmt.Printf("usage: %s <host> <port>\n", os.Args[0]) | |
| os.Exit(-1) | |
| } | |
| hostname := os.Args[1] | |
| port, err := strconv.Atoi(os.Args[2]) | |
| client, err := ipmi.NewClient(&ipmi.Connection{ | |
| Hostname: hostname, | |
| Port: port, | |
| Username: "admin", | |
| Password: "password", | |
| Interface: "lanplus", | |
| }) | |
| if err != nil { | |
| fmt.Println("failed to create connection.") | |
| os.Exit(-1) | |
| } | |
| err = client.Open() | |
| if err != nil { | |
| fmt.Println("failed to connect BMC server.") | |
| os.Exit(-1) | |
| } | |
| err = client.Control(ipmi.ControlPowerDown) | |
| if err != nil { | |
| fmt.Println("failed to reset power state", err) | |
| os.Exit(-1) | |
| } | |
| client.Close() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment