-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor/nanocld: cleaner image service with file separation (#1110)
- Loading branch information
Showing
10 changed files
with
414 additions
and
343 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
|
||
use crate::{ | ||
models::{SystemState, VmImageDb}, | ||
repositories::generic::*, | ||
utils, | ||
}; | ||
|
||
/// Clone a virtual machine image | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
post, | ||
tag = "VmImages", | ||
request_body = String, | ||
path = "/vms/images/{name}/clone/{clone_name}", | ||
params( | ||
("name" = String, Path, description = "The name of the vm image"), | ||
("clone_name" = String, Path, description = "The name of the clone"), | ||
), | ||
responses( | ||
(status = 200, description = "The snapshot have been created", body = VmImage), | ||
), | ||
))] | ||
#[web::post("/vms/images/{name}/clone/{clone_name}")] | ||
pub async fn clone_vm_image( | ||
state: web::types::State<SystemState>, | ||
path: web::types::Path<(String, String, String)>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let name = path.1.to_owned(); | ||
let clone_name = path.2.to_owned(); | ||
utils::key::validate_name(&clone_name)?; | ||
let image = VmImageDb::read_by_pk(&name, &state.inner.pool).await?; | ||
let rx = utils::vm_image::clone(&clone_name, &image, &state).await?; | ||
Ok(web::HttpResponse::Ok().streaming(rx)) | ||
} |
Oops, something went wrong.