@@ -351,16 +351,31 @@ func (s *Service) GetSubnetsByFilter(opts subnets.ListOptsBuilder) ([]subnets.Su
351
351
// GetSubnetByFilter gets a single subnet specified by the given SubnetFilter.
352
352
// It returns an ErrFilterMatch if no or multiple subnets are found.
353
353
func (s * Service ) GetSubnetByFilter (filter * infrav1.SubnetFilter ) (* subnets.Subnet , error ) {
354
+ return s .getSubnetByFilter (filter .ToListOpt ())
355
+ }
356
+
357
+ // GetNetworkSubnetByFilter gets a single subnet of the given network, specified by the given SubnetFilter.
358
+ // It returns an ErrFilterMatch if no or multiple subnets are found.
359
+ func (s * Service ) GetNetworkSubnetByFilter (networkID string , filter * infrav1.SubnetFilter ) (* subnets.Subnet , error ) {
360
+ listOpt := filter .ToListOpt ()
361
+ listOpt .NetworkID = networkID
362
+
363
+ return s .getSubnetByFilter (listOpt )
364
+ }
365
+
366
+ // getSubnetByFilter gets a single subnet specified by the given gophercloud ListOpts.
367
+ // It returns an ErrFilterMatch if no or multiple subnets are found.
368
+ func (s * Service ) getSubnetByFilter (listOpts subnets.ListOpts ) (* subnets.Subnet , error ) {
354
369
// If the ID is set, we can just get the subnet by ID.
355
- if filter .ID != "" {
356
- subnet , err := s .client .GetSubnet (filter .ID )
370
+ if listOpts .ID != "" {
371
+ subnet , err := s .client .GetSubnet (listOpts .ID )
357
372
if capoerrors .IsNotFound (err ) {
358
373
return nil , ErrNoMatches
359
374
}
360
375
return subnet , err
361
376
}
362
377
363
- subnets , err := s .GetSubnetsByFilter (filter . ToListOpt () )
378
+ subnets , err := s .GetSubnetsByFilter (listOpts )
364
379
if err != nil {
365
380
return nil , err
366
381
}
0 commit comments