pub fn from_json(
        config_json: &str,
        instance_info: &InstanceInfo,
        mmds_size_limit: usize,
        metadata_json: Option<&str>,
    ) -> std::result::Result<Self, Error> {
        let vmm_config: VmmConfig = serde_json::from_slice::<VmmConfig>(config_json.as_bytes())
            .map_err(Error::InvalidJson)?;

        if let Some(logger) = vmm_config.logger {
            init_logger(logger, instance_info).map_err(Error::Logger)?;
        }

        if let Some(metrics) = vmm_config.metrics {
            init_metrics(metrics).map_err(Error::Metrics)?;
        }

        let mut resources: Self = Self {
            mmds_size_limit,
            ..Default::default()
        };
        if let Some(machine_config) = vmm_config.machine_config {
            let machine_config = VmUpdateConfig::from(machine_config);
            resources
                .update_vm_config(&machine_config)
                .map_err(Error::VmConfig)?;
        }

        resources
            .set_boot_source(vmm_config.boot_source)
            .map_err(Error::BootSource)?;

        for drive_config in vmm_config.block_devices.into_iter() {
            resources
                .set_block_device(drive_config)
                .map_err(Error::BlockDevice)?;
        }

        for net_config in vmm_config.net_devices.into_iter() {
            resources
                .build_net_device(net_config)
                .map_err(Error::NetDevice)?;
        }

        if let Some(vsock_config) = vmm_config.vsock_device {
            resources
                .set_vsock_device(vsock_config)
                .map_err(Error::VsockDevice)?;
        }

        if let Some(balloon_config) = vmm_config.balloon_device {
            resources
                .set_balloon_device(balloon_config)
                .map_err(Error::BalloonDevice)?;
        }

        // Init the data store from file, if present.
        if let Some(data) = metadata_json {
            resources
                .locked_mmds_or_default()
                .put_data(
                    serde_json::from_str(&data)
                        .expect("MMDS error: metadata provided not valid json"),
                )
                .map_err(Error::Mmds)?;
            info!("Successfully added metadata to mmds from file");
        }

        if let Some(mmds_config) = vmm_config.mmds_config {
            resources
                .set_mmds_config(mmds_config, &instance_info.id)
                .map_err(Error::MmdsConfig)?;
        }

        Ok(resources)
    }
/// Configures Vmm resources as described by the `config_json` param.
Configures Vmm resources as described by the `config_json` param.
Configures Vmm resources as described by the ` config_json ` param .
pub fn from_json(
        config_json: &str,
        instance_info: &InstanceInfo,
        mmds_size_limit: usize,
        metadata_json: Option<&str>,
    ) -> std::result::Result<Self, Error> {
        let vmm_config: VmmConfig = serde_json::from_slice::<VmmConfig>(config_json.as_bytes())
            .map_err(Error::InvalidJson)?;
        if let Some(logger) = vmm_config.logger {
            init_logger(logger, instance_info).map_err(Error::Logger)?;
        }
        if let Some(metrics) = vmm_config.metrics {
            init_metrics(metrics).map_err(Error::Metrics)?;
        }
        let mut resources: Self = Self {
            mmds_size_limit,
            ..Default::default()
        };
        if let Some(machine_config) = vmm_config.machine_config {
            let machine_config = VmUpdateConfig::from(machine_config);
            resources
                .update_vm_config(&machine_config)
                .map_err(Error::VmConfig)?;
        }
        resources
            .set_boot_source(vmm_config.boot_source)
            .map_err(Error::BootSource)?;
        for drive_config in vmm_config.block_devices.into_iter() {
            resources
                .set_block_device(drive_config)
                .map_err(Error::BlockDevice)?;
        }
        for net_config in vmm_config.net_devices.into_iter() {
            resources
                .build_net_device(net_config)
                .map_err(Error::NetDevice)?;
        }
        if let Some(vsock_config) = vmm_config.vsock_device {
            resources
                .set_vsock_device(vsock_config)
                .map_err(Error::VsockDevice)?;
        }
        if let Some(balloon_config) = vmm_config.balloon_device {
            resources
                .set_balloon_device(balloon_config)
                .map_err(Error::BalloonDevice)?;
        }
        // Init the data store from file, if present.
        if let Some(data) = metadata_json {
            resources
                .locked_mmds_or_default()
                .put_data(
                    serde_json::from_str(&data)
                        .expect("MMDS error: metadata provided not valid json"),
                )
                .map_err(Error::Mmds)?;
            info!("Successfully added metadata to mmds from file");
        }
        if let Some(mmds_config) = vmm_config.mmds_config {
            resources
                .set_mmds_config(mmds_config, &instance_info.id)
                .map_err(Error::MmdsConfig)?;
        }
        Ok(resources)
    }
pub fn from_json ( config_json : & str , instance_info : & InstanceInfo , mmds_size_limit : usize , metadata_json : Option < & str > , ) -> std :: result :: Result < Self , Error > { let vmm_config : VmmConfig = serde_json :: from_slice :: < VmmConfig > ( config_json . as_bytes ( ) ) . map_err ( Error :: InvalidJson ) ? ; if let Some ( logger ) = vmm_config . logger { init_logger ( logger , instance_info ) . map_err ( Error :: Logger ) ? ; } if let Some ( metrics ) = vmm_config . metrics { init_metrics ( metrics ) . map_err ( Error :: Metrics ) ? ; } let mut resources : Self = Self { mmds_size_limit , .. Default :: default ( ) } ; if let Some ( machine_config ) = vmm_config . machine_config { let machine_config = VmUpdateConfig :: from ( machine_config ) ; resources . update_vm_config ( & machine_config ) . map_err ( Error :: VmConfig ) ? ; } resources . set_boot_source ( vmm_config . boot_source ) . map_err ( Error :: BootSource ) ? ; for drive_config in vmm_config . block_devices . into_iter ( ) { resources . set_block_device ( drive_config ) . map_err ( Error :: BlockDevice ) ? ; } for net_config in vmm_config . net_devices . into_iter ( ) { resources . build_net_device ( net_config ) . map_err ( Error :: NetDevice ) ? ; } if let Some ( vsock_config ) = vmm_config . vsock_device { resources . set_vsock_device ( vsock_config ) . map_err ( Error :: VsockDevice ) ? ; } if let Some ( balloon_config ) = vmm_config . balloon_device { resources . set_balloon_device ( balloon_config ) . map_err ( Error :: BalloonDevice ) ? ; } // Init the data store from file, if present. if let Some ( data ) = metadata_json { resources . locked_mmds_or_default ( ) . put_data ( serde_json :: from_str ( & data ) . expect ( " " ) , ) . map_err ( Error :: Mmds ) ? ; info ! ( " " ) ; } if let Some ( mmds_config ) = vmm_config . mmds_config { resources . set_mmds_config ( mmds_config , & instance_info . id ) . map_err ( Error :: MmdsConfig ) ? ; } Ok ( resources ) }
Configures Vmm resources as described by the `config_json` param.
Configures Vmm resources as described by the ` config_json ` param .
config_json
&str
instance_info
&InstanceInfo
mmds_size_limit
usize
metadata_json
Option<&str>
config_json
&str
instance_info
&InstanceInfo
mmds_size_limit
usize
metadata_json
Option<&str>