| package devices |
| |
| import ( |
| "fmt" |
| "net/http" |
| ) |
| |
| // ActsPDUConn contains all of the information necessary to communicate with the PDUs |
| // used in Fuchsia lab946. |
| type ActsPDUConn struct { |
| host string |
| username string |
| password string |
| } |
| |
| // NewActsPDUConn initializes an ActsPDU object that we can use to reboot later. |
| func NewActsPDUConn(host, username, password string) *ActsPDUConn { |
| return &ActsPDUConn{host: host, username: username, password: password} |
| } |
| |
| // Reboot uses to PDU to powercycle the given port. The port should be either 0 or 1. |
| func (a *ActsPDUConn) Reboot(port int) error { |
| if port != 0 && port != 1 { |
| return fmt.Errorf("port must be either 0 or 1, got %d", port) |
| } |
| req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/cmd.cgi?rb=%d", a.host, port), nil) |
| if err != nil { |
| return err |
| } |
| req.SetBasicAuth(a.username, a.password) |
| client := &http.Client{} |
| if _, err := client.Do(req); err != nil { |
| return err |
| } |
| return nil |
| } |