本文整理汇总了Golang中minicli.Response.Response方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.Response方法的具体用法?Golang Response.Response怎么用?Golang Response.Response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类minicli.Response
的用法示例。
在下文中一共展示了Response.Response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例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: 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)
}
示例5: 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
}
示例6: cliHelp
func cliHelp(c *minicli.Command, resp *minicli.Response) error {
input := ""
if args, ok := c.ListArgs["command"]; ok {
input = strings.Join(args, " ")
}
resp.Response = minicli.Help(input)
return nil
}
示例7: cliCCPrefix
// prefix
func cliCCPrefix(c *minicli.Command, resp *minicli.Response) error {
if prefix, ok := c.StringArgs["prefix"]; ok {
ccPrefix = prefix
return nil
}
resp.Response = ccPrefix
return nil
}
示例8: cliHostTap
// routines for interfacing bridge mechanisms with the cli
func cliHostTap(c *minicli.Command, resp *minicli.Response) error {
if c.BoolArgs["create"] {
b := c.StringArgs["bridge"]
tap, err := hostTapCreate(b, c.StringArgs["tap"], c.StringArgs["vlan"])
if err != nil {
return err
}
if c.BoolArgs["dhcp"] {
log.Debug("obtaining dhcp on tap %v", tap)
var out string
out, err = processWrapper("dhcp", tap)
if err != nil {
err = fmt.Errorf("dhcp error %v: `%v`", err, out)
}
} else if c.StringArgs["ip"] != "" {
ip := c.StringArgs["ip"]
log.Debug("setting ip on tap %v: %v", tap, ip)
var out string
out, err = processWrapper("ip", "addr", "add", "dev", tap, ip)
if err != nil {
err = fmt.Errorf("ip error %v: `%v`", err, out)
}
}
if err != nil {
// One of the above cases failed, try to clean up the tap
if err := hostTapDelete(tap); err != nil {
// Welp, we're boned
log.Error("zombie tap -- %v %v", tap, err)
}
return err
}
// Success!
if ns := GetNamespace(); ns != nil {
// TODO: probably need lock...
ns.Taps[tap] = true
}
resp.Response = tap
return nil
} else if c.BoolArgs["delete"] {
return hostTapDelete(c.StringArgs["id"])
}
// Must be the list command
hostTapList(resp)
return nil
}
示例9: 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
}
示例10: cliMeshageList
func cliMeshageList(c *minicli.Command, resp *minicli.Response) error {
mesh := meshageNode.Mesh()
var keys []string
for k, _ := range mesh {
keys = append(keys, k)
}
sort.Strings(keys)
for _, key := range keys {
v := mesh[key]
resp.Response += fmt.Sprintf("%s\n", key)
sort.Strings(v)
for _, x := range v {
resp.Response += fmt.Sprintf(" |--%s\n", x)
}
}
return nil
}
示例11: cliMeshageDegree
// cli commands for meshage control
func cliMeshageDegree(c *minicli.Command, resp *minicli.Response) error {
if c.StringArgs["degree"] != "" {
degree, err := strconv.ParseUint(c.StringArgs["degree"], 0, 10)
if err != nil {
return err
}
meshageNode.SetDegree(uint(degree))
return nil
}
resp.Response = fmt.Sprintf("%d", meshageNode.GetDegree())
return nil
}
示例12: cliVmQmp
func cliVmQmp(c *minicli.Command, resp *minicli.Response) error {
vm, err := vms.FindKvmVM(c.StringArgs["vm"])
if err != nil {
return err
}
out, err := vm.QMPRaw(c.StringArgs["qmp"])
if err != nil {
return err
}
resp.Response = out
return nil
}
示例13: cliQuit
func cliQuit(c *minicli.Command, resp *minicli.Response) error {
if v, ok := c.StringArgs["delay"]; ok {
delay, err := strconv.Atoi(v)
if err != nil {
return err
}
go func() {
time.Sleep(time.Duration(delay) * time.Second)
teardown()
}()
resp.Response = fmt.Sprintf("quitting after %v seconds", delay)
return nil
}
teardown()
return errors.New("unreachable")
}
示例14: cliMeshageTimeout
func cliMeshageTimeout(c *minicli.Command, resp *minicli.Response) error {
if c.StringArgs["timeout"] != "" {
timeout, err := strconv.Atoi(c.StringArgs["timeout"])
if err != nil {
return err
}
meshageTimeout = time.Duration(timeout) * time.Second
// If the timeout is 0, set to "unlimited"
if meshageTimeout == 0 {
meshageTimeout = math.MaxInt64
}
return nil
}
// get current value
resp.Response = fmt.Sprintf("%v", meshageTimeout)
return nil
}
示例15: cliLogFilter
func cliLogFilter(c *minicli.Command, resp *minicli.Response) error {
if len(c.StringArgs) == 0 {
var filters []string
loggers := log.Loggers()
for _, l := range loggers {
filt, _ := log.Filters(l)
for _, f := range filt {
var found bool
for _, v := range filters {
if v == f {
found = true
}
}
if !found {
filters = append(filters, f)
}
}
}
if len(filters) != 0 {
resp.Response = fmt.Sprintf("%v", filters)
}
return nil
}
filter := c.StringArgs["filter"]
for _, l := range log.Loggers() {
err := log.AddFilter(l, filter)
if err != nil {
return err
}
}
return nil
}