Skip to content

Commit

Permalink
enabling the return of ansible_host for satellite hosts as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmidefaz committed Jul 25, 2024
1 parent 9dcc74d commit 0d868a4
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions internal/api/controllers/private/highlevelConnectionStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type rhcSatellite struct {
SatelliteInstanceID string
SatelliteOrgID string
SatelliteVersion string
Hosts []string
HostsWithAnsibleHosts []HostIdWithAnsibleHost
SourceID string
RhcClientID *string
SourceAvailabilityStatus *string
Expand Down Expand Up @@ -110,15 +110,12 @@ func sortHostsByRecipient(details []inventory.HostDetails) (satelliteDetails []i
return satelliteConnectedHosts, directConnectedHosts, hostsNotConnected
}

func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *string, ansibleHost *string, orgID OrgId, hosts []string, recipientType string, status string) RecipientWithConnectionInfo {
func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *string, orgID OrgId, hosts []HostIdWithAnsibleHost, recipientType string, status string) RecipientWithConnectionInfo {
formatedHosts := make([]HostId, len(hosts))
var formatedSatID SatelliteId
var formatedSatOrgID SatelliteOrgId
var formatedRHCClientID public.RunRecipient

var formattedAnsibleHost AnsibleHost
formattedHostWithAnsibleHost := make([]HostIdWithAnsibleHost, len(hosts))

if satID != nil {
formatedSatID = SatelliteId(*satID)
}
Expand All @@ -131,13 +128,8 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
formatedRHCClientID = public.RunRecipient(*rhcClientID)
}

if ansibleHost != nil {
formattedAnsibleHost = AnsibleHost(*ansibleHost)
}

for i, host := range hosts {
formatedHosts[i] = HostId(host)
formattedHostWithAnsibleHost[i] = HostIdWithAnsibleHost{HostId: HostId(host), AnsibleHost: formattedAnsibleHost}
formatedHosts[i] = host.HostId
}

connectionInfo := RecipientWithConnectionInfo{
Expand All @@ -148,7 +140,7 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
SatOrgId: formatedSatOrgID,
Status: status,
Systems: formatedHosts,
SystemsInfo: formattedHostWithAnsibleHost,
SystemsInfo: hosts,
}

return connectionInfo
Expand All @@ -171,7 +163,13 @@ func getDirectConnectStatus(ctx echo.Context, client connectors.CloudConnectorCl
connectionStatus = "disconnected"
}

responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, host.AnsibleHost, orgId, []string{host.ID}, string(RecipientType_directConnect), connectionStatus))
ansibleHost := AnsibleHost("")
if host.AnsibleHost != nil {
ansibleHost = AnsibleHost(*host.AnsibleHost)
}
hostWithAnsibleHost := []HostIdWithAnsibleHost{{ansibleHost, HostId(host.ID)}}

responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, orgId, hostWithAnsibleHost, string(RecipientType_directConnect), connectionStatus))
}

return responses, nil
Expand All @@ -198,14 +196,20 @@ func groupHostsBySatellite(hostDetails []inventory.HostDetails) map[string]*rhcS
satInstanceAndOrg := *host.SatelliteInstanceID + *host.SatelliteOrgID
_, exists := hostsGroupedBySatellite[satInstanceAndOrg]

ansibleHost := AnsibleHost("")
if host.AnsibleHost != nil {
ansibleHost = AnsibleHost(*host.AnsibleHost)
}
hostWithAnsibleHost := HostIdWithAnsibleHost{ansibleHost, HostId(host.ID)}

if exists {
hostsGroupedBySatellite[satInstanceAndOrg].Hosts = append(hostsGroupedBySatellite[satInstanceAndOrg].Hosts, host.ID)
hostsGroupedBySatellite[satInstanceAndOrg].HostsWithAnsibleHosts = append(hostsGroupedBySatellite[satInstanceAndOrg].HostsWithAnsibleHosts, hostWithAnsibleHost)
} else {
hostsGroupedBySatellite[satInstanceAndOrg] = &rhcSatellite{
SatelliteInstanceID: *host.SatelliteInstanceID,
SatelliteOrgID: *host.SatelliteOrgID,
SatelliteVersion: *host.SatelliteVersion,
Hosts: []string{host.ID},
SatelliteInstanceID: *host.SatelliteInstanceID,
SatelliteOrgID: *host.SatelliteOrgID,
SatelliteVersion: *host.SatelliteVersion,
HostsWithAnsibleHosts: []HostIdWithAnsibleHost{hostWithAnsibleHost},
}
}
}
Expand Down Expand Up @@ -247,21 +251,21 @@ func createSatelliteConnectionResponses(ctx echo.Context, hostsGroupedBySatellit
connectionStatus = "disconnected"
}

responses = append(responses, formatConnectionResponse(&satellite.SatelliteInstanceID, &satellite.SatelliteOrgID, satellite.RhcClientID, nil, orgId, satellite.Hosts, string(RecipientType_satellite), connectionStatus))
responses = append(responses, formatConnectionResponse(&satellite.SatelliteInstanceID, &satellite.SatelliteOrgID, satellite.RhcClientID, orgId, satellite.HostsWithAnsibleHosts, string(RecipientType_satellite), connectionStatus))
}
}

return responses, nil
}

func getRHCStatus(hostDetails []inventory.HostDetails, orgID OrgId) RecipientWithConnectionInfo {
hostIDs := make([]string, len(hostDetails))
hostIDs := make([]HostIdWithAnsibleHost, len(hostDetails))

for i, host := range hostDetails {
hostIDs[i] = host.ID
hostIDs[i] = HostIdWithAnsibleHost{AnsibleHost(*host.AnsibleHost), HostId(host.ID)}
}

return formatConnectionResponse(nil, nil, nil, nil, orgID, hostIDs, "none", "rhc_not_configured")
return formatConnectionResponse(nil, nil, nil, orgID, hostIDs, "none", "rhc_not_configured")
}

func concatResponses(satellite []RecipientWithConnectionInfo, directConnect []RecipientWithConnectionInfo, noRHC []RecipientWithConnectionInfo) []RecipientWithConnectionInfo {
Expand Down

0 comments on commit 0d868a4

Please sign in to comment.