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


Golang Response.Tabular方法代码示例

本文整理汇总了Golang中minicli.Response.Tabular方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.Tabular方法的具体用法?Golang Response.Tabular怎么用?Golang Response.Tabular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在minicli.Response的用法示例。


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

示例1: dnsmasqDNSInfo

func dnsmasqDNSInfo(c *minicli.Command, resp *minicli.Response) {
	// print info
	resp.Header = []string{"ID", "IP", "Hostname"}
	resp.Tabular = [][]string{}
	if c.StringArgs["ID"] == Wildcard {
		for id, v := range dnsmasqServers {
			for ip, host := range v.Hostnames {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), ip, host})
			}
		}
	} else {
		id, err := strconv.Atoi(c.StringArgs["ID"])
		if err != nil {
			resp.Error = "Invalid dnsmasq ID"
			return
		}
		if _, ok := dnsmasqServers[id]; ok {
			for ip, host := range dnsmasqServers[id].Hostnames {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), ip, host})
			}
		} else {
			resp.Error = "Invalid dnsmasq ID"
		}
	}
}
开发者ID:jenareljam,项目名称:minimega,代码行数:25,代码来源:dnsmasq.go

示例2: cliCCClients

// clients
func cliCCClients(c *minicli.Command, resp *minicli.Response) error {
	resp.Header = []string{
		"UUID", "hostname", "arch", "OS",
		"IP", "MAC",
	}
	resp.Tabular = [][]string{}

	clients := ccNode.GetActiveClients()

	var uuids []string
	for k, _ := range clients {
		uuids = append(uuids, k)
	}
	sort.Strings(uuids)

	for _, i := range uuids {
		v := clients[i]
		row := []string{
			v.UUID,
			v.Hostname,
			v.Arch,
			v.OS,
			fmt.Sprintf("%v", v.IPs),
			fmt.Sprintf("%v", v.MACs),
		}

		resp.Tabular = append(resp.Tabular, row)
	}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:32,代码来源:cc_cli.go

示例3: dnsmasqHostInfo

func dnsmasqHostInfo(c *minicli.Command, resp *minicli.Response) {
	// print info about the mapping
	resp.Header = []string{"ID", "MAC", "IP"}
	resp.Tabular = [][]string{}
	if c.StringArgs["ID"] == Wildcard {
		for id, v := range dnsmasqServers {
			for mac, ip := range v.DHCPhosts {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), mac, ip})
			}
		}
	} else {
		id, err := strconv.Atoi(c.StringArgs["ID"])
		if err != nil {
			resp.Error = "Invalid dnsmasq ID"
			return
		}
		if _, ok := dnsmasqServers[id]; ok {
			for mac, ip := range dnsmasqServers[id].DHCPhosts {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), mac, ip})
			}
		} else {
			resp.Error = "Invalid dnsmasq ID"
		}
	}
}
开发者ID:jenareljam,项目名称:minimega,代码行数:25,代码来源:dnsmasq.go

示例4: cliCapture

func cliCapture(c *minicli.Command, resp *minicli.Response) error {
	if c.BoolArgs["netflow"] {
		// Capture to netflow
		return cliCaptureNetflow(c, resp)
	} else if c.BoolArgs["pcap"] {
		// Capture to pcap
		return cliCapturePcap(c, resp)
	}

	// Print capture info
	resp.Header = []string{
		"ID",
		"Type",
		"Bridge",
		"VM/interface",
		"Path",
		"Mode",
		"Compress",
	}

	resp.Tabular = [][]string{}
	for _, v := range captureEntries {
		row := []string{
			strconv.Itoa(v.ID),
			v.Type,
			v.Bridge,
			fmt.Sprintf("%v/%v", v.VM, v.Interface),
			v.Path,
			v.Mode,
			strconv.FormatBool(v.Compress),
		}
		resp.Tabular = append(resp.Tabular, row)
	}

	return nil

	// TODO: How does this fit in?
	//
	// get netflow stats for each bridge
	//var nfstats string
	//b := enumerateBridges()
	//for _, v := range b {
	//	nf, err := getNetflowFromBridge(v)
	//	if err != nil {
	//		if !strings.Contains(err.Error(), "has no netflow object") {
	//			return cliResponse{
	//				Error: err.Error(),
	//			}
	//		}
	//		continue
	//	}
	//	nfstats += fmt.Sprintf("Bridge %v:\n", v)
	//	nfstats += fmt.Sprintf("minimega listening on port: %v\n", nf.GetPort())
	//	nfstats += nf.GetStats()
	//}

	//out := o.String() + "\n" + nfstats
}
开发者ID:cdshann,项目名称:minimega,代码行数:58,代码来源:capture_cli.go

示例5: hostTapList

func hostTapList(resp *minicli.Response) {
	resp.Header = []string{"bridge", "tap", "vlan"}
	resp.Tabular = [][]string{}

	// find all the host taps first
	for k, b := range bridges {
		for name, tap := range b.Taps {
			if tap.host {
				resp.Tabular = append(resp.Tabular, []string{
					k, name, strconv.Itoa(tap.lan),
				})
			}
		}
	}
}
开发者ID:jenareljam,项目名称:minimega,代码行数:15,代码来源:bridge.go

示例6: cliBridge

func cliBridge(c *minicli.Command, resp *minicli.Response) error {
	iface := c.StringArgs["interface"]
	remoteIP := c.StringArgs["remote"]

	// Get the specifed bridge. If we're listing the bridges, we'll get the
	// default bridge which should be fine.
	br, err := getBridge(c.StringArgs["bridge"])
	if err != nil {
		return err
	}

	if c.BoolArgs["trunk"] {
		return br.AddTrunk(iface)
	} else if c.BoolArgs["notrunk"] {
		return br.RemoveTrunk(iface)
	} else if c.BoolArgs["tunnel"] {
		t := bridge.TunnelVXLAN
		if c.BoolArgs["gre"] {
			t = bridge.TunnelGRE
		}

		return br.AddTunnel(t, remoteIP)
	} else if c.BoolArgs["notunnel"] {
		return br.RemoveTunnel(iface)
	}

	// Must want to list bridges
	resp.Header = []string{"Bridge", "Existed before minimega", "Active VLANs", "Trunk ports", "Tunnels"}
	resp.Tabular = [][]string{}

	for _, info := range bridges.Info() {
		vlans := []string{}
		for k, _ := range info.VLANs {
			vlans = append(vlans, printVLAN(k))
		}
		sort.Strings(vlans)

		row := []string{
			info.Name,
			strconv.FormatBool(info.PreExist),
			fmt.Sprintf("%v", vlans),
			fmt.Sprintf("%v", info.Trunks),
			fmt.Sprintf("%v", info.Tunnels)}
		resp.Tabular = append(resp.Tabular, row)
	}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:48,代码来源:bridge_cli.go

示例7: cliVmMigrate

func cliVmMigrate(c *minicli.Command, resp *minicli.Response) error {
	if _, ok := c.StringArgs["vm"]; !ok { // report current migrations
		resp.Header = []string{"id", "name", "status", "%% complete"}

		for _, vm := range vms.FindKvmVMs() {
			status, complete, err := vm.QueryMigrate()
			if err != nil {
				return err
			}
			if status == "" {
				continue
			}

			resp.Tabular = append(resp.Tabular, []string{
				fmt.Sprintf("%v", vm.GetID()),
				vm.GetName(),
				status,
				fmt.Sprintf("%.2f", complete)})
		}

		return nil
	}

	vm, err := vms.FindKvmVM(c.StringArgs["vm"])
	if err != nil {
		return err
	}

	return vm.Migrate(c.StringArgs["filename"])
}
开发者ID:cdshann,项目名称:minimega,代码行数:30,代码来源:vm_cli.go

示例8: cliHost

func cliHost(c *minicli.Command, resp *minicli.Response) error {
	// If they selected one of the fields to display
	for k := range c.BoolArgs {
		val, err := hostInfoFns[k]()
		if err != nil {
			return err
		}

		resp.Response = val
		return nil
	}

	// Must want all fields
	resp.Header = hostInfoKeys

	row := []string{}
	for _, k := range resp.Header {
		val, err := hostInfoFns[k]()
		if err != nil {
			return err
		}

		row = append(row, val)
	}
	resp.Tabular = [][]string{row}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:28,代码来源:stats.go

示例9: cliCC

func cliCC(c *minicli.Command, resp *minicli.Response) error {
	// Ensure that cc is running before proceeding
	if ccNode == nil {
		return errors.New("cc service not running")
	}

	if len(c.BoolArgs) > 0 {
		// Invoke a particular handler
		for k, fn := range ccCliSubHandlers {
			if c.BoolArgs[k] {
				log.Debug("cc handler %v", k)
				return fn(c, resp)
			}
		}

		return errors.New("unreachable")
	}

	// Getting status
	clients := ccNode.GetActiveClients()

	resp.Header = []string{"number of clients"}
	resp.Tabular = [][]string{
		[]string{
			fmt.Sprintf("%v", len(clients)),
		},
	}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:30,代码来源:cc_cli.go

示例10: hostTapList

func hostTapList(resp *minicli.Response) {
	resp.Header = []string{"bridge", "tap", "vlan", "option"}
	resp.Tabular = [][]string{}

	// find all the host taps first
	for k, v := range bridges {
		for lan, t := range v.lans {
			for tap, ti := range t.Taps {
				if ti.host {
					resp.Tabular = append(resp.Tabular, []string{
						k, tap, strconv.Itoa(lan), ti.hostOption,
					})
				}
			}
		}
	}
}
开发者ID:summits,项目名称:minimega,代码行数:17,代码来源:bridge.go

示例11: cliFile

func cliFile(c *minicli.Command, resp *minicli.Response) error {
	if c.BoolArgs["get"] {
		return iom.Get(c.StringArgs["file"])
	} else if c.BoolArgs["delete"] {
		return iom.Delete(c.StringArgs["file"])
	} else if c.BoolArgs["status"] {
		transfers := iom.Status()
		resp.Header = []string{"Filename", "Temporary directory", "Completed parts", "Queued"}
		resp.Tabular = [][]string{}

		for _, f := range transfers {
			completed := fmt.Sprintf("%v/%v", len(f.Parts), f.NumParts)
			row := []string{f.Filename, f.Dir, completed, fmt.Sprintf("%v", f.Queued)}
			resp.Tabular = append(resp.Tabular, row)
		}

		return nil
	}

	// must be "list"
	path := c.StringArgs["path"]
	if path == "" {
		path = "/"
	}

	resp.Header = []string{"dir", "name", "size"}
	resp.Tabular = [][]string{}

	files, err := iom.List(path)
	if err == nil && files != nil {
		for _, f := range files {
			var dir string
			if f.Dir {
				dir = "<dir>"
			}

			row := []string{dir, f.Name, strconv.FormatInt(f.Size, 10)}
			resp.Tabular = append(resp.Tabular, row)
		}
	}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:43,代码来源:iomeshage.go

示例12: cliVNCList

// List all active recordings and playbacks
func cliVNCList(c *minicli.Command, resp *minicli.Response) error {
	resp.Header = []string{"name", "type", "time", "filename"}
	resp.Tabular = [][]string{}

	vncRecordingLock.RLock()
	for _, v := range vncKBRecording {
		resp.Tabular = append(resp.Tabular, []string{
			v.VM.Name, "record kb",
			time.Since(v.start).String(),
			v.file.Name(),
		})
	}
	vncRecordingLock.RUnlock()

	vncRecordingLock.RLock()
	for _, v := range vncFBRecording {
		resp.Tabular = append(resp.Tabular, []string{
			v.VM.Name, "record fb",
			time.Since(v.start).String(),
			v.file.Name(),
		})
	}
	vncRecordingLock.RUnlock()

	vncPlayingLock.RLock()
	for _, v := range vncPlaying {
		var r string
		if v.state == Pause {
			r = "PAUSED"
		} else {
			r = v.timeRemaining() + " remaining"
		}

		resp.Tabular = append(resp.Tabular, []string{
			v.VM.Name, "playback kb",
			r,
			v.file.Name(),
		})
	}
	vncPlayingLock.RUnlock()
	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:43,代码来源:vnc_cli.go

示例13: cliDnsmasq

func cliDnsmasq(c *minicli.Command, resp *minicli.Response) error {
	if c.StringArgs["id"] == Wildcard {
		// Must be "kill all"
		return dnsmasqKillAll()
	} else if c.StringArgs["id"] != "" {
		// Must be "kill <id>"
		id, err := strconv.Atoi(c.StringArgs["id"])
		if err != nil {
			return err
		}

		return dnsmasqKill(id)
	} else if c.StringArgs["listen"] != "" || c.StringArgs["config"] != "" {
		// Must be "start"
		// We don't need to differentiate between the two start commands
		// because dnsmasqStart expects the zero string value when values
		// are not specified.
		return dnsmasqStart(
			c.StringArgs["listen"],
			c.StringArgs["low"],
			c.StringArgs["high"],
			c.StringArgs["config"])
	}

	// Must be "list"
	resp.Header = []string{"ID", "Listening Address", "Min", "Max", "Path", "PID"}
	resp.Tabular = [][]string{}
	for id, c := range dnsmasqServers {
		pid := dnsmasqPID(id)
		resp.Tabular = append(resp.Tabular, []string{
			strconv.Itoa(id),
			c.Addr,
			c.MinRange,
			c.MaxRange,
			c.Path,
			strconv.Itoa(pid)})
	}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:40,代码来源:dnsmasq.go

示例14: cliCCProcess

// process
func cliCCProcess(c *minicli.Command, resp *minicli.Response) error {
	if c.BoolArgs["kill"] {
		return cliCCProcessKill(c, resp)
	} else if c.BoolArgs["killall"] {
		return cliCCProcessKillAll(c, resp)
	}

	// list processes
	v := c.StringArgs["vm"]

	var activeVms []string

	if v == Wildcard {
		clients := ccNode.GetActiveClients()
		for _, client := range clients {
			activeVms = append(activeVms, client.UUID)
		}
	} else {
		// get the vm uuid
		vm := vms.FindVM(v)
		if vm == nil {
			return vmNotFound(v)
		}
		log.Debug("got vm: %v %v", vm.GetID(), vm.GetName())
		activeVms = []string{vm.GetUUID()}
	}

	resp.Header = []string{"name", "uuid", "pid", "command"}
	for _, uuid := range activeVms {
		vm := vms.FindVM(uuid)
		if vm == nil {
			return vmNotFound(v)
		}

		processes, err := ccNode.GetProcesses(uuid)
		if err != nil {
			return err
		}

		for _, p := range processes {
			resp.Tabular = append(resp.Tabular, []string{
				vm.GetName(),
				vm.GetUUID(),
				fmt.Sprintf("%v", p.PID),
				strings.Join(p.Command, " "),
			})
		}
	}

	return nil
}
开发者ID:cdshann,项目名称:minimega,代码行数:52,代码来源:cc_cli.go

示例15: hostTapList

// hostTapList populates resp with information about all the host taps.
func hostTapList(resp *minicli.Response) {
	resp.Header = []string{"bridge", "tap", "vlan"}
	resp.Tabular = [][]string{}

	// no namespace active => add an extra column
	ns := GetNamespace()
	if ns == nil {
		resp.Header = append(resp.Header, "namespace")
	}

	// find all the host taps first
	for _, tap := range bridges.HostTaps() {
		// skip taps that don't belong to the active namespace
		if ns != nil && !ns.HasTap(tap.Name) {
			continue
		}

		row := []string{
			tap.Bridge, tap.Name, printVLAN(tap.VLAN),
		}

		// no namespace active => find namespace tap belongs to so that we can
		// populate that column
		if ns == nil {
			v := ""
			for _, n := range ListNamespaces() {
				if ns := GetOrCreateNamespace(n); ns.HasTap(tap.Name) {
					v = ns.Name
					break
				}
			}

			row = append(row, v)
		}

		resp.Tabular = append(resp.Tabular, row)
	}
}
开发者ID:cdshann,项目名称:minimega,代码行数:39,代码来源:bridge.go


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