Skip to content

Commit

Permalink
mock up saga step for creating disks during instance create
Browse files Browse the repository at this point in the history
  • Loading branch information
jmpesp committed Mar 21, 2022
1 parent 581bdee commit f5c0195
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 30 deletions.
14 changes: 7 additions & 7 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,8 @@ pub enum VpcFirewallRuleTarget {
Ip(IpAddr),
/// The rule applies to a specific IP subnet
IpNet(IpNet),
// Tags not yet implemented
// Tag(Name),
/* Tags not yet implemented
* Tag(Name), */
}

/// The `VpcFirewallRuleHostFilter` is used to filter traffic on the basis of
Expand Down Expand Up @@ -1455,9 +1455,9 @@ pub enum VpcFirewallRuleHostFilter {
Ip(IpAddr),
/// The rule applies to traffic from/to a specific IP subnet
IpNet(IpNet),
// TODO: Internet gateways not yet implemented
// #[display("inetgw:{0}")]
// InternetGateway(Name),
/* TODO: Internet gateways not yet implemented
* #[display("inetgw:{0}")]
* InternetGateway(Name), */
}

/// Port number used in a transport-layer protocol like TCP or UDP
Expand Down Expand Up @@ -1673,8 +1673,8 @@ pub struct NetworkInterface {

/// The IP address assigned to this interface.
pub ip: IpAddr,
// TODO-correctness: We need to split this into an optional V4 and optional
// V6 address, at least one of which must be specified.
/* TODO-correctness: We need to split this into an optional V4 and optional
* V6 address, at least one of which must be specified. */
}

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions nexus/src/db/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,11 +2243,11 @@ pub struct NetworkInterface {
pub subnet_id: Uuid,
pub mac: MacAddr,
pub ip: ipnetwork::IpNetwork,
// TODO-correctness: We need to split this into an optional V4 and optional V6 address, at
// least one of which will always be specified.
//
// If user requests an address of either kind, give exactly that and not the other.
// If neither is specified, auto-assign one of each?
/* TODO-correctness: We need to split this into an optional V4 and optional V6 address, at
* least one of which will always be specified.
*
* If user requests an address of either kind, give exactly that and not the other.
* If neither is specified, auto-assign one of each? */
}

impl From<NetworkInterface> for external::NetworkInterface {
Expand Down
4 changes: 2 additions & 2 deletions nexus/src/internal_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct SledAgentStartupInfo {
pub struct ZpoolPutRequest {
/// Total size of the pool.
pub size: ByteCount,
// TODO: We could include any other data from `ZpoolInfo` we want,
// such as "allocated/free" space and pool health?
/* TODO: We could include any other data from `ZpoolInfo` we want,
* such as "allocated/free" space and pool health? */
}

#[derive(Serialize, Deserialize, JsonSchema)]
Expand Down
43 changes: 42 additions & 1 deletion nexus/src/sagas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ pub fn saga_instance_create() -> SagaTemplate<SagaInstanceCreate> {
new_action_noop_undo(sic_create_network_interfaces),
);

template_builder.append(
"create_disks",
"CreateDisksForInstance",
ActionFunc::new_action(
sic_create_disks_for_instance,
sic_create_disks_for_instance_undo,
),
);

template_builder.append(
"attach_disks",
"AttachDisksToInstance",
Expand Down Expand Up @@ -488,6 +497,38 @@ async fn sic_create_network_interfaces_undo(
Ok(())
}

/// Create disks during instance creation, and return a list of disk names
// TODO implement
async fn sic_create_disks_for_instance(
sagactx: ActionContext<SagaInstanceCreate>,
) -> Result<Vec<String>, ActionError> {
let saga_params = sagactx.saga_params();
let saga_disks = &saga_params.create_params.disks;

for disk in saga_disks {
match disk {
params::InstanceDiskAttachment::Create(_create_params) => {
return Err(ActionError::action_failed(
"Creating disk during instance create unsupported!"
.to_string(),
));
}

_ => {}
}
}

Ok(vec![])
}

/// Undo disks created during instance creation
// TODO implement
async fn sic_create_disks_for_instance_undo(
_sagactx: ActionContext<SagaInstanceCreate>,
) -> Result<(), anyhow::Error> {
Ok(())
}

async fn sic_attach_disks_to_instance(
sagactx: ActionContext<SagaInstanceCreate>,
) -> Result<(), ActionError> {
Expand Down Expand Up @@ -519,7 +560,7 @@ async fn ensure_instance_disk_attach_state(
for disk in saga_disks {
match disk {
params::InstanceDiskAttachment::Create(_) => {
todo!();
// TODO grab disks created in sic_create_disks_for_instance
}
params::InstanceDiskAttachment::Attach(instance_disk_attach) => {
let disk_name: db::model::Name =
Expand Down
1 change: 0 additions & 1 deletion nexus/tests/integration_tests/unauthorized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async fn test_unauthorized(cptestctx: &ControlPlaneTestContext) {
}
}

//
// SETUP PHASE
//

Expand Down
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
max_width = 80
use_small_heuristics = "max"
edition = "2021"

unstable_features = true
normalize_comments = true
16 changes: 8 additions & 8 deletions sled-agent/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ pub struct DatasetEnsureBody {
pub partition_kind: DatasetKind,
// The address on which the zone will listen for requests.
pub address: SocketAddr,
// NOTE: We could insert a UUID here, if we want that to be set by the
// caller explicitly? Currently, the lack of a UUID implies that
// "at most one partition type" exists within a zpool.
//
// It's unclear if this is actually necessary - making this change
// would also require the RSS to query existing datasets before
// requesting new ones (after all, we generally wouldn't want to
// create two CRDB datasets with different UUIDs on the same zpool).
/* NOTE: We could insert a UUID here, if we want that to be set by the
* caller explicitly? Currently, the lack of a UUID implies that
* "at most one partition type" exists within a zpool.
*
* It's unclear if this is actually necessary - making this change
* would also require the RSS to query existing datasets before
* requesting new ones (after all, we generally wouldn't want to
* create two CRDB datasets with different UUIDs on the same zpool). */
}

impl From<DatasetEnsureBody> for sled_agent_client::types::DatasetEnsureBody {
Expand Down
12 changes: 6 additions & 6 deletions sp-sim/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ pub struct Config {
pub simulated_sps: SimulatedSps,
/// Server-wide logging configuration.
pub log: ConfigLogging,
// Type of SP to simulate.
// pub sp_type: SpType,
// Components to simulate.
// pub components: SpComponents,
// UDP listen address.
// pub bind_address: SocketAddr,
/* Type of SP to simulate.
* pub sp_type: SpType,
* Components to simulate.
* pub components: SpComponents,
* UDP listen address.
* pub bind_address: SocketAddr, */
}

impl Config {
Expand Down

0 comments on commit f5c0195

Please sign in to comment.