mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Enhance instance loading to support remote instances and handle node configuration
This commit is contained in:
@@ -270,24 +270,43 @@ func (im *instanceManager) loadInstance(name, path string) error {
|
|||||||
return fmt.Errorf("instance name mismatch: file=%s, instance.Name=%s", name, persistedInstance.Name)
|
return fmt.Errorf("instance name mismatch: file=%s, instance.Name=%s", name, persistedInstance.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
statusCallback := func(oldStatus, newStatus instance.InstanceStatus) {
|
options := persistedInstance.GetOptions()
|
||||||
im.onStatusChange(persistedInstance.Name, oldStatus, newStatus)
|
|
||||||
|
// Check if this is a remote instance
|
||||||
|
isRemote := options != nil && len(options.Nodes) > 0
|
||||||
|
|
||||||
|
var statusCallback func(oldStatus, newStatus instance.InstanceStatus)
|
||||||
|
if !isRemote {
|
||||||
|
// Only set status callback for local instances
|
||||||
|
statusCallback = func(oldStatus, newStatus instance.InstanceStatus) {
|
||||||
|
im.onStatusChange(persistedInstance.Name, oldStatus, newStatus)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new inst using NewInstance (handles validation, defaults, setup)
|
// Create new inst using NewInstance (handles validation, defaults, setup)
|
||||||
inst := instance.NewInstance(name, &im.backendsConfig, &im.instancesConfig, persistedInstance.GetOptions(), statusCallback)
|
inst := instance.NewInstance(name, &im.backendsConfig, &im.instancesConfig, options, statusCallback)
|
||||||
|
|
||||||
// Restore persisted fields that NewInstance doesn't set
|
// Restore persisted fields that NewInstance doesn't set
|
||||||
inst.Created = persistedInstance.Created
|
inst.Created = persistedInstance.Created
|
||||||
inst.SetStatus(persistedInstance.Status)
|
inst.SetStatus(persistedInstance.Status)
|
||||||
|
|
||||||
// Check for port conflicts and add to maps
|
// Handle remote instance mapping
|
||||||
if inst.GetPort() > 0 {
|
if isRemote {
|
||||||
port := inst.GetPort()
|
nodeName := options.Nodes[0]
|
||||||
if im.ports[port] {
|
nodeConfig, exists := im.nodeConfigMap[nodeName]
|
||||||
return fmt.Errorf("port conflict: instance %s wants port %d which is already in use", name, port)
|
if !exists {
|
||||||
|
return fmt.Errorf("node %s not found for remote instance %s", nodeName, name)
|
||||||
|
}
|
||||||
|
im.instanceNodeMap[name] = nodeConfig
|
||||||
|
} else {
|
||||||
|
// Check for port conflicts only for local instances
|
||||||
|
if inst.GetPort() > 0 {
|
||||||
|
port := inst.GetPort()
|
||||||
|
if im.ports[port] {
|
||||||
|
return fmt.Errorf("port conflict: instance %s wants port %d which is already in use", name, port)
|
||||||
|
}
|
||||||
|
im.ports[port] = true
|
||||||
}
|
}
|
||||||
im.ports[port] = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
im.instances[name] = inst
|
im.instances[name] = inst
|
||||||
|
|||||||
Reference in New Issue
Block a user