yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/loadbalancerbackend.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package aws 16 17 import ( 18 "context" 19 "fmt" 20 21 api "yunion.io/x/cloudmux/pkg/apis/compute" 22 "yunion.io/x/cloudmux/pkg/multicloud" 23 ) 24 25 type SElbBackend struct { 26 multicloud.SResourceBase 27 AwsTags 28 region *SRegion 29 group *SElbBackendGroup 30 31 Target Target `json:"Target"` 32 TargetHealth TargetHealth `json:"TargetHealth"` 33 } 34 35 type Target struct { 36 ID string `json:"Id"` 37 Port int `json:"Port"` 38 } 39 40 type TargetHealth struct { 41 State string `json:"State"` 42 Reason string `json:"Reason"` 43 Description string `json:"Description"` 44 } 45 46 func (self *SElbBackend) GetId() string { 47 return fmt.Sprintf("%s::%s::%d", self.group.GetId(), self.Target.ID, self.Target.Port) 48 } 49 50 func (self *SElbBackend) GetName() string { 51 return self.GetId() 52 } 53 54 func (self *SElbBackend) GetGlobalId() string { 55 return self.GetId() 56 } 57 58 func (self *SElbBackend) GetStatus() string { 59 return api.LB_STATUS_ENABLED 60 } 61 62 func (self *SElbBackend) Refresh() error { 63 return nil 64 } 65 66 func (self *SElbBackend) IsEmulated() bool { 67 return false 68 } 69 70 func (self *SElbBackend) GetProjectId() string { 71 return "" 72 } 73 74 func (self *SElbBackend) GetWeight() int { 75 return 0 76 } 77 78 func (self *SElbBackend) GetPort() int { 79 return self.Target.Port 80 } 81 82 func (self *SElbBackend) GetBackendType() string { 83 return api.LB_BACKEND_GUEST 84 } 85 86 func (self *SElbBackend) GetBackendRole() string { 87 return api.LB_BACKEND_ROLE_DEFAULT 88 } 89 90 func (self *SElbBackend) GetBackendId() string { 91 return self.Target.ID 92 } 93 94 func (self *SElbBackend) SyncConf(ctx context.Context, port, weight int) error { 95 return self.region.SyncElbBackend(self.GetId(), self.GetBackendId(), self.Target.Port, port) 96 } 97 98 func (self *SElbBackend) GetIpAddress() string { 99 return "" 100 } 101 102 func (self *SRegion) SyncElbBackend(backendId, serverId string, oldPort, newPort int) error { 103 err := self.RemoveElbBackend(backendId, serverId, 0, oldPort) 104 if err != nil { 105 return err 106 } 107 108 _, err = self.AddElbBackend(backendId, serverId, 0, newPort) 109 if err != nil { 110 return err 111 } 112 113 return nil 114 }