当前位置: 首页>>代码示例>>Golang>>正文


Golang cli.Context类代码示例

本文整理汇总了Golang中github.com/coreos/fleet/third_party/github.com/codegangsta/cli.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: verifyUnitAction

func verifyUnitAction(c *cli.Context) {
	r := getRegistry()

	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])
	payload := r.GetPayload(name)

	if payload == nil {
		fmt.Println("Job not found.")
		syscall.Exit(1)
	}

	sv, err := sign.NewSignatureVerifierFromSSHAgent()
	if err != nil {
		fmt.Println("Fail to create SignatureVerifier:", err)
		return
	}

	s := r.GetSignatureSetOfPayload(name)
	ok, err := sv.VerifyPayload(payload, s)
	if !ok || err != nil {
		fmt.Printf("Check of payload %s failed: %v\n", payload.Name, err)
		return
	}

	fmt.Printf("Succeed to verify job(%s).\n", payload.Name)
}
开发者ID:nullstyle,项目名称:fleet,代码行数:31,代码来源:verify.go

示例2: listMachinesAction

func listMachinesAction(c *cli.Context) {
	if !c.Bool("no-legend") {
		fmt.Fprintln(out, "MACHINE\tIP\tMETADATA")
	}

	full := c.Bool("full")

	for _, m := range registryCtl.GetActiveMachines() {
		mach := machineBootIDLegend(m, full)

		ip := m.PublicIP
		if len(ip) == 0 {
			ip = "-"
		}

		metadata := "-"
		if len(m.Metadata) != 0 {
			metadata = formatMetadata(m.Metadata)
		}

		fmt.Fprintf(out, "%s\t%s\t%s\n", mach, ip, metadata)
	}

	out.Flush()
}
开发者ID:nullstyle,项目名称:fleet,代码行数:25,代码来源:list_machines.go

示例3: listMachinesAction

func listMachinesAction(c *cli.Context) {
	r := getRegistry(c)

	if !c.Bool("no-legend") {
		fmt.Fprintln(out, "MACHINE\tIP\tMETADATA")
	}

	full := c.Bool("full")

	for _, m := range r.GetActiveMachines() {
		mach := m.BootId
		if !full {
			mach = ellipsize(mach, 8)
		}

		ip := m.PublicIP
		if len(ip) == 0 {
			ip = "-"
		}

		metadata := "-"
		if len(m.Metadata) != 0 {
			metadata = formatMetadata(m.Metadata)
		}

		fmt.Fprintf(out, "%s\t%s\t%s\n", mach, ip, metadata)
	}

	out.Flush()
}
开发者ID:natacado,项目名称:fleet,代码行数:30,代码来源:list_machines.go

示例4: getTunnelFlag

func getTunnelFlag(context *cli.Context) string {
	tun := context.GlobalString("tunnel")
	if tun != "" && !strings.Contains(tun, ":") {
		tun += ":22"
	}
	return tun
}
开发者ID:natacado,项目名称:fleet,代码行数:7,代码来源:cmd.go

示例5: listUnitsAction

func listUnitsAction(c *cli.Context) {
	r := getRegistry(c)

	if !c.Bool("no-legend") {
		fmt.Fprintln(out, "UNIT\tLOAD\tACTIVE\tSUB\tDESC\tMACHINE")
	}

	names := make(map[string]bool, 0)
	sortable := make(sort.StringSlice, 0)

	for _, p := range r.GetAllPayloads() {
		if _, ok := names[p.Name]; !ok {
			names[p.Name] = true
			sortable = append(sortable, p.Name)
		}
	}

	for _, j := range r.GetAllJobs() {
		if _, ok := names[j.Name]; !ok {
			names[j.Name] = true
			sortable = append(sortable, j.Name)
		}
	}

	sortable.Sort()

	full := c.Bool("full")
	for _, name := range sortable {
		state := r.GetJobState(name)
		printJobState(name, state, full)
	}

	out.Flush()
}
开发者ID:natacado,项目名称:fleet,代码行数:34,代码来源:list_units.go

示例6: getRegistry

func getRegistry(context *cli.Context) *registry.Registry {
	tun := getTunnelFlag(context)
	endpoint := context.GlobalString("endpoint")

	machines := []string{endpoint}
	client := etcd.NewClient(machines)

	if tun != "" {
		sshClient, err := ssh.NewSSHClient("core", tun)
		if err != nil {
			panic(err)
		}

		dial := func(network, addr string) (net.Conn, error) {
			tcpaddr, err := net.ResolveTCPAddr(network, addr)
			if err != nil {
				return nil, err
			}
			return sshClient.DialTCP(network, nil, tcpaddr)
		}

		tr := http.Transport{
			Dial: dial,
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		}

		client.SetTransport(&tr)
	}

	return registry.New(client)
}
开发者ID:natacado,项目名称:fleet,代码行数:33,代码来源:cmd.go

示例7: stopUnitAction

func stopUnitAction(c *cli.Context) {
	r := getRegistry()

	for _, v := range c.Args() {
		name := path.Base(v)
		r.StopJob(name)
	}
}
开发者ID:RandomStuffs22,项目名称:fleet,代码行数:8,代码来源:stop.go

示例8: destroyUnitsAction

func destroyUnitsAction(c *cli.Context) {
	for _, v := range c.Args() {
		name := path.Base(v)
		registryCtl.StopJob(name)
		registryCtl.DestroyPayload(name)
		registryCtl.DestroySignatureSetOfPayload(name)
	}
}
开发者ID:jsdir,项目名称:fleet,代码行数:8,代码来源:destroy.go

示例9: destroyUnitsAction

func destroyUnitsAction(c *cli.Context) {
	r := getRegistry()

	for _, v := range c.Args() {
		name := path.Base(v)
		r.StopJob(name)
		r.DestroyPayload(name)
	}
}
开发者ID:RandomStuffs22,项目名称:fleet,代码行数:9,代码来源:destroy.go

示例10: statusUnitsAction

func statusUnitsAction(c *cli.Context) {
	for i, v := range c.Args() {
		// This extra newline here to match systemctl status output
		if i != 0 {
			fmt.Printf("\n")
		}

		name := path.Base(v)
		printUnitStatus(c, name)
	}
}
开发者ID:nullstyle,项目名称:fleet,代码行数:11,代码来源:status.go

示例11: journalAction

func journalAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}
	jobName := c.Args()[0]

	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
	if c.Bool("follow") {
		cmd += " -f"
	}

	// check if the job is running on this machine
	var channel *ssh.Channel
	var err error
	if machine.IsLocalMachineState(js.MachineState) {
		channel = runLocalCommand(cmd)
	} else {
		channel, err = runRemoteCommand(cmd, js.MachineState.PublicIP)
		if err != nil {
			log.Fatalf("Unable to run command over SSH: %v", err)
		}
	}

	readSSHChannel(channel)
}
开发者ID:nullstyle,项目名称:fleet,代码行数:33,代码来源:journal.go

示例12: sshAction

func sshAction(c *cli.Context) {
	unit := c.String("unit")
	machine := c.String("machine")

	if unit != "" && machine != "" {
		log.Fatal("Both flags, machine and unit provided, please specify only one")
	}

	args := c.Args()
	var err error
	var addr string

	switch {
	case machine != "":
		addr, _ = findAddressInMachineList(machine)
	case unit != "":
		addr, _ = findAddressInRunningUnits(unit)
	default:
		addr, err = globalMachineLookup(args)
		args = args[1:]
	}

	if err != nil {
		log.Fatal(err)
	}

	if addr == "" {
		log.Fatalf("Requested machine could not be found")
	}

	agentForwarding := c.Bool("agent")

	var sshClient *ssh.SSHForwardingClient
	if tun := getTunnelFlag(); tun != "" {
		sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), agentForwarding)
	} else {
		sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), agentForwarding)
	}
	if err != nil {
		log.Fatal(err.Error())
		return
	}

	defer sshClient.Close()

	if len(args) > 0 {
		cmd := strings.Join(args, " ")
		channel, err := ssh.Execute(sshClient, cmd)
		if err != nil {
			log.Fatalf("Unable to run command over SSH: %s", err.Error())
		}

		readSSHChannel(channel)
	} else {
		if err := ssh.Shell(sshClient); err != nil {
			log.Fatalf(err.Error())
		}
	}
}
开发者ID:nullstyle,项目名称:fleet,代码行数:59,代码来源:ssh.go

示例13: printUnitAction

func printUnitAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])
	payload := registryCtl.GetPayload(name)

	if payload == nil {
		fmt.Println("Job not found.")
		syscall.Exit(1)
	}

	fmt.Print(payload.Unit.String())
}
开发者ID:nullstyle,项目名称:fleet,代码行数:16,代码来源:cat.go

示例14: listUnitsAction

func listUnitsAction(c *cli.Context) {
	if !c.Bool("no-legend") {
		fmt.Fprintln(out, "UNIT\tLOAD\tACTIVE\tSUB\tDESC\tMACHINE")
	}

	names, sortable := findAllUnits()

	full := c.Bool("full")
	for _, name := range sortable {
		state := registryCtl.GetJobState(name)
		description := names[name]
		printJobState(name, description, state, full)
	}

	out.Flush()
}
开发者ID:jsdir,项目名称:fleet,代码行数:16,代码来源:list_units.go

示例15: journalAction

func journalAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}
	jobName := c.Args()[0]

	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)

	var err error
	var sshClient *gossh.ClientConn
	if tun := getTunnelFlag(); tun != "" {
		sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
	} else {
		sshClient, err = ssh.NewSSHClient("core", addr)
	}
	if err != nil {
		log.Fatal(err.Error())
	}

	defer sshClient.Close()

	cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
	if c.Bool("follow") {
		cmd += " -f"
	}
	stdout, err := ssh.Execute(sshClient, cmd)
	if err != nil {
		log.Fatalf("Unable to run command over SSH: %s", err.Error())
	}

	for true {
		bytes, prefix, err := stdout.ReadLine()
		if err != nil {
			break
		}

		fmt.Print(string(bytes))
		if !prefix {
			fmt.Print("\n")
		}
	}
}
开发者ID:jsdir,项目名称:fleet,代码行数:50,代码来源:journal.go


注:本文中的github.com/coreos/fleet/third_party/github.com/codegangsta/cli.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。