* [pdm-devel] [PATCH datacenter-manager 1/2] Revert "server: use types indead of string for migration parameters"
2025-11-18 12:21 [pdm-devel] [PATCH datacenter-manager 0/2] fix PDM migrate endpoints Hannes Laimer
@ 2025-11-18 12:21 ` Hannes Laimer
2025-11-18 12:21 ` [pdm-devel] [PATCH datacenter-manager 2/2] api: migrate: use arrays for storage and bridge mappings Hannes Laimer
1 sibling, 0 replies; 3+ messages in thread
From: Hannes Laimer @ 2025-11-18 12:21 UTC (permalink / raw)
To: pdm-devel
The problem with using the flattened PVE type directly is that the
`target-endpoint` it expects differs from what PDM wants as
`target-endpoint`. Specififically, PDM expects it to be an optional
string identifying the target node. The PVE type however has a
PropertyString<ProxmoxRemote> as `target-endpoint`, which has two
mandatory fields (host and api-token). The only way to have this working
with the PVE type is to have the UI set `target-endpoint` to something
like:
`host=192.168.1.34,apitoken=dummy`
It does not really allow for auto-select node to be encoded properly.
This reverts commit dbb8524549c335987046ebe6e742635e1357aa3d.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
server/src/api/pve/lxc.rs | 133 ++++++++++++++++++++++++++++--------
server/src/api/pve/qemu.rs | 135 +++++++++++++++++++++++++++++--------
2 files changed, 212 insertions(+), 56 deletions(-)
diff --git a/server/src/api/pve/lxc.rs b/server/src/api/pve/lxc.rs
index 1b05a30..1ef936d 100644
--- a/server/src/api/pve/lxc.rs
+++ b/server/src/api/pve/lxc.rs
@@ -288,10 +288,29 @@ pub async fn lxc_shutdown(
schema: NODE_SCHEMA,
optional: true,
},
+ target: { schema: NODE_SCHEMA },
vmid: { schema: VMID_SCHEMA },
- migrate: {
- type: pve_api_types::MigrateLxc,
- flatten: true,
+ online: {
+ type: bool,
+ description: "Attempt an online migration if the container is running.",
+ optional: true,
+ },
+ restart: {
+ type: bool,
+ description: "Perform a restart-migration if the container is running.",
+ optional: true,
+ },
+ "target-storage": {
+ description: "Mapping of source storages to target storages.",
+ optional: true,
+ },
+ bwlimit: {
+ description: "Override I/O bandwidth limit (in KiB/s).",
+ optional: true,
+ },
+ timeout: {
+ description: "Shutdown timeout for restart-migrations.",
+ optional: true,
},
},
},
@@ -308,23 +327,35 @@ pub async fn lxc_migrate(
remote: String,
node: Option<String>,
vmid: u32,
- migrate: pve_api_types::MigrateLxc,
+ bwlimit: Option<u64>,
+ restart: Option<bool>,
+ online: Option<bool>,
+ target: String,
+ target_storage: Option<String>,
+ timeout: Option<i64>,
) -> Result<RemoteUpid, Error> {
- log::info!(
- "in-cluster migration requested for remote {remote:?} ct {vmid} to node {:?}",
- migrate.target
- );
+ let bwlimit = bwlimit.map(|n| n as f64);
+
+ log::info!("in-cluster migration requested for remote {remote:?} ct {vmid} to node {target:?}");
let (remotes, _) = pdm_config::remotes::config()?;
let pve = connect_to_remote(&remotes, &remote)?;
let node = find_node_for_vm(node, vmid, pve.as_ref()).await?;
- if node == migrate.target {
+ if node == target {
bail!("refusing migration to the same node");
}
- let upid = pve.migrate_lxc(&node, vmid, migrate).await?;
+ let params = pve_api_types::MigrateLxc {
+ bwlimit,
+ online,
+ restart,
+ target,
+ target_storage,
+ timeout,
+ };
+ let upid = pve.migrate_lxc(&node, vmid, params).await?;
new_remote_upid(remote, upid).await
}
@@ -339,10 +370,44 @@ pub async fn lxc_migrate(
optional: true,
},
vmid: { schema: VMID_SCHEMA },
+ "target-vmid": {
+ optional: true,
+ schema: VMID_SCHEMA,
+ },
+ delete: {
+ description: "Delete the original VM and related data after successful migration.",
+ optional: true,
+ default: false,
+ },
+ online: {
+ type: bool,
+ description: "Perform an online migration if the vm is running.",
+ optional: true,
+ default: false,
+ },
+ "target-storage": {
+ description: "Mapping of source storages to target storages.",
+ },
+ "target-bridge": {
+ description: "Mapping of source bridges to remote bridges.",
+ },
+ bwlimit: {
+ description: "Override I/O bandwidth limit (in KiB/s).",
+ optional: true,
+ },
+ restart: {
+ description: "Perform a restart-migration.",
+ optional: true,
+ },
+ timeout: {
+ description: "Add a shutdown timeout for the restart-migration.",
+ optional: true,
+ },
// TODO better to change remote migration to proxy to node?
- remote_migrate: {
- type: pve_api_types::RemoteMigrateLxc,
- flatten: true,
+ "target-endpoint": {
+ type: String,
+ optional: true,
+ description: "The target endpoint to use for the connection.",
},
},
},
@@ -360,7 +425,15 @@ pub async fn lxc_remote_migrate(
target: String, // this is the destination remote name
node: Option<String>,
vmid: u32,
- remote_migrate: pve_api_types::RemoteMigrateLxc,
+ target_vmid: Option<u32>,
+ delete: bool,
+ online: bool,
+ target_storage: String,
+ target_bridge: String,
+ bwlimit: Option<u64>,
+ restart: Option<bool>,
+ timeout: Option<i64>,
+ target_endpoint: Option<String>,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<RemoteUpid, Error> {
let user_info = CachedUserInfo::new()?;
@@ -374,7 +447,7 @@ pub async fn lxc_remote_migrate(
"resource",
&target,
"guest",
- &remote_migrate.target_vmid.unwrap_or(vmid).to_string(),
+ &target_vmid.unwrap_or(vmid).to_string(),
],
);
if target_privs & PRIV_RESOURCE_MIGRATE == 0 {
@@ -383,7 +456,7 @@ pub async fn lxc_remote_migrate(
"missing PRIV_RESOURCE_MIGRATE on target remote+vmid"
);
}
- if remote_migrate.delete.unwrap_or_default() {
+ if delete {
check_guest_delete_perms(rpcenv, &remote, vmid)?;
}
@@ -404,17 +477,14 @@ pub async fn lxc_remote_migrate(
// FIXME: For now we'll only try with the first node but we should probably try others, too, in
// case some are offline?
- // TODO: target_endpoint optional? if single node i guess
let target_node = target
.nodes
.iter()
- .find(
- |endpoint| match Some(remote_migrate.target_endpoint.clone()).as_deref() {
- Some(target) => target == endpoint.hostname,
- None => true,
- },
- )
- .ok_or_else(|| match Some(remote_migrate.target_endpoint.clone()) {
+ .find(|endpoint| match target_endpoint.as_deref() {
+ Some(target) => target == endpoint.hostname,
+ None => true,
+ })
+ .ok_or_else(|| match target_endpoint {
Some(endpoint) => format_err!("{endpoint} not configured for target cluster"),
None => format_err!("no nodes configured for target cluster"),
})?;
@@ -434,10 +504,19 @@ pub async fn lxc_remote_migrate(
}
log::info!("forwarding remote migration requested");
+ let params = pve_api_types::RemoteMigrateLxc {
+ target_bridge,
+ target_storage,
+ delete: Some(delete),
+ online: Some(online),
+ target_vmid,
+ target_endpoint,
+ bwlimit: bwlimit.map(|limit| limit as f64),
+ restart,
+ timeout,
+ };
log::info!("migrating vm {vmid} of node {node:?}");
- let upid = source_conn
- .remote_migrate_lxc(&node, vmid, remote_migrate)
- .await?;
+ let upid = source_conn.remote_migrate_lxc(&node, vmid, params).await?;
new_remote_upid(source, upid).await
}
diff --git a/server/src/api/pve/qemu.rs b/server/src/api/pve/qemu.rs
index 05fa92c..5e66a48 100644
--- a/server/src/api/pve/qemu.rs
+++ b/server/src/api/pve/qemu.rs
@@ -10,11 +10,11 @@ use proxmox_sortable_macro::sortable;
use pdm_api_types::remotes::REMOTE_ID_SCHEMA;
use pdm_api_types::{
- Authid, ConfigurationState, RemoteUpid, NODE_SCHEMA, PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MANAGE,
- PRIV_RESOURCE_MIGRATE, SNAPSHOT_NAME_SCHEMA, VMID_SCHEMA,
+ Authid, ConfigurationState, RemoteUpid, CIDR_FORMAT, NODE_SCHEMA, PRIV_RESOURCE_AUDIT,
+ PRIV_RESOURCE_MANAGE, PRIV_RESOURCE_MIGRATE, SNAPSHOT_NAME_SCHEMA, VMID_SCHEMA,
};
-use pve_api_types::QemuMigratePreconditions;
+use pve_api_types::{QemuMigratePreconditions, StartQemuMigrationType};
use crate::api::pve::get_remote;
@@ -297,9 +297,37 @@ pub async fn qemu_shutdown(
},
target: { schema: NODE_SCHEMA },
vmid: { schema: VMID_SCHEMA },
- migrate: {
- type: pve_api_types::MigrateQemu,
- flatten: true,
+ online: {
+ type: bool,
+ description: "Perform an online migration if the vm is running.",
+ optional: true,
+ },
+ "target-storage": {
+ description: "Mapping of source storages to target storages.",
+ optional: true,
+ },
+ bwlimit: {
+ description: "Override I/O bandwidth limit (in KiB/s).",
+ optional: true,
+ },
+ "migration-network": {
+ description: "CIDR of the (sub) network that is used for migration.",
+ type: String,
+ format: &CIDR_FORMAT,
+ optional: true,
+ },
+ "migration-type": {
+ type: StartQemuMigrationType,
+ optional: true,
+ },
+ force: {
+ description: "Allow to migrate VMs with local devices.",
+ optional: true,
+ default: false,
+ },
+ "with-local-disks": {
+ description: "Enable live storage migration for local disks.",
+ optional: true,
},
},
},
@@ -316,23 +344,38 @@ pub async fn qemu_migrate(
remote: String,
node: Option<String>,
vmid: u32,
- migrate: pve_api_types::MigrateQemu,
+ bwlimit: Option<u64>,
+ force: Option<bool>,
+ migration_network: Option<String>,
+ migration_type: Option<StartQemuMigrationType>,
+ online: Option<bool>,
+ target: String,
+ target_storage: Option<String>,
+ with_local_disks: Option<bool>,
) -> Result<RemoteUpid, Error> {
- log::info!(
- "in-cluster migration requested for remote {remote:?} vm {vmid} to node {:?}",
- migrate.target
- );
+ log::info!("in-cluster migration requested for remote {remote:?} vm {vmid} to node {target:?}");
let (remotes, _) = pdm_config::remotes::config()?;
let pve = connect_to_remote(&remotes, &remote)?;
let node = find_node_for_vm(node, vmid, pve.as_ref()).await?;
- if node == migrate.target {
+ if node == target {
bail!("refusing migration to the same node");
}
- let upid = pve.migrate_qemu(&node, vmid, migrate).await?;
+ let params = pve_api_types::MigrateQemu {
+ bwlimit,
+ force,
+ migration_network,
+ migration_type,
+ online,
+ target,
+ targetstorage: target_storage,
+ with_local_disks,
+ with_conntrack_state: None,
+ };
+ let upid = pve.migrate_qemu(&node, vmid, params).await?;
new_remote_upid(remote, upid).await
}
@@ -388,9 +431,32 @@ async fn qemu_migrate_preconditions(
optional: true,
schema: VMID_SCHEMA,
},
- remote_migrate: {
- type: pve_api_types::RemoteMigrateQemu,
- flatten: true,
+ delete: {
+ description: "Delete the original VM and related data after successful migration.",
+ optional: true,
+ default: false,
+ },
+ online: {
+ type: bool,
+ description: "Perform an online migration if the vm is running.",
+ optional: true,
+ default: false,
+ },
+ "target-storage": {
+ description: "Mapping of source storages to target storages.",
+ },
+ "target-bridge": {
+ description: "Mapping of source bridges to remote bridges.",
+ },
+ bwlimit: {
+ description: "Override I/O bandwidth limit (in KiB/s).",
+ optional: true,
+ },
+ // TODO better to change remote migration to proxy to node?
+ "target-endpoint": {
+ type: String,
+ optional: true,
+ description: "The target endpoint to use for the connection.",
},
},
},
@@ -408,7 +474,13 @@ pub async fn qemu_remote_migrate(
target: String, // this is the destination remote name
node: Option<String>,
vmid: u32,
- remote_migrate: pve_api_types::RemoteMigrateQemu,
+ target_vmid: Option<u32>,
+ delete: bool,
+ online: bool,
+ target_storage: String,
+ target_bridge: String,
+ bwlimit: Option<u64>,
+ target_endpoint: Option<String>,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<RemoteUpid, Error> {
let user_info = CachedUserInfo::new()?;
@@ -422,7 +494,7 @@ pub async fn qemu_remote_migrate(
"resource",
&target,
"guest",
- &remote_migrate.target_vmid.unwrap_or(vmid).to_string(),
+ &target_vmid.unwrap_or(vmid).to_string(),
],
);
if target_privs & PRIV_RESOURCE_MIGRATE == 0 {
@@ -432,7 +504,7 @@ pub async fn qemu_remote_migrate(
);
}
- if remote_migrate.delete.unwrap_or_default() {
+ if delete {
check_guest_delete_perms(rpcenv, &remote, vmid)?;
}
@@ -456,13 +528,11 @@ pub async fn qemu_remote_migrate(
let target_node = target
.nodes
.iter()
- .find(
- |endpoint| match Some(remote_migrate.target_endpoint.clone()).as_deref() {
- Some(target) => target == endpoint.hostname,
- None => true,
- },
- )
- .ok_or_else(|| match Some(remote_migrate.target_endpoint.clone()) {
+ .find(|endpoint| match target_endpoint.as_deref() {
+ Some(target) => target == endpoint.hostname,
+ None => true,
+ })
+ .ok_or_else(|| match target_endpoint {
Some(endpoint) => format_err!("{endpoint} not configured for target cluster"),
None => format_err!("no nodes configured for target cluster"),
})?;
@@ -482,10 +552,17 @@ pub async fn qemu_remote_migrate(
}
log::info!("forwarding remote migration requested");
+ let params = pve_api_types::RemoteMigrateQemu {
+ target_bridge,
+ target_storage,
+ delete: Some(delete),
+ online: Some(online),
+ target_vmid,
+ target_endpoint,
+ bwlimit,
+ };
log::info!("migrating vm {vmid} of node {node:?}");
- let upid = source_conn
- .remote_migrate_qemu(&node, vmid, remote_migrate)
- .await?;
+ let upid = source_conn.remote_migrate_qemu(&node, vmid, params).await?;
new_remote_upid(source, upid).await
}
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* [pdm-devel] [PATCH datacenter-manager 2/2] api: migrate: use arrays for storage and bridge mappings
2025-11-18 12:21 [pdm-devel] [PATCH datacenter-manager 0/2] fix PDM migrate endpoints Hannes Laimer
2025-11-18 12:21 ` [pdm-devel] [PATCH datacenter-manager 1/2] Revert "server: use types indead of string for migration parameters" Hannes Laimer
@ 2025-11-18 12:21 ` Hannes Laimer
1 sibling, 0 replies; 3+ messages in thread
From: Hannes Laimer @ 2025-11-18 12:21 UTC (permalink / raw)
To: pdm-devel
With [1] we generate actual arrays for string-lists, so the generated
functions we use for migration take these types containing Vec's instead
of Strings. This updates the PDM migrate endpoints to accept arrays so
they can be passed to the functions.
This also updates the strigify function used by the UI to create those
mapping strings. Now, instead of a single string it produces a list of
mapping strings.
[1] bd8eca6 ("pve-api-types: schema2rust: generate arrays for types with format `-list`")
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
lib/pdm-client/src/lib.rs | 31 +++++++++++++------------------
server/src/api/pve/lxc.rs | 27 +++++++++++++++++++++------
server/src/api/pve/qemu.rs | 27 +++++++++++++++++++++------
3 files changed, 55 insertions(+), 30 deletions(-)
diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs
index df2ebe0..642a6c1 100644
--- a/lib/pdm-client/src/lib.rs
+++ b/lib/pdm-client/src/lib.rs
@@ -1395,32 +1395,27 @@ where
return serializer.serialize_none();
}
- let mut output = String::new();
+ let mut list = Vec::with_capacity(mapping.len());
+
if mapping.len() == 1 {
let (key, value) = mapping.iter().next().unwrap();
- // special case 1: '* = *' => identity mapping
if key == "*" && value == "*" {
- return serializer.serialize_str("1");
- }
-
- // special case 2: '* = <something>' => single value of <something> )
- return serializer.serialize_str(value);
- }
-
- for (from, to) in mapping.iter() {
- if !output.is_empty() {
- output.reserve(from.len() + to.len() + 2);
- output.push(',');
+ // special case 1: '* = *' => identity mapping
+ list.push("1".to_string());
+ } else if key == "*" {
+ // special case 2: '* = <something>' => single value of <something>
+ list.push(value.clone());
} else {
- output.reserve(from.len() + to.len() + 1);
+ list.push(format!("{key}:{value}"));
+ }
+ } else {
+ for (from, to) in mapping.iter() {
+ list.push(format!("{from}:{to}"));
}
- output.push_str(from);
- output.push(':');
- output.push_str(to);
}
- serializer.serialize_str(&output)
+ list.serialize(serializer)
}
#[derive(Serialize)]
diff --git a/server/src/api/pve/lxc.rs b/server/src/api/pve/lxc.rs
index 1ef936d..ecf0bef 100644
--- a/server/src/api/pve/lxc.rs
+++ b/server/src/api/pve/lxc.rs
@@ -301,8 +301,13 @@ pub async fn lxc_shutdown(
optional: true,
},
"target-storage": {
- description: "Mapping of source storages to target storages.",
+ description: "List of storage mappings",
optional: true,
+ items: {
+ description: "Mappings of source storages to target storages.",
+ type: String,
+ },
+ type: Array,
},
bwlimit: {
description: "Override I/O bandwidth limit (in KiB/s).",
@@ -331,7 +336,7 @@ pub async fn lxc_migrate(
restart: Option<bool>,
online: Option<bool>,
target: String,
- target_storage: Option<String>,
+ target_storage: Option<Vec<String>>,
timeout: Option<i64>,
) -> Result<RemoteUpid, Error> {
let bwlimit = bwlimit.map(|n| n as f64);
@@ -386,10 +391,20 @@ pub async fn lxc_migrate(
default: false,
},
"target-storage": {
- description: "Mapping of source storages to target storages.",
+ description: "List of storage mappings",
+ items: {
+ description: "Mappings of source storages to target storages.",
+ type: String,
+ },
+ type: Array,
},
"target-bridge": {
- description: "Mapping of source bridges to remote bridges.",
+ description: "List of bridge mappings",
+ items: {
+ description: "Mappings of source bridges to remote bridges.",
+ type: String,
+ },
+ type: Array,
},
bwlimit: {
description: "Override I/O bandwidth limit (in KiB/s).",
@@ -428,8 +443,8 @@ pub async fn lxc_remote_migrate(
target_vmid: Option<u32>,
delete: bool,
online: bool,
- target_storage: String,
- target_bridge: String,
+ target_storage: Vec<String>,
+ target_bridge: Vec<String>,
bwlimit: Option<u64>,
restart: Option<bool>,
timeout: Option<i64>,
diff --git a/server/src/api/pve/qemu.rs b/server/src/api/pve/qemu.rs
index 5e66a48..4f144b7 100644
--- a/server/src/api/pve/qemu.rs
+++ b/server/src/api/pve/qemu.rs
@@ -303,8 +303,13 @@ pub async fn qemu_shutdown(
optional: true,
},
"target-storage": {
- description: "Mapping of source storages to target storages.",
+ description: "List of storage mappings",
optional: true,
+ items: {
+ description: "Mappings of source storages to target storages.",
+ type: String,
+ },
+ type: Array,
},
bwlimit: {
description: "Override I/O bandwidth limit (in KiB/s).",
@@ -350,7 +355,7 @@ pub async fn qemu_migrate(
migration_type: Option<StartQemuMigrationType>,
online: Option<bool>,
target: String,
- target_storage: Option<String>,
+ target_storage: Option<Vec<String>>,
with_local_disks: Option<bool>,
) -> Result<RemoteUpid, Error> {
log::info!("in-cluster migration requested for remote {remote:?} vm {vmid} to node {target:?}");
@@ -443,10 +448,20 @@ async fn qemu_migrate_preconditions(
default: false,
},
"target-storage": {
- description: "Mapping of source storages to target storages.",
+ description: "List of storage mappings",
+ items: {
+ description: "Mappings of source storages to target storages.",
+ type: String,
+ },
+ type: Array,
},
"target-bridge": {
- description: "Mapping of source bridges to remote bridges.",
+ description: "List of bridge mappings",
+ items: {
+ description: "Mappings of source bridges to remote bridges.",
+ type: String,
+ },
+ type: Array,
},
bwlimit: {
description: "Override I/O bandwidth limit (in KiB/s).",
@@ -477,8 +492,8 @@ pub async fn qemu_remote_migrate(
target_vmid: Option<u32>,
delete: bool,
online: bool,
- target_storage: String,
- target_bridge: String,
+ target_storage: Vec<String>,
+ target_bridge: Vec<String>,
bwlimit: Option<u64>,
target_endpoint: Option<String>,
rpcenv: &mut dyn RpcEnvironment,
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread