Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protocol = { path = "protocol" }

# oxide dependencies from github
dpd-client = { git = "https://github.com/oxidecomputer/dendrite", branch = "main" }
omicron-common = { git = "https://github.com/oxidecomputer/omicron", branch = "main" }

# public dependencies from crates.io
anyhow = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions dropshot-apis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub fn environment() -> anyhow::Result<Environment> {
pub fn all_apis() -> anyhow::Result<ManagedApis> {
let apis = vec![ManagedApiConfig {
ident: "lldpd",
versions: Versions::Lockstep {
version: semver::Version::new(0, 0, 1),
versions: Versions::Versioned {
supported_versions: lldpd_api::supported_versions(),
},
title: "Oxide LLDP Daemon",
metadata: ManagedApiMetadata {
Expand Down
1 change: 1 addition & 0 deletions lldpd-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "MPL-2.0"

[dependencies]
dropshot.workspace = true
dropshot-api-manager-types.workspace = true
lldpd-types.workspace = true
protocol.workspace = true
schemars.workspace = true
Expand Down
28 changes: 28 additions & 0 deletions lldpd-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use dropshot::{
HttpResponseOk, HttpResponseUpdatedNoContent, PaginationParams, Path,
Query, RequestContext, ResultsPage, TypedBody,
};
use dropshot_api_manager_types::api_versions;
use lldpd_types::{
build_info::BuildInfo,
interfaces::{Interface, InterfaceAdd},
Expand All @@ -20,6 +21,33 @@ use protocol::types::{ChassisId, PortId, SystemCapabilities};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

api_versions!([
// WHEN CHANGING THE API (part 1 of 2):
//
// +- Pick a new semver and define it in the list below. The list MUST
// | remain sorted, which generally means that your version should go at
// | the very top.
// |
// | Duplicate this line, uncomment the *second* copy, update that copy for
// | your new API version, and leave the first copy commented out as an
// | example for the next person.
// v
// (next_int, IDENT),
(1, INITIAL),
]);

// WHEN CHANGING THE API (part 2 of 2):
//
// The call to `api_versions!` above defines constants of type
// `semver::Version` that you can use in your Dropshot API definition to specify
// the version when a particular endpoint was added or removed. For example, if
// you used:
//
// (2, ADD_FOOBAR)
//
// Then you could use `VERSION_ADD_FOOBAR` as the version in which endpoints
// were added or removed.

#[dropshot::api_description]
pub trait LldpdApi {
type Context;
Expand Down
2 changes: 1 addition & 1 deletion lldpd-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const fn default_port() -> u16 {

// Automatically generate the client bindings using Progenitor.
progenitor::generate_api!(
spec = "../openapi/lldpd.json",
spec = "../openapi/lldpd/lldpd-latest.json",
interface = Positional,
inner_type = slog::Logger,
pre_hook = (|log: &slog::Logger, request: &reqwest::Request| {
Expand Down
1 change: 1 addition & 0 deletions lldpd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ http.workspace = true
lldpd-api.workspace = true
lldpd-common.workspace = true
lldpd-types.workspace = true
omicron-common.workspace = true
protocol.workspace = true
signal-hook.workspace = true
serde.workspace = true
Expand Down
21 changes: 14 additions & 7 deletions lldpd/src/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::net::Ipv4Addr;
use std::net::SocketAddr;
use std::sync::Arc;

use dropshot::ClientSpecifiesVersionInHeader;
use dropshot::EmptyScanParams;
use dropshot::HttpError;
use dropshot::HttpResponseCreated;
Expand All @@ -24,6 +25,7 @@ use dropshot::Query;
use dropshot::RequestContext;
use dropshot::ResultsPage;
use dropshot::TypedBody;
use dropshot::VersionPolicy;
use dropshot::WhichPage;
use lldpd_api::*;
use lldpd_types::build_info::BuildInfo;
Expand Down Expand Up @@ -573,17 +575,22 @@ fn launch_server(
default_handler_task_mode: dropshot::HandlerTaskMode::Detached,
log_headers: Vec::new(),
};
let log = global
.log
.new(o!("unit" => "api-server", "server_id" => id.to_string()));

slog::info!(log, "starting api server {id} on {addr}");
dropshot::HttpServerStarter::new(
&config_dropshot,
dropshot::ServerBuilder::new(
http_api(),
global.clone(),
&log,
global
.log
.new(o!("unit" => "api-server", "server_id" => id.to_string())),
)
.config(config_dropshot)
.version_policy(VersionPolicy::Dynamic(Box::new(
ClientSpecifiesVersionInHeader::new(
omicron_common::api::VERSION_HEADER,
lldpd_api::latest_version(),
),
)))
.build_starter()
.map(|s| s.start())
.map_err(|e| anyhow::anyhow!(e.to_string()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://oxide.computer",
"email": "api@oxide.computer"
},
"version": "0.0.1"
"version": "1.0.0"
},
"paths": {
"/build-info": {
Expand Down
1 change: 1 addition & 0 deletions openapi/lldpd/lldpd-latest.json