@@ -21,7 +21,8 @@ use tracing::info;
2121
2222use crate :: command:: CommandExecutor ;
2323
24- use super :: instance:: InstanceInfo ;
24+ #[ allow( unused_imports) ]
25+ use super :: instance:: { InstanceInfo , InstanceName } ;
2526use super :: json_parser:: LxdJsonParser ;
2627
2728/// A specialized LXD client for instance management.
@@ -67,7 +68,7 @@ impl LxdClient {
6768 /// This function will return an error if:
6869 /// * LXD command execution fails
6970 /// * JSON parsing fails
70- pub fn get_instance_ip ( & self , instance_name : & str ) -> Result < Option < IpAddr > > {
71+ pub fn get_instance_ip ( & self , instance_name : & InstanceName ) -> Result < Option < IpAddr > > {
7172 info ! ( "Getting IP address for instance: {}" , instance_name) ;
7273
7374 let Some ( instance) = self . get_instance_by_name ( instance_name) ? else {
@@ -108,7 +109,7 @@ impl LxdClient {
108109 /// * JSON parsing fails
109110 pub fn wait_for_instance_ip (
110111 & self ,
111- instance_name : & str ,
112+ instance_name : & InstanceName ,
112113 timeout_seconds : u64 ,
113114 poll_interval_seconds : u64 ,
114115 ) -> Result < IpAddr > {
@@ -162,14 +163,17 @@ impl LxdClient {
162163 /// This function will return an error if:
163164 /// * LXD command execution fails
164165 /// * JSON parsing fails
165- pub fn get_instance_by_name ( & self , instance_name : & str ) -> Result < Option < InstanceInfo > > {
166+ pub fn get_instance_by_name (
167+ & self ,
168+ instance_name : & InstanceName ,
169+ ) -> Result < Option < InstanceInfo > > {
166170 info ! ( "Getting instance by name: {}" , instance_name) ;
167171
168172 let instances = self . list ( Some ( instance_name) ) ?;
169173
170174 Ok ( instances
171175 . into_iter ( )
172- . find ( |inst| inst. name . as_str ( ) == instance_name) )
176+ . find ( |inst| inst. name . as_str ( ) == instance_name. as_str ( ) ) )
173177 }
174178
175179 /// List instances in JSON format
@@ -188,13 +192,13 @@ impl LxdClient {
188192 /// * The LXD command fails
189193 /// * LXD is not installed or accessible
190194 /// * JSON parsing fails
191- fn list ( & self , instance_name : Option < & str > ) -> Result < Vec < InstanceInfo > > {
195+ fn list ( & self , instance_name : Option < & InstanceName > ) -> Result < Vec < InstanceInfo > > {
192196 info ! ( "Listing LXD instances" ) ;
193197
194198 let mut args = vec ! [ "list" , "--format=json" ] ;
195199
196200 if let Some ( name) = instance_name {
197- args. push ( name) ;
201+ args. push ( name. as_str ( ) ) ;
198202 info ! ( "Filtering by instance name: {}" , name) ;
199203 }
200204
@@ -223,10 +227,10 @@ impl LxdClient {
223227 /// This function will return an error if:
224228 /// * The LXD command fails with an unexpected error
225229 /// * LXD is not installed or accessible
226- pub fn delete_instance ( & self , instance_name : & str , force : bool ) -> Result < ( ) > {
230+ pub fn delete_instance ( & self , instance_name : & InstanceName , force : bool ) -> Result < ( ) > {
227231 info ! ( "Deleting LXD instance: {}" , instance_name) ;
228232
229- let mut args = vec ! [ "delete" , instance_name] ;
233+ let mut args = vec ! [ "delete" , instance_name. as_str ( ) ] ;
230234 if force {
231235 args. push ( "--force" ) ;
232236 }
0 commit comments