appliance.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  
  20  	"github.com/sacloud/iaas-api-go/types"
  21  )
  22  
  23  // ApplianceRemark アプライアンスの設定/ステータスなど
  24  //
  25  // Appliance.Remarkを表現する
  26  type ApplianceRemark struct {
  27  	Zone            *ApplianceRemarkZone          `json:",omitempty" yaml:"zone,omitempty" structs:",omitempty"`
  28  	Switch          *ApplianceRemarkSwitch        `json:",omitempty" yaml:"switch,omitempty" structs:",omitempty"`
  29  	VRRP            *ApplianceVRRP                `json:",omitempty" yaml:"vrrp,omitempty" structs:",omitempty"`
  30  	Network         *ApplianceRemarkNetwork       `json:",omitempty" yaml:"network,omitempty" structs:",omitempty"`
  31  	Servers         ApplianceRemarkServers        `yaml:"servers"`
  32  	Plan            *AppliancePlan                `json:",omitempty" yaml:"plan,omitempty" structs:",omitempty"`
  33  	DBConf          *ApplianceRemarkDBConf        `json:",omitempty" yaml:"db_conf,omitempty" structs:",omitempty"`        // for database
  34  	SourceAppliance *ApplianceSource              `json:",omitempty" yaml:"db_conf,omitempty" structs:",omitempty"`        // for database
  35  	MobileGateway   *ApplianceRemarkMobileGateway `json:",omitempty" yaml:"mobile_gateway,omitempty" structs:",omitempty"` // for mobile gateway
  36  	Router          *ApplianceRemarkRouter        `json:",omitempty" yaml:"router,omitempty" structs:",omitempty"`         // for vpc router
  37  }
  38  
  39  // ApplianceRemarkMobileGateway モバイルゲートウェイのグローバルIP
  40  type ApplianceRemarkMobileGateway struct {
  41  	GlobalAddress string
  42  }
  43  
  44  // ApplianceRemarkRouter VPCルータのバージョンなど
  45  type ApplianceRemarkRouter struct {
  46  	VPCRouterVersion int `json:",omitempty" yaml:"vpc_router_version,omitempty" structs:",omitempty"`
  47  }
  48  
  49  // ApplianceSource クローン元アプライアンス データベースのクローン時に利用
  50  type ApplianceSource struct {
  51  	ID types.ID `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
  52  }
  53  
  54  // UnmarshalJSON 配列/オブジェクトが混在することへの対応
  55  func (s *ApplianceSource) UnmarshalJSON(b []byte) error {
  56  	if string(b) == "[]" {
  57  		return nil
  58  	}
  59  	type alias ApplianceSource
  60  
  61  	var a alias
  62  	if err := json.Unmarshal(b, &a); err != nil {
  63  		return err
  64  	}
  65  	*s = ApplianceSource(a)
  66  	return nil
  67  }
  68  
  69  // AppliancePlan アプライアンスプラン
  70  type AppliancePlan struct {
  71  	ID types.ID `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
  72  }
  73  
  74  // ApplianceVRRP アプライアンスのVRRPの設定
  75  type ApplianceVRRP struct {
  76  	VRID int `json:",omitempty" yaml:"vrid,omitempty" structs:",omitempty"`
  77  }
  78  
  79  // ApplianceRemarkNetwork Appliance ネットワーク設定
  80  type ApplianceRemarkNetwork struct {
  81  	DefaultRoute   string `json:",omitempty" yaml:"default_route,omitempty" structs:",omitempty"`
  82  	NetworkMaskLen int    `json:",omitempty" yaml:"network_mask_len,omitempty" structs:",omitempty"`
  83  }
  84  
  85  // ApplianceRemarkServers Applianceの稼働している仮想サーバのIPアドレス
  86  type ApplianceRemarkServers []*ApplianceRemarkServer
  87  
  88  // ApplianceRemarkServer Applianceの稼働している仮想サーバのIPアドレス
  89  type ApplianceRemarkServer struct {
  90  	IPAddress string `json:",omitempty" yaml:"ip_address,omitempty" structs:",omitempty"`
  91  }
  92  
  93  // ApplianceRemarkSwitch Applianceに接続されているスイッチのID
  94  type ApplianceRemarkSwitch struct {
  95  	ID    types.ID     `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
  96  	Scope types.EScope `json:",omitempty" yaml:"scope,omitempty" structs:",omitempty"`
  97  }
  98  
  99  // ApplianceRemarkZone Applianceの属するゾーンのID
 100  type ApplianceRemarkZone struct {
 101  	ID types.ID `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
 102  }
 103  
 104  // UnmarshalJSON 配列/オブジェクトが混在することへの対応
 105  func (s *ApplianceRemarkNetwork) UnmarshalJSON(b []byte) error {
 106  	if string(b) == "[]" {
 107  		return nil
 108  	}
 109  	type alias ApplianceRemarkNetwork
 110  
 111  	var a alias
 112  	if err := json.Unmarshal(b, &a); err != nil {
 113  		return err
 114  	}
 115  	*s = ApplianceRemarkNetwork(a)
 116  	return nil
 117  }
 118  
 119  // UnmarshalJSON 配列/オブジェクトが混在することへの対応
 120  func (s *ApplianceRemarkServer) UnmarshalJSON(b []byte) error {
 121  	if string(b) == "[]" {
 122  		return nil
 123  	}
 124  	type alias ApplianceRemarkServer
 125  
 126  	var a alias
 127  	if err := json.Unmarshal(b, &a); err != nil {
 128  		return err
 129  	}
 130  	*s = ApplianceRemarkServer(a)
 131  	return nil
 132  }
 133  
 134  // UnmarshalJSON 配列/オブジェクトが混在することへの対応
 135  func (s *ApplianceRemarkServers) UnmarshalJSON(b []byte) error {
 136  	if string(b) == "[[]]" {
 137  		return nil
 138  	}
 139  	if string(b) == `[""]` {
 140  		return nil
 141  	}
 142  	type alias ApplianceRemarkServers
 143  
 144  	var a alias
 145  	if err := json.Unmarshal(b, &a); err != nil {
 146  		return err
 147  	}
 148  	*s = ApplianceRemarkServers(a)
 149  	return nil
 150  }
 151  
 152  // MarshalJSON APIの要求するJSONフォーマットへの変換
 153  //
 154  // 値がからの場合に配列、かつ内部に空オブジェクトを指定する。(主にVPCルータへの対応)
 155  func (s *ApplianceRemarkServers) MarshalJSON() ([]byte, error) {
 156  	if s == nil || len(*s) == 0 {
 157  		return []byte("[{}]"), nil
 158  	}
 159  
 160  	type alias ApplianceRemarkServers
 161  
 162  	a := alias(*s)
 163  	return json.Marshal(a)
 164  }
 165  
 166  // ApplianceRemarkDBConf データベース設定
 167  type ApplianceRemarkDBConf struct {
 168  	Common *ApplianceRemarkDBConfCommon `json:",omitempty" yaml:"common,omitempty" structs:",omitempty"`
 169  }
 170  
 171  // ApplianceRemarkDBConfCommon データベース設定
 172  type ApplianceRemarkDBConfCommon struct {
 173  	DatabaseName     string `json:",omitempty" yaml:"database_name,omitempty" structs:",omitempty"`
 174  	DatabaseVersion  string `json:",omitempty" yaml:"database_version,omitempty" structs:",omitempty"`
 175  	DatabaseRevision string `json:",omitempty" yaml:"database_revision,omitempty" structs:",omitempty"`
 176  	DefaultUser      string `json:",omitempty" yaml:"default_user,omitempty" structs:",omitempty"`
 177  	UserPassword     string `json:",omitempty" yaml:"user_password,omitempty" structs:",omitempty"`
 178  }
 179