[pdm-devel] [PATCH datacenter-manager v3 01/11] pdm-api-types: views: add ViewConfig type
Lukas Wagner
l.wagner at proxmox.com
Wed Nov 12 11:05:32 CET 2025
On Tue Nov 11, 2025 at 11:58 AM CET, Michael Köppl wrote:
>> +/// Schema for filter rules.
>> +pub const FILTER_RULE_SCHEMA: Schema = StringSchema::new("Filter rule for resources.")
>> + .format(&ApiStringFormat::VerifyFn(verify_filter_rule))
>> + .type_text(
>> + "resource-type:storage|qemu|lxc|sdn-zone|datastore|node>\
>
> This line seems to be missing a <
>
Fixed, thank you!
>> + |resource-pool:<pool-name>\
>> + |tag:<tag-name>\
>> + |remote:<remote-name>\
>> + |resource-id:<resource-id>",
>> + )
>> + .schema();
>> +
>> +/// Schema for list of filter rules.
>> +pub const FILTER_RULE_LIST_SCHEMA: Schema =
>> + ArraySchema::new("List of filter rules.", &FILTER_RULE_SCHEMA).schema();
>> +
>> +#[api(
>> + properties: {
>> + "id": {
>> + schema: VIEW_ID_SCHEMA,
>> + },
>> + "include": {
>> + schema: FILTER_RULE_LIST_SCHEMA,
>> + optional: true,
>> + },
>> + "exclude": {
>> + schema: FILTER_RULE_LIST_SCHEMA,
>> + optional: true,
>> + }
>> + }
>> +)]
>> +#[derive(Clone, Debug, Default, Deserialize, Serialize, Updater, PartialEq)]
>> +#[serde(rename_all = "kebab-case")]
>> +/// View definition
>> +pub struct ViewConfig {
>> + /// View name.
>> + #[updater(skip)]
>> + pub id: String,
>> +
>> + /// List of includes.
>> + #[serde(default, skip_serializing_if = "Vec::is_empty")]
>> + #[updater(serde(skip_serializing_if = "Option::is_none"))]
>> + pub include: Vec<FilterRule>,
>> +
>> + /// List of excludes.
>> + #[serde(default, skip_serializing_if = "Vec::is_empty")]
>> + #[updater(serde(skip_serializing_if = "Option::is_none"))]
>> + pub exclude: Vec<FilterRule>,
>> +}
>> +
>> +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
>> +#[serde(rename_all = "kebab-case")]
>> +/// Enum for the different sections in the 'views.cfg' file.
>> +pub enum ViewConfigEntry {
>> + /// 'view' section
>> + View(ViewConfig),
>> +}
>> +
>> +const VIEW_SECTION_NAME: &str = "view";
>> +
>> +impl ApiSectionDataEntry for ViewConfigEntry {
>> + fn section_config() -> &'static SectionConfig {
>> + static CONFIG: OnceLock<SectionConfig> = OnceLock::new();
>> +
>> + CONFIG.get_or_init(|| {
>> + let mut this = SectionConfig::new(&VIEW_ID_SCHEMA);
>> +
>> + this.register_plugin(SectionConfigPlugin::new(
>> + VIEW_SECTION_NAME.into(),
>> + Some("id".to_string()),
>> + ViewConfig::API_SCHEMA.unwrap_object_schema(),
>> + ));
>> + this
>> + })
>> + }
>> +
>> + fn section_type(&self) -> &'static str {
>> + match self {
>> + ViewConfigEntry::View(_) => VIEW_SECTION_NAME,
>> + }
>> + }
>> +}
>> +
>> +#[derive(Clone, Debug, PartialEq)]
>> +/// Filter rule for includes/excludes.
>> +pub enum FilterRule {
>> + /// Match a resource type.
>> + ResourceType(ResourceType),
>> + /// Match a resource pools (for PVE guests).
>> + ResourcePool(String),
>> + /// Match a (global) resource ID, e.g. 'remote/<remote>/guest/<vmid>'.
>> + ResourceId(String),
>> + /// Match a tag (for PVE guests).
>> + Tag(String),
>> + /// Match a remote.
>> + Remote(String),
>> +}
>> +
>> +impl FromStr for FilterRule {
>> + type Err = anyhow::Error;
>> +
>> + fn from_str(s: &str) -> Result<Self, Self::Err> {
>> + Ok(match s.split_once(':') {
>> + Some(("resource-type", value)) => FilterRule::ResourceType(value.parse()?),
>> + Some(("resource-pool", value)) => {
>> + if !SAFE_ID_FORMAT.unwrap_pattern_format().is_match(value) {
>> + bail!("invalid tag value: {value}");
>
> This should probably have different error message such as "invalid
> resource pool ID".
>
Fixed as well.
More information about the pdm-devel
mailing list