github.com/Cloud-Foundations/Dominator@v0.3.4/cmd/hyper-control/getCapacity.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 hyperclient "github.com/Cloud-Foundations/Dominator/hypervisor/client" 8 "github.com/Cloud-Foundations/Dominator/lib/errors" 9 "github.com/Cloud-Foundations/Dominator/lib/json" 10 "github.com/Cloud-Foundations/Dominator/lib/log" 11 "github.com/Cloud-Foundations/Dominator/lib/srpc" 12 ) 13 14 func getCapacitySubcommand(args []string, logger log.DebugLogger) error { 15 err := getCapacity(logger) 16 if err != nil { 17 return fmt.Errorf("error getting capacity: %s", err) 18 } 19 return nil 20 } 21 22 func getCapacity(logger log.DebugLogger) error { 23 if *hypervisorHostname == "" { 24 return errors.New("hypervisorHostname unspecified") 25 } 26 clientName := fmt.Sprintf("%s:%d", *hypervisorHostname, *hypervisorPortNum) 27 client, err := srpc.DialHTTP("tcp", clientName, 0) 28 if err != nil { 29 return err 30 } 31 defer client.Close() 32 reply, err := hyperclient.GetCapacity(client) 33 if err != nil { 34 return err 35 } 36 return json.WriteWithIndent(os.Stdout, " ", reply) 37 }