本文整理汇总了Golang中minicli.Response类的典型用法代码示例。如果您正苦于以下问题:Golang Response类的具体用法?Golang Response怎么用?Golang Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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"])
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: cliShell
func cliShell(c *minicli.Command, resp *minicli.Response, background bool) error {
var sOut bytes.Buffer
var sErr bytes.Buffer
p, err := exec.LookPath(c.ListArgs["command"][0])
if err != nil {
return err
}
args := []string{p}
if len(c.ListArgs["command"]) > 1 {
args = append(args, c.ListArgs["command"][1:]...)
}
cmd := &exec.Cmd{
Path: p,
Args: args,
Env: nil,
Dir: "",
Stdout: &sOut,
Stderr: &sErr,
}
log.Info("starting: %v", args)
if err := cmd.Start(); err != nil {
return err
}
if background {
go func() {
if err := cmd.Wait(); err != nil {
log.Error(err.Error())
return
}
log.Info("command %v exited", args)
if out := sOut.String(); out != "" {
log.Info(out)
}
if err := sErr.String(); err != "" {
log.Info(err)
}
}()
return nil
}
if err = cmd.Wait(); err != nil {
return err
}
resp.Response = sOut.String()
resp.Error = sErr.String()
return nil
}
示例7: 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
}
示例8: cliVmConfig
func cliVmConfig(c *minicli.Command, resp *minicli.Response) error {
if c.BoolArgs["save"] {
// Save the current config
savedInfo[c.StringArgs["name"]] = vmConfig.Copy()
return nil
} else if c.BoolArgs["restore"] {
if name, ok := c.StringArgs["name"]; ok {
// Try to restore an existing config
if _, ok := savedInfo[name]; !ok {
return fmt.Errorf("config %v does not exist", name)
}
vmConfig = savedInfo[name].Copy()
return nil
} else if len(savedInfo) == 0 {
return errors.New("no vm configs saved")
}
// List the save configs
for k := range savedInfo {
resp.Response += fmt.Sprintln(k)
}
return nil
} else if c.BoolArgs["clone"] {
// Clone the config of an existing vm
vm := vms.FindVM(c.StringArgs["vm"])
if vm == nil {
return vmNotFound(c.StringArgs["vm"])
}
switch vm := vm.(type) {
case *KvmVM:
vmConfig.BaseConfig = vm.BaseConfig.Copy()
vmConfig.KVMConfig = vm.KVMConfig.Copy()
case *ContainerVM:
vmConfig.BaseConfig = vm.BaseConfig.Copy()
vmConfig.ContainerConfig = vm.ContainerConfig.Copy()
}
return nil
}
// Print the config
resp.Response = vmConfig.String()
return nil
}
示例9: 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),
})
}
}
}
}
示例10: 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
}
示例11: cliVmConfigField
func cliVmConfigField(c *minicli.Command, resp *minicli.Response, field string) error {
// If there are no args it means that we want to display the current value
nArgs := len(c.StringArgs) + len(c.ListArgs) + len(c.BoolArgs)
var ok bool
var fns VMConfigFns
var config interface{}
// Find the right config functions, baseConfigFns has highest priority
if fns, ok = baseConfigFns[field]; ok {
config = &vmConfig.BaseConfig
} else if fns, ok = kvmConfigFns[field]; ok {
config = &vmConfig.KVMConfig
} else if fns, ok = containerConfigFns[field]; ok {
config = &vmConfig.ContainerConfig
} else {
return fmt.Errorf("unknown config field: `%s`", field)
}
if nArgs == 0 {
resp.Response = fns.Print(config)
return nil
}
return fns.Update(config, c)
}
示例12: cliLogFile
func cliLogFile(c *minicli.Command, resp *minicli.Response) error {
if len(c.StringArgs) == 0 {
// Print true or false depending on whether file is enabled
if logFile != nil {
resp.Response = logFile.Name()
}
return nil
}
// Enable logging to file if it's not already enabled
level, _ := log.LevelInt(*f_loglevel)
if logFile != nil {
if err := stopFileLogger(); err != nil {
return err
}
}
err := os.MkdirAll(filepath.Dir(c.StringArgs["file"]), 0755)
if err != nil {
return err
}
flags := os.O_WRONLY | os.O_APPEND | os.O_CREATE
logFile, err = os.OpenFile(c.StringArgs["file"], flags, 0660)
if err != nil {
return err
}
log.AddLogger("file", logFile, level, false)
return nil
}
示例13: cliVmConfigTag
func cliVmConfigTag(c *minicli.Command, resp *minicli.Response) error {
k := c.StringArgs["key"]
if v, ok := c.StringArgs["value"]; ok {
// Setting a new value
vmConfig.Tags[k] = v
} else if k != "" {
// Printing a single tag
resp.Response = vmConfig.Tags[k]
} else {
// Printing all configured tags
resp.Response = vmConfig.TagsString()
}
return nil
}
示例14: 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,
})
}
}
}
}
}
示例15: cliMeshageStatus
func cliMeshageStatus(c *minicli.Command, resp *minicli.Response) error {
mesh := meshageNode.Mesh()
degree := meshageNode.GetDegree()
nodes := len(mesh)
resp.Header = []string{"mesh size", "degree", "peers", "context", "port"}
resp.Tabular = [][]string{
[]string{
strconv.Itoa(nodes),
strconv.FormatUint(uint64(degree), 10),
strconv.Itoa(len(mesh[hostname])),
*f_context,
strconv.Itoa(*f_port),
},
}
return nil
}