@@ -119,6 +119,8 @@ pub struct NodeAgent {
119119 security_group_reconciler : SecurityGroupReconciler ,
120120 route_reconciler : RouteReconciler ,
121121 // Clients for init-from-reality
122+ vmm_client : VmmClient ,
123+ net_client : NetClient ,
122124 zfs_client : ZfsClient ,
123125}
124126
@@ -143,13 +145,15 @@ impl NodeAgent {
143145 resources,
144146 audit,
145147 known_ids : HashMap :: new ( ) ,
146- vm_reconciler : VmReconciler :: new ( vmm_client, zfs_client. clone ( ) ) ,
148+ vm_reconciler : VmReconciler :: new ( vmm_client. clone ( ) , zfs_client. clone ( ) ) ,
147149 network_reconciler : NetworkReconciler :: new ( net_client. clone ( ) ) ,
148150 nic_reconciler : NicReconciler :: new ( net_client. clone ( ) ) ,
149151 template_reconciler : TemplateReconciler :: new ( zfs_client. clone ( ) ) ,
150152 volume_reconciler : VolumeReconciler :: new ( zfs_client. clone ( ) ) ,
151- security_group_reconciler : SecurityGroupReconciler :: new ( net_client) ,
153+ security_group_reconciler : SecurityGroupReconciler :: new ( net_client. clone ( ) ) ,
152154 route_reconciler : RouteReconciler :: new ( ) ,
155+ vmm_client,
156+ net_client,
153157 zfs_client,
154158 }
155159 }
@@ -168,6 +172,72 @@ impl NodeAgent {
168172
169173 /// Initialize known_ids from local sub-services (init from reality).
170174 async fn init_from_reality ( & mut self ) {
175+ // VMs from VMM
176+ match self . vmm_client . list_vms ( ) . await {
177+ Ok ( vms) => {
178+ let ids: HashSet < String > = vms. iter ( ) . map ( |v| v. id . clone ( ) ) . collect ( ) ;
179+ info ! ( "Init from reality: {} VMs" , ids. len( ) ) ;
180+ self . known_ids . insert ( "vm" . to_string ( ) , ids) ;
181+ }
182+ Err ( e) => {
183+ warn ! ( "Failed to list VMs from VMM: {}" , e) ;
184+ self . known_ids . insert ( "vm" . to_string ( ) , HashSet :: new ( ) ) ;
185+ }
186+ }
187+
188+ // Networks from net
189+ match self . net_client . list_networks ( ) . await {
190+ Ok ( networks) => {
191+ let ids: HashSet < String > = networks. iter ( ) . map ( |n| n. id . clone ( ) ) . collect ( ) ;
192+ info ! ( "Init from reality: {} networks" , ids. len( ) ) ;
193+ self . known_ids . insert ( "network" . to_string ( ) , ids) ;
194+ }
195+ Err ( e) => {
196+ warn ! ( "Failed to list networks from net: {}" , e) ;
197+ self . known_ids . insert ( "network" . to_string ( ) , HashSet :: new ( ) ) ;
198+ }
199+ }
200+
201+ // NICs from net
202+ match self . net_client . list_nics ( ) . await {
203+ Ok ( nics) => {
204+ let ids: HashSet < String > = nics. iter ( ) . map ( |n| n. id . clone ( ) ) . collect ( ) ;
205+ info ! ( "Init from reality: {} NICs" , ids. len( ) ) ;
206+ self . known_ids . insert ( "nic" . to_string ( ) , ids) ;
207+ }
208+ Err ( e) => {
209+ warn ! ( "Failed to list NICs from net: {}" , e) ;
210+ self . known_ids . insert ( "nic" . to_string ( ) , HashSet :: new ( ) ) ;
211+ }
212+ }
213+
214+ // Security groups from net
215+ match self . net_client . list_security_groups ( ) . await {
216+ Ok ( sgs) => {
217+ let ids: HashSet < String > = sgs. iter ( ) . map ( |s| s. id . clone ( ) ) . collect ( ) ;
218+ info ! ( "Init from reality: {} security groups" , ids. len( ) ) ;
219+ self . known_ids . insert ( "security_group" . to_string ( ) , ids) ;
220+ }
221+ Err ( e) => {
222+ warn ! ( "Failed to list security groups from net: {}" , e) ;
223+ self . known_ids
224+ . insert ( "security_group" . to_string ( ) , HashSet :: new ( ) ) ;
225+ }
226+ }
227+
228+ // Volumes from ZFS
229+ match self . zfs_client . list_volumes ( ) . await {
230+ Ok ( volumes) => {
231+ let ids: HashSet < String > = volumes. iter ( ) . map ( |v| v. name . clone ( ) ) . collect ( ) ;
232+ info ! ( "Init from reality: {} volumes" , ids. len( ) ) ;
233+ self . known_ids . insert ( "volume" . to_string ( ) , ids) ;
234+ }
235+ Err ( e) => {
236+ warn ! ( "Failed to list volumes from ZFS: {}" , e) ;
237+ self . known_ids . insert ( "volume" . to_string ( ) , HashSet :: new ( ) ) ;
238+ }
239+ }
240+
171241 // Templates from ZFS
172242 match self . zfs_client . list_templates ( ) . await {
173243 Ok ( templates) => {
@@ -182,10 +252,8 @@ impl NodeAgent {
182252 }
183253 }
184254
185- // Other resource types start empty — the first manifest will populate them
186- for key in & [ "vm" , "network" , "nic" , "volume" , "security_group" , "route" ] {
187- self . known_ids . entry ( key. to_string ( ) ) . or_default ( ) ;
188- }
255+ // Routes start empty (no local daemon to query)
256+ self . known_ids . entry ( "route" . to_string ( ) ) . or_default ( ) ;
189257 }
190258
191259 /// Main agent loop.
0 commit comments