Skip to content

Commit 3c5d1af

Browse files
authored
Add instance ID to managed host api page, if appropriate. (#2004)
## Description In the api web page for a managed host, this adds an "INSTANCE" row under lifecycle if the host is assigned to an instance. We have the link going from instance to host, but we did not have one going back. ## Type of Change <!-- Check one that best describes this PR --> - [ ] **Add** - New feature or capability - [X] **Change** - Changes in existing functionality - [ ] **Fix** - Bug fixes - [ ] **Remove** - Removed features or deprecated functionality - [ ] **Internal** - Internal changes (refactoring, tests, docs, etc.) ## Related Issues (Optional) <!-- If applicable, provide GitHub Issue. --> ## Breaking Changes - [ ] This PR contains breaking changes <!-- If checked above, describe the breaking changes and migration steps --> ## Testing <!-- How was this tested? Check all that apply --> - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [X] Manual testing performed - [ ] No testing required (docs, internal refactor, etc.) ## Additional Notes <!-- Any additional context, deployment notes, or reviewer guidance --> --------- Signed-off-by: Stoo Davies <189670495+stoo-davies@users.noreply.github.com>
1 parent c3bb1ce commit 3c5d1af

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

crates/api/src/web/machine.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,27 @@ pub async fn detail(
795795

796796
let mut display: MachineDetail = machine.into();
797797

798+
if display.is_host {
799+
match state
800+
.find_instance_by_machine_id(tonic::Request::new(machine_id))
801+
.await
802+
.map(|response| response.into_inner())
803+
{
804+
Ok(instances) => {
805+
if let Some(instance_id) = instances
806+
.instances
807+
.first()
808+
.and_then(|instance| instance.id.as_ref())
809+
{
810+
display.lifecycle_detail.associated_instance_id = Some(instance_id.to_string());
811+
}
812+
}
813+
Err(err) => {
814+
tracing::warn!(%err, %machine_id, "find_instance_by_machine_id failed");
815+
}
816+
}
817+
}
818+
798819
if display.has_instance_type {
799820
match fetch_instance_type_names(&state, vec![display.instance_type_id.clone()]).await {
800821
Ok(mut instance_types) => {

crates/api/src/web/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub(crate) struct StateSlaDetail {
162162
#[template(path = "lifecycle_detail.html")]
163163
pub(crate) struct LifecycleDetail {
164164
pub state_display: StateDisplay,
165+
pub associated_instance_id: Option<String>,
165166
pub json_state: Option<String>,
166167
pub version: String,
167168
pub time_in_state: String,
@@ -187,6 +188,7 @@ impl LifecycleDetail {
187188
state,
188189
time_in_state_above_sla,
189190
},
191+
associated_instance_id: None,
190192
json_state,
191193
time_in_state: config_version::since_state_change_humanized(&version),
192194
version,

crates/api/templates/lifecycle_detail.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ <h2>Lifecycle</h2>
44
<th>State</th>
55
<td>{{ state_display|safe }}</td>
66
</tr>
7+
{% if let Some(associated_instance_id) = associated_instance_id %}
8+
<tr><th>Instance</th><td><a href="/admin/instance/{{ associated_instance_id }}">{{ associated_instance_id }}</a></td></tr>
9+
{% endif %}
710
{% if let Some(json_state) = json_state %}
811
<tr>
912
<th>JSON State</th>

0 commit comments

Comments
 (0)