WIP building REST structures
This commit is contained in:
parent
9d4f19822d
commit
246f5ef842
@ -9,7 +9,6 @@ enum LibVirtStructError {
|
|||||||
StructureExtraction(&'static str),
|
StructureExtraction(&'static str),
|
||||||
#[error("DomainExtractionError: {0}")]
|
#[error("DomainExtractionError: {0}")]
|
||||||
DomainExtraction(String),
|
DomainExtraction(String),
|
||||||
|
|
||||||
#[error("ParseFilteringChain: {0}")]
|
#[error("ParseFilteringChain: {0}")]
|
||||||
ParseFilteringChain(String),
|
ParseFilteringChain(String),
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,20 @@ pub struct NetworkFilter {
|
|||||||
|
|
||||||
impl NetworkFilter {
|
impl NetworkFilter {
|
||||||
pub fn from_xml(xml: NetworkFilterXML) -> anyhow::Result<Self> {
|
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 {
|
Ok(Self {
|
||||||
name: xml.name,
|
name: xml.name,
|
||||||
uuid: xml.uuid,
|
uuid: xml.uuid,
|
||||||
@ -106,7 +120,7 @@ impl NetworkFilter {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|i| i.filter.to_string())
|
.map(|i| i.filter.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
rules: vec![], // TODO !
|
rules,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,6 +140,35 @@ pub enum NetworkFilterAction {
|
|||||||
Continue,
|
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)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||||
pub enum NetworkFilterDirection {
|
pub enum NetworkFilterDirection {
|
||||||
In,
|
In,
|
||||||
@ -133,6 +176,31 @@ pub enum NetworkFilterDirection {
|
|||||||
InOut,
|
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)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||||
pub enum Layer4State {
|
pub enum Layer4State {
|
||||||
NEW,
|
NEW,
|
||||||
|
Loading…
Reference in New Issue
Block a user