Skip to content

Commit

Permalink
Merge pull request #185 from lucab/ups/oem-platform
Browse files Browse the repository at this point in the history
util/cmdline: rename "OEM ID" to "Platform ID"
  • Loading branch information
Luca Bruno authored Mar 26, 2019
2 parents 9a67fdc + e758810 commit 5289e06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ use std::env;
use errors::*;
use metadata::fetch_metadata;

/// Path to kernel command-line (requires procfs mount).
const CMDLINE_PATH: &str = "/proc/cmdline";
const CMDLINE_OEM_FLAG: &str = "coreos.oem.id";

#[derive(Debug)]
struct Config {
Expand Down Expand Up @@ -199,7 +199,7 @@ fn init() -> Result<Config> {
Some(provider) => String::from(provider),
None => {
if matches.is_present("cmdline") {
util::get_oem(CMDLINE_PATH, CMDLINE_OEM_FLAG)?
util::get_platform(CMDLINE_PATH)?
} else {
return Err("Must set either --provider or --cmdline".into());
}
Expand Down
20 changes: 15 additions & 5 deletions src/util/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ use errors::*;
use std::io::Read;
use std::{fs, io};

// Get OEM ID value from cmdline file.
pub fn get_oem(fpath: &str, flagname: &str) -> Result<String> {
/// Platform key.
#[cfg(not(feature = "cl-legacy"))]
const CMDLINE_PLATFORM_FLAG: &str = "ignition.platform.id";
/// Platform key (CL and RHCOS legacy name: "OEM").
#[cfg(feature = "cl-legacy")]
const CMDLINE_PLATFORM_FLAG: &str = "coreos.oem.id";

// Get platform/OEM value from cmdline file.
pub fn get_platform(fpath: &str) -> Result<String> {
// open the cmdline file
let file =
fs::File::open(fpath).chain_err(|| format!("Failed to open cmdline file ({})", fpath))?;
Expand All @@ -36,11 +43,14 @@ pub fn get_oem(fpath: &str, flagname: &str) -> Result<String> {
.read_to_string(&mut contents)
.chain_err(|| format!("Failed to read cmdline file ({})", fpath))?;

match find_flag_value(flagname, &contents) {
Some(s) => Ok(s),
match find_flag_value(CMDLINE_PLATFORM_FLAG, &contents) {
Some(platform) => {
trace!("found '{}' flag: {}", CMDLINE_PLATFORM_FLAG, platform);
Ok(platform)
}
None => bail!(
"Couldn't find flag '{}' in cmdline file ({})",
flagname,
CMDLINE_PLATFORM_FLAG,
fpath
),
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::path::Path;
use std::time::Duration;

mod cmdline;
pub use self::cmdline::get_oem;
pub use self::cmdline::get_platform;

fn key_lookup_line(delim: char, key: &str, line: &str) -> Option<String> {
match line.find(delim) {
Expand Down

0 comments on commit 5289e06

Please sign in to comment.