all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] applied: [PATCH backup] api: apt: support refreshing package index
@ 2020-07-23  9:22 Thomas Lamprecht
  0 siblings, 0 replies; only message in thread
From: Thomas Lamprecht @ 2020-07-23  9:22 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/api2/node/apt.rs | 64 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 4 deletions(-)

diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index 55d360f..c65e414 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -3,10 +3,13 @@ use anyhow::{Error, bail};
 use serde_json::{json, Value};
 
 use proxmox::{list_subdirs_api_method, const_regex};
-use proxmox::api::{api, Router, Permission, SubdirMap};
+use proxmox::api::{api, RpcEnvironment, RpcEnvironmentType, Permission};
+use proxmox::api::router::{Router, SubdirMap};
 
-use crate::config::acl::PRIV_SYS_AUDIT;
-use crate::api2::types::{APTUpdateInfo, NODE_SCHEMA};
+use crate::server::WorkerTask;
+
+use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
+use crate::api2::types::{APTUpdateInfo, NODE_SCHEMA, UPID_SCHEMA};
 
 const_regex! {
     VERSION_EPOCH_REGEX = r"^\d+:";
@@ -202,8 +205,61 @@ fn apt_update_available(_param: Value) -> Result<Value, Error> {
     Ok(json!(ret))
 }
 
+#[api(
+    input: {
+        properties: {
+            node: {
+                schema: NODE_SCHEMA,
+            },
+            quiet: {
+                description: "Only produces output suitable for logging, omitting progress indicators.",
+                type: bool,
+                default: false,
+                optional: true,
+            },
+        },
+    },
+    returns: {
+        schema: UPID_SCHEMA,
+    },
+    access: {
+        permission: &Permission::Privilege(&[], PRIV_SYS_MODIFY, false),
+    },
+)]
+/// Update the APT database
+pub fn apt_update_database(
+    quiet: Option<bool>,
+    rpcenv: &mut dyn RpcEnvironment,
+) -> Result<String, Error> {
+
+    let username = rpcenv.get_user().unwrap();
+    let to_stdout = if rpcenv.env_type() == RpcEnvironmentType::CLI { true } else { false };
+    let quiet = quiet.unwrap_or(false);
+
+    let upid_str = WorkerTask::new_thread("aptupdate", None, &username.clone(), to_stdout, move |worker| {
+        if !quiet { worker.log("starting apt-get update") }
+
+        // TODO: set proxy /etc/apt/apt.conf.d/76pbsproxy like PVE
+
+        let mut command = std::process::Command::new("apt-get");
+        command.arg("update");
+
+        let output = crate::tools::run_command(command, None)?;
+        if !quiet { worker.log(output) }
+
+        // TODO: add mail notify for new updates like PVE
+
+        Ok(())
+    })?;
+
+    Ok(upid_str)
+}
+
 const SUBDIRS: SubdirMap = &[
-    ("update", &Router::new().get(&API_METHOD_APT_UPDATE_AVAILABLE)),
+    ("update", &Router::new()
+        .get(&API_METHOD_APT_UPDATE_AVAILABLE)
+        .post(&API_METHOD_APT_UPDATE_DATABASE)
+    ),
 ];
 
 pub const ROUTER: Router = Router::new()
-- 
2.27.0





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-23  9:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23  9:22 [pbs-devel] applied: [PATCH backup] api: apt: support refreshing package index Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal