Skip to content

Commit b434e18

Browse files
committed
Shatter nexus::defaults into nexus-defaults
1 parent 2e8d674 commit b434e18

18 files changed

+51
-22
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"nexus",
1414
"nexus/authz-macros",
1515
"nexus/db-macros",
16+
"nexus/defaults",
1617
"nexus/test-utils",
1718
"nexus/test-utils-macros",
1819
"nexus/types",
@@ -46,6 +47,7 @@ default-members = [
4647
"nexus",
4748
"nexus/authz-macros",
4849
"nexus/db-macros",
50+
"nexus/defaults",
4951
"nexus/types",
5052
"package",
5153
"rpaths",

nexus/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ usdt = "0.3.1"
6060

6161
authz-macros = { path = "authz-macros" }
6262
db-macros = { path = "db-macros" }
63+
nexus-defaults = { path = "defaults" }
6364
nexus-types = { path = "types" }
6465

6566
[dependencies.chrono]

nexus/defaults/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "nexus-defaults"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MPL-2.0"
6+
7+
[dependencies]
8+
ipnetwork = "0.18"
9+
lazy_static = "1.4.0"
10+
rand = "0.8.5"
11+
serde_json = "1.0"
12+
13+
omicron-common = { path = "../../common" }
File renamed without changes.

nexus/src/app/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::context::OpContext;
99
use crate::db;
1010
use crate::db::lookup::LookupPath;
1111
use crate::db::model::Name;
12-
use crate::defaults;
1312
use crate::external_api::params;
1413
use crate::external_api::shared;
1514
use anyhow::Context;
15+
use nexus_defaults as defaults;
1616
use omicron_common::api::external::CreateResult;
1717
use omicron_common::api::external::DataPageParams;
1818
use omicron_common::api::external::DeleteResult;

nexus/src/app/sagas/instance_create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use crate::context::OpContext;
1313
use crate::db::identity::Resource;
1414
use crate::db::lookup::LookupPath;
1515
use crate::db::queries::network_interface::InsertError as InsertNicError;
16-
use crate::defaults::DEFAULT_PRIMARY_NIC_NAME;
1716
use crate::external_api::params;
1817
use crate::saga_interface::SagaContext;
1918
use crate::{authn, authz, db};
2019
use chrono::Utc;
2120
use lazy_static::lazy_static;
21+
use nexus_defaults::DEFAULT_PRIMARY_NIC_NAME;
2222
use omicron_common::api::external::Error;
2323
use omicron_common::api::external::Generation;
2424
use omicron_common::api::external::IdentityMetadataCreateParams;

nexus/src/app/vpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::db::lookup::LookupPath;
1111
use crate::db::model::Name;
1212
use crate::db::model::VpcRouterKind;
1313
use crate::db::queries::vpc_subnet::SubnetError;
14-
use crate::defaults;
1514
use crate::external_api::params;
15+
use nexus_defaults as defaults;
1616
use omicron_common::api::external;
1717
use omicron_common::api::external::CreateResult;
1818
use omicron_common::api::external::DataPageParams;

nexus/src/app/vpc_subnet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::db::lookup::LookupPath;
1212
use crate::db::model::Name;
1313
use crate::db::model::VpcSubnet;
1414
use crate::db::queries::vpc_subnet::SubnetError;
15-
use crate::defaults;
1615
use crate::external_api::params;
16+
use nexus_defaults as defaults;
1717
use omicron_common::api::external;
1818
use omicron_common::api::external::CreateResult;
1919
use omicron_common::api::external::DataPageParams;

nexus/src/config.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ impl TryFrom<UnvalidatedTunables> for Tunables {
8484

8585
impl Tunables {
8686
fn validate_ipv4_prefix(prefix: u8) -> Result<(), InvalidTunable> {
87-
let absolute_max: u8 = 32_u8.checked_sub(
88-
// Always need space for the reserved Oxide addresses, including the
89-
// broadcast address at the end of the subnet.
90-
((crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES + 1) as f32)
87+
let absolute_max: u8 = 32_u8
88+
.checked_sub(
89+
// Always need space for the reserved Oxide addresses, including the
90+
// broadcast address at the end of the subnet.
91+
((nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES + 1) as f32)
9192
.log2() // Subnet size to bit prefix.
9293
.ceil() // Round up to a whole number of bits.
93-
as u8
94-
).expect("Invalid absolute maximum IPv4 subnet prefix");
95-
if prefix >= crate::defaults::MIN_VPC_IPV4_SUBNET_PREFIX
94+
as u8,
95+
)
96+
.expect("Invalid absolute maximum IPv4 subnet prefix");
97+
if prefix >= nexus_defaults::MIN_VPC_IPV4_SUBNET_PREFIX
9698
&& prefix <= absolute_max
9799
{
98100
Ok(())

nexus/src/db/model/ipv4net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use crate::defaults;
65
use diesel::backend::{Backend, RawValue};
76
use diesel::deserialize::{self, FromSql};
87
use diesel::pg::Pg;
98
use diesel::serialize::{self, ToSql};
109
use diesel::sql_types;
1110
use ipnetwork::IpNetwork;
11+
use nexus_defaults as defaults;
1212
use omicron_common::api::external;
1313
use std::net::Ipv4Addr;
1414

nexus/src/db/model/ipv6net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use crate::defaults;
65
use diesel::backend::{Backend, RawValue};
76
use diesel::deserialize::{self, FromSql};
87
use diesel::pg::Pg;
98
use diesel::serialize::{self, ToSql};
109
use diesel::sql_types;
1110
use ipnetwork::IpNetwork;
11+
use nexus_defaults as defaults;
1212
use omicron_common::api::external;
1313
use rand::{rngs::StdRng, SeedableRng};
1414
use std::net::Ipv6Addr;

nexus/src/db/model/vpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use crate::db::collection_insert::DatastoreCollection;
77
use crate::db::identity::Resource;
88
use crate::db::model::Vni;
99
use crate::db::schema::{vpc, vpc_firewall_rule};
10-
use crate::defaults;
1110
use crate::external_api::params;
1211
use chrono::{DateTime, Utc};
1312
use db_macros::Resource;
1413
use ipnetwork::IpNetwork;
14+
use nexus_defaults as defaults;
1515
use nexus_types::external_api::views;
1616
use omicron_common::api::external;
1717
use uuid::Uuid;

nexus/src/db/queries/network_interface.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::db::pool::DbConnection;
1212
use crate::db::queries::next_item::DefaultShiftGenerator;
1313
use crate::db::queries::next_item::NextItem;
1414
use crate::db::schema::network_interface::dsl;
15-
use crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
1615
use chrono::DateTime;
1716
use chrono::Utc;
1817
use diesel::pg::Pg;
@@ -26,6 +25,7 @@ use diesel::QueryResult;
2625
use diesel::RunQueryDsl;
2726
use ipnetwork::IpNetwork;
2827
use ipnetwork::Ipv4Network;
28+
use nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
2929
use omicron_common::api::external;
3030
use std::net::IpAddr;
3131
use uuid::Uuid;
@@ -1615,10 +1615,10 @@ mod tests {
16151615
fn available_ipv4_addresses(&self) -> [usize; 2] {
16161616
[
16171617
self.subnets[0].ipv4_block.size() as usize
1618-
- crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
1618+
- nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
16191619
- 1,
16201620
self.subnets[1].ipv4_block.size() as usize
1621-
- crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
1621+
- nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
16221622
- 1,
16231623
]
16241624
}
@@ -1778,7 +1778,7 @@ mod tests {
17781778
let addresses = context.net1.subnets[0]
17791779
.ipv4_block
17801780
.iter()
1781-
.skip(crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES);
1781+
.skip(nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES);
17821782

17831783
for (i, expected_address) in addresses.take(2).enumerate() {
17841784
let instance =

nexus/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod cidata;
2020
pub mod config; // Public for testing
2121
pub mod context; // Public for documentation examples
2222
pub mod db; // Public for documentation examples
23-
pub mod defaults; // Public for testing
2423
pub mod external_api; // Public for testing
2524
pub mod internal_api; // Public for testing
2625
mod populate;

nexus/tests/integration_tests/endpoints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ lazy_static! {
222222

223223
// The instance needs a network interface, too.
224224
pub static ref DEMO_INSTANCE_NIC_NAME: Name =
225-
omicron_nexus::defaults::DEFAULT_PRIMARY_NIC_NAME.parse().unwrap();
225+
nexus_defaults::DEFAULT_PRIMARY_NIC_NAME.parse().unwrap();
226226
pub static ref DEMO_INSTANCE_NIC_URL: String =
227227
format!("{}/{}", *DEMO_INSTANCE_NICS_URL, *DEMO_INSTANCE_NIC_NAME);
228228
pub static ref DEMO_INSTANCE_NIC_CREATE: params::NetworkInterfaceCreate =

nexus/tests/integration_tests/instances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async fn test_instances_create_reboot_halt(
208208
assert_eq!(network_interfaces[0].instance_id, instance.identity.id);
209209
assert_eq!(
210210
network_interfaces[0].identity.name,
211-
omicron_nexus::defaults::DEFAULT_PRIMARY_NIC_NAME
211+
nexus_defaults::DEFAULT_PRIMARY_NIC_NAME
212212
);
213213

214214
// Now, simulate completion of instance boot and check the state reported.

nexus/tests/integration_tests/subnet_allocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use dropshot::HttpErrorResponseBody;
1010
use http::method::Method;
1111
use http::StatusCode;
1212
use ipnetwork::Ipv4Network;
13+
use nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
1314
use nexus_test_utils::http_testing::AuthnMode;
1415
use nexus_test_utils::http_testing::NexusRequest;
1516
use nexus_test_utils::http_testing::RequestBuilder;
@@ -23,7 +24,6 @@ use omicron_common::api::external::{
2324
ByteCount, IdentityMetadataCreateParams, InstanceCpuCount, Ipv4Net,
2425
NetworkInterface,
2526
};
26-
use omicron_nexus::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
2727
use omicron_nexus::external_api::params;
2828
use std::net::Ipv4Addr;
2929

0 commit comments

Comments
 (0)