yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/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 azure
    16  
    17  import (
    18  	"context"
    19  	"strconv"
    20  	"strings"
    21  
    22  	"github.com/pkg/errors"
    23  
    24  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    25  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    26  	"yunion.io/x/cloudmux/pkg/multicloud"
    27  )
    28  
    29  type SLoadbalancerBackend struct {
    30  	multicloud.SResourceBase
    31  
    32  	lbbg *SLoadbalancerBackendGroup
    33  	// networkInterfaces 通过接口地址反查虚拟机地址
    34  	Name        string `json:"name"`
    35  	ID          string `json:"id"`
    36  	Type        string `json:"type"`
    37  	BackendPort int
    38  	BackendIP   string
    39  }
    40  
    41  func (self *SLoadbalancerBackend) GetId() string {
    42  	return self.ID + "::" + strconv.Itoa(self.BackendPort)
    43  }
    44  
    45  func (self *SLoadbalancerBackend) GetName() string {
    46  	return self.Name
    47  }
    48  
    49  func (self *SLoadbalancerBackend) GetGlobalId() string {
    50  	return strings.ToLower(self.GetId())
    51  }
    52  
    53  func (self *SLoadbalancerBackend) GetStatus() string {
    54  	return api.LB_STATUS_ENABLED
    55  }
    56  
    57  func (self *SLoadbalancerBackend) GetSysTags() map[string]string {
    58  	return nil
    59  }
    60  
    61  func (self *SLoadbalancerBackend) GetTags() (map[string]string, error) {
    62  	return nil, nil
    63  }
    64  
    65  func (self *SLoadbalancerBackend) SetTags(tags map[string]string, replace bool) error {
    66  	return errors.Wrap(cloudprovider.ErrNotImplemented, "SetTags")
    67  }
    68  
    69  func (self *SLoadbalancerBackend) GetProjectId() string {
    70  	return getResourceGroup(self.ID)
    71  }
    72  
    73  func (self *SLoadbalancerBackend) GetWeight() int {
    74  	return 0
    75  }
    76  
    77  func (self *SLoadbalancerBackend) GetPort() int {
    78  	return self.BackendPort
    79  }
    80  
    81  func (self *SLoadbalancerBackend) GetBackendType() string {
    82  	return self.Type
    83  }
    84  
    85  func (self *SLoadbalancerBackend) GetBackendRole() string {
    86  	return api.LB_BACKEND_ROLE_DEFAULT
    87  }
    88  
    89  func (self *SLoadbalancerBackend) GetBackendId() string {
    90  	return self.ID
    91  }
    92  
    93  func (self *SLoadbalancerBackend) GetIpAddress() string {
    94  	return self.BackendIP
    95  }
    96  
    97  func (self *SLoadbalancerBackend) SyncConf(ctx context.Context, port, weight int) error {
    98  	return errors.Wrap(cloudprovider.ErrNotImplemented, "SyncConf")
    99  }