yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/loadbalancer_backendgroup.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 google
    16  
    17  import (
    18  	"context"
    19  	"time"
    20  
    21  	"yunion.io/x/pkg/errors"
    22  
    23  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    24  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    25  )
    26  
    27  type SLoadBalancerBackendGroup struct {
    28  	lb       *SLoadbalancer
    29  	backends []SLoadbalancerBackend
    30  
    31  	backendService SBackendServices //
    32  
    33  	Id   string `json:"id"`
    34  	Name string `json:"name"`
    35  }
    36  
    37  func (self *SLoadBalancerBackendGroup) GetId() string {
    38  	return self.Id
    39  }
    40  
    41  func (self *SLoadBalancerBackendGroup) GetName() string {
    42  	return self.Name
    43  }
    44  
    45  func (self *SLoadBalancerBackendGroup) GetGlobalId() string {
    46  	return self.backendService.GetGlobalId()
    47  }
    48  
    49  func (self *SLoadBalancerBackendGroup) GetStatus() string {
    50  	return api.LB_STATUS_ENABLED
    51  }
    52  
    53  func (self *SLoadBalancerBackendGroup) Refresh() error {
    54  	return nil
    55  }
    56  
    57  func (self *SLoadBalancerBackendGroup) IsEmulated() bool {
    58  	return true
    59  }
    60  
    61  func (self *SLoadBalancerBackendGroup) GetSysTags() map[string]string {
    62  	return nil
    63  }
    64  
    65  func (self *SLoadBalancerBackendGroup) GetTags() (map[string]string, error) {
    66  	return nil, nil
    67  }
    68  
    69  func (self *SLoadBalancerBackendGroup) SetTags(tags map[string]string, replace bool) error {
    70  	return cloudprovider.ErrNotSupported
    71  }
    72  
    73  func (self *SLoadBalancerBackendGroup) GetProjectId() string {
    74  	return self.lb.GetProjectId()
    75  }
    76  
    77  func (self *SLoadBalancerBackendGroup) IsDefault() bool {
    78  	return false
    79  }
    80  
    81  func (self *SLoadBalancerBackendGroup) GetCreatedAt() time.Time {
    82  	return time.Time{}
    83  }
    84  
    85  func (self *SLoadBalancerBackendGroup) GetType() string {
    86  	return api.LB_BACKENDGROUP_TYPE_NORMAL
    87  }
    88  
    89  func (self *SLoadBalancerBackendGroup) GetLoadbalancerId() string {
    90  	return self.lb.GetGlobalId()
    91  }
    92  
    93  func (self *SLoadBalancerBackendGroup) GetILoadbalancerBackends() ([]cloudprovider.ICloudLoadbalancerBackend, error) {
    94  	backends, err := self.GetLoadbalancerBackends()
    95  	if err != nil {
    96  		return nil, errors.Wrap(err, "GetLoadbalancerBackends")
    97  	}
    98  
    99  	ibackends := make([]cloudprovider.ICloudLoadbalancerBackend, len(backends))
   100  	for i := range backends {
   101  		ibackends[i] = &backends[i]
   102  	}
   103  
   104  	return ibackends, nil
   105  }
   106  
   107  func (self *SLoadBalancerBackendGroup) GetILoadbalancerBackendById(backendId string) (cloudprovider.ICloudLoadbalancerBackend, error) {
   108  	backends, err := self.GetLoadbalancerBackends()
   109  	if err != nil {
   110  		return nil, errors.Wrap(err, "GetLoadbalancerBackends")
   111  	}
   112  
   113  	for i := range backends {
   114  		if backends[i].GetGlobalId() == backendId {
   115  			return &backends[i], nil
   116  		}
   117  	}
   118  
   119  	return nil, cloudprovider.ErrNotFound
   120  }
   121  
   122  func (self *SLoadBalancerBackendGroup) GetProtocolType() string {
   123  	return ""
   124  }
   125  
   126  func (self *SLoadBalancerBackendGroup) GetScheduler() string {
   127  	return ""
   128  }
   129  
   130  func (self *SLoadBalancerBackendGroup) GetHealthCheck() (*cloudprovider.SLoadbalancerHealthCheck, error) {
   131  	return nil, nil
   132  }
   133  
   134  func (self *SLoadBalancerBackendGroup) GetStickySession() (*cloudprovider.SLoadbalancerStickySession, error) {
   135  	return nil, nil
   136  }
   137  
   138  func (self *SLoadBalancerBackendGroup) AddBackendServer(serverId string, weight int, port int) (cloudprovider.ICloudLoadbalancerBackend, error) {
   139  	return nil, cloudprovider.ErrNotSupported
   140  }
   141  
   142  func (self *SLoadBalancerBackendGroup) RemoveBackendServer(serverId string, weight int, port int) error {
   143  	return cloudprovider.ErrNotSupported
   144  }
   145  
   146  func (self *SLoadBalancerBackendGroup) Delete(ctx context.Context) error {
   147  	return cloudprovider.ErrNotSupported
   148  }
   149  
   150  func (self *SLoadBalancerBackendGroup) Sync(ctx context.Context, group *cloudprovider.SLoadbalancerBackendGroup) error {
   151  	return cloudprovider.ErrNotSupported
   152  }
   153  
   154  func (self *SLoadbalancer) GetLoadbalancerBackendGroups() ([]SLoadBalancerBackendGroup, error) {
   155  	bss, err := self.GetBackendServices()
   156  	if err != nil {
   157  		return nil, errors.Wrap(err, "GetBackendServices")
   158  	}
   159  
   160  	ret := make([]SLoadBalancerBackendGroup, 0)
   161  	for i := range bss {
   162  		group := SLoadBalancerBackendGroup{
   163  			lb:             self,
   164  			backendService: bss[i],
   165  			Id:             bss[i].GetId(),
   166  			Name:           bss[i].GetName(),
   167  		}
   168  
   169  		ret = append(ret, group)
   170  	}
   171  
   172  	return ret, nil
   173  }