@@ -51,7 +51,38 @@ type Member struct {
5151 Address string
5252 ProtocolPort int
5353 Weight int
54+ AdminStateUp bool
5455 OperatingStatus string
56+ Backup bool
57+ MonitorAddress string
58+ MonitorPort int
59+ Tags []string
60+ }
61+
62+ // MemberCreateOpts contains editable fields for creating a pool member.
63+ type MemberCreateOpts struct {
64+ Name string
65+ Address string
66+ ProtocolPort int
67+ Weight int
68+ AdminStateUp bool
69+ Backup bool
70+ MonitorAddress string
71+ MonitorPort * int
72+ Tags []string
73+ }
74+
75+ // MemberUpdateOpts contains editable fields for updating a pool member.
76+ type MemberUpdateOpts struct {
77+ Name * string
78+ Weight * int
79+ AdminStateUp * bool
80+ Backup * bool
81+ MonitorAddress * string
82+ MonitorAddressSet bool
83+ MonitorPort * int
84+ MonitorPortSet bool
85+ Tags * []string
5586}
5687
5788// HealthMonitor is a simplified health monitor.
@@ -347,25 +378,24 @@ func UpdatePool(ctx context.Context, client *gophercloud.ServiceClient, id strin
347378}
348379
349380// CreateMember adds a member to a pool.
350- func CreateMember (ctx context.Context , client * gophercloud.ServiceClient , poolID , name , address string , port , weight int ) (* Member , error ) {
351- opts := pools.CreateMemberOpts {
352- Name : name ,
353- Address : address ,
354- ProtocolPort : port ,
355- Weight : & weight ,
356- }
357- m , err := pools .CreateMember (ctx , client , poolID , opts ).Extract ()
381+ func CreateMember (ctx context.Context , client * gophercloud.ServiceClient , poolID string , opts MemberCreateOpts ) (* Member , error ) {
382+ createOpts := pools.CreateMemberOpts {
383+ Name : opts .Name ,
384+ Address : opts .Address ,
385+ ProtocolPort : opts .ProtocolPort ,
386+ Weight : & opts .Weight ,
387+ AdminStateUp : & opts .AdminStateUp ,
388+ Backup : & opts .Backup ,
389+ MonitorAddress : opts .MonitorAddress ,
390+ MonitorPort : opts .MonitorPort ,
391+ Tags : cloneStringSlice (opts .Tags ),
392+ }
393+ m , err := pools .CreateMember (ctx , client , poolID , createOpts ).Extract ()
358394 if err != nil {
359395 return nil , fmt .Errorf ("creating member: %w" , err )
360396 }
361- return & Member {
362- ID : m .ID ,
363- Name : m .Name ,
364- Address : m .Address ,
365- ProtocolPort : m .ProtocolPort ,
366- Weight : m .Weight ,
367- OperatingStatus : m .OperatingStatus ,
368- }, nil
397+ member := simplifyMember (m )
398+ return & member , nil
369399}
370400
371401// DeleteMember removes a member from a pool.
@@ -377,13 +407,9 @@ func DeleteMember(ctx context.Context, client *gophercloud.ServiceClient, poolID
377407 return nil
378408}
379409
380- // UpdateMember updates a member's name and/or weight.
381- func UpdateMember (ctx context.Context , client * gophercloud.ServiceClient , poolID , memberID string , name * string , weight * int ) error {
382- opts := pools.UpdateMemberOpts {
383- Name : name ,
384- Weight : weight ,
385- }
386- _ , err := pools .UpdateMember (ctx , client , poolID , memberID , opts ).Extract ()
410+ // UpdateMember updates an existing member.
411+ func UpdateMember (ctx context.Context , client * gophercloud.ServiceClient , poolID , memberID string , opts MemberUpdateOpts ) error {
412+ _ , err := pools .UpdateMember (ctx , client , poolID , memberID , memberUpdateRequest (opts )).Extract ()
387413 if err != nil {
388414 return fmt .Errorf ("updating member %s: %w" , memberID , err )
389415 }
@@ -399,14 +425,7 @@ func ListMembers(ctx context.Context, client *gophercloud.ServiceClient, poolID
399425 return false , err
400426 }
401427 for _ , m := range extracted {
402- result = append (result , Member {
403- ID : m .ID ,
404- Name : m .Name ,
405- Address : m .Address ,
406- ProtocolPort : m .ProtocolPort ,
407- Weight : m .Weight ,
408- OperatingStatus : m .OperatingStatus ,
409- })
428+ result = append (result , simplifyMember (& m ))
410429 }
411430 return true , nil
412431 })
@@ -415,3 +434,68 @@ func ListMembers(ctx context.Context, client *gophercloud.ServiceClient, poolID
415434 }
416435 return result , nil
417436}
437+
438+ type memberUpdateRequest MemberUpdateOpts
439+
440+ func (opts memberUpdateRequest ) ToMemberUpdateMap () (map [string ]any , error ) {
441+ body := map [string ]any {}
442+ if opts .Name != nil {
443+ body ["name" ] = * opts .Name
444+ }
445+ if opts .Weight != nil {
446+ body ["weight" ] = * opts .Weight
447+ }
448+ if opts .AdminStateUp != nil {
449+ body ["admin_state_up" ] = * opts .AdminStateUp
450+ }
451+ if opts .Backup != nil {
452+ body ["backup" ] = * opts .Backup
453+ }
454+ if opts .MonitorAddressSet {
455+ if opts .MonitorAddress == nil {
456+ body ["monitor_address" ] = nil
457+ } else {
458+ body ["monitor_address" ] = * opts .MonitorAddress
459+ }
460+ }
461+ if opts .MonitorPortSet {
462+ if opts .MonitorPort == nil {
463+ body ["monitor_port" ] = nil
464+ } else {
465+ body ["monitor_port" ] = * opts .MonitorPort
466+ }
467+ }
468+ if opts .Tags != nil {
469+ if len (* opts .Tags ) == 0 {
470+ body ["tags" ] = []string {}
471+ } else {
472+ body ["tags" ] = cloneStringSlice (* opts .Tags )
473+ }
474+ }
475+ return map [string ]any {"member" : body }, nil
476+ }
477+
478+ func simplifyMember (m * pools.Member ) Member {
479+ return Member {
480+ ID : m .ID ,
481+ Name : m .Name ,
482+ Address : m .Address ,
483+ ProtocolPort : m .ProtocolPort ,
484+ Weight : m .Weight ,
485+ AdminStateUp : m .AdminStateUp ,
486+ OperatingStatus : m .OperatingStatus ,
487+ Backup : m .Backup ,
488+ MonitorAddress : m .MonitorAddress ,
489+ MonitorPort : m .MonitorPort ,
490+ Tags : cloneStringSlice (m .Tags ),
491+ }
492+ }
493+
494+ func cloneStringSlice (values []string ) []string {
495+ if len (values ) == 0 {
496+ return nil
497+ }
498+ out := make ([]string , len (values ))
499+ copy (out , values )
500+ return out
501+ }
0 commit comments