CreateConfiguredDriver creates a driver.ConfiguredDriver for the given instance. pidFileOwner identifies the caller (e.g. "ha" or "cli") to isolate driver PID files.
(ctx context.Context, inst *limatype.Instance, sshLocalPort int, pidFileOwner string)
| 23 | // CreateConfiguredDriver creates a driver.ConfiguredDriver for the given instance. |
| 24 | // pidFileOwner identifies the caller (e.g. "ha" or "cli") to isolate driver PID files. |
| 25 | func CreateConfiguredDriver(ctx context.Context, inst *limatype.Instance, sshLocalPort int, pidFileOwner string) (*driver.ConfiguredDriver, error) { |
| 26 | limaDriver := inst.Config.VMType |
| 27 | extDriver, intDriver, exists := registry.Get(*limaDriver) |
| 28 | if !exists { |
| 29 | return nil, fmt.Errorf("unknown or unsupported VM type: %s", *limaDriver) |
| 30 | } |
| 31 | if pidFileOwner == "" { |
| 32 | pidFileOwner = OwnerCLI |
| 33 | } |
| 34 | if extDriver != nil { |
| 35 | extDriver.PIDFileOwner = pidFileOwner |
| 36 | extDriver.Logger.Debugf("Using external driver %#q", extDriver.Name) |
| 37 | if extDriver.Client == nil || extDriver.Command == nil { |
| 38 | logrus.Debugf("Starting new instance of external driver %#q", extDriver.Name) |
| 39 | if err := server.Start(ctx, extDriver, inst.Name); err != nil { |
| 40 | extDriver.Logger.Errorf("Failed to start external driver %#q: %v", extDriver.Name, err) |
| 41 | return nil, err |
| 42 | } |
| 43 | } else { |
| 44 | logrus.Debugf("Reusing existing external driver %#q instance", extDriver.Name) |
| 45 | extDriver.InstanceName = inst.Name |
| 46 | } |
| 47 | |
| 48 | info := extDriver.Client.Info(ctx) |
| 49 | if !info.Features.StaticSSHPort { |
| 50 | inst.SSHLocalPort = sshLocalPort |
| 51 | } |
| 52 | return extDriver.Client.Configure(ctx, inst), nil |
| 53 | } |
| 54 | |
| 55 | info := intDriver.Info(ctx) |
| 56 | logrus.Debugf("Using internal driver %#q", info.Name) |
| 57 | if !info.Features.StaticSSHPort { |
| 58 | inst.SSHLocalPort = sshLocalPort |
| 59 | } |
| 60 | return intDriver.Configure(ctx, inst), nil |
| 61 | } |