(
&self,
req: &Request,
api_notifier: EventFd,
api_sender: Sender<ApiRequest>,
)
| 262 | |
| 263 | impl EndpointHandler for VmCreate { |
| 264 | fn handle_request( |
| 265 | &self, |
| 266 | req: &Request, |
| 267 | api_notifier: EventFd, |
| 268 | api_sender: Sender<ApiRequest>, |
| 269 | ) -> Response { |
| 270 | match req.method() { |
| 271 | Method::Put => { |
| 272 | match &req.body { |
| 273 | Some(body) => { |
| 274 | // Deserialize into a VmConfig |
| 275 | let mut vm_config: Box<VmConfig> = match serde_json::from_slice(body.raw()) |
| 276 | .map_err(HttpError::SerdeJsonDeserialize) |
| 277 | { |
| 278 | Ok(config) => config, |
| 279 | Err(e) => return error_response(e, StatusCode::BadRequest), |
| 280 | }; |
| 281 | |
| 282 | if let Some(ref mut nets) = vm_config.net { |
| 283 | let mut cfgs = nets.iter_mut().collect::<Vec<&mut _>>(); |
| 284 | let cfgs = cfgs.as_mut_slice(); |
| 285 | |
| 286 | // For the VmCreate call, we do not accept FDs from the socket currently. |
| 287 | // This call sets all FDs to null while doing the same logging as |
| 288 | // similar code paths. |
| 289 | for cfg in cfgs { |
| 290 | if let Err(e) = attach_fds_to_cfg(vec![], *cfg) |
| 291 | .map_err(|e| error_response(e, StatusCode::InternalServerError)) |
| 292 | { |
| 293 | return e; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | match crate::api::VmCreate |
| 299 | .send(api_notifier, api_sender, vm_config) |
| 300 | .map_err(HttpError::ApiError) |
| 301 | { |
| 302 | Ok(_) => Response::new(Version::Http11, StatusCode::NoContent), |
| 303 | Err(e) => error_response(e, StatusCode::InternalServerError), |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | None => Response::new(Version::Http11, StatusCode::BadRequest), |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | _ => error_response(HttpError::BadRequest, StatusCode::BadRequest), |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | pub trait GetHandler { |
no test coverage detected