@@ -21,6 +21,7 @@ type NetworkManager interface {
2121 WaitForEipStatus (region , eip string , toStatus EipStatus ) error
2222
2323 BindSLB (region , instanceId , slbId string , weight int ) error
24+ BindSlbServerGroup (region , instanceId , slbId string , weight int ,port int ) error
2425 DescribeSecurityGroupAttribute (region , groupId string ) (ecs.DescribeSecurityGroupAttributeResponse , error )
2526 JoinSecurityGroup (region , instanceId , groupId string ) error
2627}
@@ -34,6 +35,11 @@ type BackendServerType struct {
3435 ServerId string
3536 Weight int
3637}
38+ type SlbServerGroupBackendServerType struct {
39+ ServerId string
40+ Weight int
41+ Port int
42+ }
3743
3844func NewNetworkManager (config Config , logger boshlog.Logger ) NetworkManager {
3945 return NetworkManagerImpl {
@@ -139,6 +145,29 @@ func (a NetworkManagerImpl) WaitForEipStatus(region, eip string, toStatus EipSta
139145 return nil
140146}
141147
148+ func (a NetworkManagerImpl ) BindSlbServerGroup (region , instanceId string , slbServerGroupId string , weight int ,port int ) error {
149+ client ,err := a .config .NewSlbClient (region )
150+ if err != nil {
151+ return err
152+ }
153+ if weight == 0 {
154+ weight = DefaultSlbWeight
155+ }
156+ bytes , _ := json .Marshal ([]SlbServerGroupBackendServerType {
157+ {ServerId : instanceId , Weight : weight ,Port : port },
158+ })
159+ args := slb .CreateAddVServerGroupBackendServersRequest ()
160+ args .VServerGroupId = slbServerGroupId
161+ args .BackendServers = string (bytes )
162+ servers , err := client .AddVServerGroupBackendServers (args )
163+ if err != nil {
164+ a .logger .Error ("NetworkManager" , "BindSlbServerGroup %s to %s failed %v" , instanceId , slbServerGroupId , err )
165+ return bosherr .WrapErrorf (err , "BindSlbServerGroup %s to %s failed" , instanceId , slbServerGroupId )
166+ }
167+
168+ a .logger .Info ("NetworkManager" , "BindSlbServerGroup %s to %s, after bind server=%v" , instanceId , slbServerGroupId , servers )
169+ return err
170+ }
142171//
143172// TODO: add retry
144173func (a NetworkManagerImpl ) BindSLB (region , instanceId string , slbId string , weight int ) error {
0 commit comments