@@ -33,6 +33,7 @@ func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL stri
33
33
return false , errors .New ("invalid media type" )
34
34
}
35
35
36
+ supportedMediaTypes := []string {}
36
37
for _ , m := range managers {
37
38
virtualMedia , err := m .VirtualMedia ()
38
39
if err != nil {
@@ -43,24 +44,32 @@ func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL stri
43
44
}
44
45
45
46
for _ , vm := range virtualMedia {
47
+ if ! slices .Contains (vm .MediaTypes , mediaKind ) {
48
+ for _ , mt := range vm .MediaTypes {
49
+ supportedMediaTypes = append (supportedMediaTypes , string (mt ))
50
+ }
51
+ continue
52
+ }
46
53
if mediaURL == "" {
47
54
// Only ejecting the media was requested.
48
- // For BMC's that don't support the "inserted" property, we need to eject the media if it's not already ejected.
49
55
if vm .Inserted && vm .SupportsMediaEject {
50
56
if err := vm .EjectMedia (); err != nil {
51
- return false , err
57
+ return false , fmt . Errorf ( "error ejecting media: %v" , err )
52
58
}
53
59
}
54
60
return true , nil
55
61
}
62
+ // Ejecting the media before inserting a new new media makes the success rate of inserting the new media higher.
56
63
if vm .Inserted && vm .SupportsMediaEject {
57
64
if err := vm .EjectMedia (); err != nil {
58
- return false , err
65
+ return false , fmt . Errorf ( "error ejecting media before inserting media: %v" , err )
59
66
}
60
67
}
61
- if ! slices .Contains (vm .MediaTypes , mediaKind ) {
62
- return false , fmt .Errorf ("media kind %s not supported by BMC, supported media kinds %q" , kind , vm .MediaTypes )
68
+
69
+ if ! vm .SupportsMediaInsert {
70
+ return false , fmt .Errorf ("BMC does not support inserting virtual media of kind: %s" , kind )
63
71
}
72
+
64
73
if err := vm .InsertMedia (mediaURL , true , true ); err != nil {
65
74
// Some BMC's (Supermicro X11SDV-4C-TLN2F, for example) don't support the "inserted" and "writeProtected" properties,
66
75
// so we try to insert the media without them if the first attempt fails.
@@ -72,8 +81,7 @@ func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL stri
72
81
}
73
82
}
74
83
75
- // If we actual get here, then something very unexpected happened as there isn't a known code path that would cause this error to be returned.
76
- return false , errors .New ("unexpected error setting virtual media" )
84
+ return false , fmt .Errorf ("not a supported media type: %s. supported media types: %v" , kind , supportedMediaTypes )
77
85
}
78
86
79
87
func (c * Client ) InsertedVirtualMedia (ctx context.Context ) ([]string , error ) {
0 commit comments