WIP building REST structures
This commit is contained in:
		@@ -9,7 +9,6 @@ enum LibVirtStructError {
 | 
			
		||||
    StructureExtraction(&'static str),
 | 
			
		||||
    #[error("DomainExtractionError: {0}")]
 | 
			
		||||
    DomainExtraction(String),
 | 
			
		||||
 | 
			
		||||
    #[error("ParseFilteringChain: {0}")]
 | 
			
		||||
    ParseFilteringChain(String),
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -96,6 +96,20 @@ pub struct NetworkFilter {
 | 
			
		||||
 | 
			
		||||
impl NetworkFilter {
 | 
			
		||||
    pub fn from_xml(xml: NetworkFilterXML) -> anyhow::Result<Self> {
 | 
			
		||||
        let mut rules = Vec::with_capacity(xml.rules.len());
 | 
			
		||||
        for rule in &xml.rules {
 | 
			
		||||
            let mut selectors = Vec::new();
 | 
			
		||||
 | 
			
		||||
            // TODO : add other selectors
 | 
			
		||||
 | 
			
		||||
            rules.push(NetworkFilterRule {
 | 
			
		||||
                action: NetworkFilterAction::from_xml(&rule.action)?,
 | 
			
		||||
                direction: NetworkFilterDirection::from_xml(&rule.direction)?,
 | 
			
		||||
                priority: rule.priority,
 | 
			
		||||
                selectors,
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Ok(Self {
 | 
			
		||||
            name: xml.name,
 | 
			
		||||
            uuid: xml.uuid,
 | 
			
		||||
@@ -106,7 +120,7 @@ impl NetworkFilter {
 | 
			
		||||
                .iter()
 | 
			
		||||
                .map(|i| i.filter.to_string())
 | 
			
		||||
                .collect(),
 | 
			
		||||
            rules: vec![], // TODO !
 | 
			
		||||
            rules,
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -126,6 +140,35 @@ pub enum NetworkFilterAction {
 | 
			
		||||
    Continue,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl NetworkFilterAction {
 | 
			
		||||
    pub fn from_xml(xml: &str) -> anyhow::Result<Self> {
 | 
			
		||||
        Ok(match xml {
 | 
			
		||||
            "drop" => Self::Drop,
 | 
			
		||||
            "reject" => Self::Reject,
 | 
			
		||||
            "accept" => Self::Accept,
 | 
			
		||||
            "return" => Self::Return,
 | 
			
		||||
            "continue" => Self::Continue,
 | 
			
		||||
            s => {
 | 
			
		||||
                return Err(LibVirtStructError::ParseFilteringChain(format!(
 | 
			
		||||
                    "Unkown filter action {s}!"
 | 
			
		||||
                ))
 | 
			
		||||
                .into())
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn to_xml(&self) -> String {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::Drop => "drop",
 | 
			
		||||
            Self::Reject => "reject",
 | 
			
		||||
            Self::Accept => "accept",
 | 
			
		||||
            Self::Return => "return",
 | 
			
		||||
            Self::Continue => "continue",
 | 
			
		||||
        }
 | 
			
		||||
        .to_string()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
 | 
			
		||||
pub enum NetworkFilterDirection {
 | 
			
		||||
    In,
 | 
			
		||||
@@ -133,6 +176,31 @@ pub enum NetworkFilterDirection {
 | 
			
		||||
    InOut,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl NetworkFilterDirection {
 | 
			
		||||
    pub fn from_xml(xml: &str) -> anyhow::Result<Self> {
 | 
			
		||||
        Ok(match xml {
 | 
			
		||||
            "in" => Self::In,
 | 
			
		||||
            "out" => Self::Out,
 | 
			
		||||
            "inout" => Self::InOut,
 | 
			
		||||
            s => {
 | 
			
		||||
                return Err(LibVirtStructError::ParseFilteringChain(format!(
 | 
			
		||||
                    "Unkown filter direction {s}!"
 | 
			
		||||
                ))
 | 
			
		||||
                .into())
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn to_xml(&self) -> String {
 | 
			
		||||
        match self {
 | 
			
		||||
            NetworkFilterDirection::In => "in",
 | 
			
		||||
            NetworkFilterDirection::Out => "out",
 | 
			
		||||
            NetworkFilterDirection::InOut => "inout",
 | 
			
		||||
        }
 | 
			
		||||
        .to_string()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
 | 
			
		||||
pub enum Layer4State {
 | 
			
		||||
    NEW,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user