github.com/Cloud-Foundations/Dominator@v0.3.4/cmd/vm-control/getHypervisors.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/Cloud-Foundations/Dominator/lib/errors"
     8  	"github.com/Cloud-Foundations/Dominator/lib/json"
     9  	"github.com/Cloud-Foundations/Dominator/lib/log"
    10  	proto "github.com/Cloud-Foundations/Dominator/proto/fleetmanager"
    11  )
    12  
    13  func getHypervisorsSubcommand(args []string, logger log.DebugLogger) error {
    14  	if err := getHypervisors(logger); err != nil {
    15  		return fmt.Errorf("error geting Hypervisors: %s", err)
    16  	}
    17  	return nil
    18  }
    19  
    20  func getHypervisors(logger log.DebugLogger) error {
    21  	fleetManager := fmt.Sprintf("%s:%d",
    22  		*fleetManagerHostname, *fleetManagerPortNum)
    23  	client, err := dialFleetManager(fleetManager)
    24  	if err != nil {
    25  		return err
    26  	}
    27  	defer client.Close()
    28  	request := proto.GetHypervisorsInLocationRequest{
    29  		HypervisorTagsToMatch: hypervisorTagsToMatch,
    30  		IncludeUnhealthy:      *includeUnhealthy,
    31  		IncludeVMs:            true,
    32  		Location:              *location,
    33  		SubnetId:              *subnetId,
    34  	}
    35  	var reply proto.GetHypervisorsInLocationResponse
    36  	err = client.RequestReply("FleetManager.GetHypervisorsInLocation",
    37  		request, &reply)
    38  	if err != nil {
    39  		return err
    40  	}
    41  	if err := errors.New(reply.Error); err != nil {
    42  		return err
    43  	}
    44  	return json.WriteWithIndent(os.Stdout, "    ", reply.Hypervisors)
    45  }