Skip to content

Commit

Permalink
WIP: start making nexus-side glue
Browse files Browse the repository at this point in the history
  • Loading branch information
lif committed Dec 14, 2023
1 parent b4b332d commit 6d16f2b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
36 changes: 36 additions & 0 deletions nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ impl super::Nexus {
//
// If the operation failed, kick the sled agent error back up to
// the caller to let it decide how to handle it.
//
// When creating the zone for the first time, we just get
// Ok(None) here, which is a no-op. We later asynchronously get
// a cpapi call invoking Self::write_returned_instance_state
match instance_put_result {
Ok(state) => self
.write_returned_instance_state(&instance_id, state)
Expand All @@ -934,6 +938,38 @@ impl super::Nexus {
}
}

/// TODO describe how this relates to [Self::instance_request_state] (above)
pub(crate) async fn instance_handle_creation_result(
&self,
opctx: &OpContext,
instance_id: &Uuid,
result: Result<
Option<nexus::SledInstanceState>,
sled_agent_client::types::Error,
>,
) -> Result<(), Error> {
let (.., authz_instance, db_instance) =
LookupPath::new(&opctx, &self.db_datastore)
.instance_id(*instance_id)
.lookup_for(authz::Action::Modify)
.await?;

let state = self
.db_datastore
.instance_fetch_with_vmm(opctx, &authz_instance)
.await?;

// TODO: add param for sled-agent to show its 'previous' and compare with this
let prev_instance_runtime = &state.instance().runtime_state;

self.handle_instance_put_result(
instance_id,
prev_instance_runtime,
result.map_err(Into::into), // TODO: this isn't real
).await?;
todo!()
}

/// Modifies the runtime state of the Instance as requested. This generally
/// means booting or halting the Instance.
pub(crate) async fn instance_ensure_registered(
Expand Down
28 changes: 28 additions & 0 deletions nexus/src/internal_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,34 @@ async fn cpapi_instances_put(
apictx.internal_latencies.instrument_dropshot_handler(&rqctx, handler).await
}

/// Asynchronously report the result of a potentially long-running
/// instance_put call to sled-agent made during instance creation.
#[endpoint {
method = PUT,
path = "/instances/{instance_id}/creation-result",
}]
async fn cpapi_handle_instance_put_result(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<InstancePathParam>,
result: TypedBody<Result<
Option<SledInstanceState>,
sled_agent_client::types::Error
>>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
let path = path_params.into_inner();
let result = result.into_inner();
let opctx = crate::context::op_context_for_internal_api(&rqctx).await;
let handler = async {
nexus
.instance_handle_creation_result(&opctx, &path.instance_id, result)
.await?;
Ok(HttpResponseUpdatedNoContent())
};
apictx.internal_latencies.instrument_dropshot_handler(&rqctx, handler).await
}

/// Path parameters for Disk requests (internal API)
#[derive(Deserialize, JsonSchema)]
struct DiskPathParam {
Expand Down
3 changes: 2 additions & 1 deletion sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,8 @@ mod tests {
first_port: 0,
last_port: 0,
},
external_ips: vec![],
ephemeral_ip: None,
floating_ips: vec![],
firewall_rules: vec![],
dhcp_config: DhcpConfig {
dns_servers: vec![],
Expand Down

0 comments on commit 6d16f2b

Please sign in to comment.