当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.ParseURL方法代码示例

本文整理汇总了Golang中github.com/vmware/govmomi/vim25.Client.ParseURL方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ParseURL方法的具体用法?Golang Client.ParseURL怎么用?Golang Client.ParseURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/vmware/govmomi/vim25.Client的用法示例。


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

示例1: uploadBundle

//
// uploadBundle creates and uploads the ssh key tar bundle to the VM
// using the ProcessManager.
//
// Parameters:
//   vmMoRef: ManagedObjectReference of the VM to which the bundle has to be
//     uploaded
//   ctx: The context for this API call
//   client: Client object that contains the vSphere connection
//
// Returns:
//   (error): errors from generating, uploading bundles from OperationsManager
//      and ProcessManager
//
func (d *Driver) uploadBundle(vmMoRef types.ManagedObjectReference, ctx context.Context, client *vim25.Client) error {
	log.Infof("Provisioning certs and ssh keys...")
	// Generate a tar keys bundle
	if err := d.generateKeyBundle(); err != nil {
		return err
	}

	opman := guest.NewOperationsManager(client, vmMoRef)

	fileman, err := opman.FileManager(ctx)
	if err != nil {
		return err
	}

	src := d.ResolveStorePath("userdata.tar")
	s, err := os.Stat(src)
	if err != nil {
		return err
	}

	auth := AuthFlag{}
	flag := FileAttrFlag{}
	auth.auth.Username = B2DUser
	auth.auth.Password = B2DPass
	flag.SetPerms(0, 0, 660)

	log.Infof("Uploading the tar bundle to the VM")
	url, err := fileman.InitiateFileTransferToGuest(ctx, auth.Auth(), "/tmp/userdata.tar", flag.Attr(), s.Size(), true)
	if err != nil {
		return err
	}
	u, err := client.ParseURL(url)
	if err != nil {
		return err
	}
	if err = client.UploadFile(src, u, nil); err != nil {
		return err
	}

	procman, err := opman.ProcessManager(ctx)
	if err != nil {
		return err
	}

	var env []string
	guestspec := types.GuestProgramSpec{
		ProgramPath:      "/usr/bin/sudo",
		Arguments:        "tar xf /tmp/userdata.tar -C /home/docker/",
		WorkingDirectory: "",
		EnvVariables:     env,
	}

	log.Debugf("Unbundling the keys into user directory")
	pid, err := procman.StartProgram(ctx, auth.Auth(), &guestspec)
	if err != nil {
		return err
	}

	// Wait for tar to complete
	pids := []int64{pid}
	done := false
	for done != true {
		procs, err := procman.ListProcesses(ctx, auth.Auth(), pids)
		if err != nil {
			return err
		}
		if procs[0].EndTime != nil {
			done = true
		}
	}

	guestspec = types.GuestProgramSpec{
		ProgramPath:      "/usr/bin/sudo",
		Arguments:        "chown -R docker:staff /home/docker",
		WorkingDirectory: "",
		EnvVariables:     env,
	}

	log.Debugf("Setting permissions for untarred files")
	_, err = procman.StartProgram(ctx, auth.Auth(), &guestspec)
	if err != nil {
		log.Debugf("Error Setting permissions for untarred files")
		return err
	}

	return nil
//.........这里部分代码省略.........
开发者ID:containerx,项目名称:machine,代码行数:101,代码来源:vsphere.go


注:本文中的github.com/vmware/govmomi/vim25.Client.ParseURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。