Skip to content

Instantly share code, notes, and snippets.

@ljjjustin
Created March 27, 2018 09:46
Show Gist options
  • Select an option

  • Save ljjjustin/21f6f8cbf38f292cbbcffc39c6ee5ff9 to your computer and use it in GitHub Desktop.

Select an option

Save ljjjustin/21f6f8cbf38f292cbbcffc39c6ee5ff9 to your computer and use it in GitHub Desktop.
go demo: IPMI poweroff
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