github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/common/get_logs.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/sirupsen/logrus"
     6  	"github.com/emc-advanced-dev/pkg/errors"
     7  	"github.com/solo-io/unik/pkg/types"
     8  	"github.com/layer-x/layerx-commons/lxhttpclient"
     9  )
    10  
    11  const UnikLogsPort = 9967
    12  
    13  func GetInstanceLogs(instance *types.Instance) (string, error) {
    14  	if instance.IpAddress == "" {
    15  		return "", errors.New("instance has not been assigned a public ip address", nil)
    16  	}
    17  	_, body, err := lxhttpclient.Get(instance.IpAddress+fmt.Sprintf(":%v", UnikLogsPort), "/logs", nil)
    18  	if err != nil {
    19  		return "", errors.New("faiiled to connect to instance at "+instance.IpAddress+" for logs", err)
    20  	}
    21  	logrus.WithFields(logrus.Fields{"response-length": len(body), "instance": instance}).Debugf("received stdout from instance")
    22  	return string(body), nil
    23  }