MCPcopy
hub / github.com/lima-vm/lima / CreateConfiguredDriver

Function CreateConfiguredDriver

pkg/driverutil/instance.go:25–61  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
25func 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}

Callers 8

PrepareFunction · 0.92
unregisterFunction · 0.92
CreateFunction · 0.92
DelFunction · 0.92
SaveFunction · 0.92
LoadFunction · 0.92
ListFunction · 0.92
NewFunction · 0.92

Calls 4

GetFunction · 0.92
StartFunction · 0.92
InfoMethod · 0.65
ConfigureMethod · 0.65

Tested by

no test coverage detected