(&self)
| 440 | } |
| 441 | |
| 442 | pub fn validate(&self) -> Result<(), VmSendMigrationConfigError> { |
| 443 | match self.destination_url.as_str() { |
| 444 | url if url |
| 445 | .strip_prefix("tcp:") |
| 446 | .is_some_and(|addr| !addr.is_empty()) => {} |
| 447 | url if url |
| 448 | .strip_prefix("unix:") |
| 449 | .is_some_and(|path| !path.is_empty()) => |
| 450 | { |
| 451 | if self.connections.get() > 1 { |
| 452 | return Err(VmSendMigrationConfigError::ValidationError( |
| 453 | "UNIX sockets and connections option cannot be used at the same time." |
| 454 | .to_string(), |
| 455 | )); |
| 456 | } |
| 457 | } |
| 458 | _ => { |
| 459 | return Err(VmSendMigrationConfigError::ValidationError( |
| 460 | "destination_url must use tcp:<host>:<port> or unix:<path>.".to_string(), |
| 461 | )); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | if self.connections.get() > MAX_MIGRATION_CONNECTIONS { |
| 466 | return Err(VmSendMigrationConfigError::ValidationError(format!( |
| 467 | "connections must not exceed {MAX_MIGRATION_CONNECTIONS}." |
| 468 | ))); |
| 469 | } |
| 470 | |
| 471 | if self.local { |
| 472 | if !self.destination_url.starts_with("unix:") { |
| 473 | return Err(VmSendMigrationConfigError::ValidationError( |
| 474 | "local option is only supported with UNIX sockets.".to_string(), |
| 475 | )); |
| 476 | } |
| 477 | |
| 478 | if self.connections.get() > 1 { |
| 479 | return Err(VmSendMigrationConfigError::ValidationError( |
| 480 | "local option and connections option cannot be used at the same time." |
| 481 | .to_string(), |
| 482 | )); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | Ok(()) |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | pub enum ApiResponsePayload { |
no test coverage detected