@@ -1625,29 +1625,19 @@ func ApiResourcesToStructs(in *api.Resources) *structs.Resources {
16251625 out .Devices = []* structs.RequestedDevice {}
16261626
16271627 for _ , d := range in .Devices {
1628- //temp
1629- var count uint64
1630- if d .Count != nil {
1631- count = * d .Count
1632- }
1633-
1634- out .Devices = append (out .Devices , & structs.RequestedDevice {
1635- Name : d .Name ,
1636- Count : count ,
1637- Constraints : ApiConstraintsToStructs (d .Constraints ),
1638- Affinities : ApiAffinitiesToStructs (d .Affinities ),
1639- ShareDevices : ApiSharingToStructs (d .ShareDevices ),
1640- })
16411628 rd := & structs.RequestedDevice {
16421629 Name : d .Name ,
16431630 Constraints : ApiConstraintsToStructs (d .Constraints ),
16441631 Affinities : ApiAffinitiesToStructs (d .Affinities ),
16451632 }
16461633 // Only set Count if not using FirstAvailable
1647- if d .Count != nil {
1634+ if d .Count != nil && len ( d . FirstAvailable ) == 0 {
16481635 rd .Count = * d .Count
16491636 }
1650- // Convert FirstAvailable options
1637+ if d .ShareDevices != nil && len (d .FirstAvailable ) == 0 {
1638+ rd .ShareDevices = ApiShareDevicesToStructs (d .ShareDevices )
1639+ }
1640+ //// Convert FirstAvailable options
16511641 if len (d .FirstAvailable ) > 0 {
16521642 rd .FirstAvailable = make ([]* structs.DeviceOption , len (d .FirstAvailable ))
16531643 for i , opt := range d .FirstAvailable {
@@ -1657,16 +1647,12 @@ func ApiResourcesToStructs(in *api.Resources) *structs.Resources {
16571647 if opt .Count != nil {
16581648 rd .FirstAvailable [i ].Count = * opt .Count
16591649 }
1650+ rd .FirstAvailable [i ].Name = opt .Name
1651+ if opt .ShareDevices != nil {
1652+ rd .FirstAvailable [i ].ShareDevices = ApiShareDevicesToStructs (opt .ShareDevices )
1653+ }
16601654 }
16611655 }
1662- //TODO: temp build out make better soon
1663- if d .ShareDevices != nil || len (d .FirstAvailable ) > 0 {
1664- rd .DevicePreferences = & structs.DevicePreferences {FirstAvailable : rd .FirstAvailable }
1665- }
1666- if d .ShareDevices != nil {
1667- rd .DevicePreferences .Enabled = d .ShareDevices .Enabled
1668- rd .DevicePreferences .SharedDeviceId = d .ShareDevices .SharedDeviceId
1669- }
16701656 out .Devices = append (out .Devices , rd )
16711657 }
16721658 }
@@ -1684,6 +1670,16 @@ func ApiResourcesToStructs(in *api.Resources) *structs.Resources {
16841670
16851671 return out
16861672}
1673+ func ApiShareDevicesToStructs (in * api.ShareDevices ) * structs.ShareDevices {
1674+ if in == nil {
1675+ return nil
1676+ }
1677+ return & structs.ShareDevices {
1678+ Enabled : in .Enabled ,
1679+ SharedDeviceId : in .SharedDeviceId ,
1680+ }
1681+
1682+ }
16871683
16881684func ApiNetworkResourceToStructs (in []* api.NetworkResource ) []* structs.NetworkResource {
16891685 var out []* structs.NetworkResource
@@ -2367,14 +2363,3 @@ func validateEvalPriorityOpt(priority int) HTTPCodedError {
23672363 }
23682364 return nil
23692365}
2370-
2371- func ApiSharingToStructs (in * api.ShareDevices ) * structs.ShareDevices {
2372- if in == nil {
2373- return nil
2374- }
2375- return & structs.ShareDevices {
2376- Enabled : in .Enabled ,
2377- SharedDeviceId : in .SharedDeviceId ,
2378- }
2379-
2380- }
0 commit comments