本文整理匯總了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
}