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

Golang config.MachineConfigModel类代码示例

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

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



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

示例1: doCleanup

// doCleanup ...
// @isSkipHostCleanup : !!! should only be specified in case the host will be destroyed right after
//   the cleanup. 'will-be-destroyed' will leave the host as-it-is, uncleared!!
func doCleanup(configModel config.MachineConfigModel, isSkipHostCleanup string) error {
	log.Infof("==> doCleanup (mode: %s)", configModel.CleanupMode)

	if isSkipHostCleanup != "will-be-destroyed" {
		if configModel.CleanupMode == config.CleanupModeRollback {
			if err := utils.Run(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "snapshot", "pop", "--no-delete"); err != nil {
				return err
			}
		} else if configModel.CleanupMode == config.CleanupModeRecreate {
			if err := doRecreateCleanup(configModel); err != nil {
				return err
			}
		} else if configModel.CleanupMode == config.CleanupModeDestroy {
			if err := doDestroyCleanup(configModel); err != nil {
				return err
			}
		} else if configModel.CleanupMode == config.CleanupModeCustomCommand {
			if err := doCustomCleanup(configModel); err != nil {
				return err
			}
		} else {
			return fmt.Errorf("Unsupported CleanupMode: %s", configModel.CleanupMode)
		}
	} else {
		log.Warnln("Skipping Host Cleanup! This option should only be used if the Host is destroyed immediately after this cleanup!!")
	}

	if err := config.DeleteSSHFilesFromDir(MachineWorkdir.Get()); err != nil {
		return fmt.Errorf("Failed to delete SSH file from workdir: %s", err)
	}

	return nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:36,代码来源:cleanup.go


示例2: doDestroy

func doDestroy(configModel config.MachineConfigModel) error {
	log.Infoln("==> doDestroy")

	if err := utils.Run(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "destroy", "-f"); err != nil {
		return fmt.Errorf("'vagrant destroy' failed with error: %s", err)
	}

	return nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:9,代码来源:destroy.go


示例3: doSetupSSH

func doSetupSSH(configModel config.MachineConfigModel) (config.SSHConfigModel, error) {
	log.Infoln("==> doSetupSSH")
	sshConfigModel := config.SSHConfigModel{}

	// Read `vagrant ssh-config` log/output
	outputs, err := utils.RunAndReturnCombinedOutput(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "ssh-config")
	if err != nil {
		log.Errorf("'vagrant ssh-config' failed with output: %s", outputs)
		return sshConfigModel, err
	}
	log.Debugln("===> (raw) vagrant ssh-config retrieved")

	// Convert `vagrant ssh-config` to our SSHConfigModel
	sshConfigModel, err = config.CreateSSHConfigFromVagrantSSHConfigLog(outputs)
	if err != nil {
		log.Errorf("'vagrant ssh-config' returned an invalid output (failed to scan SSH Config): %s", outputs)
		return sshConfigModel, err
	}
	log.Debugln("===> vagrant ssh-config parsed")

	// Generate SSH Keypair
	privBytes, pubBytes, err := utils.GenerateSSHKeypair()
	if err != nil {
		return sshConfigModel, err
	}
	log.Debugln("===> SSH Keypair generated")

	// Write the SSH Keypair to file
	privKeyFilePth, _, err := config.WriteSSHKeypairToFiles(MachineWorkdir.Get(), privBytes, pubBytes)
	if err != nil {
		return sshConfigModel, err
	}
	log.Debugln("===> SSH Keypair written to file")

	// Replace the ~/.ssh/authorized_keys inside the VM to only allow
	//  the new keypair
	replaceAuthKeysCmd := fmt.Sprintf(`printf "%s" > ~/.ssh/authorized_keys`, pubBytes)
	log.Debugf("===> Running command through SSH: %s", replaceAuthKeysCmd)
	if err := utils.RunCommandThroughSSH(sshConfigModel, replaceAuthKeysCmd); err != nil {
		return sshConfigModel, err
	}
	log.Debugln("===> SSH Keypair is now authorized to access the VM")

	// Save private key as the new identity
	sshConfigModel.IdentityPath = privKeyFilePth
	if err := sshConfigModel.WriteIntoFileInDir(MachineWorkdir.Get()); err != nil {
		return sshConfigModel, err
	}
	log.Debugln("===> New identity (private SSH key) saved into config in workdir")

	log.Debugln("==> doSetupSSH [done]")
	return sshConfigModel, nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:53,代码来源:setup.go


示例4: doRecreateCleanup

func doRecreateCleanup(configModel config.MachineConfigModel) error {
	// destroy
	if err := destroyCommon(configModel); err != nil {
		return fmt.Errorf("doRecreateCleanup: failed to destroy: %s", err)
	}

	// re-create
	if err := utils.Run(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "up"); err != nil {
		return fmt.Errorf("'vagrant up' failed with error: %s", err)
	}

	log.Infoln("Machine created and ready!")
	return nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:14,代码来源:cleanup.go


示例5: getVagrantStatus

func getVagrantStatus(configModel config.MachineConfigModel) (vagrant.MachineReadableItem, error) {
	// Read `vagrant status` log/output
	outputs, err := utils.RunAndReturnCombinedOutput(MachineWorkdir.Get(),
		configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()),
		"vagrant", "status", "--machine-readable")
	if err != nil {
		return vagrant.MachineReadableItem{}, fmt.Errorf("'vagrant status' failed. Output was: %s", outputs)
	}
	statusItms := vagrant.ParseMachineReadableItemsFromString(outputs, "", "state")
	if len(statusItms) != 1 {
		return vagrant.MachineReadableItem{}, fmt.Errorf("Failed to determine the 'status' of the machine. Output was: %s", outputs)
	}
	return statusItms[0], nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:14,代码来源:cleanup.go


示例6: doCreateIfRequired

func doCreateIfRequired(configModel config.MachineConfigModel) error {
	machineStatus, err := getVagrantStatus(configModel)
	if err != nil {
		return fmt.Errorf("Failed to get vagrant status: %s", err)
	}

	log.Debugf("doCreateIfRequired: machineStatus: %#v", machineStatus)

	if machineStatus.Type == "state" && machineStatus.Data == "not_created" {
		log.Infoln("Machine not yet created - creating with 'vagrant up'...")

		if err := utils.Run(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "up"); err != nil {
			return fmt.Errorf("'vagrant up' failed with error: %s", err)
		}

		log.Infoln("Machine created!")
	}

	return nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:20,代码来源:setup.go


示例7: doCustomCleanup

func doCustomCleanup(configModel config.MachineConfigModel) error {
	log.Infoln("Cleanup mode: custom-command")
	if configModel.CustomCleanupCommand == "" {
		return errors.New("cleanup mode was custom-command, but no custom cleanup command specified")
	}
	log.Infof("=> Specified custom command: %s", configModel.CustomCleanupCommand)

	// Read `vagrant status` log/output
	machineStatus := vagrant.MachineReadableItem{}
	if outputs, err := utils.RunAndReturnCombinedOutput(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "status", "--machine-readable"); err != nil {
		if err != nil {
			log.Errorf("'vagrant status' failed with output: %s", outputs)
			return err
		}
	} else {
		statusItms := vagrant.ParseMachineReadableItemsFromString(outputs, "", "state")
		if len(statusItms) != 1 {
			return fmt.Errorf("Failed to determine the 'status' of the machine. Output was: %s", outputs)
		}
		machineStatus = statusItms[0]
	}

	if machineStatus.Data == "not_created" {
		log.Infoln("Machine not yet created - creating with 'vagrant up'...")
		if err := utils.Run(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", "up"); err != nil {
			return fmt.Errorf("'vagrant up' failed with error: %s", err)
		}
		log.Infoln("Machine created!")
	} else {
		log.Infof("Machine already created - using the specified custom-command (%s) to clean it up...", configModel.CustomCleanupCommand)
		if err := utils.Run(MachineWorkdir.Get(), configModel.AllCmdEnvsForConfigType(MachineConfigTypeID.Get()), "vagrant", configModel.CustomCleanupCommand); err != nil {
			return fmt.Errorf("'vagrant %s' failed with error: %s", configModel.CustomCleanupCommand, err)
		}
		log.Infoln("Successful custom cleanup")
	}

	log.Infoln("Machine created and ready!")
	return nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:39,代码来源:cleanup.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang bson.Raw类代码示例发布时间:2022-05-24
下一篇:
Golang models.StepModel类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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