src/api2/node.rs: add node parameter
This commit is contained in:
parent
7ae0bf52dd
commit
d8d40dd0c2
|
@ -26,13 +26,12 @@ lazy_static! {
|
||||||
pub static ref PVE_CONFIG_DIGEST_SCHEMA: Arc<Schema> =
|
pub static ref PVE_CONFIG_DIGEST_SCHEMA: Arc<Schema> =
|
||||||
StringSchema::new("Prevent changes if current configuration file has different SHA256 digest. This can be used to prevent concurrent modifications.")
|
StringSchema::new("Prevent changes if current configuration file has different SHA256 digest. This can be used to prevent concurrent modifications.")
|
||||||
.format(PVE_CONFIG_DIGEST_FORMAT.clone()).into();
|
.format(PVE_CONFIG_DIGEST_FORMAT.clone()).into();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
|
|
||||||
let nodes = Router::new()
|
let nodes = Router::new()
|
||||||
.subdir("localhost", node::router());
|
.match_all("node", node::router());
|
||||||
|
|
||||||
let route = Router::new()
|
let route = Router::new()
|
||||||
.get(ApiMethod::new(
|
.get(ApiMethod::new(
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
use failure::*;
|
||||||
|
|
||||||
|
use crate::tools;
|
||||||
use crate::api_schema::*;
|
use crate::api_schema::*;
|
||||||
use crate::api_schema::router::*;
|
use crate::api_schema::router::*;
|
||||||
use serde_json::{json};
|
use serde_json::{json};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
mod tasks;
|
mod tasks;
|
||||||
mod time;
|
mod time;
|
||||||
|
@ -9,6 +14,23 @@ mod dns;
|
||||||
mod syslog;
|
mod syslog;
|
||||||
mod services;
|
mod services;
|
||||||
|
|
||||||
|
lazy_static!{
|
||||||
|
|
||||||
|
pub static ref NODE_SCHEMA: Arc<Schema> = Arc::new(
|
||||||
|
StringSchema::new("Node name (or 'localhost')")
|
||||||
|
.format(
|
||||||
|
Arc::new(ApiStringFormat::VerifyFn(|node| {
|
||||||
|
if node == "localhost" || node == tools::nodename() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(format_err!("no such node '{}'", node))
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
|
|
||||||
let route = Router::new()
|
let route = Router::new()
|
||||||
|
|
|
@ -129,6 +129,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
get_dns,
|
get_dns,
|
||||||
ObjectSchema::new("Read DNS settings.")
|
ObjectSchema::new("Read DNS settings.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
).returns(
|
).returns(
|
||||||
ObjectSchema::new("Returns DNS server IPs and sreach domain.")
|
ObjectSchema::new("Returns DNS server IPs and sreach domain.")
|
||||||
.required("digest", PVE_CONFIG_DIGEST_SCHEMA.clone())
|
.required("digest", PVE_CONFIG_DIGEST_SCHEMA.clone())
|
||||||
|
@ -142,6 +143,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
update_dns,
|
update_dns,
|
||||||
ObjectSchema::new("Returns DNS server IPs and sreach domain.")
|
ObjectSchema::new("Returns DNS server IPs and sreach domain.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("search", SEARCH_DOMAIN_SCHEMA.clone())
|
.required("search", SEARCH_DOMAIN_SCHEMA.clone())
|
||||||
.optional("dns1", FIRST_DNS_SERVER_SCHEMA.clone())
|
.optional("dns1", FIRST_DNS_SERVER_SCHEMA.clone())
|
||||||
.optional("dns2", SECOND_DNS_SERVER_SCHEMA.clone())
|
.optional("dns2", SECOND_DNS_SERVER_SCHEMA.clone())
|
||||||
|
|
|
@ -20,7 +20,9 @@ pub fn router() -> Router {
|
||||||
let route = Router::new()
|
let route = Router::new()
|
||||||
.get(ApiMethod::new(
|
.get(ApiMethod::new(
|
||||||
get_network_config,
|
get_network_config,
|
||||||
ObjectSchema::new("Read network configuration.")));
|
ObjectSchema::new("Read network configuration.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
|
));
|
||||||
|
|
||||||
route
|
route
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,6 +226,7 @@ pub fn router() -> Router {
|
||||||
Ok(Value::from(result))
|
Ok(Value::from(result))
|
||||||
},
|
},
|
||||||
ObjectSchema::new("Directory index.")
|
ObjectSchema::new("Directory index.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("service", service_id_schema.clone()))
|
.required("service", service_id_schema.clone()))
|
||||||
)
|
)
|
||||||
.subdir(
|
.subdir(
|
||||||
|
@ -234,7 +235,8 @@ pub fn router() -> Router {
|
||||||
.get(ApiMethod::new(
|
.get(ApiMethod::new(
|
||||||
get_service_state,
|
get_service_state,
|
||||||
ObjectSchema::new("Read service properties.")
|
ObjectSchema::new("Read service properties.")
|
||||||
.required("service", service_id_schema.clone()))
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
|
.required("service", service_id_schema.clone()))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.subdir(
|
.subdir(
|
||||||
|
@ -244,6 +246,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
start_service,
|
start_service,
|
||||||
ObjectSchema::new("Start service.")
|
ObjectSchema::new("Start service.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("service", service_id_schema.clone())
|
.required("service", service_id_schema.clone())
|
||||||
).protected(true)
|
).protected(true)
|
||||||
)
|
)
|
||||||
|
@ -255,6 +258,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
stop_service,
|
stop_service,
|
||||||
ObjectSchema::new("Stop service.")
|
ObjectSchema::new("Stop service.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("service", service_id_schema.clone())
|
.required("service", service_id_schema.clone())
|
||||||
).protected(true)
|
).protected(true)
|
||||||
)
|
)
|
||||||
|
@ -266,6 +270,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
restart_service,
|
restart_service,
|
||||||
ObjectSchema::new("Restart service.")
|
ObjectSchema::new("Restart service.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("service", service_id_schema.clone())
|
.required("service", service_id_schema.clone())
|
||||||
).protected(true)
|
).protected(true)
|
||||||
)
|
)
|
||||||
|
@ -277,6 +282,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
reload_service,
|
reload_service,
|
||||||
ObjectSchema::new("Reload service.")
|
ObjectSchema::new("Reload service.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("service", service_id_schema.clone())
|
.required("service", service_id_schema.clone())
|
||||||
).protected(true)
|
).protected(true)
|
||||||
)
|
)
|
||||||
|
@ -288,6 +294,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
list_services,
|
list_services,
|
||||||
ObjectSchema::new("Service list.")
|
ObjectSchema::new("Service list.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
).returns(
|
).returns(
|
||||||
ArraySchema::new(
|
ArraySchema::new(
|
||||||
"Returns a list of systemd services.",
|
"Returns a list of systemd services.",
|
||||||
|
|
|
@ -101,7 +101,8 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
get_syslog,
|
get_syslog,
|
||||||
ObjectSchema::new("Read server time and time zone settings.")
|
ObjectSchema::new("Read server time and time zone settings.")
|
||||||
.optional(
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
|
.optional(
|
||||||
"start",
|
"start",
|
||||||
IntegerSchema::new("Start line number.")
|
IntegerSchema::new("Start line number.")
|
||||||
.minimum(0)
|
.minimum(0)
|
||||||
|
|
|
@ -24,7 +24,7 @@ fn get_task_status(
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
json!({
|
json!({
|
||||||
"status": "running",
|
"status": "stopped",
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ fn extract_upid(param: &Value) -> Result<UPID, Error> {
|
||||||
fn read_task_log(
|
fn read_task_log(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
_rpcenv: &mut RpcEnvironment,
|
rpcenv: &mut RpcEnvironment,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
|
|
||||||
let upid = extract_upid(¶m)?;
|
let upid = extract_upid(¶m)?;
|
||||||
|
@ -78,6 +78,8 @@ fn read_task_log(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpcenv.set_result_attrib("total", Value::from(count));
|
||||||
|
|
||||||
Ok(json!(lines))
|
Ok(json!(lines))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +143,7 @@ fn list_tasks(
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
|
|
||||||
let upid_schema : Arc<Schema> = Arc::new(
|
let upid_schema: Arc<Schema> = Arc::new(
|
||||||
StringSchema::new("Unique Process/Task ID.")
|
StringSchema::new("Unique Process/Task ID.")
|
||||||
.max_length(256)
|
.max_length(256)
|
||||||
.into()
|
.into()
|
||||||
|
@ -157,6 +159,7 @@ pub fn router() -> Router {
|
||||||
Ok(Value::from(result))
|
Ok(Value::from(result))
|
||||||
},
|
},
|
||||||
ObjectSchema::new("Directory index.")
|
ObjectSchema::new("Directory index.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("upid", upid_schema.clone()))
|
.required("upid", upid_schema.clone()))
|
||||||
)
|
)
|
||||||
.subdir(
|
.subdir(
|
||||||
|
@ -165,6 +168,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
read_task_log,
|
read_task_log,
|
||||||
ObjectSchema::new("Read task log.")
|
ObjectSchema::new("Read task log.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("upid", upid_schema.clone())
|
.required("upid", upid_schema.clone())
|
||||||
.optional(
|
.optional(
|
||||||
"start",
|
"start",
|
||||||
|
@ -187,6 +191,7 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
get_task_status,
|
get_task_status,
|
||||||
ObjectSchema::new("Get task status.")
|
ObjectSchema::new("Get task status.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.required("upid", upid_schema.clone()))
|
.required("upid", upid_schema.clone()))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -196,6 +201,7 @@ pub fn router() -> Router {
|
||||||
.get(ApiMethod::new(
|
.get(ApiMethod::new(
|
||||||
list_tasks,
|
list_tasks,
|
||||||
ObjectSchema::new("List tasks.")
|
ObjectSchema::new("List tasks.")
|
||||||
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
.optional(
|
.optional(
|
||||||
"start",
|
"start",
|
||||||
IntegerSchema::new("List tasks beginning from this offset.")
|
IntegerSchema::new("List tasks beginning from this offset.")
|
||||||
|
|
|
@ -79,7 +79,8 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
get_time,
|
get_time,
|
||||||
ObjectSchema::new("Read server time and time zone settings.")
|
ObjectSchema::new("Read server time and time zone settings.")
|
||||||
).returns(
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
|
).returns(
|
||||||
ObjectSchema::new("Returns server time and timezone.")
|
ObjectSchema::new("Returns server time and timezone.")
|
||||||
.required("timezone", StringSchema::new("Time zone"))
|
.required("timezone", StringSchema::new("Time zone"))
|
||||||
.required("time", IntegerSchema::new("Seconds since 1970-01-01 00:00:00 UTC.")
|
.required("time", IntegerSchema::new("Seconds since 1970-01-01 00:00:00 UTC.")
|
||||||
|
@ -92,7 +93,9 @@ pub fn router() -> Router {
|
||||||
ApiMethod::new(
|
ApiMethod::new(
|
||||||
set_timezone,
|
set_timezone,
|
||||||
ObjectSchema::new("Set time zone.")
|
ObjectSchema::new("Set time zone.")
|
||||||
.required("timezone", StringSchema::new("Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names."))
|
.required("node", crate::api2::node::NODE_SCHEMA.clone())
|
||||||
|
.required("timezone", StringSchema::new(
|
||||||
|
"Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names."))
|
||||||
).protected(true).reload_timezone(true)
|
).protected(true).reload_timezone(true)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue