@@ -21,7 +21,8 @@ use tracing::info;
21
21
22
22
use crate :: command:: CommandExecutor ;
23
23
24
- use super :: instance:: InstanceInfo ;
24
+ #[ allow( unused_imports) ]
25
+ use super :: instance:: { InstanceInfo , InstanceName } ;
25
26
use super :: json_parser:: LxdJsonParser ;
26
27
27
28
/// A specialized LXD client for instance management.
@@ -67,7 +68,7 @@ impl LxdClient {
67
68
/// This function will return an error if:
68
69
/// * LXD command execution fails
69
70
/// * 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 > > {
71
72
info ! ( "Getting IP address for instance: {}" , instance_name) ;
72
73
73
74
let Some ( instance) = self . get_instance_by_name ( instance_name) ? else {
@@ -108,7 +109,7 @@ impl LxdClient {
108
109
/// * JSON parsing fails
109
110
pub fn wait_for_instance_ip (
110
111
& self ,
111
- instance_name : & str ,
112
+ instance_name : & InstanceName ,
112
113
timeout_seconds : u64 ,
113
114
poll_interval_seconds : u64 ,
114
115
) -> Result < IpAddr > {
@@ -162,14 +163,17 @@ impl LxdClient {
162
163
/// This function will return an error if:
163
164
/// * LXD command execution fails
164
165
/// * 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 > > {
166
170
info ! ( "Getting instance by name: {}" , instance_name) ;
167
171
168
172
let instances = self . list ( Some ( instance_name) ) ?;
169
173
170
174
Ok ( instances
171
175
. into_iter ( )
172
- . find ( |inst| inst. name . as_str ( ) == instance_name) )
176
+ . find ( |inst| inst. name . as_str ( ) == instance_name. as_str ( ) ) )
173
177
}
174
178
175
179
/// List instances in JSON format
@@ -188,13 +192,13 @@ impl LxdClient {
188
192
/// * The LXD command fails
189
193
/// * LXD is not installed or accessible
190
194
/// * 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 > > {
192
196
info ! ( "Listing LXD instances" ) ;
193
197
194
198
let mut args = vec ! [ "list" , "--format=json" ] ;
195
199
196
200
if let Some ( name) = instance_name {
197
- args. push ( name) ;
201
+ args. push ( name. as_str ( ) ) ;
198
202
info ! ( "Filtering by instance name: {}" , name) ;
199
203
}
200
204
@@ -223,10 +227,10 @@ impl LxdClient {
223
227
/// This function will return an error if:
224
228
/// * The LXD command fails with an unexpected error
225
229
/// * 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 < ( ) > {
227
231
info ! ( "Deleting LXD instance: {}" , instance_name) ;
228
232
229
- let mut args = vec ! [ "delete" , instance_name] ;
233
+ let mut args = vec ! [ "delete" , instance_name. as_str ( ) ] ;
230
234
if force {
231
235
args. push ( "--force" ) ;
232
236
}
0 commit comments