nv_redfish/port/collection.rs
1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::Port;
17use crate::schema::port_collection::PortCollection as PortCollectionSchema;
18use crate::Error;
19use crate::NvBmc;
20use nv_redfish_core::Bmc;
21use nv_redfish_core::NavProperty;
22use std::sync::Arc;
23
24/// Network port collection.
25///
26/// Provides functions to access collection members.
27pub struct PortCollection<B: Bmc> {
28 bmc: NvBmc<B>,
29 collection: Arc<PortCollectionSchema>,
30}
31
32impl<B: Bmc> PortCollection<B> {
33 pub(crate) async fn new(
34 bmc: &NvBmc<B>,
35 nav: &NavProperty<PortCollectionSchema>,
36 ) -> Result<Self, Error<B>> {
37 let collection = bmc.expand_property(nav).await?;
38 Ok(Self {
39 bmc: bmc.clone(),
40 collection,
41 })
42 }
43
44 /// List all ports in this collection.
45 ///
46 /// # Errors
47 ///
48 /// Returns an error if fetching port data fails.
49 pub async fn members(&self) -> Result<Vec<Port<B>>, Error<B>> {
50 let mut members = Vec::new();
51 for member in &self.collection.members {
52 members.push(Port::new(&self.bmc, member).await?);
53 }
54 Ok(members)
55 }
56}