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