update to proxmox-sys 0.2 crate

- imported pbs-api-types/src/common_regex.rs from old proxmox crate
- use hex crate to generate/parse hex digest
- remove all reference to proxmox crate (use proxmox-sys and
  proxmox-serde instead)

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer
2021-11-23 17:57:00 +01:00
parent bd00ff10e4
commit 25877d05ac
201 changed files with 627 additions and 1535 deletions

View File

@ -4,7 +4,7 @@ use std::collections::HashMap;
use anyhow::{Error, bail, format_err};
use apt_pkg_native::Cache;
use proxmox::tools::fs::{file_read_optional_string, replace_file, CreateOptions};
use proxmox_sys::fs::{file_read_optional_string, replace_file, CreateOptions};
use proxmox_schema::const_regex;
use pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR_M;
@ -102,7 +102,7 @@ fn get_changelog_url(
command.arg("changelog");
command.arg("--print-uris");
command.arg(package);
let output = pbs_tools::run_command(command, None)?; // format: 'http://foo/bar' package.changelog
let output = proxmox_sys::command::run_command(command, None)?; // format: 'http://foo/bar' package.changelog
let output = match output.splitn(2, ' ').next() {
Some(output) => {
if output.len() < 2 {

View File

@ -27,7 +27,7 @@ pub fn get_lvm_devices(
let mut command = std::process::Command::new(PVS_BIN_PATH);
command.args(&["--reportformat", "json", "--noheadings", "--readonly", "-o", "pv_name"]);
let output = pbs_tools::run_command(command, None)?;
let output = proxmox_sys::command::run_command(command, None)?;
let mut device_set: HashSet<u64> = HashSet::new();

View File

@ -14,9 +14,9 @@ use once_cell::sync::OnceCell;
use ::serde::{Deserialize, Serialize};
use proxmox::sys::error::io_err_other;
use proxmox::sys::linux::procfs::{MountInfo, mountinfo::Device};
use proxmox::{io_bail, io_format_err};
use proxmox_sys::error::io_err_other;
use proxmox_sys::linux::procfs::{MountInfo, mountinfo::Device};
use proxmox_sys::{io_bail, io_format_err};
use proxmox_schema::api;
use pbs_api_types::{BLOCKDEVICE_NAME_REGEX, StorageStatus};
@ -498,7 +498,7 @@ impl Disk {
let mut map = HashMap::new();
for item in pbs_tools::fs::read_subdir(libc::AT_FDCWD, sys_path)? {
for item in proxmox_sys::fs::read_subdir(libc::AT_FDCWD, sys_path)? {
let item = item?;
let name = match item.file_name().to_str() {
Ok(name) => name,
@ -574,7 +574,7 @@ pub fn get_lsblk_info() -> Result<Vec<LsblkInfo>, Error> {
let mut command = std::process::Command::new("lsblk");
command.args(&["--json", "-o", "path,parttype,fstype"]);
let output = pbs_tools::run_command(command, None)?;
let output = proxmox_sys::command::run_command(command, None)?;
let mut output: serde_json::Value = output.parse()?;
@ -680,7 +680,7 @@ fn scan_partitions(
let mut found_dm = false;
let mut found_partitions = false;
for item in pbs_tools::fs::read_subdir(libc::AT_FDCWD, &sys_path)? {
for item in proxmox_sys::fs::read_subdir(libc::AT_FDCWD, &sys_path)? {
let item = item?;
let name = match item.file_name().to_str() {
Ok(name) => name,
@ -770,7 +770,7 @@ pub fn get_disks(
let mut result = HashMap::new();
for item in pbs_tools::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX)? {
for item in proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX)? {
let item = item?;
let name = item.file_name().to_str().unwrap().to_string();
@ -886,7 +886,7 @@ pub fn reread_partition_table(disk: &Disk) -> Result<(), Error> {
command.arg("--rereadpt");
command.arg(disk_path);
pbs_tools::run_command(command, None)?;
proxmox_sys::command::run_command(command, None)?;
Ok(())
}
@ -905,7 +905,7 @@ pub fn inititialize_gpt_disk(disk: &Disk, uuid: Option<&str>) -> Result<(), Erro
command.arg(disk_path);
command.args(&["-U", uuid]);
pbs_tools::run_command(command, None)?;
proxmox_sys::command::run_command(command, None)?;
Ok(())
}
@ -922,7 +922,7 @@ pub fn create_single_linux_partition(disk: &Disk) -> Result<Disk, Error> {
command.args(&["-n1", "-t1:8300"]);
command.arg(disk_path);
pbs_tools::run_command(command, None)?;
proxmox_sys::command::run_command(command, None)?;
let mut partitions = disk.partitions()?;
@ -975,7 +975,7 @@ pub fn create_file_system(disk: &Disk, fs_type: FileSystemType) -> Result<(), Er
command.args(&["-t", &fs_type]);
command.arg(disk_path);
pbs_tools::run_command(command, None)?;
proxmox_sys::command::run_command(command, None)?;
Ok(())
}
@ -984,7 +984,7 @@ pub fn create_file_system(disk: &Disk, fs_type: FileSystemType) -> Result<(), Er
pub fn complete_disk_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
let mut list = Vec::new();
let dir = match pbs_tools::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX) {
let dir = match proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX) {
Ok(dir) => dir,
Err(_) => return list,
};
@ -1013,7 +1013,7 @@ pub fn get_fs_uuid(disk: &Disk) -> Result<String, Error> {
command.args(&["-o", "export"]);
command.arg(disk_path);
let output = pbs_tools::run_command(command, None)?;
let output = proxmox_sys::command::run_command(command, None)?;
for line in output.lines() {
if let Some(uuid) = line.strip_prefix("UUID=") {

View File

@ -91,7 +91,7 @@ pub fn get_smart_data(
};
command.arg(disk_path);
let output = pbs_tools::run_command(command, Some(|exitcode|
let output = proxmox_sys::command::run_command(command, Some(|exitcode|
(exitcode & 0b0111) == 0 // only bits 0-2 are fatal errors
))?;

View File

@ -34,7 +34,7 @@ pub fn zfs_pool_stats(pool: &OsStr) -> Result<Option<BlockDevStat>, Error> {
path.push(pool);
path.push("io");
let text = match proxmox::tools::fs::file_read_optional_string(&path)? {
let text = match proxmox_sys::fs::file_read_optional_string(&path)? {
Some(text) => text,
None => { return Ok(None); }
};

View File

@ -147,7 +147,7 @@ pub fn zpool_list(pool: Option<String>, verbose: bool) -> Result<Vec<ZFSPoolInfo
if let Some(pool) = pool { command.arg(pool); }
let output = pbs_tools::run_command(command, None)?;
let output = proxmox_sys::command::run_command(command, None)?;
parse_zpool_list(&output)
}

View File

@ -364,7 +364,7 @@ pub fn zpool_status(pool: &str) -> Result<Vec<(String, String)>, Error> {
let mut command = std::process::Command::new("zpool");
command.args(&["status", "-p", "-P", pool]);
let output = pbs_tools::run_command(command, None)?;
let output = proxmox_sys::command::run_command(command, None)?;
parse_zpool_status(&output)
}

View File

@ -18,5 +18,5 @@ use tokio::{
};
use tokio_openssl::SslStream;
use proxmox::sys::linux::socket::set_tcp_keepalive;
use proxmox_sys::linux::socket::set_tcp_keepalive;
use proxmox_http::http::{MaybeTlsStream, ProxyConfig};

View File

@ -32,12 +32,12 @@ pub fn md5sum(data: &[u8]) -> Result<DigestBytes, Error> {
pub fn get_hardware_address() -> Result<String, Error> {
static FILENAME: &str = "/etc/ssh/ssh_host_rsa_key.pub";
let contents = proxmox::tools::fs::file_get_contents(FILENAME)
let contents = proxmox_sys::fs::file_get_contents(FILENAME)
.map_err(|e| format_err!("Error getting host key - {}", e))?;
let digest = md5sum(&contents)
.map_err(|e| format_err!("Error digesting host key - {}", e))?;
Ok(proxmox::tools::bin_to_hex(&digest).to_uppercase())
Ok(hex::encode(&digest).to_uppercase())
}
pub fn assert_if_modified(digest1: &str, digest2: &str) -> Result<(), Error> {

View File

@ -6,7 +6,7 @@ use serde_json::json;
use proxmox_schema::api;
use proxmox::tools::fs::{replace_file, CreateOptions};
use proxmox_sys::fs::{replace_file, CreateOptions};
use proxmox_http::client::SimpleHttp;
use pbs_tools::json::json_object_to_query;
@ -99,7 +99,7 @@ async fn register_subscription(
checktime: i64
) -> Result<(String, String), Error> {
// WHCMS sample code feeds the key into this, but it's just a challenge, so keep it simple
let rand = proxmox::tools::bin_to_hex(&proxmox::sys::linux::random_data(16)?);
let rand = hex::encode(&proxmox_sys::linux::random_data(16)?);
let challenge = format!("{}{}", checktime, rand);
let params = json!({
@ -180,7 +180,7 @@ fn parse_register_response(
if let SubscriptionStatus::ACTIVE = info.status {
let response_raw = format!("{}{}", SHARED_KEY_DATA, challenge);
let expected = proxmox::tools::bin_to_hex(&tools::md5sum(response_raw.as_bytes())?);
let expected = hex::encode(&tools::md5sum(response_raw.as_bytes())?);
if expected != md5hash {
bail!("Subscription API challenge failed, expected {} != got {}", expected, md5hash);
}
@ -241,7 +241,7 @@ pub fn check_subscription(key: String, server_id: String) -> Result<Subscription
/// reads in subscription information and does a basic integrity verification
pub fn read_subscription() -> Result<Option<SubscriptionInfo>, Error> {
let cfg = proxmox::tools::fs::file_read_optional_string(&SUBSCRIPTION_FN)?;
let cfg = proxmox_sys::fs::file_read_optional_string(&SUBSCRIPTION_FN)?;
let cfg = if let Some(cfg) = cfg { cfg } else { return Ok(None); };
let mut cfg = cfg.lines();

View File

@ -6,7 +6,7 @@ use super::types::*;
use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
use proxmox::tools::{fs::replace_file, fs::CreateOptions};
use proxmox_sys::{fs::replace_file, fs::CreateOptions};
lazy_static! {
@ -104,7 +104,7 @@ fn init_mount() -> SectionConfig {
fn parse_systemd_config(config: &SectionConfig, filename: &str) -> Result<SectionConfigData, Error> {
let raw = proxmox::tools::fs::file_get_contents(filename)?;
let raw = proxmox_sys::fs::file_get_contents(filename)?;
let input = String::from_utf8(raw)?;
let data = config.parse(filename, &input)?;

View File

@ -97,7 +97,7 @@ pub fn reload_unit(unit: &str) -> Result<(), Error> {
fn test_escape_unit() -> Result<(), Error> {
fn test_escape(i: &str, expected: &str, is_path: bool) {
use proxmox::tools::systemd::{escape_unit, unescape_unit};
use proxmox_sys::systemd::{escape_unit, unescape_unit};
let escaped = escape_unit(i, is_path);
assert_eq!(escaped, expected);