load_balancer.go raw
1 // Copyright 2022-2025 The sacloud/iaas-api-go Authors
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 naked
16
17 import (
18 "encoding/json"
19 "time"
20
21 "github.com/sacloud/iaas-api-go/types"
22 )
23
24 // LoadBalancer ロードバランサ
25 type LoadBalancer struct {
26 ID types.ID `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
27 Name string `json:",omitempty" yaml:"name,omitempty" structs:",omitempty"`
28 Description string `yaml:"description"`
29 Tags types.Tags `yaml:"tags"`
30 Icon *Icon `json:",omitempty" yaml:"icon,omitempty" structs:",omitempty"`
31 CreatedAt *time.Time `json:",omitempty" yaml:"created_at,omitempty" structs:",omitempty"`
32 ModifiedAt *time.Time `json:",omitempty" yaml:"modified_at,omitempty" structs:",omitempty"`
33 Availability types.EAvailability `json:",omitempty" yaml:"availability,omitempty" structs:",omitempty"`
34 Class string `json:",omitempty" yaml:"class,omitempty" structs:",omitempty"`
35 ServiceClass string `json:",omitempty" yaml:"service_class,omitempty" structs:",omitempty"`
36 Plan *AppliancePlan `json:",omitempty" yaml:"plan,omitempty" structs:",omitempty"`
37 Instance *Instance `json:",omitempty" yaml:"instance,omitempty" structs:",omitempty"`
38 Interfaces Interfaces `json:",omitempty" yaml:"interfaces,omitempty" structs:",omitempty"`
39 Switch *Switch `json:",omitempty" yaml:"switch,omitempty" structs:",omitempty"`
40 Settings *LoadBalancerSettings `json:",omitempty" yaml:"settings,omitempty" structs:",omitempty"`
41 SettingsHash string `json:",omitempty" yaml:"settings_hash,omitempty" structs:",omitempty"`
42 Remark *ApplianceRemark `json:",omitempty" yaml:"remark,omitempty" structs:",omitempty"`
43 }
44
45 // LoadBalancerSettingsUpdate ロードバランサ
46 type LoadBalancerSettingsUpdate struct {
47 Settings *LoadBalancerSettings `json:",omitempty" yaml:"settings,omitempty" structs:",omitempty"`
48 SettingsHash string `json:",omitempty" yaml:"settings_hash,omitempty" structs:",omitempty"`
49 }
50
51 // LoadBalancerSettings ロードバランサの設定
52 type LoadBalancerSettings struct {
53 LoadBalancer []*LoadBalancerSetting `yaml:"load_balancer"`
54 }
55
56 // MarshalJSON nullの場合に空配列を出力するための実装
57 func (s LoadBalancerSettings) MarshalJSON() ([]byte, error) {
58 if s.LoadBalancer == nil {
59 s.LoadBalancer = make([]*LoadBalancerSetting, 0)
60 }
61 type alias LoadBalancerSettings
62 tmp := alias(s)
63 return json.Marshal(&tmp)
64 }
65
66 // LoadBalancerSetting ロードバランサの設定
67 type LoadBalancerSetting struct {
68 VirtualIPAddress string `json:",omitempty" yaml:"virtual_ip_address,omitempty" structs:",omitempty"`
69 Port types.StringNumber `json:",omitempty" yaml:"port,omitempty" structs:",omitempty"`
70 DelayLoop types.StringNumber `json:",omitempty" yaml:"delay_loop,omitempty" structs:",omitempty"`
71 SorryServer string `json:",omitempty" yaml:"sorry_server,omitempty" structs:",omitempty"`
72 Description string `yaml:"description"`
73 Servers []*LoadBalancerDestinationServer `yaml:"servers"`
74 }
75
76 // MarshalJSON nullの場合に空配列を出力するための実装
77 func (s LoadBalancerSetting) MarshalJSON() ([]byte, error) {
78 if s.Servers == nil {
79 s.Servers = make([]*LoadBalancerDestinationServer, 0)
80 }
81
82 type alias LoadBalancerSetting
83 tmp := alias(s)
84 return json.Marshal(&tmp)
85 }
86
87 // LoadBalancerDestinationServer ロードバランサ配下の実サーバ
88 type LoadBalancerDestinationServer struct {
89 IPAddress string `json:",omitempty" yaml:"ip_address,omitempty" structs:",omitempty"`
90 Port types.StringNumber `json:",omitempty" yaml:"port,omitempty" structs:",omitempty"`
91 Enabled types.StringFlag `yaml:"enabled"`
92 HealthCheck *LoadBalancerHealthCheck `json:",omitempty" yaml:"health_check,omitempty" structs:",omitempty"`
93 }
94
95 // LoadBalancerHealthCheck ヘルスチェック
96 type LoadBalancerHealthCheck struct {
97 Protocol types.Protocol `json:",omitempty" yaml:"protocol,omitempty" structs:""` // プロトコル
98 Host string `json:",omitempty" yaml:"host,omitempty" structs:""` // 対象ホスト
99 Path string `json:",omitempty" yaml:"path,omitempty" structs:""` // HTTP/HTTPSの場合のリクエストパス
100 Status types.StringNumber `json:",omitempty" yaml:"status,omitempty" structs:""` // 期待するステータスコード
101 Port types.StringNumber `json:",omitempty" yaml:"port,omitempty" structs:""` // ポート番号
102 Retry types.StringNumber `json:",omitempty" yaml:"retry,omitempty" struct:",omitempty"` // リトライ回数
103 ConnectTimeout types.StringNumber `json:",omitempty" yaml:"connect_timeout,omitempty" struct:",omitempty"` // タイムアウト
104 }
105
106 // LoadBalancerStatus ロードバランサのステータス
107 type LoadBalancerStatus struct {
108 VirtualIPAddress string `json:",omitempty" yaml:"virtual_ip_address,omitempty" structs:",omitempty"`
109 Port types.StringNumber `json:",omitempty" yaml:"port,omitempty" structs:",omitempty"`
110 CPS types.StringNumber `json:",omitempty" yaml:"cps,omitempty" structs:",omitempty"`
111 Servers []*LoadBalancerServerStatus `json:",omitempty" yaml:"servers,omitempty" structs:",omitempty"`
112 }
113
114 // LoadBalancerServerStatus ロードバランサの実サーバのステータス
115 type LoadBalancerServerStatus struct {
116 ActiveConn types.StringNumber `json:",omitempty" yaml:"active_conn,omitempty" structs:",omitempty"`
117 Status types.EServerInstanceStatus `json:",omitempty" yaml:"status,omitempty" structs:",omitempty"`
118 IPAddress string `json:",omitempty" yaml:"ip_address,omitempty" structs:",omitempty"`
119 Port types.StringNumber `json:",omitempty" yaml:"port,omitempty" structs:",omitempty"`
120 CPS types.StringNumber `json:",omitempty" yaml:"cps,omitempty" structs:",omitempty"`
121 }
122