Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Aug 26, 2024
1 parent 9ac0744 commit 0082488
Showing 1 changed file with 233 additions and 35 deletions.
268 changes: 233 additions & 35 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::inventory::ZoneType;
use crate::omicron_zone_config::{OmicronZone, OmicronZoneNic};
use crate::schema::bp_omicron_zone::ntp_dns_servers;
use crate::schema::{
blueprint, bp_omicron_physical_disk, bp_omicron_zone, bp_omicron_zone_nic,
bp_sled_omicron_physical_disks, bp_sled_omicron_zones, bp_sled_state,
Expand All @@ -19,19 +20,23 @@ use crate::{
};
use chrono::{DateTime, Utc};
use ipnetwork::IpNetwork;
use nexus_types::deployment::BlueprintPhysicalDiskConfig;
use nexus_types::deployment::BlueprintPhysicalDisksConfig;
use nexus_sled_agent_shared::inventory::OmicronZoneDataset;
use nexus_types::deployment::BlueprintTarget;
use nexus_types::deployment::BlueprintZoneConfig;
use nexus_types::deployment::BlueprintZoneDisposition;
use nexus_types::deployment::BlueprintZonesConfig;
use nexus_types::deployment::CockroachDbPreserveDowngrade;
use nexus_types::deployment::{
blueprint_zone_type, BlueprintPhysicalDisksConfig,
};
use nexus_types::deployment::{BlueprintPhysicalDiskConfig, BlueprintZoneType};
use omicron_common::api::internal::shared::NetworkInterface;
use omicron_common::disk::DiskIdentity;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use omicron_uuid_kinds::ZpoolUuid;
use omicron_uuid_kinds::{ExternalIpKind, SledKind, ZpoolKind};
use std::net::{IpAddr, SocketAddrV6};
use uuid::Uuid;

/// See [`nexus_types::deployment::Blueprint`].
Expand Down Expand Up @@ -260,44 +265,237 @@ impl BpOmicronZone {
let external_ip_id = blueprint_zone
.zone_type
.external_networking()
.map(|(ip, _)| ip.id());
let zone = OmicronZone::new(
sled_id,
blueprint_zone.id.into_untyped_uuid(),
blueprint_zone.underlay_address,
blueprint_zone.filesystem_pool.as_ref().map(|pool| pool.id()),
&blueprint_zone.zone_type.clone().into(),
external_ip_id,
)?;
Ok(Self {
.map(|(ip, _)| ip.id().into());

// Create a dummy record to start, then fill in the rest
let mut bp_omicron_zone = BpOmicronZone {
// Fill in the known fields that don't require inspecting
// `blueprint_zone.zone_type`
blueprint_id,
sled_id: zone.sled_id.into(),
id: zone.id,
underlay_address: zone.underlay_address,
zone_type: zone.zone_type,
primary_service_ip: zone.primary_service_ip,
primary_service_port: zone.primary_service_port,
second_service_ip: zone.second_service_ip,
second_service_port: zone.second_service_port,
dataset_zpool_name: zone.dataset_zpool_name,
bp_nic_id: zone.nic_id,
dns_gz_address: zone.dns_gz_address,
dns_gz_address_index: zone.dns_gz_address_index,
ntp_ntp_servers: zone.ntp_ntp_servers,
ntp_dns_servers: zone.ntp_dns_servers,
ntp_domain: zone.ntp_domain,
nexus_external_tls: zone.nexus_external_tls,
nexus_external_dns_servers: zone.nexus_external_dns_servers,
snat_ip: zone.snat_ip,
snat_first_port: zone.snat_first_port,
snat_last_port: zone.snat_last_port,
disposition: to_db_bp_zone_disposition(blueprint_zone.disposition),
external_ip_id: zone.external_ip_id.map(From::from),
sled_id: sled_id.into(),
id: blueprint_zone.id.into_untyped_uuid(),
underlay_address: blueprint_zone.underlay_address.into(),
external_ip_id,
filesystem_pool: blueprint_zone
.filesystem_pool
.as_ref()
.map(|pool| pool.id().into()),
})

// Set the remainder of the fields to a default
disposition: DbBpZoneDisposition::InService,
zone_type: ZoneType::BoundaryNtp,
primary_service_ip: "::1"
.parse::<std::net::Ipv6Addr>()
.unwrap()
.into(),
primary_service_port: 0.into(),
second_service_ip: None,
second_service_port: None,
dataset_zpool_name: None,
bp_nic_id: None,
dns_gz_address: None,
dns_gz_address_index: None,
ntp_ntp_servers: None,
ntp_dns_servers: None,
ntp_domain: None,
nexus_external_tls: None,
nexus_external_dns_servers: None,
snat_ip: None,
snat_first_port: None,
snat_last_port: None,
};

match &blueprint_zone.zone_type {
BlueprintZoneType::BoundaryNtp(
blueprint_zone_type::BoundaryNtp {
address,
ntp_servers,
dns_servers,
domain,
nic,
external_ip,
},
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.zone_type = ZoneType::BoundaryNtp;

// Set the zone specific fields
let snat_cfg = external_ip.snat_cfg;
let (first_port, last_port) = snat_cfg.port_range_raw();
bp_omicron_zone.ntp_ntp_servers = Some(ntp_servers.clone());
bp_omicron_zone.ntp_dns_servers = Some(
dns_servers
.into_iter()
.cloned()
.map(IpNetwork::from)
.collect(),
);
bp_omicron_zone.ntp_domain.clone_from(domain);
bp_omicron_zone.snat_ip = Some(IpNetwork::from(snat_cfg.ip));
bp_omicron_zone.snat_first_port =
Some(SqlU16::from(first_port));
bp_omicron_zone.snat_last_port = Some(SqlU16::from(last_port));
bp_omicron_zone.bp_nic_id = Some(nic.id);
}
BlueprintZoneType::Clickhouse(
blueprint_zone_type::Clickhouse { address, dataset },
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::Clickhouse;
}
BlueprintZoneType::ClickhouseKeeper(
blueprint_zone_type::ClickhouseKeeper { address, dataset },
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::ClickhouseKeeper;
}
BlueprintZoneType::ClickhouseServer(
blueprint_zone_type::ClickhouseServer { address, dataset },
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::ClickhouseServer;
}
BlueprintZoneType::CockroachDb(
blueprint_zone_type::CockroachDb { address, dataset },
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::CockroachDb;
}
BlueprintZoneType::Crucible(blueprint_zone_type::Crucible {
address,
dataset,
}) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::Crucible;
}
BlueprintZoneType::CruciblePantry(
blueprint_zone_type::CruciblePantry { address },
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.zone_type = ZoneType::CruciblePantry;
}
BlueprintZoneType::ExternalDns(
blueprint_zone_type::ExternalDns {
dataset,
http_address,
dns_address,
nic,
},
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(http_address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::ExternalDns;

// Set the zone specific fields
bp_omicron_zone.bp_nic_id = Some(nic.id);
bp_omicron_zone.second_service_ip =
Some(IpNetwork::from(dns_address.addr.ip()));
bp_omicron_zone.second_service_port =
Some(SqlU16::from(dns_address.addr.port()));
}
BlueprintZoneType::InternalDns(
blueprint_zone_type::InternalDns {
dataset,
http_address,
dns_address,
gz_address,
gz_address_index,
},
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(http_address);
bp_omicron_zone.set_zpool_name(dataset);
bp_omicron_zone.zone_type = ZoneType::InternalDns;

// Set the zone specific fields
bp_omicron_zone.second_service_ip =
Some(IpNetwork::from(IpAddr::V6(*dns_address.ip())));
bp_omicron_zone.second_service_port =
Some(SqlU16::from(dns_address.port()));

bp_omicron_zone.dns_gz_address =
Some(ipv6::Ipv6Addr::from(gz_address));
bp_omicron_zone.dns_gz_address_index =
Some(SqlU32::from(*gz_address_index));
}
BlueprintZoneType::InternalNtp(
blueprint_zone_type::InternalNtp {
address,
ntp_servers,
dns_servers,
domain,
},
) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.zone_type = ZoneType::InternalNtp;

// Set the zone specific fields
bp_omicron_zone.ntp_ntp_servers = Some(ntp_servers.clone());
bp_omicron_zone.ntp_dns_servers = Some(
dns_servers.iter().cloned().map(IpNetwork::from).collect(),
);
bp_omicron_zone.ntp_domain.clone_from(domain);
}
BlueprintZoneType::Nexus(blueprint_zone_type::Nexus {
internal_address,
external_ip,
nic,
external_tls,
external_dns_servers,
}) => {
// Set the common fields
bp_omicron_zone
.set_primary_service_ip_and_port(internal_address);
bp_omicron_zone.zone_type = ZoneType::Nexus;

// Set the zone specific fields
bp_omicron_zone.bp_nic_id = Some(nic.id);
bp_omicron_zone.second_service_ip =
Some(IpNetwork::from(external_ip.ip));
bp_omicron_zone.nexus_external_tls = Some(*external_tls);
bp_omicron_zone.nexus_external_dns_servers = Some(
external_dns_servers
.iter()
.cloned()
.map(IpNetwork::from)
.collect(),
);
}
BlueprintZoneType::Oximeter(blueprint_zone_type::Oximeter {
address,
}) => {
// Set the common fields
bp_omicron_zone.set_primary_service_ip_and_port(address);
bp_omicron_zone.zone_type = ZoneType::Oximeter;
}
}

Ok(bp_omicron_zone)
}

fn set_primary_service_ip_and_port(&mut self, address: &SocketAddrV6) {
let (primary_service_ip, primary_service_port) =
(ipv6::Ipv6Addr::from(*address.ip()), SqlU16::from(address.port()));
self.primary_service_ip = primary_service_ip;
self.primary_service_port = primary_service_port;
}

fn set_zpool_name(&mut self, dataset: &OmicronZoneDataset) {
self.dataset_zpool_name = Some(dataset.pool_name.to_string());
}

pub fn into_blueprint_zone_config(
Expand Down

0 comments on commit 0082488

Please sign in to comment.