本文整理汇总了Golang中github.com/vmware/vic/pkg/vsphere/vm.VirtualMachine.IsToolsRunning方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachine.IsToolsRunning方法的具体用法?Golang VirtualMachine.IsToolsRunning怎么用?Golang VirtualMachine.IsToolsRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/vic/pkg/vsphere/vm.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.IsToolsRunning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: enableSSH
func (d *Dispatcher) enableSSH(ctx context.Context, vch *vm.VirtualMachine, password, authorizedKey string) error {
op, err := trace.FromContext(ctx)
if err != nil {
op = trace.NewOperation(ctx, "enable ssh in appliance")
}
state, err := vch.PowerState(op)
if err != nil {
log.Errorf("Failed to get appliance power state, service might not be available at this moment.")
}
if state != types.VirtualMachinePowerStatePoweredOn {
err = errors.Errorf("VCH appliance is not powered on, state %s", state)
op.Errorf("%s", err)
return err
}
running, err := vch.IsToolsRunning(op)
if err != nil || !running {
err = errors.New("Tools is not running in the appliance, unable to continue")
op.Errorf("%s", err)
return err
}
manager := guest.NewOperationsManager(d.session.Client.Client, vch.Reference())
processManager, err := manager.ProcessManager(op)
if err != nil {
err = errors.Errorf("Unable to manage processes in appliance VM: %s", err)
op.Errorf("%s", err)
return err
}
auth := types.NamePasswordAuthentication{}
spec := types.GuestProgramSpec{
ProgramPath: "enable-ssh",
Arguments: string(authorizedKey),
WorkingDirectory: "/",
EnvVariables: []string{},
}
_, err = processManager.StartProgram(op, &auth, &spec)
if err != nil {
err = errors.Errorf("Unable to enable SSH in appliance VM: %s", err)
op.Errorf("%s", err)
return err
}
if password == "" {
return nil
}
// set the password as well
spec = types.GuestProgramSpec{
ProgramPath: "passwd",
Arguments: password,
WorkingDirectory: "/",
EnvVariables: []string{},
}
_, err = processManager.StartProgram(op, &auth, &spec)
if err != nil {
err = errors.Errorf("Unable to enable in appliance VM: %s", err)
op.Errorf("%s", err)
return err
}
return nil
}