當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Response.Response方法代碼示例

本文整理匯總了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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:49,代碼來源:vmconfig_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:16,代碼來源:vmconfig_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:28,代碼來源:stats.go

示例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)
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:26,代碼來源:vmconfig_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:33,代碼來源:log_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:9,代碼來源:misc_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:10,代碼來源:cc_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:57,代碼來源:bridge_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:55,代碼來源:shell.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:20,代碼來源:command_meshage.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:15,代碼來源:command_meshage.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:14,代碼來源:vm_cli.go

示例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")
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:19,代碼來源:misc_cli.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:20,代碼來源:command_meshage.go

示例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
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:38,代碼來源:log_cli.go


注:本文中的minicli.Response.Response方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。