github.com/Cloud-Foundations/Dominator@v0.3.4/cmd/domtool/listSubs.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/errors"
     7  	"github.com/Cloud-Foundations/Dominator/lib/log"
     8  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
     9  	"github.com/Cloud-Foundations/Dominator/proto/dominator"
    10  )
    11  
    12  func listSubsSubcommand(args []string, logger log.DebugLogger) error {
    13  	if err := listSubs(getClient()); err != nil {
    14  		return fmt.Errorf("error listing subs: %s", err)
    15  	}
    16  	return nil
    17  }
    18  
    19  func listSubs(client *srpc.Client) error {
    20  	hostnames, err := getSubsFromFile()
    21  	if err != nil {
    22  		return err
    23  	}
    24  	request := dominator.ListSubsRequest{
    25  		Hostnames:        hostnames,
    26  		LocationsToMatch: locationsToMatch,
    27  		StatusesToMatch:  statusesToMatch,
    28  		TagsToMatch:      tagsToMatch,
    29  	}
    30  	var reply dominator.ListSubsResponse
    31  	if err := client.RequestReply("Dominator.ListSubs", request,
    32  		&reply); err != nil {
    33  		return err
    34  	}
    35  	if err := errors.New(reply.Error); err != nil {
    36  		return err
    37  	}
    38  	for _, hostname := range reply.Hostnames {
    39  		fmt.Println(hostname)
    40  	}
    41  	return nil
    42  }