Files

48 lines
1.4 KiB
Go

// Copyright (C) 2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package node
import (
"github.com/luxfi/cli/v2/pkg/ansible"
"github.com/luxfi/cli/v2/pkg/application"
"github.com/luxfi/cli/v2/pkg/models"
"github.com/luxfi/cli/v2/pkg/utils"
)
func GetHostWithCloudID(app *application.Lux, clusterName string, cloudID string) (*models.Host, error) {
hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName))
if err != nil {
return nil, err
}
monitoringInventoryFile := app.GetMonitoringInventoryDir(clusterName)
if utils.FileExists(monitoringInventoryFile) {
monitoringHosts, err := ansible.GetInventoryFromAnsibleInventoryFile(monitoringInventoryFile)
if err != nil {
return nil, err
}
hosts = append(hosts, monitoringHosts...)
}
for _, host := range hosts {
if host.GetCloudID() == cloudID {
return host, nil
}
}
return nil, nil
}
func GetWarpRelayerHost(app *application.Lux, clusterName string) (*models.Host, error) {
clusterConfig, err := app.GetClusterConfig(clusterName)
if err != nil {
return nil, err
}
relayerCloudID := ""
for _, cloudID := range clusterConfig.GetCloudIDs() {
if nodeConfig, err := app.LoadClusterNodeConfig(cloudID); err != nil {
return nil, err
} else if nodeConfig.IsWarpRelayer {
relayerCloudID = nodeConfig.NodeID
}
}
return GetHostWithCloudID(app, clusterName, relayerCloudID)
}