Skip to content

Commit

Permalink
Shatter nexus::defaults into nexus-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
jgallagher committed Jul 22, 2022
1 parent 91a79a4 commit 4f7e8a6
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 22 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"nexus",
"nexus/authz-macros",
"nexus/db-macros",
"nexus/defaults",
"nexus/test-utils",
"nexus/test-utils-macros",
"nexus/types",
Expand Down Expand Up @@ -46,6 +47,7 @@ default-members = [
"nexus",
"nexus/authz-macros",
"nexus/db-macros",
"nexus/defaults",
"nexus/types",
"package",
"rpaths",
Expand Down
1 change: 1 addition & 0 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ usdt = "0.3.1"

authz-macros = { path = "authz-macros" }
db-macros = { path = "db-macros" }
nexus-defaults = { path = "defaults" }
nexus-types = { path = "types" }

[dependencies.chrono]
Expand Down
13 changes: 13 additions & 0 deletions nexus/defaults/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "nexus-defaults"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[dependencies]
ipnetwork = "0.18"
lazy_static = "1.4.0"
rand = "0.8.5"
serde_json = "1.0"

omicron-common = { path = "../../common" }
File renamed without changes.
2 changes: 1 addition & 1 deletion nexus/src/app/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use crate::context::OpContext;
use crate::db;
use crate::db::lookup::LookupPath;
use crate::db::model::Name;
use crate::defaults;
use crate::external_api::params;
use crate::external_api::shared;
use anyhow::Context;
use nexus_defaults as defaults;
use omicron_common::api::external::CreateResult;
use omicron_common::api::external::DataPageParams;
use omicron_common::api::external::DeleteResult;
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/instance_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::context::OpContext;
use crate::db::identity::Resource;
use crate::db::lookup::LookupPath;
use crate::db::queries::network_interface::InsertError as InsertNicError;
use crate::defaults::DEFAULT_PRIMARY_NIC_NAME;
use crate::external_api::params;
use crate::saga_interface::SagaContext;
use crate::{authn, authz, db};
use chrono::Utc;
use lazy_static::lazy_static;
use nexus_defaults::DEFAULT_PRIMARY_NIC_NAME;
use omicron_common::api::external::Error;
use omicron_common::api::external::Generation;
use omicron_common::api::external::IdentityMetadataCreateParams;
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::db::lookup::LookupPath;
use crate::db::model::Name;
use crate::db::model::VpcRouterKind;
use crate::db::queries::vpc_subnet::SubnetError;
use crate::defaults;
use crate::external_api::params;
use nexus_defaults as defaults;
use omicron_common::api::external;
use omicron_common::api::external::CreateResult;
use omicron_common::api::external::DataPageParams;
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/vpc_subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::db::lookup::LookupPath;
use crate::db::model::Name;
use crate::db::model::VpcSubnet;
use crate::db::queries::vpc_subnet::SubnetError;
use crate::defaults;
use crate::external_api::params;
use nexus_defaults as defaults;
use omicron_common::api::external;
use omicron_common::api::external::CreateResult;
use omicron_common::api::external::DataPageParams;
Expand Down
16 changes: 9 additions & 7 deletions nexus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ impl TryFrom<UnvalidatedTunables> for Tunables {

impl Tunables {
fn validate_ipv4_prefix(prefix: u8) -> Result<(), InvalidTunable> {
let absolute_max: u8 = 32_u8.checked_sub(
// Always need space for the reserved Oxide addresses, including the
// broadcast address at the end of the subnet.
((crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES + 1) as f32)
let absolute_max: u8 = 32_u8
.checked_sub(
// Always need space for the reserved Oxide addresses, including the
// broadcast address at the end of the subnet.
((nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES + 1) as f32)
.log2() // Subnet size to bit prefix.
.ceil() // Round up to a whole number of bits.
as u8
).expect("Invalid absolute maximum IPv4 subnet prefix");
if prefix >= crate::defaults::MIN_VPC_IPV4_SUBNET_PREFIX
as u8,
)
.expect("Invalid absolute maximum IPv4 subnet prefix");
if prefix >= nexus_defaults::MIN_VPC_IPV4_SUBNET_PREFIX
&& prefix <= absolute_max
{
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/db/model/ipv4net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::defaults;
use diesel::backend::{Backend, RawValue};
use diesel::deserialize::{self, FromSql};
use diesel::pg::Pg;
use diesel::serialize::{self, ToSql};
use diesel::sql_types;
use ipnetwork::IpNetwork;
use nexus_defaults as defaults;
use omicron_common::api::external;
use std::net::Ipv4Addr;

Expand Down
2 changes: 1 addition & 1 deletion nexus/src/db/model/ipv6net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::defaults;
use diesel::backend::{Backend, RawValue};
use diesel::deserialize::{self, FromSql};
use diesel::pg::Pg;
use diesel::serialize::{self, ToSql};
use diesel::sql_types;
use ipnetwork::IpNetwork;
use nexus_defaults as defaults;
use omicron_common::api::external;
use rand::{rngs::StdRng, SeedableRng};
use std::net::Ipv6Addr;
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/db/model/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::db::collection_insert::DatastoreCollection;
use crate::db::identity::Resource;
use crate::db::model::Vni;
use crate::db::schema::{vpc, vpc_firewall_rule};
use crate::defaults;
use crate::external_api::params;
use chrono::{DateTime, Utc};
use db_macros::Resource;
use ipnetwork::IpNetwork;
use nexus_defaults as defaults;
use nexus_types::external_api::views;
use omicron_common::api::external;
use uuid::Uuid;
Expand Down
8 changes: 4 additions & 4 deletions nexus/src/db/queries/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::db::pool::DbConnection;
use crate::db::queries::next_item::DefaultShiftGenerator;
use crate::db::queries::next_item::NextItem;
use crate::db::schema::network_interface::dsl;
use crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
use chrono::DateTime;
use chrono::Utc;
use diesel::pg::Pg;
Expand All @@ -26,6 +25,7 @@ use diesel::QueryResult;
use diesel::RunQueryDsl;
use ipnetwork::IpNetwork;
use ipnetwork::Ipv4Network;
use nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
use omicron_common::api::external;
use std::net::IpAddr;
use uuid::Uuid;
Expand Down Expand Up @@ -1806,10 +1806,10 @@ mod tests {
fn available_ipv4_addresses(&self) -> [usize; 2] {
[
self.subnets[0].ipv4_block.size() as usize
- crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
- nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
- 1,
self.subnets[1].ipv4_block.size() as usize
- crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
- nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES
- 1,
]
}
Expand Down Expand Up @@ -1969,7 +1969,7 @@ mod tests {
let addresses = context.net1.subnets[0]
.ipv4_block
.iter()
.skip(crate::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES);
.skip(nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES);

for (i, expected_address) in addresses.take(2).enumerate() {
let instance =
Expand Down
1 change: 0 additions & 1 deletion nexus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod cidata;
pub mod config; // Public for testing
pub mod context; // Public for documentation examples
pub mod db; // Public for documentation examples
pub mod defaults; // Public for testing
pub mod external_api; // Public for testing
pub mod internal_api; // Public for testing
mod populate;
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ lazy_static! {

// The instance needs a network interface, too.
pub static ref DEMO_INSTANCE_NIC_NAME: Name =
omicron_nexus::defaults::DEFAULT_PRIMARY_NIC_NAME.parse().unwrap();
nexus_defaults::DEFAULT_PRIMARY_NIC_NAME.parse().unwrap();
pub static ref DEMO_INSTANCE_NIC_URL: String =
format!("{}/{}", *DEMO_INSTANCE_NICS_URL, *DEMO_INSTANCE_NIC_NAME);
pub static ref DEMO_INSTANCE_NIC_CREATE: params::NetworkInterfaceCreate =
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async fn test_instances_create_reboot_halt(
assert_eq!(network_interfaces[0].instance_id, instance.identity.id);
assert_eq!(
network_interfaces[0].identity.name,
omicron_nexus::defaults::DEFAULT_PRIMARY_NIC_NAME
nexus_defaults::DEFAULT_PRIMARY_NIC_NAME
);

// Now, simulate completion of instance boot and check the state reported.
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/subnet_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dropshot::HttpErrorResponseBody;
use http::method::Method;
use http::StatusCode;
use ipnetwork::Ipv4Network;
use nexus_defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
use nexus_test_utils::http_testing::AuthnMode;
use nexus_test_utils::http_testing::NexusRequest;
use nexus_test_utils::http_testing::RequestBuilder;
Expand All @@ -23,7 +24,6 @@ use omicron_common::api::external::{
ByteCount, IdentityMetadataCreateParams, InstanceCpuCount, Ipv4Net,
NetworkInterface,
};
use omicron_nexus::defaults::NUM_INITIAL_RESERVED_IP_ADDRESSES;
use omicron_nexus::external_api::params;
use std::net::Ipv4Addr;

Expand Down

0 comments on commit 4f7e8a6

Please sign in to comment.