本文整理匯總了Golang中github.com/flynn/flynn/pkg/cluster.Client.Host方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Host方法的具體用法?Golang Client.Host怎麽用?Golang Client.Host使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flynn/flynn/pkg/cluster.Client
的用法示例。
在下文中一共展示了Client.Host方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runStop
func runStop(args *docopt.Args, client *cluster.Client) error {
success := true
clients := make(map[string]*cluster.Host)
for _, id := range args.All["ID"].([]string) {
hostID, err := cluster.ExtractHostID(id)
if err != nil {
fmt.Printf("could not parse %s: %s", id, err)
success = false
continue
}
hostClient, ok := clients[hostID]
if !ok {
var err error
hostClient, err = client.Host(hostID)
if err != nil {
fmt.Printf("could not connect to host %s: %s\n", hostID, err)
success = false
continue
}
clients[hostID] = hostClient
}
if err := hostClient.StopJob(id); err != nil {
fmt.Printf("could not stop job %s: %s\n", id, err)
success = false
continue
}
fmt.Println(id, "stopped")
}
if !success {
return errors.New("could not stop all jobs")
}
return nil
}
示例2: getLog
func getLog(hostID, jobID string, client *cluster.Client, follow, init bool, stdout, stderr io.Writer) error {
hostClient, err := client.Host(hostID)
if err != nil {
return fmt.Errorf("could not connect to host %s: %s", hostID, err)
}
attachReq := &host.AttachReq{
JobID: jobID,
Flags: host.AttachFlagStdout | host.AttachFlagStderr | host.AttachFlagLogs,
}
if follow {
attachReq.Flags |= host.AttachFlagStream
}
if init {
attachReq.Flags |= host.AttachFlagInitLog
}
attachClient, err := hostClient.Attach(attachReq, false)
if err != nil {
switch err {
case host.ErrJobNotRunning:
return nil
case cluster.ErrWouldWait:
return errors.New("no such job")
}
return err
}
defer attachClient.Close()
_, err = attachClient.Receive(stdout, stderr)
return err
}
示例3: runTagsDel
func runTagsDel(args *docopt.Args, client *cluster.Client) error {
host, err := client.Host(args.String["<hostid>"])
if err != nil {
return err
}
vars := args.All["<var>"].([]string)
tags := make(map[string]string, len(vars))
for _, v := range vars {
// empty tags get deleted on the host
tags[v] = ""
}
return host.UpdateTags(tags)
}
示例4: runInspect
func runInspect(args *docopt.Args, client *cluster.Client) error {
hostID, jobID, err := cluster.ParseJobID(args.String["ID"])
if err != nil {
return err
}
hostClient, err := client.Host(hostID)
if err != nil {
return fmt.Errorf("could not connect to host %s: %s", hostID, err)
}
job, err := hostClient.GetJob(jobID)
if err != nil {
return fmt.Errorf("no such job")
}
printJobDesc(job, os.Stdout, !args.Bool["--omit-env"])
return nil
}
示例5: runTagsSet
func runTagsSet(args *docopt.Args, client *cluster.Client) error {
host, err := client.Host(args.String["<hostid>"])
if err != nil {
return err
}
pairs := args.All["<var>=<val>"].([]string)
tags := make(map[string]string, len(pairs))
for _, s := range pairs {
keyVal := strings.SplitN(s, "=", 2)
if len(keyVal) == 1 && keyVal[0] != "" {
tags[keyVal[0]] = "true"
} else if len(keyVal) == 2 {
tags[keyVal[0]] = keyVal[1]
}
}
return host.UpdateTags(tags)
}
示例6: runVolumeCreate
func runVolumeCreate(args *docopt.Args, client *cluster.Client) error {
hostId := args.String["<host>"]
hostClient, err := client.Host(hostId)
if err != nil {
fmt.Println("could not connect to host", hostId)
}
provider := "default"
if args.String["--provider"] != "" {
provider = args.String["--provider"]
}
v, err := hostClient.CreateVolume(provider)
if err != nil {
fmt.Printf("could not create volume: %s\n", err)
return err
}
fmt.Printf("created volume %s on %s\n", v.ID, hostId)
return nil
}
示例7: runSignal
func runSignal(args *docopt.Args, client *cluster.Client) error {
id := args.String["ID"]
sig, err := strconv.Atoi(args.String["SIGNAL"])
if err != nil {
fmt.Println("invalid value for SIGNAL")
return err
}
hostID, err := cluster.ExtractHostID(id)
if err != nil {
fmt.Println("could not parse", id)
return err
}
hostClient, err := client.Host(hostID)
if err != nil {
fmt.Println("could not connect to host", hostID)
return err
}
if err := hostClient.SignalJob(id, sig); err != nil {
fmt.Println("could not signal job", id)
return err
}
fmt.Printf("sent signal %d to %s successfully\n", sig, id)
return nil
}