Skip to content

Commit

Permalink
return ansible_host with the high level connection status response
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmidefaz committed Jul 16, 2024
1 parent 94a284e commit 93718f1
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 47 deletions.
1 change: 1 addition & 0 deletions internal/api/connectors/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (this *inventoryConnectorImpl) GetHostConnectionDetails(ctx context.Context
SatelliteVersion: satelliteFacts.SatelliteVersion,
SatelliteOrgID: satelliteFacts.SatelliteOrgID,
RHCClientID: systemProfileResults[*host.Id].SystemProfile.RhcClientId,
AnsibleHost: host.AnsibleHost,
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/api/connectors/inventory/inventory_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (this *inventoryConnectorMock) GetHostConnectionDetails(
satelliteOrgID := "5"
satelliteVersion := "6.11"
rhcClientID := "32af5948-301f-449a-a25b-ff34c83264a2"
ansibleHost := "test-ansible-host"

hostDetails := HostDetails{
ID: "c484f980-ab8d-401b-90e7-aa1d4ccf8c0e",
Expand All @@ -43,6 +44,7 @@ func (this *inventoryConnectorMock) GetHostConnectionDetails(
ID: "fe30b997-c15a-44a9-89df-c236c3b5c540",
OwnerID: &ownerID,
RHCClientID: &rhcClientID,
AnsibleHost: &ansibleHost,
}

hostDetailsList := []HostDetails{hostDetails, directConnectDetails}
Expand Down
1 change: 1 addition & 0 deletions internal/api/connectors/inventory/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type HostDetails struct {
SatelliteVersion *string `json:"satellite_version,omitempty"`
SatelliteOrgID *string `json:"satellite_org_id,omitempty"`
RHCClientID *string `json:"rhc_client_id,omitempty"`
AnsibleHost *string `json:"ansible_host,omitempty"`
}

type InventoryConnector interface {
Expand Down
14 changes: 10 additions & 4 deletions internal/api/controllers/private/highlevelConnectionStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ func sortHostsByRecipient(details []inventory.HostDetails) (satelliteDetails []i
return satelliteConnectedHosts, directConnectedHosts, hostsNotConnected
}

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

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

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

for i, host := range hosts {
formatedHosts[i] = HostId(host)
}
Expand All @@ -140,6 +145,7 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
SatOrgId: formatedSatOrgID,
Status: status,
Systems: formatedHosts,
AnsibleHost: formatedAnsibleHost,
}

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

responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, orgId, []string{host.ID}, string(RecipientType_directConnect), connectionStatus))
responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, host.AnsibleHost, orgId, []string{host.ID}, string(RecipientType_directConnect), connectionStatus))
}

return responses, nil
Expand Down Expand Up @@ -238,7 +244,7 @@ func createSatelliteConnectionResponses(ctx echo.Context, hostsGroupedBySatellit
connectionStatus = "disconnected"
}

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

Expand All @@ -252,7 +258,7 @@ func getRHCStatus(hostDetails []inventory.HostDetails, orgID OrgId) RecipientWit
hostIDs[i] = host.ID
}

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

func concatResponses(satellite []RecipientWithConnectionInfo, directConnect []RecipientWithConnectionInfo, noRHC []RecipientWithConnectionInfo) []RecipientWithConnectionInfo {
Expand Down
7 changes: 6 additions & 1 deletion internal/api/controllers/private/runsCreateActions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ func parseRunHosts(input *RunInputHosts) []generic.RunHostsInput {
result := make([]generic.RunHostsInput, len(*input))

for i, host := range *input {
var ansibleHost *string
if host.AnsibleHost != nil {
ansibleHostString := string(*host.AnsibleHost)
ansibleHost = &ansibleHostString
}
result[i] = generic.RunHostsInput{
AnsibleHost: host.AnsibleHost,
AnsibleHost: ansibleHost,
}

if host.InventoryId != nil {
Expand Down
67 changes: 34 additions & 33 deletions internal/api/controllers/private/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion internal/api/controllers/private/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion internal/api/tests/private/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/api/tests/private/runsCreateV1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

var (
ansibleHost = "localhost"
ansibleHost = AnsibleHost("localhost")
)

func dispatch(payload *ApiInternalRunsCreateJSONRequestBody) (*RunsCreated, *ApiInternalRunsCreateResponse) {
Expand Down
18 changes: 12 additions & 6 deletions schema/private.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ components:
type: object
properties:
ansible_host:
type: string
description: |
Host name as known to Ansible inventory.
Used to identify the host in status reports.
example: localhost
minLength: 1
$ref: '#/components/schemas/AnsibleHost'
inventory_id:
type: string
format: uuid
Expand Down Expand Up @@ -336,6 +331,8 @@ components:
description: Indicates the current run status of the recipient
type: string
enum: [connected, disconnected, rhc_not_configured]
ansible_host:
$ref: '#/components/schemas/AnsibleHost'
required:
- recipient
- org_id
Expand All @@ -344,6 +341,7 @@ components:
- sat_org_id
- systems
- status
- ansible_host


HighLevelRecipientStatus:
Expand Down Expand Up @@ -385,6 +383,14 @@ components:
example: jharting
minLength: 1

AnsibleHost:
type: string
description: |
Host name as known to Ansible inventory.
Used to identify the host in status reports.
example: localhost
minLength: 1

Version:
description: Version of the API
type: string
Expand Down

0 comments on commit 93718f1

Please sign in to comment.