• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang util.HomePath函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudius-systems/capstan/util.HomePath函数的典型用法代码示例。如果您正苦于以下问题:Golang HomePath函数的具体用法?Golang HomePath怎么用?Golang HomePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: DeleteVM

func DeleteVM(name string) error {
	gcUtil("deleteinstance", "--delete_boot_pd", "-f", name)

	gcUtil("deletedisk", "-f", name)

	dir := filepath.Join(util.HomePath(), ".capstan/instances/gce", name)
	c := &VMConfig{
		InstanceDir: dir,
		ConfigFile:  filepath.Join(dir, "osv.config"),
	}
	cmd := exec.Command("rm", "-f", c.ConfigFile)
	_, err := cmd.Output()
	if err != nil {
		fmt.Printf("rm failed: %s", c.ConfigFile)
		return err
	}

	cmd = exec.Command("rmdir", c.InstanceDir)
	_, err = cmd.Output()
	if err != nil {
		fmt.Printf("rmdir failed: %s", c.InstanceDir)
		return err
	}

	return nil
}
开发者ID:pelamlio,项目名称:capstan,代码行数:26,代码来源:gce.go


示例2: StopVM

func StopVM(name string) error {
	dir := filepath.Join(util.HomePath(), ".capstan/instances/qemu", name)
	c := &VMConfig{
		Monitor: filepath.Join(dir, "osv.monitor"),
	}
	conn, err := net.Dial("unix", c.Monitor)
	if err != nil {
		// The instance is stopped already
		return nil
	}

	writer := bufio.NewWriter(conn)

	cmd := `{ "execute": "qmp_capabilities"}`
	writer.WriteString(cmd)

	cmd = `{ "execute": "system_powerdown" }`
	writer.WriteString(cmd)

	cmd = `{ "execute": "quit" }`
	writer.WriteString(cmd)

	writer.Flush()

	return nil
}
开发者ID:nivertech,项目名称:capstan,代码行数:26,代码来源:qemu.go


示例3: DeleteVM

func DeleteVM(name string) error {
	dir := filepath.Join(util.HomePath(), ".capstan/instances/vmw", name)
	c := &VMConfig{
		VMXFile:    filepath.Join(dir, "osv.vmx"),
		ConfigFile: filepath.Join(dir, "osv.config"),
	}

	cmd := exec.Command("rm", "-f", c.ConfigFile)
	_, err := cmd.Output()
	if err != nil {
		fmt.Printf("Failed to delete: %s", c.ConfigFile)
		return err
	}

	cmd, err = vmxRun("-T", "ws", "deleteVM", c.VMXFile)
	if err != nil {
		fmt.Printf("Failed to delete VM %s", c.VMXFile)
		return err
	}
	err = cmd.Wait()
	if err != nil {
		fmt.Printf("Failed to delete VM %s", c.VMXFile)
		return err
	}
	return nil
}
开发者ID:networkelements,项目名称:capstan,代码行数:26,代码来源:vmw.go


示例4: DeleteVM

func DeleteVM(name string) error {
	dir := filepath.Join(util.HomePath(), ".capstan/instances/vbox", name)
	c := &VMConfig{
		ConfigFile: filepath.Join(dir, "osv.config"),
	}

	cmd := exec.Command("rm", "-f", c.ConfigFile)
	_, err := cmd.Output()
	if err != nil {
		fmt.Printf("Failed to delete: %s", c.ConfigFile)
		return err
	}

	return VBoxManage("unregistervm", name, "--delete")
}
开发者ID:networkelements,项目名称:capstan,代码行数:15,代码来源:vbox.go


示例5: StopVM

func StopVM(name string) error {
	dir := filepath.Join(util.HomePath(), ".capstan/instances/vmw", name)
	c := &VMConfig{
		VMXFile: filepath.Join(dir, "osv.vmx"),
	}
	cmd, err := vmxRun("-T", "ws", "stop", c.VMXFile)
	if err != nil {
		fmt.Printf("Failed to stop VM", c.VMXFile)
		return err
	}
	err = cmd.Wait()
	if err != nil {
		fmt.Printf("Failed to stop VM", c.VMXFile)
		return err
	}
	return nil
}
开发者ID:posix4e,项目名称:capstan,代码行数:17,代码来源:vmw.go


示例6: LoadConfig

func LoadConfig(name string) (*VMConfig, error) {
	dir := filepath.Join(util.HomePath(), ".capstan/instances/gce", name)
	file := filepath.Join(dir, "osv.config")
	c := VMConfig{}

	data, err := ioutil.ReadFile(file)
	if err != nil {
		fmt.Printf("Failed to open: %s\n", file)
		return nil, err
	}
	err = yaml.Unmarshal(data, &c)
	if err != nil {
		return nil, err
	}

	return &c, nil
}
开发者ID:pelamlio,项目名称:capstan,代码行数:17,代码来源:gce.go


示例7: Stop

func Stop(name string) error {
	instanceName := ""
	instancePlatform := ""
	rootDir := filepath.Join(util.HomePath(), ".capstan", "instances")
	platforms, _ := ioutil.ReadDir(rootDir)
	for _, platform := range platforms {
		if platform.IsDir() {
			platformDir := filepath.Join(rootDir, platform.Name())
			instances, _ := ioutil.ReadDir(platformDir)
			for _, instance := range instances {
				if instance.IsDir() {
					if name == instance.Name() {
						instanceName = instance.Name()
						instancePlatform = platform.Name()
					}
				}
			}
		}
	}

	if instanceName == "" {
		fmt.Printf("Instance: %s not found\n", name)
		return nil
	}

	var err error
	switch instancePlatform {
	case "qemu":
		err = qemu.StopVM(name)
	case "vbox":
		err = vbox.StopVM(name)
	case "vmw":
		err = vmw.StopVM(name)
	}

	if err != nil {
		fmt.Printf("Failed to stop instance: %s\n", name)
	}

	fmt.Printf("Stopped instance: %s\n", name)
	return nil
}
开发者ID:posix4e,项目名称:capstan,代码行数:42,代码来源:stop.go


示例8: Instances

func Instances() error {
	header := fmt.Sprintf("%-20s %-10s %-10s %-15s", "Name", "Platform", "Status", "Image")
	fmt.Println(header)
	rootDir := filepath.Join(util.HomePath(), ".capstan", "instances")
	platforms, _ := ioutil.ReadDir(rootDir)
	for _, platform := range platforms {
		if platform.IsDir() {
			platformDir := filepath.Join(rootDir, platform.Name())
			instances, _ := ioutil.ReadDir(platformDir)
			for _, instance := range instances {
				if instance.IsDir() {
					instanceDir := filepath.Join(platformDir, instance.Name())
					printInstance(instance.Name(), platform.Name(), instanceDir)
				}
			}
		}
	}

	return nil
}
开发者ID:posix4e,项目名称:capstan,代码行数:20,代码来源:instance.go


示例9: DeleteVM

func DeleteVM(name string) error {
	dir := filepath.Join(util.HomePath(), ".capstan/instances/qemu", name)
	c := &VMConfig{
		InstanceDir: dir,
		Monitor:     filepath.Join(dir, "osv.monitor"),
		Image:       filepath.Join(dir, "disk.qcow2"),
		ConfigFile:  filepath.Join(dir, "osv.config"),
	}
	cmd := exec.Command("rm", "-f", c.Image, " ", c.Monitor, " ", c.ConfigFile)
	_, err := cmd.Output()
	if err != nil {
		fmt.Printf("rm failed: %s, %s", c.Image, c.Monitor)
		return err
	}

	cmd = exec.Command("rmdir", c.InstanceDir)
	_, err = cmd.Output()
	if err != nil {
		fmt.Printf("rmdir failed: %s", c.InstanceDir)
		return err
	}

	return nil
}
开发者ID:nivertech,项目名称:capstan,代码行数:24,代码来源:qemu.go


示例10: Run


//.........这里部分代码省略.........
	fmt.Printf("Created instance: %s\n", id)
	// Do not set RawTerm for gce
	if config.Hypervisor != "gce" {
		util.RawTerm()
		defer util.ResetTerm()
	}

	switch config.Hypervisor {
	case "qemu":
		dir := filepath.Join(os.Getenv("HOME"), ".capstan/instances/qemu", id)
		bridge := config.Bridge
		if bridge == "" {
			bridge = "virbr0"
		}
		config := &qemu.VMConfig{
			Name:        id,
			Image:       path,
			Verbose:     true,
			Memory:      size,
			Cpus:        config.Cpus,
			Networking:  config.Networking,
			Bridge:      bridge,
			NatRules:    config.NatRules,
			BackingFile: true,
			InstanceDir: dir,
			Monitor:     filepath.Join(dir, "osv.monitor"),
			ConfigFile:  filepath.Join(dir, "osv.config"),
		}
		cmd, err = qemu.LaunchVM(config)
	case "vbox":
		if format != image.VDI && format != image.VMDK {
			return fmt.Errorf("%s: image format of %s is not supported, unable to run it.", config.Hypervisor, path)
		}
		dir := filepath.Join(util.HomePath(), ".capstan/instances/vbox", id)
		bridge := config.Bridge
		if bridge == "" {
			bridge = "vboxnet0"
		}
		config := &vbox.VMConfig{
			Name:       id,
			Dir:        filepath.Join(util.HomePath(), ".capstan/instances/vbox"),
			Image:      path,
			Memory:     size,
			Cpus:       config.Cpus,
			Networking: config.Networking,
			Bridge:     bridge,
			NatRules:   config.NatRules,
			ConfigFile: filepath.Join(dir, "osv.config"),
		}
		cmd, err = vbox.LaunchVM(config)
	case "gce":
		if format != image.GCE_TARBALL && format != image.GCE_GS {
			return fmt.Errorf("%s: image format of %s is not supported, unable to run it.", config.Hypervisor, path)
		}
		dir := filepath.Join(util.HomePath(), ".capstan/instances/gce", id)
		c := &gce.VMConfig{
			Name:        id,
			Image:       id,
			Network:     "default",
			MachineType: "n1-standard-1",
			Zone:        "us-central1-a",
			ConfigFile:  filepath.Join(dir, "osv.config"),
			InstanceDir: dir,
		}
		if format == image.GCE_TARBALL {
			c.CloudStoragePath = strings.TrimSuffix(config.GCEUploadDir, "/") + "/" + id + ".tar.gz"
开发者ID:networkelements,项目名称:capstan,代码行数:67,代码来源:run.go


示例11: Run

func Run(repo *util.Repo, config *RunConfig) error {
	var path string
	if config.ImageName != "" {
		if _, err := os.Stat(config.ImageName); os.IsNotExist(err) {
			if repo.ImageExists(config.Hypervisor, config.ImageName) {
				path = repo.ImagePath(config.Hypervisor, config.ImageName)
			} else if util.IsRemoteImage(config.ImageName) {
				err := Pull(repo, config.Hypervisor, config.ImageName)
				if err != nil {
					return err
				}
				path = repo.ImagePath(config.Hypervisor, config.ImageName)
			} else {
				return fmt.Errorf("%s: no such image", config.ImageName)
			}
		} else {
			path = config.ImageName
		}
	} else {
		config.ImageName = repo.DefaultImage()
		if config.ImageName == "" {
			return fmt.Errorf("No Capstanfile found, unable to run.")
		}
		if !repo.ImageExists(config.Hypervisor, config.ImageName) {
			if !util.ConfigExists("Capstanfile") {
				return fmt.Errorf("%s: no such image", config.ImageName)
			}
			err := Build(repo, config.Hypervisor, config.ImageName, config.Verbose)
			if err != nil {
				return err
			}
		}
		path = repo.ImagePath(config.Hypervisor, config.ImageName)
	}
	format, err := image.Probe(path)
	if err != nil {
		return err
	}
	if format == image.Unknown {
		return fmt.Errorf("%s: image format not recognized, unable to run it.", path)
	}
	size, err := util.ParseMemSize(config.Memory)
	if err != nil {
		return err
	}
	var cmd *exec.Cmd
	switch config.Hypervisor {
	case "qemu":
		id := util.ID()
		dir := filepath.Join(os.Getenv("HOME"), ".capstan/instances/qemu", id)
		config := &qemu.VMConfig{
			Name:        id,
			Image:       path,
			Verbose:     true,
			Memory:      size,
			Cpus:        config.Cpus,
			NatRules:    config.NatRules,
			BackingFile: true,
			InstanceDir: dir,
			Monitor:     filepath.Join(dir, "osv.monitor"),
		}
		fmt.Printf("Created instance: %s\n", id)
		tio, _ := util.RawTerm()
		defer util.ResetTerm(tio)
		cmd, err = qemu.LaunchVM(config)
		defer qemu.DeleteVM(config)
	case "vbox":
		if format != image.VDI && format != image.VMDK {
			return fmt.Errorf("%s: image format of %s is not supported, unable to run it.", config.Hypervisor, path)
		}
		id := util.ID()
		config := &vbox.VMConfig{
			Name:     id,
			Dir:      filepath.Join(util.HomePath(), ".capstan/instances/vbox"),
			Image:    path,
			Memory:   size,
			Cpus:     config.Cpus,
			NatRules: config.NatRules,
		}
		fmt.Printf("Created instance: %s\n", id)
		tio, _ := util.RawTerm()
		defer util.ResetTerm(tio)
		cmd, err = vbox.LaunchVM(config)
		defer vbox.DeleteVM(config)
	case "gce":
		id := util.ID()
		bucket := "osvimg"
		config := &gce.VMConfig{
			Name:             "osv-capstan-" + id,
			Image:            "osv-capstan-" + id,
			Network:          "default",
			MachineType:      "n1-standard-1",
			Zone:             "us-central1-a",
			CloudStoragePath: "gs://" + bucket + "/osv-capstan-" + id + ".tar.gz",
			Tarball:          path,
		}
		cmd, err = gce.LaunchVM(config)
	case "vmw":
		id := util.ID()
		if format != image.VMDK {
//.........这里部分代码省略.........
开发者ID:posix4e,项目名称:capstan,代码行数:101,代码来源:run.go



注:本文中的github.com/cloudius-systems/capstan/util.HomePath函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.Repo类代码示例发布时间:2022-05-23
下一篇:
Golang fakeyagnats.FakeYagnats类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap