MCPcopy Index your code
hub / github.com/cloud-hypervisor/cloud-hypervisor / parse

Method parse

vmm/src/api/mod.rs:359–432  ·  view source on GitHub ↗
(migration: &str)

Source from the content-addressed store, hash-verified

357 }
358
359 pub fn parse(migration: &str) -> Result<Self, VmSendMigrationConfigError> {
360 let mut parser = OptionParser::new();
361 parser
362 .add("destination_url")
363 .add("local")
364 .add("downtime_ms")
365 .add("timeout_s")
366 .add("timeout_strategy")
367 .add("connections");
368 parser
369 .parse(migration)
370 .map_err(VmSendMigrationConfigError::ParseError)?;
371
372 let destination_url = parser.get("destination_url").ok_or_else(|| {
373 VmSendMigrationConfigError::ParseError(OptionParserError::InvalidSyntax(
374 "destination_url is required".to_string(),
375 ))
376 })?;
377 let local = parser
378 .convert::<Toggle>("local")
379 .map_err(VmSendMigrationConfigError::ParseError)?
380 .unwrap_or(Toggle(false))
381 .0;
382 let downtime_ms = match parser
383 .convert::<u64>("downtime_ms")
384 .map_err(VmSendMigrationConfigError::ParseError)?
385 {
386 Some(v) => NonZeroU64::new(v).ok_or_else(|| {
387 VmSendMigrationConfigError::ParseError(OptionParserError::InvalidValue(
388 "downtime_ms must be non-zero".to_string(),
389 ))
390 })?,
391 None => Self::default_downtime_ms(),
392 };
393 let timeout_s = match parser
394 .convert::<u64>("timeout_s")
395 .map_err(VmSendMigrationConfigError::ParseError)?
396 {
397 Some(v) => NonZeroU64::new(v).ok_or_else(|| {
398 VmSendMigrationConfigError::ParseError(OptionParserError::InvalidValue(
399 "timeout_s must be non-zero".to_string(),
400 ))
401 })?,
402 None => Self::default_timeout_s(),
403 };
404 let timeout_strategy = parser
405 .convert("timeout_strategy")
406 .map_err(VmSendMigrationConfigError::ParseError)?
407 .unwrap_or_default();
408 let connections = match parser
409 .convert::<u32>("connections")
410 .map_err(VmSendMigrationConfigError::ParseError)?
411 {
412 Some(v) => NonZeroU32::new(v).ok_or_else(|| {
413 VmSendMigrationConfigError::ParseError(OptionParserError::InvalidValue(
414 "connections must be non-zero".to_string(),
415 ))
416 })?,

Callers 1

load_igvmFunction · 0.45

Calls 6

newFunction · 0.85
ToggleClass · 0.85
addMethod · 0.80
convertMethod · 0.80
getMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected