fix: recover only managed homelab edge instance
This commit is contained in:
parent
dc13b19893
commit
3080289280
|
|
@ -7995,6 +7995,8 @@ refresh_oci_edge_endpoint() {
|
|||
local oci_bin=""
|
||||
local vnic_id=""
|
||||
local instance_compartment="${LAB_OCI_COMPARTMENT_ID:-}"
|
||||
local candidate_compartment=""
|
||||
local candidate_id=""
|
||||
|
||||
# A recreated OCI instance can receive a new public IP. Prefer the
|
||||
# foundation output over inventory so a standalone `edge` run is
|
||||
|
|
@ -8034,6 +8036,40 @@ refresh_oci_edge_endpoint() {
|
|||
fi
|
||||
fi
|
||||
|
||||
# State may have been lost even though the Jeannie-created instance still
|
||||
# exists. Recover only the exact managed identity: display name
|
||||
# homelab-edge plus managed_by=jeannie. Never adopt arbitrary jump boxes.
|
||||
if [[ -z "${discovered_edge_instance_id}" && -n "${LAB_OCI_TENANCY_ID:-}" ]] &&
|
||||
declare -F oci_cli_resolve >/dev/null 2>&1; then
|
||||
oci_bin="${oci_bin:-$(oci_cli_resolve 2>/dev/null || true)}"
|
||||
if [[ -n "${oci_bin}" ]]; then
|
||||
local -a edge_compartments=("${instance_compartment}" "${LAB_OCI_TENANCY_ID}")
|
||||
for candidate_compartment in "${edge_compartments[@]}"; do
|
||||
[[ -n "${candidate_compartment}" ]] || continue
|
||||
candidate_id="$("${oci_bin}" compute instance list \
|
||||
--compartment-id "${candidate_compartment}" --all \
|
||||
--query 'data[?"display-name"==`homelab-edge` && "freeform-tags"."managed_by"==`jeannie` && "lifecycle-state"!=`TERMINATED`].id | [0]' \
|
||||
--raw-output 2>/dev/null || true)"
|
||||
if [[ -n "${candidate_id}" && "${candidate_id}" != "null" ]]; then
|
||||
discovered_edge_instance_id="${candidate_id}"
|
||||
instance_compartment="${candidate_compartment}"
|
||||
LAB_OCI_EDGE_INSTANCE_MANAGED=true
|
||||
export LAB_OCI_EDGE_INSTANCE_MANAGED
|
||||
vnic_id="$("${oci_bin}" compute vnic-attachment list \
|
||||
--compartment-id "${instance_compartment}" \
|
||||
--instance-id "${discovered_edge_instance_id}" \
|
||||
--query 'data[0]."vnic-id"' --raw-output 2>/dev/null || true)"
|
||||
if [[ -n "${vnic_id}" && "${vnic_id}" != "null" ]]; then
|
||||
discovered_edge_ip="$("${oci_bin}" network vnic get \
|
||||
--vnic-id "${vnic_id}" \
|
||||
--query 'data."public-ip"' --raw-output 2>/dev/null || true)"
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${discovered_edge_ip}" || "${discovered_edge_ip}" == "null" ]]; then
|
||||
if [[ "${LAB_OCI_EDGE_INSTANCE_MANAGED:-false}" == "true" ]]; then
|
||||
echo "Jeannie-managed OCI edge instance has no resolvable public IP; refusing stale LAB_EDGE_HOST." >&2
|
||||
|
|
|
|||
Loading…
Reference in New Issue