1
0
Fork 0

ACME TLS ALPN

This commit is contained in:
Ludovic Fernandez 2018-07-03 12:44:04 +02:00 committed by Traefiker Bot
parent 17ad5153b8
commit 139f280f35
258 changed files with 25528 additions and 1516 deletions

View file

@ -0,0 +1,9 @@
package sacloud
// Account さくらのクラウド アカウント
type Account struct {
*Resource
propName // 名称
Class string `json:",omitempty"` // リソースクラス
Code string `json:",omitempty"` // アカウントコード
}

View file

@ -0,0 +1,57 @@
package sacloud
// Appliance アプライアンス基底クラス
type Appliance struct {
*Resource // ID
propAvailability // 有功状態
propName // 名称
propDescription // 説明
propPlanID // プラン
propServiceClass // サービスクラス
propInstance // インスタンス
propSwitch // スイッチ
propInterfaces // インターフェース配列
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
Class string `json:",omitempty"` // リソースクラス
SettingHash string `json:",omitempty"` // 設定ハッシュ値
}
//HACK Appliance:Zone.IDがRoute/LoadBalancerの場合でデータ型が異なるため
//それぞれのstruct定義でZoneだけ上書きした構造体を定義して使う
// ApplianceRemarkBase アプライアンス Remark 基底クラス
type ApplianceRemarkBase struct {
Servers []interface{} // 配下のサーバー群
Switch *ApplianceRemarkSwitch `json:",omitempty"` // 接続先スイッチ
VRRP *ApplianceRemarkVRRP `json:",omitempty"` // VRRP
Network *ApplianceRemarkNetwork `json:",omitempty"` // ネットワーク
//Zone *Resource `json:",omitempty"`
//Plan *Resource
}
//type ApplianceServer struct {
// IPAddress string `json:",omitempty"`
//}
// ApplianceRemarkSwitch スイッチ
type ApplianceRemarkSwitch struct {
ID string `json:",omitempty"` // リソースID
propScope // スコープ
}
// ApplianceRemarkVRRP VRRP
type ApplianceRemarkVRRP struct {
VRID int // VRID
}
// ApplianceRemarkNetwork ネットワーク
type ApplianceRemarkNetwork struct {
NetworkMaskLen int `json:",omitempty"` // ネットワークマスク長
DefaultRoute string // デフォルトルート
}

View file

@ -0,0 +1,27 @@
package sacloud
// AllowArchiveSizes 作成できるアーカイブのサイズ
func AllowArchiveSizes() []string {
return []string{"20", "40", "60", "80", "100", "250", "500", "750", "1024"}
}
// Archive アーカイブ
type Archive struct {
*Resource // ID
propAvailability // 有功状態
propName // 名称
propDescription // 説明
propSizeMB // サイズ(MB単位)
propMigratedMB // コピー済みデータサイズ(MB単位)
propScope // スコープ
propCopySource // コピー元情報
propServiceClass // サービスクラス
propPlanID // プランID
propJobStatus // マイグレーションジョブステータス
propOriginalArchiveID // オリジナルアーカイブID
propStorage // ストレージ
propBundleInfo // バンドル情報
propTags // タグ
propIcon // アイコン
propCreatedAt // 作成日時
}

View file

@ -0,0 +1,79 @@
package sacloud
// AuthStatus 現在の認証状態
type AuthStatus struct {
Account *Account // アカウント
Member *Member // 会員情報
AuthClass EAuthClass `json:",omitempty"` // 認証クラス
AuthMethod EAuthMethod `json:",omitempty"` // 認証方法
ExternalPermission string `json:",omitempty"` // 他サービスへのアクセス権
IsAPIKey bool `json:",omitempty"` // APIキーでのアクセスフラグ
OperationPenalty string `json:",omitempty"` // オペレーションペナルティ
Permission EPermission `json:",omitempty"` // 権限
IsOk bool `json:"is_ok,omitempty"` // 結果
// RESTFilter [unknown type] `json:",omitempty"`
// User [unknown type] `json:",omitempty"`
}
// --------------------------------------------------------
// EAuthClass 認証種別
type EAuthClass string
var (
// EAuthClassAccount アカウント認証
EAuthClassAccount = EAuthClass("account")
)
// --------------------------------------------------------
// EAuthMethod 認証方法
type EAuthMethod string
var (
// EAuthMethodAPIKey APIキー認証
EAuthMethodAPIKey = EAuthMethod("apikey")
)
// --------------------------------------------------------
// EExternalPermission 他サービスへのアクセス権
type EExternalPermission string
var (
// EExternalPermissionBill 請求情報
EExternalPermissionBill = EExternalPermission("bill")
// EExternalPermissionCDN ウェブアクセラレータ
EExternalPermissionCDN = EExternalPermission("cdn")
)
// --------------------------------------------------------
// EOperationPenalty ペナルティ
type EOperationPenalty string
var (
// EOperationPenaltyNone ペナルティなし
EOperationPenaltyNone = EOperationPenalty("none")
)
// --------------------------------------------------------
// EPermission アクセスレベル
type EPermission string
var (
// EPermissionCreate 作成・削除権限
EPermissionCreate = EPermission("create")
// EPermissionArrange 設定変更権限
EPermissionArrange = EPermission("arrange")
// EPermissionPower 電源操作権限
EPermissionPower = EPermission("power")
// EPermissionView リソース閲覧権限
EPermissionView = EPermission("view")
)

View file

@ -0,0 +1,88 @@
package sacloud
import (
"encoding/json"
"fmt"
)
// AutoBackup 自動バックアップ(CommonServiceItem)
type AutoBackup struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
Status *AutoBackupStatus `json:",omitempty"` // ステータス
Provider *AutoBackupProvider `json:",omitempty"` // プロバイダ
Settings *AutoBackupSettings `json:",omitempty"` // 設定
}
// AutoBackupSettings 自動バックアップ設定
type AutoBackupSettings struct {
AccountID json.Number `json:"AccountId,omitempty"` // アカウントID
DiskID string `json:"DiskId,omitempty"` // ディスクID
ZoneID int64 `json:"ZoneId,omitempty"` // ゾーンID
ZoneName string `json:",omitempty"` // ゾーン名称
Autobackup *AutoBackupRecordSets `json:",omitempty"` // 自動バックアップ定義
}
// AutoBackupStatus 自動バックアップステータス
type AutoBackupStatus struct {
AccountID json.Number `json:"AccountId,omitempty"` // アカウントID
DiskID string `json:"DiskId,omitempty"` // ディスクID
ZoneID int64 `json:"ZoneId,omitempty"` // ゾーンID
ZoneName string `json:",omitempty"` // ゾーン名称
}
// AutoBackupProvider 自動バックアッププロバイダ
type AutoBackupProvider struct {
Class string `json:",omitempty"` // クラス
}
// CreateNewAutoBackup 自動バックアップ 作成(CommonServiceItem)
func CreateNewAutoBackup(backupName string, diskID int64) *AutoBackup {
return &AutoBackup{
Resource: &Resource{},
propName: propName{Name: backupName},
Status: &AutoBackupStatus{
DiskID: fmt.Sprintf("%d", diskID),
},
Provider: &AutoBackupProvider{
Class: "autobackup",
},
Settings: &AutoBackupSettings{
Autobackup: &AutoBackupRecordSets{
BackupSpanType: "weekdays",
},
},
}
}
// AllowAutoBackupWeekdays 自動バックアップ実行曜日リスト
func AllowAutoBackupWeekdays() []string {
return []string{"mon", "tue", "wed", "thu", "fri", "sat", "sun"}
}
// AutoBackupRecordSets 自動バックアップ定義
type AutoBackupRecordSets struct {
BackupSpanType string // バックアップ間隔タイプ
BackupSpanWeekdays []string // バックアップ実施曜日
MaximumNumberOfArchives int // 世代数
}
// SetBackupSpanWeekdays バックアップ実行曜日設定
func (a *AutoBackup) SetBackupSpanWeekdays(weekdays []string) {
a.Settings.Autobackup.BackupSpanWeekdays = weekdays
}
// SetBackupMaximumNumberOfArchives 世代数設定
func (a *AutoBackup) SetBackupMaximumNumberOfArchives(max int) {
a.Settings.Autobackup.MaximumNumberOfArchives = max
}

32
vendor/github.com/sacloud/libsacloud/sacloud/bill.go generated vendored Normal file
View file

@ -0,0 +1,32 @@
package sacloud
import "time"
// Bill 請求情報
type Bill struct {
Amount int64 `json:",omitempty"` // 金額
BillID int64 `json:",omitempty"` // 請求ID
Date *time.Time `json:",omitempty"` // 請求日
MemberID string `json:",omitempty"` // 会員ID
Paid bool `json:",omitempty"` // 支払済フラグ
PayLimit *time.Time `json:",omitempty"` // 支払い期限
PaymentClassID int `json:",omitempty"` // 支払いクラスID
}
// BillDetail 支払い明細情報
type BillDetail struct {
Amount int64 `json:",omitempty"` // 金額
ContractID int64 `json:",omitempty"` // 契約ID
Description string `json:",omitempty"` // 説明
Index int `json:",omitempty"` // インデックス
ServiceClassID int64 `json:",omitempty"` // サービスクラスID
Usage int64 `json:",omitempty"` // 秒数
Zone string `json:",omitempty"` // ゾーン
ContractEndAt *time.Time `json:",omitempty"` // 契約終了日時
}
// IsContractEnded 支払済か判定
func (d *BillDetail) IsContractEnded(t time.Time) bool {
return d.ContractEndAt != nil && d.ContractEndAt.Before(t)
}

30
vendor/github.com/sacloud/libsacloud/sacloud/bridge.go generated vendored Normal file
View file

@ -0,0 +1,30 @@
package sacloud
import (
"encoding/json"
)
// Bridge ブリッジ
type Bridge struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propRegion // リージョン
propCreatedAt // 作成日時
Info *struct { // インフォ
Switches []*struct { // 接続スイッチリスト
*Switch // スイッチ
ID json.Number `json:",omitempty"` // (HACK) ID
}
}
SwitchInZone *struct { // ゾーン内接続スイッチ
*Resource // ID
propScope // スコープ
Name string `json:",omitempty"` // 名称
ServerCount int `json:",omitempty"` // 接続サーバー数
ApplianceCount int `json:",omitempty"` // 接続アプライアンス数
}
}

17
vendor/github.com/sacloud/libsacloud/sacloud/cdrom.go generated vendored Normal file
View file

@ -0,0 +1,17 @@
package sacloud
// CDROM ISOイメージ(CDROM)
type CDROM struct {
*Resource // ID
propName // 名称
propDescription // 説明
propAvailability // 有功状態
propSizeMB // サイズ(MB単位)
propScope // スコープ
propServiceClass // サービスクラス
propStorageClass // ストレージクラス
propStorage // ストレージ
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
}

View file

@ -0,0 +1,326 @@
package sacloud
import (
"fmt"
"strconv"
"time"
)
// Resource IDを持つ、さくらのクラウド上のリソース
type Resource struct {
ID int64 // ID
}
// ResourceIDHolder ID保持インターフェース
type ResourceIDHolder interface {
SetID(int64)
GetID() int64
}
// EmptyID 空ID
const EmptyID int64 = 0
// NewResource 新規リソース作成
func NewResource(id int64) *Resource {
return &Resource{ID: id}
}
// NewResourceByStringID ID文字列からリソース作成
func NewResourceByStringID(id string) *Resource {
intID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
panic(err)
}
return &Resource{ID: intID}
}
// SetID ID 設定
func (n *Resource) SetID(id int64) {
n.ID = id
}
// GetID ID 取得
func (n *Resource) GetID() int64 {
if n == nil {
return -1
}
return n.ID
}
// GetStrID 文字列でID取得
func (n *Resource) GetStrID() string {
if n == nil {
return ""
}
return fmt.Sprintf("%d", n.ID)
}
// EAvailability 有効状態
type EAvailability string
var (
// EAAvailable 有効
EAAvailable = EAvailability("available")
// EAUploading アップロード中
EAUploading = EAvailability("uploading")
// EAFailed 失敗
EAFailed = EAvailability("failed")
// EAMigrating マイグレーション中
EAMigrating = EAvailability("migrating")
)
// IsAvailable 有効状態が"有効"か判定
func (e EAvailability) IsAvailable() bool {
return e == EAAvailable
}
// IsUploading 有効状態が"アップロード中"か判定
func (e EAvailability) IsUploading() bool {
return e == EAUploading
}
// IsFailed 有効状態が"失敗"か判定
func (e EAvailability) IsFailed() bool {
return e == EAFailed
}
// IsMigrating 有効状態が"マイグレーション中"か判定
func (e EAvailability) IsMigrating() bool {
return e == EAMigrating
}
// EInterfaceDriver インターフェースドライバ
type EInterfaceDriver string
var (
// InterfaceDriverVirtIO virtio
InterfaceDriverVirtIO = EInterfaceDriver("virtio")
// InterfaceDriverE1000 e1000
InterfaceDriverE1000 = EInterfaceDriver("e1000")
)
// EServerInstanceStatus サーバーインスタンスステータス
type EServerInstanceStatus struct {
Status string `json:",omitempty"` // 現在のステータス
BeforeStatus string `json:",omitempty"` // 前のステータス
}
// IsUp インスタンスが起動しているか判定
func (e *EServerInstanceStatus) IsUp() bool {
return e.Status == "up"
}
// IsDown インスタンスがダウンしているか確認
func (e *EServerInstanceStatus) IsDown() bool {
return e.Status == "down"
}
// GetStatus ステータス 取得
func (e *EServerInstanceStatus) GetStatus() string {
return e.Status
}
// GetBeforeStatus 以前のステータス 取得
func (e *EServerInstanceStatus) GetBeforeStatus() string {
return e.BeforeStatus
}
// EScope スコープ
type EScope string
var (
// ESCopeShared sharedスコープ
ESCopeShared = EScope("shared")
// ESCopeUser userスコープ
ESCopeUser = EScope("user")
)
// EDiskConnection ディスク接続方法
type EDiskConnection string
// SakuraCloudResources さくらのクラウド上のリソース種別一覧
type SakuraCloudResources struct {
Server *Server `json:",omitempty"` // サーバー
Disk *Disk `json:",omitempty"` // ディスク
Note *Note `json:",omitempty"` // スタートアップスクリプト
Archive *Archive `json:",omitempty"` // アーカイブ
PacketFilter *PacketFilter `json:",omitempty"` // パケットフィルタ
PrivateHost *PrivateHost `json:",omitempty"` // 専有ホスト
Bridge *Bridge `json:",omitempty"` // ブリッジ
Icon *Icon `json:",omitempty"` // アイコン
Image *Image `json:",omitempty"` // 画像
Interface *Interface `json:",omitempty"` // インターフェース
Internet *Internet `json:",omitempty"` // ルーター
IPAddress *IPAddress `json:",omitempty"` // IPv4アドレス
IPv6Addr *IPv6Addr `json:",omitempty"` // IPv6アドレス
IPv6Net *IPv6Net `json:",omitempty"` // IPv6ネットワーク
License *License `json:",omitempty"` // ライセンス
Switch *Switch `json:",omitempty"` // スイッチ
CDROM *CDROM `json:",omitempty"` // ISOイメージ
SSHKey *SSHKey `json:",omitempty"` // 公開鍵
Subnet *Subnet `json:",omitempty"` // IPv4ネットワーク
DiskPlan *ProductDisk `json:",omitempty"` // ディスクプラン
InternetPlan *ProductInternet `json:",omitempty"` // ルータープラン
LicenseInfo *ProductLicense `json:",omitempty"` // ライセンス情報
ServerPlan *ProductServer `json:",omitempty"` // サーバープラン
PrivateHostPlan *ProductPrivateHost `json:",omitempty"` // 専有ホストプラン
Region *Region `json:",omitempty"` // リージョン
Zone *Zone `json:",omitempty"` // ゾーン
FTPServer *FTPServer `json:",omitempty"` // FTPサーバー情報
WebAccelSite *WebAccelSite `json:"Site,omitempty"` // ウェブアクセラレータ サイト
//REMARK: CommonServiceItemとApplianceはapiパッケージにて別途定義
}
// SakuraCloudResourceList さくらのクラウド上のリソース種別一覧(複数形)
type SakuraCloudResourceList struct {
Servers []Server `json:",omitempty"` // サーバー
Disks []Disk `json:",omitempty"` // ディスク
Notes []Note `json:",omitempty"` // スタートアップスクリプト
Archives []Archive `json:",omitempty"` // アーカイブ
PacketFilters []PacketFilter `json:",omitempty"` // パケットフィルタ
PrivateHosts []PrivateHost `json:",omitempty"` // 専有ホスト
Bridges []Bridge `json:",omitempty"` // ブリッジ
Icons []Icon `json:",omitempty"` // アイコン
Interfaces []Interface `json:",omitempty"` // インターフェース
Internet []Internet `json:",omitempty"` // ルーター
IPAddress []IPAddress `json:",omitempty"` // IPv4アドレス
IPv6Addrs []IPv6Addr `json:",omitempty"` // IPv6アドレス
IPv6Nets []IPv6Net `json:",omitempty"` // IPv6ネットワーク
Licenses []License `json:",omitempty"` // ライセンス
Switches []Switch `json:",omitempty"` // スイッチ
CDROMs []CDROM `json:",omitempty"` // ISOイメージ
SSHKeys []SSHKey `json:",omitempty"` // 公開鍵
Subnets []Subnet `json:",omitempty"` // IPv4ネットワーク
DiskPlans []ProductDisk `json:",omitempty"` // ディスクプラン
InternetPlans []ProductInternet `json:",omitempty"` // ルータープラン
LicenseInfo []ProductLicense `json:",omitempty"` // ライセンス情報
ServerPlans []ProductServer `json:",omitempty"` // サーバープラン
PrivateHostPlans []ProductPrivateHost `json:",omitempty"` // 専有ホストプラン
Regions []Region `json:",omitempty"` // リージョン
Zones []Zone `json:",omitempty"` // ゾーン
ServiceClasses []PublicPrice `json:",omitempty"` // サービスクラス(価格情報)
WebAccelSites []WebAccelSite `json:"Sites,omitempty"` // ウェブアクセラレータ サイト
//REMARK:CommonServiceItemとApplianceはapiパッケージにて別途定義
}
// Request APIリクエスト型
type Request struct {
SakuraCloudResources // さくらのクラウドリソース
From int `json:",omitempty"` // ページング FROM
Count int `json:",omitempty"` // 取得件数
Sort []string `json:",omitempty"` // ソート
Filter map[string]interface{} `json:",omitempty"` // フィルタ
Exclude []string `json:",omitempty"` // 除外する項目
Include []string `json:",omitempty"` // 取得する項目
}
// AddFilter フィルタの追加
func (r *Request) AddFilter(key string, value interface{}) *Request {
if r.Filter == nil {
r.Filter = map[string]interface{}{}
}
r.Filter[key] = value
return r
}
// AddSort ソートの追加
func (r *Request) AddSort(keyName string) *Request {
if r.Sort == nil {
r.Sort = []string{}
}
r.Sort = append(r.Sort, keyName)
return r
}
// AddExclude 除外対象の追加
func (r *Request) AddExclude(keyName string) *Request {
if r.Exclude == nil {
r.Exclude = []string{}
}
r.Exclude = append(r.Exclude, keyName)
return r
}
// AddInclude 選択対象の追加
func (r *Request) AddInclude(keyName string) *Request {
if r.Include == nil {
r.Include = []string{}
}
r.Include = append(r.Include, keyName)
return r
}
// ResultFlagValue レスポンス値でのフラグ項目
type ResultFlagValue struct {
IsOk bool `json:"is_ok,omitempty"` // is_ok項目
Success bool `json:",omitempty"` // success項目
}
// SearchResponse 検索レスポンス
type SearchResponse struct {
Total int `json:",omitempty"` // トータル件数
From int `json:",omitempty"` // ページング開始ページ
Count int `json:",omitempty"` // 件数
ResponsedAt *time.Time `json:",omitempty"` // 応答日時
*SakuraCloudResourceList // さくらのクラウドリソース(複数形)
}
// Response レスポンス型
type Response struct {
*ResultFlagValue // フラグ値
*SakuraCloudResources // さくらのクラウドリソース(単数形)
}
// ResultErrorValue レスポンスエラー型
type ResultErrorValue struct {
IsFatal bool `json:"is_fatal,omitempty"` // IsFatal
Serial string `json:"serial,omitempty"` // Serial
Status string `json:"status,omitempty"` // Status
ErrorCode string `json:"error_code,omitempty"` // ErrorCode
ErrorMessage string `json:"error_msg,omitempty"` // ErrorMessage
}
// MigrationJobStatus マイグレーションジョブステータス
type MigrationJobStatus struct {
Status string `json:",omitempty"` // ステータス
Delays *struct { // Delays
Start *struct { // 開始
Max int `json:",omitempty"` // 最大
Min int `json:",omitempty"` // 最小
} `json:",omitempty"`
Finish *struct { // 終了
Max int `json:",omitempty"` // 最大
Min int `json:",omitempty"` // 最小
} `json:",omitempty"`
}
}
var (
// TagGroupA サーバをグループ化し起動ホストを分離します(グループA)
TagGroupA = "@group=a"
// TagGroupB サーバをグループ化し起動ホストを分離します(グループB)
TagGroupB = "@group=b"
// TagGroupC サーバをグループ化し起動ホストを分離します(グループC)
TagGroupC = "@group=b"
// TagGroupD サーバをグループ化し起動ホストを分離します(グループD)
TagGroupD = "@group=b"
// TagAutoReboot サーバ停止時に自動起動します
TagAutoReboot = "@auto-reboot"
// TagKeyboardUS リモートスクリーン画面でUSキーボード入力します
TagKeyboardUS = "@keyboard-us"
// TagBootCDROM 優先ブートデバイスをCD-ROMに設定します
TagBootCDROM = "@boot-cdrom"
// TagBootNetwork 優先ブートデバイスをPXE bootに設定します
TagBootNetwork = "@boot-network"
)
// DatetimeLayout さくらのクラウドAPIで利用される日付型のレイアウト(RFC3339)
var DatetimeLayout = "2006-01-02T15:04:05-07:00"

View file

@ -0,0 +1,435 @@
package sacloud
import (
"encoding/json"
"strings"
)
// Database データベース(appliance)
type Database struct {
*Appliance // アプライアンス共通属性
Remark *DatabaseRemark `json:",omitempty"` // リマーク
Settings *DatabaseSettings `json:",omitempty"` // データベース設定
}
// DatabaseRemark データベースリマーク
type DatabaseRemark struct {
*ApplianceRemarkBase
propPlanID // プランID
DBConf *DatabaseCommonRemarks // コンフィグ
Network *DatabaseRemarkNetwork // ネットワーク
SourceAppliance *Resource // クローン元DB
Zone struct { // ゾーン
ID json.Number `json:",omitempty"` // ゾーンID
}
}
// DatabaseRemarkNetwork ネットワーク
type DatabaseRemarkNetwork struct {
NetworkMaskLen int `json:",omitempty"` // ネットワークマスク長
DefaultRoute string `json:",omitempty"` // デフォルトルート
}
// UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
func (s *DatabaseRemarkNetwork) UnmarshalJSON(data []byte) error {
targetData := strings.Replace(strings.Replace(string(data), " ", "", -1), "\n", "", -1)
if targetData == `[]` {
return nil
}
tmp := &struct {
// NetworkMaskLen
NetworkMaskLen int `json:",omitempty"`
// DefaultRoute
DefaultRoute string `json:",omitempty"`
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
s.NetworkMaskLen = tmp.NetworkMaskLen
s.DefaultRoute = tmp.DefaultRoute
return nil
}
// DatabaseCommonRemarks リマークリスト
type DatabaseCommonRemarks struct {
Common *DatabaseCommonRemark // Common
}
// DatabaseCommonRemark リマーク
type DatabaseCommonRemark struct {
DatabaseName string `json:",omitempty"` // 名称
DatabaseRevision string `json:",omitempty"` // リビジョン
DatabaseTitle string `json:",omitempty"` // タイトル
DatabaseVersion string `json:",omitempty"` // バージョン
ReplicaPassword string `json:",omitempty"` // レプリケーションパスワード
ReplicaUser string `json:",omitempty"` // レプリケーションユーザー
}
// DatabaseSettings データベース設定リスト
type DatabaseSettings struct {
DBConf *DatabaseSetting `json:",omitempty"` // コンフィグ
}
// DatabaseSetting データベース設定
type DatabaseSetting struct {
Backup *DatabaseBackupSetting `json:",omitempty"` // バックアップ設定
Common *DatabaseCommonSetting `json:",oitempty"` // 共通設定
}
// DatabaseServer データベースサーバー情報
type DatabaseServer struct {
IPAddress string `json:",omitempty"` // IPアドレス
Port string `json:",omitempty"` // ポート
Enabled string `json:",omitempty"` // 有効/無効
Status string `json:",omitempty"` // ステータス
ActiveConn string `json:",omitempty"` // アクティブコネクション
}
// DatabasePlan プラン
type DatabasePlan int
var (
// DatabasePlanMini ミニプラン(後方互換用)
DatabasePlanMini = DatabasePlan(10)
// DatabasePlan10G 10Gプラン
DatabasePlan10G = DatabasePlan(10)
// DatabasePlan30G 30Gプラン
DatabasePlan30G = DatabasePlan(30)
// DatabasePlan90G 90Gプラン
DatabasePlan90G = DatabasePlan(90)
// DatabasePlan240G 240Gプラン
DatabasePlan240G = DatabasePlan(240)
// DatabasePlan500G 500Gプラン
DatabasePlan500G = DatabasePlan(500)
// DatabasePlan1T 1Tプラン
DatabasePlan1T = DatabasePlan(1000)
)
// AllowDatabasePlans 指定可能なデータベースプラン
func AllowDatabasePlans() []int {
return []int{
int(DatabasePlan10G),
int(DatabasePlan30G),
int(DatabasePlan90G),
int(DatabasePlan240G),
int(DatabasePlan500G),
int(DatabasePlan1T),
}
}
// DatabaseBackupSetting バックアップ設定
type DatabaseBackupSetting struct {
Rotate int `json:",omitempty"` // ローテーション世代数
Time string `json:",omitempty"` // 開始時刻
}
// DatabaseCommonSetting 共通設定
type DatabaseCommonSetting struct {
DefaultUser string `json:",omitempty"` // ユーザー名
UserPassword string `json:",omitempty"` // ユーザーパスワード
WebUI interface{} `json:",omitempty"` // WebUIのIPアドレス or FQDN
ServicePort string // ポート番号
SourceNetwork SourceNetwork // 接続許可ネットワーク
}
// SourceNetwork 接続許可ネットワーク
type SourceNetwork []string
// UnmarshalJSON JSONアンマーシャル(配列と文字列が混在するためここで対応)
func (s *SourceNetwork) UnmarshalJSON(data []byte) error {
// SourceNetworkが未設定の場合、APIレスポンスが""となるため回避する
if string(data) == `""` {
return nil
}
tmp := []string{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
source := SourceNetwork(tmp)
*s = source
return nil
}
// MarshalJSON JSONマーシャル(配列と文字列が混在するためここで対応)
func (s *SourceNetwork) MarshalJSON() ([]byte, error) {
if s == nil {
return []byte(""), nil
}
list := []string(*s)
if len(list) == 0 || (len(list) == 1 && list[0] == "") {
return []byte(`""`), nil
}
return json.Marshal(list)
}
// CreateDatabaseValue データベース作成用パラメータ
type CreateDatabaseValue struct {
Plan DatabasePlan // プラン
AdminPassword string // 管理者パスワード
DefaultUser string // ユーザー名
UserPassword string // パスワード
SourceNetwork []string // 接続許可ネットワーク
ServicePort string // ポート
// BackupRotate int // バックアップ世代数
BackupTime string // バックアップ開始時間
SwitchID string // 接続先スイッチ
IPAddress1 string // IPアドレス1
MaskLen int // ネットワークマスク長
DefaultRoute string // デフォルトルート
Name string // 名称
Description string // 説明
Tags []string // タグ
Icon *Resource // アイコン
WebUI bool // WebUI有効
DatabaseName string // データベース名
DatabaseRevision string // リビジョン
DatabaseTitle string // データベースタイトル
DatabaseVersion string // データベースバージョン
ReplicaUser string // ReplicaUser レプリケーションユーザー
SourceAppliance *Resource // クローン元DB
//ReplicaPassword string // in current API version , setted admin password
}
// NewCreatePostgreSQLDatabaseValue PostgreSQL作成用パラメーター
func NewCreatePostgreSQLDatabaseValue() *CreateDatabaseValue {
return &CreateDatabaseValue{
DatabaseName: "postgres",
DatabaseVersion: "10",
}
}
// NewCreateMariaDBDatabaseValue MariaDB作成用パラメーター
func NewCreateMariaDBDatabaseValue() *CreateDatabaseValue {
return &CreateDatabaseValue{
DatabaseName: "MariaDB",
DatabaseVersion: "10.2",
}
}
// NewCloneDatabaseValue クローンDB作成用パラメータ
func NewCloneDatabaseValue(db *Database) *CreateDatabaseValue {
return &CreateDatabaseValue{
DatabaseName: db.Remark.DBConf.Common.DatabaseName,
DatabaseVersion: db.Remark.DBConf.Common.DatabaseVersion,
SourceAppliance: NewResource(db.ID),
}
}
// CreateNewDatabase データベース作成
func CreateNewDatabase(values *CreateDatabaseValue) *Database {
db := &Database{
// Appliance
Appliance: &Appliance{
// Class
Class: "database",
// Name
propName: propName{Name: values.Name},
// Description
propDescription: propDescription{Description: values.Description},
// TagsType
propTags: propTags{
// Tags
Tags: values.Tags,
},
// Icon
propIcon: propIcon{
&Icon{
// Resource
Resource: values.Icon,
},
},
// Plan
//propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
},
// Remark
Remark: &DatabaseRemark{
// ApplianceRemarkBase
ApplianceRemarkBase: &ApplianceRemarkBase{
// Servers
Servers: []interface{}{""},
},
// DBConf
DBConf: &DatabaseCommonRemarks{
// Common
Common: &DatabaseCommonRemark{
// DatabaseName
DatabaseName: values.DatabaseName,
// DatabaseRevision
DatabaseRevision: values.DatabaseRevision,
// DatabaseTitle
DatabaseTitle: values.DatabaseTitle,
// DatabaseVersion
DatabaseVersion: values.DatabaseVersion,
// ReplicaUser
// ReplicaUser: values.ReplicaUser,
// ReplicaPassword
// ReplicaPassword: values.AdminPassword,
},
},
// Plan
propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
SourceAppliance: values.SourceAppliance,
},
// Settings
Settings: &DatabaseSettings{
// DBConf
DBConf: &DatabaseSetting{
// Backup
Backup: &DatabaseBackupSetting{
// Rotate
// Rotate: values.BackupRotate,
Rotate: 8,
// Time
Time: values.BackupTime,
},
// Common
Common: &DatabaseCommonSetting{
// DefaultUser
DefaultUser: values.DefaultUser,
// UserPassword
UserPassword: values.UserPassword,
// SourceNetwork
SourceNetwork: SourceNetwork(values.SourceNetwork),
// ServicePort
ServicePort: values.ServicePort,
},
},
},
}
db.Remark.Switch = &ApplianceRemarkSwitch{
// ID
ID: values.SwitchID,
}
db.Remark.Network = &DatabaseRemarkNetwork{
// NetworkMaskLen
NetworkMaskLen: values.MaskLen,
// DefaultRoute
DefaultRoute: values.DefaultRoute,
}
db.Remark.Servers = []interface{}{
map[string]interface{}{"IPAddress": values.IPAddress1},
}
if values.WebUI {
db.Settings.DBConf.Common.WebUI = values.WebUI
}
return db
}
// CloneNewDatabase データベース作成
func CloneNewDatabase(values *CreateDatabaseValue) *Database {
db := &Database{
// Appliance
Appliance: &Appliance{
// Class
Class: "database",
// Name
propName: propName{Name: values.Name},
// Description
propDescription: propDescription{Description: values.Description},
// TagsType
propTags: propTags{
// Tags
Tags: values.Tags,
},
// Icon
propIcon: propIcon{
&Icon{
// Resource
Resource: values.Icon,
},
},
// Plan
//propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
},
// Remark
Remark: &DatabaseRemark{
// ApplianceRemarkBase
ApplianceRemarkBase: &ApplianceRemarkBase{
// Servers
Servers: []interface{}{""},
},
// DBConf
DBConf: &DatabaseCommonRemarks{
// Common
Common: &DatabaseCommonRemark{
DatabaseName: values.DatabaseName,
DatabaseVersion: values.DatabaseVersion,
},
},
// Plan
propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
SourceAppliance: values.SourceAppliance,
},
// Settings
Settings: &DatabaseSettings{
// DBConf
DBConf: &DatabaseSetting{
// Backup
Backup: &DatabaseBackupSetting{
// Rotate
// Rotate: values.BackupRotate,
Rotate: 8,
// Time
Time: values.BackupTime,
},
// Common
Common: &DatabaseCommonSetting{
// SourceNetwork
SourceNetwork: SourceNetwork(values.SourceNetwork),
// ServicePort
ServicePort: values.ServicePort,
},
},
},
}
db.Remark.Switch = &ApplianceRemarkSwitch{
// ID
ID: values.SwitchID,
}
db.Remark.Network = &DatabaseRemarkNetwork{
// NetworkMaskLen
NetworkMaskLen: values.MaskLen,
// DefaultRoute
DefaultRoute: values.DefaultRoute,
}
db.Remark.Servers = []interface{}{
map[string]interface{}{"IPAddress": values.IPAddress1},
}
if values.WebUI {
db.Settings.DBConf.Common.WebUI = values.WebUI
}
return db
}
// AddSourceNetwork 接続許可ネットワーク 追加
func (s *Database) AddSourceNetwork(nw string) {
res := []string(s.Settings.DBConf.Common.SourceNetwork)
res = append(res, nw)
s.Settings.DBConf.Common.SourceNetwork = SourceNetwork(res)
}
// DeleteSourceNetwork 接続許可ネットワーク 削除
func (s *Database) DeleteSourceNetwork(nw string) {
res := []string{}
for _, s := range s.Settings.DBConf.Common.SourceNetwork {
if s != nw {
res = append(res, s)
}
}
s.Settings.DBConf.Common.SourceNetwork = SourceNetwork(res)
}

View file

@ -0,0 +1,128 @@
package sacloud
import (
"encoding/json"
"strconv"
"strings"
"time"
)
// DatabaseStatus データベース ステータス
type DatabaseStatus struct {
*EServerInstanceStatus
DBConf *DatabaseStatusDBConf `json:",omitempty"`
}
// DatabaseStatusDBConf データベース設定
type DatabaseStatusDBConf struct {
Version *DatabaseStatusVersion `json:"version,omitempty"`
Log []*DatabaseLog `json:"log,omitempty"`
Backup *DatabaseBackupInfo `json:"backup,omitempty"`
}
// DatabaseStatusVersion データベース設定バージョン情報
type DatabaseStatusVersion struct {
LastModified string `json:"lastmodified,omitempty"`
CommitHash string `json:"commithash,omitempty"`
Status string `json:"status,omitempty"`
Tag string `json:"tag,omitempty"`
Expire string `json:"expire,omitempty"`
}
// DatabaseLog データベースログ
type DatabaseLog struct {
Name string `json:"name,omitempty"`
Data string `json:"data,omitempty"`
}
// IsSystemdLog systemcltのログか判定
func (l *DatabaseLog) IsSystemdLog() bool {
return l.Name == "systemctl"
}
// Logs ログボディ取得
func (l *DatabaseLog) Logs() []string {
return strings.Split(l.Data, "\n")
}
// ID ログのID取得
func (l *DatabaseLog) ID() string {
return l.Name
}
// DatabaseBackupInfo データベースバックアップ情報
type DatabaseBackupInfo struct {
History []*DatabaseBackupHistory `json:"history,omitempty"`
}
// DatabaseBackupHistory データベースバックアップ履歴情報
type DatabaseBackupHistory struct {
CreatedAt time.Time `json:"createdat,omitempty"`
Availability string `json:"availability,omitempty"`
RecoveredAt *time.Time `json:"recoveredat,omitempty"`
Size int64 `json:"size,omitempty"`
}
// ID バックアップ履歴のID取得
func (h *DatabaseBackupHistory) ID() string {
return h.CreatedAt.Format(time.RFC3339)
}
// FormatCreatedAt 指定のレイアウトで作成日時を文字列化
func (h *DatabaseBackupHistory) FormatCreatedAt(layout string) string {
return h.CreatedAt.Format(layout)
}
// FormatRecoveredAt 指定のレイアウトで復元日時を文字列化
//
// 復元日時がnilの場合は空の文字列を返す
func (h *DatabaseBackupHistory) FormatRecoveredAt(layout string) string {
if h.RecoveredAt == nil {
return ""
}
return h.RecoveredAt.Format(layout)
}
// UnmarshalJSON JSON復号処理
func (h *DatabaseBackupHistory) UnmarshalJSON(data []byte) error {
var tmpMap = map[string]interface{}{}
if err := json.Unmarshal(data, &tmpMap); err != nil {
return err
}
if recoveredAt, ok := tmpMap["recoveredat"]; ok {
if strRecoveredAt, ok := recoveredAt.(string); ok {
if _, err := time.Parse(time.RFC3339, strRecoveredAt); err != nil {
tmpMap["recoveredat"] = nil
}
}
}
data, err := json.Marshal(tmpMap)
if err != nil {
return err
}
tmp := &struct {
CreatedAt time.Time `json:"createdat,omitempty"`
Availability string `json:"availability,omitempty"`
RecoveredAt *time.Time `json:"recoveredat,omitempty"`
Size string `json:"size,omitempty"`
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
h.CreatedAt = tmp.CreatedAt
h.Availability = tmp.Availability
h.RecoveredAt = tmp.RecoveredAt
s, err := strconv.ParseInt(tmp.Size, 10, 64)
if err == nil {
h.Size = s
} else {
return err
}
return nil
}

View file

@ -0,0 +1,8 @@
package sacloud
// DeleteCacheResult ウェブアクセラレータ キャッシュ削除APIレスポンス
type DeleteCacheResult struct {
URL string `json:",omitempty"` // URL
Status int `json:",omitempty"` // ステータス
Result string `json:",omitempty"` // 結果
}

202
vendor/github.com/sacloud/libsacloud/sacloud/disk.go generated vendored Normal file
View file

@ -0,0 +1,202 @@
package sacloud
import "fmt"
// Disk ディスク
type Disk struct {
*Resource // ID
propAvailability // 有功状態
propName // 名称
propDescription // 説明
propSizeMB // サイズ(MB単位)
propMigratedMB // コピー済みデータサイズ(MB単位)
propCopySource // コピー元情報
propJobStatus // マイグレーションジョブステータス
propBundleInfo // バンドル情報
propServer // サーバー
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propPlanID // プランID
propDiskConnection // ディスク接続情報
propDistantFrom // ストレージ隔離対象ディスク
ReinstallCount int `json:",omitempty"` // 再インストール回数
Storage struct { // ストレージ
*Resource // ID
Name string `json:",omitempty"` // 名称
DiskPlan ProductDisk `json:",ommitempty"` // ディスクプラン
MountIndex int64 `json:",omitempty"` // マウント順
Class string `json:",omitempty"` // クラス
}
}
// DiskPlanID ディスクプランID
type DiskPlanID int64
const (
// DiskPlanHDDID HDDプランID
DiskPlanHDDID = DiskPlanID(2)
// DiskPlanSSDID SSDプランID
DiskPlanSSDID = DiskPlanID(4)
// DiskConnectionVirtio 準仮想化モード(virtio)
DiskConnectionVirtio EDiskConnection = "virtio"
// DiskConnectionIDE IDE
DiskConnectionIDE EDiskConnection = "ide"
)
var (
// DiskPlanHDD HDDプラン
DiskPlanHDD = &Resource{ID: int64(DiskPlanHDDID)}
// DiskPlanSSD SSDプラン
DiskPlanSSD = &Resource{ID: int64(DiskPlanSSDID)}
)
// ToResource ディスクプランIDからリソースへの変換
func (d DiskPlanID) ToResource() *Resource {
return &Resource{ID: int64(d)}
}
// CreateNewDisk ディスクの作成
func CreateNewDisk() *Disk {
return &Disk{
propPlanID: propPlanID{Plan: DiskPlanSSD},
propDiskConnection: propDiskConnection{Connection: DiskConnectionVirtio},
propSizeMB: propSizeMB{SizeMB: 20480},
}
}
// SetDiskPlan プラン文字列(ssd or sdd)からプラン設定
func (d *Disk) SetDiskPlan(strPlan string) {
switch strPlan {
case "ssd":
d.Plan = DiskPlanSSD
case "hdd":
d.Plan = DiskPlanHDD
default:
panic(fmt.Errorf("Invalid plan:%s", strPlan))
}
}
// SetDiskPlanToHDD HDDプラン 設定
func (d *Disk) SetDiskPlanToHDD() {
d.Plan = DiskPlanHDD
}
// SetDiskPlanToSSD SSDプラン 設定
func (d *Disk) SetDiskPlanToSSD() {
d.Plan = DiskPlanSSD
}
// DiskEditValue ディスクの修正用パラメータ
//
// 設定を行う項目のみ値をセットする。値のセットにはセッターを利用すること。
type DiskEditValue struct {
Password *string `json:",omitempty"` // パスワード
SSHKey *SSHKey `json:",omitempty"` // 公開鍵(単体)
SSHKeys []*SSHKey `json:",omitempty"` // 公開鍵(複数)
DisablePWAuth *bool `json:",omitempty"` // パスワード認証無効化フラグ
HostName *string `json:",omitempty"` // ホスト名
Notes []*Resource `json:",omitempty"` // スタートアップスクリプト
UserIPAddress *string `json:",omitempty"` // IPアドレス
UserSubnet *struct { // サブネット情報
DefaultRoute string `json:",omitempty"` // デフォルトルート
NetworkMaskLen string `json:",omitempty"` // ネットワークマスク長
} `json:",omitempty"`
}
// SetHostName ホスト名 設定
func (d *DiskEditValue) SetHostName(value string) {
d.HostName = &value
}
// SetPassword パスワード 設定
func (d *DiskEditValue) SetPassword(value string) {
d.Password = &value
}
// AddSSHKeys 公開鍵 設定
func (d *DiskEditValue) AddSSHKeys(keyID string) {
if d.SSHKeys == nil {
d.SSHKeys = []*SSHKey{}
}
d.SSHKeys = append(d.SSHKeys, &SSHKey{Resource: NewResourceByStringID(keyID)})
}
// SetSSHKeys 公開鍵 設定
func (d *DiskEditValue) SetSSHKeys(keyIDs []string) {
if d.SSHKeys == nil {
d.SSHKeys = []*SSHKey{}
}
for _, keyID := range keyIDs {
d.SSHKeys = append(d.SSHKeys, &SSHKey{Resource: NewResourceByStringID(keyID)})
}
}
// AddSSHKeyByString 公開鍵(文字列) 追加
func (d *DiskEditValue) AddSSHKeyByString(key string) {
if d.SSHKeys == nil {
d.SSHKeys = []*SSHKey{}
}
d.SSHKeys = append(d.SSHKeys, &SSHKey{PublicKey: key})
}
// SetSSHKeyByString 公開鍵(文字列) 設定
func (d *DiskEditValue) SetSSHKeyByString(keys []string) {
if d.SSHKeys == nil {
d.SSHKeys = []*SSHKey{}
}
for _, key := range keys {
d.SSHKeys = append(d.SSHKeys, &SSHKey{PublicKey: key})
}
}
// SetDisablePWAuth パスワード認証無効化フラグ 設定
func (d *DiskEditValue) SetDisablePWAuth(disable bool) {
d.DisablePWAuth = &disable
}
// SetNotes スタートアップスクリプト 設定
func (d *DiskEditValue) SetNotes(noteIDs []string) {
d.Notes = []*Resource{}
for _, noteID := range noteIDs {
d.Notes = append(d.Notes, NewResourceByStringID(noteID))
}
}
// AddNote スタートアップスクリプト 追加
func (d *DiskEditValue) AddNote(noteID string) {
if d.Notes == nil {
d.Notes = []*Resource{}
}
d.Notes = append(d.Notes, NewResourceByStringID(noteID))
}
// SetUserIPAddress IPアドレス 設定
func (d *DiskEditValue) SetUserIPAddress(ip string) {
d.UserIPAddress = &ip
}
// SetDefaultRoute デフォルトルート 設定
func (d *DiskEditValue) SetDefaultRoute(route string) {
if d.UserSubnet == nil {
d.UserSubnet = &struct {
DefaultRoute string `json:",omitempty"`
NetworkMaskLen string `json:",omitempty"`
}{}
}
d.UserSubnet.DefaultRoute = route
}
// SetNetworkMaskLen ネットワークマスク長 設定
func (d *DiskEditValue) SetNetworkMaskLen(length string) {
if d.UserSubnet == nil {
d.UserSubnet = &struct {
DefaultRoute string `json:",omitempty"`
NetworkMaskLen string `json:",omitempty"`
}{}
}
d.UserSubnet.NetworkMaskLen = length
}

189
vendor/github.com/sacloud/libsacloud/sacloud/dns.go generated vendored Normal file
View file

@ -0,0 +1,189 @@
package sacloud
import (
"fmt"
"strings"
)
// DNS DNS(CommonServiceItem)
type DNS struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
Status DNSStatus `json:",omitempty"` // ステータス
Provider DNSProvider `json:",omitempty"` // プロバイダ
Settings DNSSettings `json:",omitempty"` // 設定
}
// DNSSettings DNS設定リスト
type DNSSettings struct {
DNS DNSRecordSets `json:",omitempty"` // DNSレコード設定リスト
}
// DNSStatus DNSステータス
type DNSStatus struct {
Zone string `json:",omitempty"` // 対象ゾーン
NS []string `json:",omitempty"` // ネームサーバーリスト
}
// DNSProvider プロバイダ
type DNSProvider struct {
Class string `json:",omitempty"` // クラス
}
// CreateNewDNS DNS作成
func CreateNewDNS(zoneName string) *DNS {
return &DNS{
Resource: &Resource{},
propName: propName{Name: zoneName},
Status: DNSStatus{
Zone: zoneName,
},
Provider: DNSProvider{
Class: "dns",
},
Settings: DNSSettings{
DNS: DNSRecordSets{},
},
}
}
// AllowDNSTypes DNSレコード種別リスト
func AllowDNSTypes() []string {
return []string{"A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV"}
}
// SetZone DNSゾーン名 設定
func (d *DNS) SetZone(zone string) {
d.Name = zone
d.Status.Zone = zone
}
// HasDNSRecord DNSレコード設定を保持しているか判定
func (d *DNS) HasDNSRecord() bool {
return len(d.Settings.DNS.ResourceRecordSets) > 0
}
// CreateNewRecord DNSレコード作成(汎用)
func (d *DNS) CreateNewRecord(name string, rtype string, rdata string, ttl int) *DNSRecordSet {
return &DNSRecordSet{
// Name
Name: name,
// Type
Type: rtype,
// RData
RData: rdata,
// TTL
TTL: ttl,
}
}
// CreateNewMXRecord DNSレコード作成(MXレコード)
func (d *DNS) CreateNewMXRecord(name string, rdata string, ttl int, priority int) *DNSRecordSet {
if rdata != "" && !strings.HasSuffix(rdata, ".") {
rdata = rdata + "."
}
return &DNSRecordSet{
// Name
Name: name,
// Type
Type: "MX",
// RData
RData: fmt.Sprintf("%d %s", priority, rdata),
// TTL
TTL: ttl,
}
}
// CreateNewSRVRecord DNSレコード作成(SRVレコード)
func (d *DNS) CreateNewSRVRecord(name string, rdata string, ttl int, priority int, weight int, port int) *DNSRecordSet {
return &DNSRecordSet{
// Name
Name: name,
// Type
Type: "SRV",
// RData
RData: fmt.Sprintf("%d %d %d %s", priority, weight, port, rdata),
// TTL
TTL: ttl,
}
}
// AddRecord レコードの追加
func (d *DNS) AddRecord(record *DNSRecordSet) {
var recordSet = d.Settings.DNS.ResourceRecordSets
var isExist = false
for i := range recordSet {
if recordSet[i].Name == record.Name && recordSet[i].Type == record.Type && recordSet[i].RData == record.RData {
d.Settings.DNS.ResourceRecordSets[i].TTL = record.TTL
isExist = true
}
}
if !isExist {
d.Settings.DNS.ResourceRecordSets = append(d.Settings.DNS.ResourceRecordSets, *record)
}
}
// ClearRecords レコード クリア
func (d *DNS) ClearRecords() {
d.Settings.DNS = DNSRecordSets{}
}
// DNSRecordSets DNSレコード設定リスト
type DNSRecordSets struct {
// ResourceRecordSets DNSレコード設定リスト
ResourceRecordSets []DNSRecordSet
}
// AddDNSRecordSet ホスト名とIPアドレスにてAレコードを登録
func (d *DNSRecordSets) AddDNSRecordSet(name string, ip string) {
var record DNSRecordSet
var isExist = false
for i := range d.ResourceRecordSets {
if d.ResourceRecordSets[i].Name == name && d.ResourceRecordSets[i].Type == "A" {
d.ResourceRecordSets[i].RData = ip
isExist = true
}
}
if !isExist {
record = DNSRecordSet{
// Name
Name: name,
// Type
Type: "A",
// RData
RData: ip,
}
d.ResourceRecordSets = append(d.ResourceRecordSets, record)
}
}
// DeleteDNSRecordSet ホスト名とIPアドレスにてAレコードを削除する
func (d *DNSRecordSets) DeleteDNSRecordSet(name string, ip string) {
res := []DNSRecordSet{}
for i := range d.ResourceRecordSets {
if d.ResourceRecordSets[i].Name != name || d.ResourceRecordSets[i].Type != "A" || d.ResourceRecordSets[i].RData != ip {
res = append(res, d.ResourceRecordSets[i])
}
}
d.ResourceRecordSets = res
}
// DNSRecordSet DNSレコード設定
type DNSRecordSet struct {
Name string `json:",omitempty"` // ホスト名
Type string `json:",omitempty"` // レコードタイプ
RData string `json:",omitempty"` // レコードデータ
TTL int `json:",omitempty"` // TTL
}

3
vendor/github.com/sacloud/libsacloud/sacloud/doc.go generated vendored Normal file
View file

@ -0,0 +1,3 @@
// Package sacloud is define models for SakuraCloud.
//
package sacloud

36
vendor/github.com/sacloud/libsacloud/sacloud/feed.go generated vendored Normal file
View file

@ -0,0 +1,36 @@
package sacloud
import (
"strconv"
"time"
)
// NewsFeed メンテナンス/障害情報お知らせ
type NewsFeed struct {
StrDate string `json:"date,omitempty"`
Description string `json:"desc,omitempty"`
StrEventStart string `json:"event_start,omitempty"`
StrEventEnd string `json:"event_end,omitempty"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
}
// Date 対象日時
func (f *NewsFeed) Date() time.Time {
return f.parseTime(f.StrDate)
}
// EventStart 掲載開始日時
func (f *NewsFeed) EventStart() time.Time {
return f.parseTime(f.StrEventStart)
}
// EventEnd 掲載終了日時
func (f *NewsFeed) EventEnd() time.Time {
return f.parseTime(f.StrEventEnd)
}
func (f *NewsFeed) parseTime(sec string) time.Time {
s, _ := strconv.ParseInt(sec, 10, 64)
return time.Unix(s, 0)
}

View file

@ -0,0 +1,15 @@
package sacloud
// FTPServer FTPサーバー接続情報
type FTPServer struct {
HostName string `json:",omitempty"` // FTPサーバーホスト名
IPAddress string `json:",omitempty"` // FTPサーバー IPアドレス
User string `json:",omitempty"` // 接続ユーザー名
Password string `json:",omitempty"` // パスワード
}
// FTPOpenRequest FTP接続オープンリクエスト
type FTPOpenRequest struct {
ChangePassword bool // パスワード変更フラグ
}

216
vendor/github.com/sacloud/libsacloud/sacloud/gslb.go generated vendored Normal file
View file

@ -0,0 +1,216 @@
package sacloud
import "fmt"
// GSLB GSLB(CommonServiceItem)
type GSLB struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
Status GSLBStatus `json:",omitempty"` // ステータス
Provider GSLBProvider `json:",omitempty"` // プロバイダ
Settings GSLBSettings `json:",omitempty"` // GSLB設定
}
// GSLBSettings GSLB設定
type GSLBSettings struct {
GSLB GSLBRecordSets `json:",omitempty"` // GSLB GSLBエントリー
}
// GSLBStatus GSLBステータス
type GSLBStatus struct {
FQDN string `json:",omitempty"` // GSLBのFQDN
}
// GSLBProvider プロバイダ
type GSLBProvider struct {
Class string `json:",omitempty"` // クラス
}
// CreateNewGSLB GSLB作成
func CreateNewGSLB(gslbName string) *GSLB {
return &GSLB{
Resource: &Resource{},
propName: propName{Name: gslbName},
Provider: GSLBProvider{
Class: "gslb",
},
Settings: GSLBSettings{
GSLB: GSLBRecordSets{
DelayLoop: 10,
HealthCheck: defaultGSLBHealthCheck,
Weighted: "True",
Servers: []GSLBServer{},
},
},
}
}
// AllowGSLBHealthCheckProtocol GSLB監視プロトコルリスト
func AllowGSLBHealthCheckProtocol() []string {
return []string{"http", "https", "ping", "tcp"}
}
// HasGSLBServer GSLB配下にサーバーを保持しているか判定
func (g *GSLB) HasGSLBServer() bool {
return len(g.Settings.GSLB.Servers) > 0
}
// CreateGSLBServer GSLB配下のサーバーを作成
func (g *GSLB) CreateGSLBServer(ip string) *GSLBServer {
return &GSLBServer{
IPAddress: ip,
Enabled: "True",
Weight: "1",
}
}
// AddGSLBServer GSLB配下にサーバーを追加
func (g *GSLB) AddGSLBServer(server *GSLBServer) {
var isExist = false
for i := range g.Settings.GSLB.Servers {
if g.Settings.GSLB.Servers[i].IPAddress == server.IPAddress {
g.Settings.GSLB.Servers[i].Enabled = server.Enabled
g.Settings.GSLB.Servers[i].Weight = server.Weight
isExist = true
}
}
if !isExist {
g.Settings.GSLB.Servers = append(g.Settings.GSLB.Servers, *server)
}
}
// ClearGSLBServer GSLB配下のサーバーをクリア
func (g *GSLB) ClearGSLBServer() {
g.Settings.GSLB.Servers = []GSLBServer{}
}
// GSLBRecordSets GSLBエントリー
type GSLBRecordSets struct {
DelayLoop int `json:",omitempty"` // 監視間隔
HealthCheck GSLBHealthCheck `json:",omitempty"` // ヘルスチェック
Weighted string `json:",omitempty"` // ウェイト
SorryServer string `json:",omitempty"` // ソーリーサーバー
Servers []GSLBServer // サーバー
}
// AddServer GSLB配下のサーバーを追加
func (g *GSLBRecordSets) AddServer(ip string) {
var record GSLBServer
var isExist = false
for i := range g.Servers {
if g.Servers[i].IPAddress == ip {
isExist = true
}
}
if !isExist {
record = GSLBServer{
IPAddress: ip,
Enabled: "True",
Weight: "1",
}
g.Servers = append(g.Servers, record)
}
}
// DeleteServer GSLB配下のサーバーを削除
func (g *GSLBRecordSets) DeleteServer(ip string) {
res := []GSLBServer{}
for i := range g.Servers {
if g.Servers[i].IPAddress != ip {
res = append(res, g.Servers[i])
}
}
g.Servers = res
}
// GSLBServer GSLB配下のサーバー
type GSLBServer struct {
IPAddress string `json:",omitempty"` // IPアドレス
Enabled string `json:",omitempty"` // 有効/無効
Weight string `json:",omitempty"` // ウェイト
}
// GSLBHealthCheck ヘルスチェック
type GSLBHealthCheck struct {
Protocol string `json:",omitempty"` // プロトコル
Host string `json:",omitempty"` // 対象ホスト
Path string `json:",omitempty"` // HTTP/HTTPSの場合のリクエストパス
Status string `json:",omitempty"` // 期待するステータスコード
Port string `json:",omitempty"` // ポート番号
}
var defaultGSLBHealthCheck = GSLBHealthCheck{
Protocol: "http",
Host: "",
Path: "/",
Status: "200",
}
// SetHTTPHealthCheck HTTPヘルスチェック 設定
func (g *GSLB) SetHTTPHealthCheck(hostHeader string, path string, responseCode int) {
g.Settings.GSLB.HealthCheck.Protocol = "http"
g.Settings.GSLB.HealthCheck.Host = hostHeader
g.Settings.GSLB.HealthCheck.Path = path
g.Settings.GSLB.HealthCheck.Status = fmt.Sprintf("%d", responseCode)
g.Settings.GSLB.HealthCheck.Port = ""
}
// SetHTTPSHealthCheck HTTPSヘルスチェック 設定
func (g *GSLB) SetHTTPSHealthCheck(hostHeader string, path string, responseCode int) {
g.Settings.GSLB.HealthCheck.Protocol = "https"
g.Settings.GSLB.HealthCheck.Host = hostHeader
g.Settings.GSLB.HealthCheck.Path = path
g.Settings.GSLB.HealthCheck.Status = fmt.Sprintf("%d", responseCode)
g.Settings.GSLB.HealthCheck.Port = ""
}
// SetPingHealthCheck Pingヘルスチェック 設定
func (g *GSLB) SetPingHealthCheck() {
g.Settings.GSLB.HealthCheck.Protocol = "ping"
g.Settings.GSLB.HealthCheck.Host = ""
g.Settings.GSLB.HealthCheck.Path = ""
g.Settings.GSLB.HealthCheck.Status = ""
g.Settings.GSLB.HealthCheck.Port = ""
}
// SetTCPHealthCheck TCPヘルスチェック 設定
func (g *GSLB) SetTCPHealthCheck(port int) {
g.Settings.GSLB.HealthCheck.Protocol = "tcp"
g.Settings.GSLB.HealthCheck.Host = ""
g.Settings.GSLB.HealthCheck.Path = ""
g.Settings.GSLB.HealthCheck.Status = ""
g.Settings.GSLB.HealthCheck.Port = fmt.Sprintf("%d", port)
}
// SetDelayLoop 監視間隔秒数 設定
func (g *GSLB) SetDelayLoop(delayLoop int) {
g.Settings.GSLB.DelayLoop = delayLoop
}
// SetWeightedEnable 重み付け応答 有効/無効 設定
func (g *GSLB) SetWeightedEnable(enable bool) {
v := "True"
if !enable {
v = "False"
}
g.Settings.GSLB.Weighted = v
}
// SetSorryServer ソーリーサーバ 設定
func (g *GSLB) SetSorryServer(server string) {
g.Settings.GSLB.SorryServer = server
}

6
vendor/github.com/sacloud/libsacloud/sacloud/host.go generated vendored Normal file
View file

@ -0,0 +1,6 @@
package sacloud
// Host さくらのクラウド ホスト(物理)
type Host struct {
propName // 名称
}

33
vendor/github.com/sacloud/libsacloud/sacloud/icon.go generated vendored Normal file
View file

@ -0,0 +1,33 @@
package sacloud
// Icon アイコン
type Icon struct {
*Resource // ID
propAvailability // 有功状態
propName // 名称
propScope // スコープ
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
URL string `json:",omitempty"` // アイコンURL
Image string `json:",omitempty"` // 画像データBase64文字列(Sizeパラメータ指定時 or 画像アップロード時に利用)
}
// Image 画像データBASE64文字列
type Image string
// GetURL アイコン画像URL取得
func (icon *Icon) GetURL() string {
return icon.URL
}
// GetImage アイコン画像データ(base64)取得
func (icon *Icon) GetImage() string {
return icon.Image
}
// SetImage アイコン画像データ(base64)設定
func (icon *Icon) SetImage(image string) {
icon.Image = image
}

View file

@ -0,0 +1,35 @@
package sacloud
import "time"
// Instance インスタンス
type Instance struct {
*EServerInstanceStatus // ステータス
Server Resource `json:",omitempty"` // サーバー
StatusChangedAt *time.Time `json:",omitempty"` // ステータス変更日時
MigrationProgress string `json:",omitempty"` // コピージョブ進捗状態
MigrationSchedule string `json:",omitempty"` // コピージョブスケジュール
IsMigrating bool `json:",omitempty"` // コピージョブ実施中フラグ
MigrationAllowed string `json:",omitempty"` // コピージョブ許可
ModifiedAt *time.Time `json:",omitempty"` // 変更日時
CDROM *CDROM `json:",omitempty"` // ISOイメージ
CDROMStorage *Storage `json:",omitempty"` // ISOイメージストレージ
Host struct { // Host
Name string `json:",omitempty"` // ホスト名
InfoURL string `json:",omitempty"` // インフォURL
Class string `json:",omitempty"` // クラス
Version int `json:",omitempty"` // バージョン
SystemVersion string `json:",omitempty"` // システムバージョン
} `json:",omitempty"`
}
// HasInfoURL Host.InfoURLに値があるか
func (i *Instance) HasInfoURL() bool {
return i != nil && i.Host.InfoURL != ""
}
// MaintenanceScheduled メンテナンス予定の有無
func (i *Instance) MaintenanceScheduled() bool {
return i.HasInfoURL()
}

View file

@ -0,0 +1,43 @@
package sacloud
// Interface インターフェース(NIC)
type Interface struct {
*Resource // ID
propServer // サーバー
propSwitch // スイッチ
MACAddress string `json:",omitempty"` // MACアドレス
IPAddress string `json:",omitempty"` // IPアドレス
UserIPAddress string `json:",omitempty"` // ユーザー指定IPアドレス
HostName string `json:",omitempty"` // ホスト名
PacketFilter *PacketFilter `json:",omitempty"` // 適用パケットフィルタ
}
// GetMACAddress MACアドレス 取得
func (i *Interface) GetMACAddress() string {
return i.MACAddress
}
//GetIPAddress IPアドレス 取得
func (i *Interface) GetIPAddress() string {
return i.IPAddress
}
// SetUserIPAddress ユーザー指定IPアドレス 設定
func (i *Interface) SetUserIPAddress(ip string) {
i.UserIPAddress = ip
}
//GetUserIPAddress ユーザー指定IPアドレス 取得
func (i *Interface) GetUserIPAddress() string {
return i.UserIPAddress
}
// GetHostName ホスト名 取得
func (i *Interface) GetHostName() string {
return i.HostName
}
// GetPacketFilter 適用パケットフィルタ 取得
func (i *Interface) GetPacketFilter() *PacketFilter {
return i.PacketFilter
}

View file

@ -0,0 +1,50 @@
package sacloud
// Internet ルーター
type Internet struct {
*Resource // ID
propName // 名称
propDescription // 説明
propScope // スコープ
propServiceClass // サービスクラス
propSwitch // 接続先スイッチ
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
BandWidthMbps int `json:",omitempty"` // 帯域
NetworkMaskLen int `json:",omitempty"` // ネットワークマスク長
//TODO Zone(API側起因のデータ型不一致のため)
// ZoneType
}
// GetBandWidthMbps 帯域幅 取得
func (i *Internet) GetBandWidthMbps() int {
return i.BandWidthMbps
}
// SetBandWidthMbps 帯域幅 設定
func (i *Internet) SetBandWidthMbps(v int) {
i.BandWidthMbps = v
}
// GetNetworkMaskLen ネットワークマスク長 取得
func (i *Internet) GetNetworkMaskLen() int {
return i.NetworkMaskLen
}
// SetNetworkMaskLen ネットワークマスク長 設定
func (i *Internet) SetNetworkMaskLen(v int) {
i.NetworkMaskLen = v
}
// AllowInternetBandWidth 設定可能な帯域幅の値リスト
func AllowInternetBandWidth() []int {
return []int{100, 250, 500, 1000, 1500, 2000, 2500, 3000}
}
// AllowInternetNetworkMaskLen 設定可能なネットワークマスク長の値リスト
func AllowInternetNetworkMaskLen() []int {
return []int{26, 27, 28}
}

View file

@ -0,0 +1,10 @@
package sacloud
// IPAddress IPアドレス(IPv4)
type IPAddress struct {
HostName string `json:",omitempty"` // HostName ホスト名
IPAddress string `json:",omitempty"` // IPAddress IPv4アドレス
Interface *Interface `json:",omitempty"` // Interface インターフェース
Subnet *Subnet `json:",omitempty"` // Subnet IPv4サブネット
}

View file

@ -0,0 +1,35 @@
package sacloud
// IPv6Addr IPアドレス(IPv6)
type IPv6Addr struct {
HostName string `json:",omitempty"` // ホスト名
IPv6Addr string `json:",omitempty"` // IPv6アドレス
Interface *Interface `json:",omitempty"` // インターフェース
IPv6Net *IPv6Net `json:",omitempty"` // IPv6サブネット
}
// GetIPv6NetID IPv6アドレスが所属するIPv6NetのIDを取得
func (a *IPv6Addr) GetIPv6NetID() int64 {
if a.IPv6Net != nil {
return a.IPv6Net.ID
}
return 0
}
// GetInternetID IPv6アドレスを所有するルータ+スイッチ(Internet)のIDを取得
func (a *IPv6Addr) GetInternetID() int64 {
if a.IPv6Net != nil && a.IPv6Net.Switch != nil && a.IPv6Net.Switch.Internet != nil {
return a.IPv6Net.Switch.Internet.ID
}
return 0
}
// CreateNewIPv6Addr IPv6アドレス作成
func CreateNewIPv6Addr() *IPv6Addr {
return &IPv6Addr{
IPv6Net: &IPv6Net{
Resource: &Resource{},
},
}
}

View file

@ -0,0 +1,18 @@
package sacloud
// IPv6Net IPv6ネットワーク(サブネット)
type IPv6Net struct {
*Resource // ID
propScope // スコープ
propServiceClass // サービスクラス
propCreatedAt // 作成日時
IPv6Prefix string `json:",omitempty"` // IPv6プレフィックス
IPv6PrefixLen int `json:",omitempty"` // IPv6プレフィックス長
IPv6PrefixTail string `json:",omitempty"` // IPv6プレフィックス末尾
IPv6Table *Resource `json:",omitempty"` // IPv6テーブル
NamedIPv6AddrCount int `json:",omitempty"` // 名前付きIPv6アドレス数
ServiceID int64 `json:",omitempty"` // サービスID
Switch *Switch `json:",omitempty"` // 接続先スイッチ
}

View file

@ -0,0 +1,27 @@
package sacloud
// License ライセンス
type License struct {
*Resource // ID
propName // 名称
propDescription // 説明
propCreatedAt // 作成日時
propModifiedAt // 変更日時
LicenseInfo *ProductLicense `json:",omitempty"` // ライセンス情報
}
// GetLicenseInfo ライセンス情報 取得
func (l *License) GetLicenseInfo() *ProductLicense {
return l.LicenseInfo
}
// SetLicenseInfo ライセンス情報 設定
func (l *License) SetLicenseInfo(license *ProductLicense) {
l.LicenseInfo = license
}
// SetLicenseInfoByID ライセンス情報 設定
func (l *License) SetLicenseInfoByID(id int64) {
l.LicenseInfo = &ProductLicense{Resource: NewResource(id)}
}

View file

@ -0,0 +1,181 @@
package sacloud
// LoadBalancer ロードバランサー
type LoadBalancer struct {
*Appliance // アプライアンス共通属性
Remark *LoadBalancerRemark `json:",omitempty"` // リマーク
Settings *LoadBalancerSettings `json:",omitempty"` // ロードバランサー設定
}
// LoadBalancerRemark リマーク
type LoadBalancerRemark struct {
*ApplianceRemarkBase
// TODO Zone
//Zone *Resource
}
// LoadBalancerSettings ロードバランサー設定リスト
type LoadBalancerSettings struct {
LoadBalancer []*LoadBalancerSetting `json:",omitempty"` // ロードバランサー設定リスト
}
// LoadBalancerSetting ロードバランサー仮想IP設定
type LoadBalancerSetting struct {
VirtualIPAddress string `json:",omitempty"` // 仮想IPアドレス
Port string `json:",omitempty"` // ポート番号
DelayLoop string `json:",omitempty"` // 監視間隔
SorryServer string `json:",omitempty"` // ソーリーサーバー
Servers []*LoadBalancerServer `json:",omitempty"` // 仮想IP配下の実サーバー
}
// LoadBalancerServer 仮想IP設定配下のサーバー
type LoadBalancerServer struct {
IPAddress string `json:",omitempty"` // IPアドレス
Port string `json:",omitempty"` // ポート番号
HealthCheck *LoadBalancerHealthCheck `json:",omitempty"` // ヘルスチェック
Enabled string `json:",omitempty"` // 有効/無効
Status string `json:",omitempty"` // ステータス
ActiveConn string `json:",omitempty"` // アクティブなコネクション
}
// LoadBalancerHealthCheck ヘルスチェック
type LoadBalancerHealthCheck struct {
Protocol string `json:",omitempty"` // プロトコル
Path string `json:",omitempty"` // HTTP/HTTPSの場合のリクエストパス
Status string `json:",omitempty"` // HTTP/HTTPSの場合の期待するレスポンスコード
}
// LoadBalancerPlan ロードバランサープラン
type LoadBalancerPlan int
var (
// LoadBalancerPlanStandard スタンダードプラン
LoadBalancerPlanStandard = LoadBalancerPlan(1)
// LoadBalancerPlanPremium プレミアムプラン
LoadBalancerPlanPremium = LoadBalancerPlan(2)
)
// CreateLoadBalancerValue ロードバランサー作成用パラメーター
type CreateLoadBalancerValue struct {
SwitchID string // 接続先スイッチID
VRID int // VRID
Plan LoadBalancerPlan // プラン
IPAddress1 string // IPアドレス
MaskLen int // ネットワークマスク長
DefaultRoute string // デフォルトルート
Name string // 名称
Description string // 説明
Tags []string // タグ
Icon *Resource // アイコン
}
// CreateDoubleLoadBalancerValue ロードバランサー(冗長化あり)作成用パラメーター
type CreateDoubleLoadBalancerValue struct {
*CreateLoadBalancerValue
IPAddress2 string // IPアドレス2
}
// AllowLoadBalancerHealthCheckProtocol ロードバランサーでのヘルスチェック対応プロトコルリスト
func AllowLoadBalancerHealthCheckProtocol() []string {
return []string{"http", "https", "ping", "tcp"}
}
// CreateNewLoadBalancerSingle ロードバランサー作成(冗長化なし)
func CreateNewLoadBalancerSingle(values *CreateLoadBalancerValue, settings []*LoadBalancerSetting) (*LoadBalancer, error) {
lb := &LoadBalancer{
Appliance: &Appliance{
Class: "loadbalancer",
propName: propName{Name: values.Name},
propDescription: propDescription{Description: values.Description},
propTags: propTags{Tags: values.Tags},
propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
propIcon: propIcon{
&Icon{
Resource: values.Icon,
},
},
},
Remark: &LoadBalancerRemark{
ApplianceRemarkBase: &ApplianceRemarkBase{
Switch: &ApplianceRemarkSwitch{
ID: values.SwitchID,
},
VRRP: &ApplianceRemarkVRRP{
VRID: values.VRID,
},
Network: &ApplianceRemarkNetwork{
NetworkMaskLen: values.MaskLen,
DefaultRoute: values.DefaultRoute,
},
Servers: []interface{}{
map[string]string{"IPAddress": values.IPAddress1},
},
},
},
}
for _, s := range settings {
lb.AddLoadBalancerSetting(s)
}
return lb, nil
}
// CreateNewLoadBalancerDouble ロードバランサー(冗長化あり)作成
func CreateNewLoadBalancerDouble(values *CreateDoubleLoadBalancerValue, settings []*LoadBalancerSetting) (*LoadBalancer, error) {
lb, err := CreateNewLoadBalancerSingle(values.CreateLoadBalancerValue, settings)
if err != nil {
return nil, err
}
lb.Remark.Servers = append(lb.Remark.Servers, map[string]string{"IPAddress": values.IPAddress2})
return lb, nil
}
// AddLoadBalancerSetting ロードバランサー仮想IP設定追加
//
// ロードバランサー設定は仮想IPアドレス単位で保持しています。
// 仮想IPを増やす場合にこのメソッドを利用します。
func (l *LoadBalancer) AddLoadBalancerSetting(setting *LoadBalancerSetting) {
if l.Settings == nil {
l.Settings = &LoadBalancerSettings{}
}
if l.Settings.LoadBalancer == nil {
l.Settings.LoadBalancer = []*LoadBalancerSetting{}
}
l.Settings.LoadBalancer = append(l.Settings.LoadBalancer, setting)
}
// DeleteLoadBalancerSetting ロードバランサー仮想IP設定の削除
func (l *LoadBalancer) DeleteLoadBalancerSetting(vip string, port string) {
res := []*LoadBalancerSetting{}
for _, l := range l.Settings.LoadBalancer {
if l.VirtualIPAddress != vip || l.Port != port {
res = append(res, l)
}
}
l.Settings.LoadBalancer = res
}
// AddServer 仮想IP設定配下へ実サーバーを追加
func (s *LoadBalancerSetting) AddServer(server *LoadBalancerServer) {
if s.Servers == nil {
s.Servers = []*LoadBalancerServer{}
}
s.Servers = append(s.Servers, server)
}
// DeleteServer 仮想IP設定配下の実サーバーを削除
func (s *LoadBalancerSetting) DeleteServer(ip string, port string) {
res := []*LoadBalancerServer{}
for _, server := range s.Servers {
if server.IPAddress != ip || server.Port != port {
res = append(res, server)
}
}
s.Servers = res
}

View file

@ -0,0 +1,9 @@
package sacloud
// Member 会員情報
type Member struct {
Class string `json:",omitempty"` // クラス
Code string `json:",omitempty"` // 会員コード
// Errors [unknown type] `json:",omitempty"`
}

View file

@ -0,0 +1,209 @@
package sacloud
import (
"encoding/json"
"fmt"
"strings"
)
// MobileGateway モバイルゲートウェイ
type MobileGateway struct {
*Appliance // アプライアンス共通属性
Remark *MobileGatewayRemark `json:",omitempty"` // リマーク
Settings *MobileGatewaySettings `json:",omitempty"` // モバイルゲートウェイ設定
}
// MobileGatewayRemark リマーク
type MobileGatewayRemark struct {
*ApplianceRemarkBase
// TODO Zone
//Zone *Resource
}
// MobileGatewaySettings モバイルゲートウェイ設定
type MobileGatewaySettings struct {
MobileGateway *MobileGatewaySetting `json:",omitempty"` // モバイルゲートウェイ設定リスト
}
// MobileGatewaySetting モバイルゲートウェイ設定
type MobileGatewaySetting struct {
InternetConnection *MGWInternetConnection `json:",omitempty"` // インターネット接続
Interfaces []*MGWInterface `json:",omitempty"` // インターフェース
StaticRoutes []*MGWStaticRoute `json:",omitempty"` // スタティックルート
}
// MGWInternetConnection インターネット接続
type MGWInternetConnection struct {
Enabled string `json:",omitempty"`
}
// MGWInterface インターフェース
type MGWInterface struct {
IPAddress []string `json:",omitempty"`
NetworkMaskLen int `json:",omitempty"`
}
// MGWStaticRoute スタティックルート
type MGWStaticRoute struct {
Prefix string `json:",omitempty"`
NextHop string `json:",omitempty"`
}
// MobileGatewayPlan モバイルゲートウェイプラン
type MobileGatewayPlan int
var (
// MobileGatewayPlanStandard スタンダードプラン // TODO 正式名称不明なため暫定の名前
MobileGatewayPlanStandard = MobileGatewayPlan(1)
)
// CreateMobileGatewayValue モバイルゲートウェイ作成用パラメーター
type CreateMobileGatewayValue struct {
Name string // 名称
Description string // 説明
Tags []string // タグ
IconID int64 // アイコン
}
// CreateNewMobileGateway モバイルゲートウェイ作成
func CreateNewMobileGateway(values *CreateMobileGatewayValue, setting *MobileGatewaySetting) (*MobileGateway, error) {
lb := &MobileGateway{
Appliance: &Appliance{
Class: "mobilegateway",
propName: propName{Name: values.Name},
propDescription: propDescription{Description: values.Description},
propTags: propTags{Tags: values.Tags},
propPlanID: propPlanID{Plan: &Resource{ID: int64(MobileGatewayPlanStandard)}},
propIcon: propIcon{
&Icon{
Resource: NewResource(values.IconID),
},
},
},
Remark: &MobileGatewayRemark{
ApplianceRemarkBase: &ApplianceRemarkBase{
Switch: &ApplianceRemarkSwitch{
propScope: propScope{
Scope: "shared",
},
},
Servers: []interface{}{
nil,
},
},
},
Settings: &MobileGatewaySettings{
MobileGateway: setting,
},
}
return lb, nil
}
// SetPrivateInterface プライベート側NICの接続
func (m *MobileGateway) SetPrivateInterface(ip string, nwMaskLen int) {
if len(m.Settings.MobileGateway.Interfaces) > 1 {
m.Settings.MobileGateway.Interfaces[1].IPAddress = []string{ip}
m.Settings.MobileGateway.Interfaces[1].NetworkMaskLen = nwMaskLen
} else {
nic := &MGWInterface{
IPAddress: []string{ip},
NetworkMaskLen: nwMaskLen,
}
m.Settings.MobileGateway.Interfaces = append(m.Settings.MobileGateway.Interfaces, nic)
}
}
// ClearPrivateInterface プライベート側NICの切断
func (m *MobileGateway) ClearPrivateInterface() {
m.Settings.MobileGateway.Interfaces = []*MGWInterface{nil}
}
// NewMobileGatewayResolver DNS登録用パラメータ作成
func NewMobileGatewayResolver(dns1, dns2 string) *MobileGatewayResolver {
return &MobileGatewayResolver{
SimGroup: &MobileGatewaySIMGroup{
DNS1: dns1,
DNS2: dns2,
},
}
}
// MobileGatewayResolver DNS登録用パラメータ
type MobileGatewayResolver struct {
SimGroup *MobileGatewaySIMGroup `json:"sim_group,omitempty"`
}
// UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
func (m *MobileGatewaySIMGroup) UnmarshalJSON(data []byte) error {
targetData := strings.Replace(strings.Replace(string(data), " ", "", -1), "\n", "", -1)
if targetData == `[]` {
return nil
}
tmp := &struct {
DNS1 string `json:"dns_1,omitempty"`
DNS2 string `json:"dns_2,omitempty"`
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
m.DNS1 = tmp.DNS1
m.DNS2 = tmp.DNS2
return nil
}
// MobileGatewaySIMGroup DNS登録用SIMグループ値
type MobileGatewaySIMGroup struct {
DNS1 string `json:"dns_1,omitempty"`
DNS2 string `json:"dns_2,omitempty"`
}
// MobileGatewaySIMRoute SIルート
type MobileGatewaySIMRoute struct {
ICCID string `json:"iccid,omitempty"`
Prefix string `json:"prefix,omitempty"`
ResourceID string `json:"resource_id,omitempty"`
}
// MobileGatewaySIMRoutes SIMルート一覧
type MobileGatewaySIMRoutes struct {
SIMRoutes []*MobileGatewaySIMRoute `json:"sim_routes"`
}
// AddSIMRoute SIMルート追加
func (m *MobileGatewaySIMRoutes) AddSIMRoute(simID int64, prefix string) bool {
var exists bool
for _, route := range m.SIMRoutes {
if route.ResourceID == fmt.Sprintf("%d", simID) && route.Prefix == prefix {
exists = true
break
}
}
if !exists {
m.SIMRoutes = append(m.SIMRoutes, &MobileGatewaySIMRoute{
ResourceID: fmt.Sprintf("%d", simID),
Prefix: prefix,
})
}
return !exists
}
// DeleteSIMRoute SIMルート削除
func (m *MobileGatewaySIMRoutes) DeleteSIMRoute(simID int64, prefix string) bool {
routes := []*MobileGatewaySIMRoute{} // nolint (JSONヘのMarshal時に要素が0の場合にNULLではなく[]とするため)
var exists bool
for _, route := range m.SIMRoutes {
if route.ResourceID == fmt.Sprintf("%d", simID) && route.Prefix == prefix {
exists = true
} else {
routes = append(routes, route)
}
}
m.SIMRoutes = routes
return exists
}

305
vendor/github.com/sacloud/libsacloud/sacloud/monitor.go generated vendored Normal file
View file

@ -0,0 +1,305 @@
package sacloud
import (
"encoding/json"
"math"
"strings"
"time"
)
// MonitorValue アクティビティモニター
type MonitorValue struct {
CPUTime *float64 `json:"CPU-TIME,omitempty"` // CPU時間
Write *float64 `json:",omitempty"` // ディスク書き込み
Read *float64 `json:",omitempty"` // ディスク読み取り
Receive *float64 `json:",omitempty"` // パケット受信
Send *float64 `json:",omitempty"` // パケット送信
In *float64 `json:",omitempty"` // パケット受信
Out *float64 `json:",omitempty"` // パケット送信
TotalMemorySize *float64 `json:"Total-Memory-Size,omitempty"` // 総メモリサイズ
UsedMemorySize *float64 `json:"Used-Memory-Size,omitempty"` // 使用済みメモリサイズ
TotalDisk1Size *float64 `json:"Total-Disk1-Size,omitempty"` // 総ディスクサイズ
UsedDisk1Size *float64 `json:"Used-Disk1-Size,omitempty"` // 使用済みディスクサイズ
TotalDisk2Size *float64 `json:"Total-Disk2-Size,omitempty"` // 総ディスクサイズ
UsedDisk2Size *float64 `json:"Used-Disk2-Size,omitempty"` // 使用済みディスクサイズ
FreeDiskSize *float64 `json:"Free-Disk-Size,omitempty"` // 空きディスクサイズ(NFS)
ResponseTimeSec *float64 `json:"responsetimesec,omitempty"` // レスポンスタイム(シンプル監視)
UplinkBPS *float64 `json:"UplinkBps,omitempty"` // 上り方向トラフィック
DownlinkBPS *float64 `json:"DownlinkBps"` // 下り方向トラフィック
}
// UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
func (m *MonitorValue) UnmarshalJSON(data []byte) error {
targetData := strings.Replace(strings.Replace(string(data), " ", "", -1), "\n", "", -1)
if targetData == `[]` {
return nil
}
tmp := &struct {
CPUTime *float64 `json:"CPU-TIME,omitempty"`
Write *float64 `json:",omitempty"`
Read *float64 `json:",omitempty"`
Receive *float64 `json:",omitempty"`
Send *float64 `json:",omitempty"`
In *float64 `json:",omitempty"`
Out *float64 `json:",omitempty"`
TotalMemorySize *float64 `json:"Total-Memory-Size,omitempty"`
UsedMemorySize *float64 `json:"Used-Memory-Size,omitempty"`
TotalDisk1Size *float64 `json:"Total-Disk1-Size,omitempty"`
UsedDisk1Size *float64 `json:"Used-Disk1-Size,omitempty"`
TotalDisk2Size *float64 `json:"Total-Disk2-Size,omitempty"`
UsedDisk2Size *float64 `json:"Used-Disk2-Size,omitempty"`
FreeDiskSize *float64 `json:"Free-Disk-Size,omitempty"`
ResponseTimeSec *float64 `json:"responsetimesec,omitempty"`
UplinkBPS *float64 `json:"UplinkBps,omitempty"`
DownlinkBPS *float64 `json:"DownlinkBps"`
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
m.CPUTime = tmp.CPUTime
m.Write = tmp.Write
m.Read = tmp.Read
m.Receive = tmp.Receive
m.Send = tmp.Send
m.In = tmp.In
m.Out = tmp.Out
m.TotalMemorySize = tmp.TotalMemorySize
m.UsedMemorySize = tmp.UsedMemorySize
m.TotalDisk1Size = tmp.TotalDisk1Size
m.UsedDisk1Size = tmp.UsedDisk1Size
m.TotalDisk2Size = tmp.TotalDisk2Size
m.UsedDisk2Size = tmp.UsedDisk2Size
m.FreeDiskSize = tmp.FreeDiskSize
m.ResponseTimeSec = tmp.ResponseTimeSec
m.UplinkBPS = tmp.UplinkBPS
m.DownlinkBPS = tmp.DownlinkBPS
return nil
}
// ResourceMonitorRequest アクティビティモニター取得リクエスト
type ResourceMonitorRequest struct {
Start *time.Time `json:",omitempty"` // 取得開始時間
End *time.Time `json:",omitempty"` // 取得終了時間
}
// NewResourceMonitorRequest アクティビティモニター取得リクエスト作成
func NewResourceMonitorRequest(start *time.Time, end *time.Time) *ResourceMonitorRequest {
res := &ResourceMonitorRequest{}
if start != nil {
t := start.Truncate(time.Second)
res.Start = &t
}
if end != nil {
t := end.Truncate(time.Second)
res.End = &t
}
return res
}
// ResourceMonitorResponse アクティビティモニターレスポンス
type ResourceMonitorResponse struct {
Data *MonitorValues `json:",omitempty"` // メトリクス
}
// MonitorSummaryData メトリクスサマリー
type MonitorSummaryData struct {
Max float64 // 最大値
Min float64 // 最小値
Avg float64 // 平均値
Count float64 // データ個数
}
// MonitorSummary アクティビティーモニター サマリー
type MonitorSummary struct {
CPU *MonitorSummaryData // CPU時間サマリー
Disk *struct { // ディスク利用サマリー
Write *MonitorSummaryData // ディスク書き込みサマリー
Read *MonitorSummaryData // ディスク読み取りサマリー
}
Interface *struct { // NIC送受信サマリー
Receive *MonitorSummaryData // 受信パケットサマリー
Send *MonitorSummaryData // 送信パケットサマリー
}
}
// MonitorValues メトリクス リスト
type MonitorValues map[string]*MonitorValue
// FlatMonitorValue フラット化したメトリクス
type FlatMonitorValue struct {
Time time.Time // 対象時刻
Value float64 // 値
}
// Calc サマリー計算
func (m *MonitorValues) Calc() *MonitorSummary {
res := &MonitorSummary{}
res.CPU = m.calcBy(func(v *MonitorValue) *float64 { return v.CPUTime })
res.Disk = &struct {
Write *MonitorSummaryData
Read *MonitorSummaryData
}{
Write: m.calcBy(func(v *MonitorValue) *float64 { return v.Write }),
Read: m.calcBy(func(v *MonitorValue) *float64 { return v.Read }),
}
res.Interface = &struct {
Receive *MonitorSummaryData
Send *MonitorSummaryData
}{
Receive: m.calcBy(func(v *MonitorValue) *float64 { return v.Receive }),
Send: m.calcBy(func(v *MonitorValue) *float64 { return v.Send }),
}
return res
}
func (m *MonitorValues) calcBy(f func(m *MonitorValue) *float64) *MonitorSummaryData {
res := &MonitorSummaryData{}
var sum float64
for _, data := range map[string]*MonitorValue(*m) {
value := f(data)
if value != nil {
res.Count++
res.Min = math.Min(res.Min, *value)
res.Max = math.Max(res.Max, *value)
sum += *value
}
}
if sum > 0 && res.Count > 0 {
res.Avg = sum / res.Count
}
return res
}
// FlattenCPUTimeValue フラット化 CPU時間
func (m *MonitorValues) FlattenCPUTimeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.CPUTime })
}
// FlattenDiskWriteValue フラット化 ディスク書き込み
func (m *MonitorValues) FlattenDiskWriteValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.Write })
}
// FlattenDiskReadValue フラット化 ディスク読み取り
func (m *MonitorValues) FlattenDiskReadValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.Read })
}
// FlattenPacketSendValue フラット化 パケット送信
func (m *MonitorValues) FlattenPacketSendValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.Send })
}
// FlattenPacketReceiveValue フラット化 パケット受信
func (m *MonitorValues) FlattenPacketReceiveValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.Receive })
}
// FlattenInternetInValue フラット化 パケット受信
func (m *MonitorValues) FlattenInternetInValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.In })
}
// FlattenInternetOutValue フラット化 パケット送信
func (m *MonitorValues) FlattenInternetOutValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.Out })
}
// FlattenTotalMemorySizeValue フラット化 総メモリサイズ
func (m *MonitorValues) FlattenTotalMemorySizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.TotalMemorySize })
}
// FlattenUsedMemorySizeValue フラット化 使用済みメモリサイズ
func (m *MonitorValues) FlattenUsedMemorySizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.UsedMemorySize })
}
// FlattenTotalDisk1SizeValue フラット化 総ディスクサイズ
func (m *MonitorValues) FlattenTotalDisk1SizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.TotalDisk1Size })
}
// FlattenUsedDisk1SizeValue フラット化 使用済みディスクサイズ
func (m *MonitorValues) FlattenUsedDisk1SizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.UsedDisk1Size })
}
// FlattenTotalDisk2SizeValue フラット化 総ディスクサイズ
func (m *MonitorValues) FlattenTotalDisk2SizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.TotalDisk2Size })
}
// FlattenUsedDisk2SizeValue フラット化 使用済みディスクサイズ
func (m *MonitorValues) FlattenUsedDisk2SizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.UsedDisk2Size })
}
// FlattenFreeDiskSizeValue フラット化 空きディスクサイズ(NFS)
func (m *MonitorValues) FlattenFreeDiskSizeValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.FreeDiskSize })
}
// FlattenResponseTimeSecValue フラット化 レスポンスタイム(シンプル監視)
func (m *MonitorValues) FlattenResponseTimeSecValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.ResponseTimeSec })
}
// FlattenUplinkBPSValue フラット化 上り方向トラフィック(セキュアモバイルSIM)
func (m *MonitorValues) FlattenUplinkBPSValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.UplinkBPS })
}
// FlattenDownlinkBPSValue フラット化 下り方向トライフィック(セキュアモバイルSIM)
func (m *MonitorValues) FlattenDownlinkBPSValue() ([]FlatMonitorValue, error) {
return m.flattenValue(func(v *MonitorValue) *float64 { return v.DownlinkBPS })
}
func (m *MonitorValues) flattenValue(f func(*MonitorValue) *float64) ([]FlatMonitorValue, error) {
var res []FlatMonitorValue
for k, v := range map[string]*MonitorValue(*m) {
if f(v) == nil {
continue
}
time, err := time.Parse(time.RFC3339, k) // RFC3339 ≒ ISO8601
if err != nil {
return res, err
}
res = append(res, FlatMonitorValue{
// Time
Time: time,
// Value
Value: *f(v),
})
}
return res, nil
}
// HasValue 取得したアクティビティーモニターに有効値が含まれるか判定
func (m *MonitorValue) HasValue() bool {
values := []*float64{
m.CPUTime,
m.Read, m.Receive,
m.Send, m.Write,
m.In, m.Out,
m.TotalMemorySize, m.UsedMemorySize,
m.TotalDisk1Size, m.UsedDisk1Size,
m.TotalDisk2Size, m.UsedDisk2Size,
m.FreeDiskSize, m.ResponseTimeSec,
m.UplinkBPS, m.DownlinkBPS,
}
for _, v := range values {
if v != nil {
return true
}
}
return false
}

110
vendor/github.com/sacloud/libsacloud/sacloud/nfs.go generated vendored Normal file
View file

@ -0,0 +1,110 @@
package sacloud
// NFS NFS
type NFS struct {
*Appliance // アプライアンス共通属性
Remark *NFSRemark `json:",omitempty"` // リマーク
Settings *NFSSettings `json:",omitempty"` // NFS設定
}
// NFSRemark リマーク
type NFSRemark struct {
*ApplianceRemarkBase
propPlanID
// TODO Zone
//Zone *Resource
//SourceAppliance *Resource // クローン元DB
}
// NFSSettings NFS設定リスト
type NFSSettings struct {
}
// NFSPlan NFSプラン
type NFSPlan int
var (
// NFSPlan100G 100Gプラン
NFSPlan100G = NFSPlan(100)
// NFSPlan500G 500Gプラン
NFSPlan500G = NFSPlan(500)
// NFSPlan1T 1T(1024GB)プラン
NFSPlan1T = NFSPlan(1024 * 1)
// NFSPlan2T 2T(2048GB)プラン
NFSPlan2T = NFSPlan(1024 * 2)
// NFSPlan4T 4T(4096GB)プラン
NFSPlan4T = NFSPlan(1024 * 4)
)
// AllowNFSPlans 指定可能なNFSプラン
func AllowNFSPlans() []int {
return []int{
int(NFSPlan100G),
int(NFSPlan500G),
int(NFSPlan1T),
int(NFSPlan2T),
int(NFSPlan4T),
}
}
// CreateNFSValue NFS作成用パラメーター
type CreateNFSValue struct {
SwitchID string // 接続先スイッチID
Plan NFSPlan // プラン
IPAddress string // IPアドレス
MaskLen int // ネットワークマスク長
DefaultRoute string // デフォルトルート
Name string // 名称
Description string // 説明
Tags []string // タグ
Icon *Resource // アイコン
SourceAppliance *Resource // クローン元NFS
}
// NewCreateNFSValue NFS作成用パラメーター
func NewCreateNFSValue() *CreateNFSValue {
return &CreateNFSValue{
Plan: NFSPlan100G,
}
}
// NewNFS NFS作成(冗長化なし)
func NewNFS(values *CreateNFSValue) *NFS {
if int(values.Plan) == 0 {
values.Plan = NFSPlan100G
}
return &NFS{
Appliance: &Appliance{
Class: "nfs",
propName: propName{Name: values.Name},
propDescription: propDescription{Description: values.Description},
propTags: propTags{Tags: values.Tags},
propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
propIcon: propIcon{
&Icon{
Resource: values.Icon,
},
},
},
Remark: &NFSRemark{
ApplianceRemarkBase: &ApplianceRemarkBase{
Switch: &ApplianceRemarkSwitch{
ID: values.SwitchID,
},
Network: &ApplianceRemarkNetwork{
NetworkMaskLen: values.MaskLen,
DefaultRoute: values.DefaultRoute,
},
Servers: []interface{}{
map[string]string{"IPAddress": values.IPAddress},
},
},
propPlanID: propPlanID{Plan: &Resource{ID: int64(values.Plan)}},
//SourceAppliance: values.SourceAppliance,
},
}
}

16
vendor/github.com/sacloud/libsacloud/sacloud/note.go generated vendored Normal file
View file

@ -0,0 +1,16 @@
package sacloud
// Note スタートアップスクリプト
type Note struct {
*Resource // ID
propName // 名称
propDescription // 説明
propAvailability // 有功状態
propScope // スコープ
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
propNoteClass // クラス
Content string // スクリプト本体
}

View file

@ -0,0 +1,127 @@
// Package ostype is define OS type of SakuraCloud public archive
package ostype
//go:generate stringer -type=ArchiveOSTypes
// ArchiveOSTypes パブリックアーカイブOS種別
type ArchiveOSTypes int
const (
// CentOS OS種別:CentOS
CentOS ArchiveOSTypes = iota
// CentOS6 OS種別:CentOS6
CentOS6
// Ubuntu OS種別:Ubuntu
Ubuntu
// Debian OS種別:Debian
Debian
// VyOS OS種別:VyOS
VyOS
// CoreOS OS種別:CoreOS
CoreOS
// RancherOS OS種別:RancherOS
RancherOS
// Kusanagi OS種別:Kusanagi(CentOS)
Kusanagi
// SophosUTM OS種別:Sophos UTM
SophosUTM
// FreeBSD OS種別:FreeBSD
FreeBSD
// Windows2012 OS種別:Windows Server 2012 R2 Datacenter Edition
Windows2012
// Windows2012RDS OS種別:Windows Server 2012 R2 for RDS
Windows2012RDS
// Windows2012RDSOffice OS種別:Windows Server 2012 R2 for RDS(Office)
Windows2012RDSOffice
// Windows2016 OS種別:Windows Server 2016 Datacenter Edition
Windows2016
// Windows2016RDS OS種別:Windows Server 2016 RDS
Windows2016RDS
// Windows2016RDSOffice OS種別:Windows Server 2016 RDS(Office)
Windows2016RDSOffice
// Windows2016SQLServerWeb OS種別:Windows Server 2016 SQLServer(Web)
Windows2016SQLServerWeb
// Windows2016SQLServerStandard OS種別:Windows Server 2016 SQLServer(Standard)
Windows2016SQLServerStandard
// Windows2016SQLServerStandardAll OS種別:Windows Server 2016 SQLServer(Standard) + RDS + Office
Windows2016SQLServerStandardAll
// Custom OS種別:カスタム
Custom
)
// OSTypeShortNames OSTypeとして利用できる文字列のリスト
var OSTypeShortNames = []string{
"centos", "centos6", "ubuntu", "debian", "vyos", "coreos",
"rancheros", "kusanagi", "sophos-utm", "freebsd",
"windows2012", "windows2012-rds", "windows2012-rds-office",
"windows2016", "windows2016-rds", "windows2016-rds-office",
"windows2016-sql-web", "windows2016-sql-standard", "windows2016-sql-standard-all",
}
// IsWindows Windowsか
func (o ArchiveOSTypes) IsWindows() bool {
switch o {
case Windows2012, Windows2012RDS, Windows2012RDSOffice,
Windows2016, Windows2016RDS, Windows2016RDSOffice,
Windows2016SQLServerWeb, Windows2016SQLServerStandard, Windows2016SQLServerStandardAll:
return true
default:
return false
}
}
// IsSupportDiskEdit ディスクの修正機能をフルサポートしているか(Windowsは一部サポートのためfalseを返す)
func (o ArchiveOSTypes) IsSupportDiskEdit() bool {
switch o {
case CentOS, CentOS6, Ubuntu, Debian, VyOS, CoreOS, RancherOS, Kusanagi, FreeBSD:
return true
default:
return false
}
}
// StrToOSType 文字列からArchiveOSTypesへの変換
func StrToOSType(osType string) ArchiveOSTypes {
switch osType {
case "centos":
return CentOS
case "centos6":
return CentOS6
case "ubuntu":
return Ubuntu
case "debian":
return Debian
case "vyos":
return VyOS
case "coreos":
return CoreOS
case "rancheros":
return RancherOS
case "kusanagi":
return Kusanagi
case "sophos-utm":
return SophosUTM
case "freebsd":
return FreeBSD
case "windows2012":
return Windows2012
case "windows2012-rds":
return Windows2012RDS
case "windows2012-rds-office":
return Windows2012RDSOffice
case "windows2016":
return Windows2016
case "windows2016-rds":
return Windows2016RDS
case "windows2016-rds-office":
return Windows2016RDSOffice
case "windows2016-sql-web":
return Windows2016SQLServerWeb
case "windows2016-sql-standard":
return Windows2016SQLServerStandard
case "windows2016-sql-standard-all":
return Windows2016SQLServerStandardAll
default:
return Custom
}
}

View file

@ -0,0 +1,16 @@
// Code generated by "stringer -type=ArchiveOSTypes"; DO NOT EDIT.
package ostype
import "strconv"
const _ArchiveOSTypes_name = "CentOSCentOS6UbuntuDebianVyOSCoreOSRancherOSKusanagiSophosUTMFreeBSDWindows2012Windows2012RDSWindows2012RDSOfficeWindows2016Windows2016RDSWindows2016RDSOfficeWindows2016SQLServerWebWindows2016SQLServerStandardWindows2016SQLServerStandardAllCustom"
var _ArchiveOSTypes_index = [...]uint8{0, 6, 13, 19, 25, 29, 35, 44, 52, 61, 68, 79, 93, 113, 124, 138, 158, 181, 209, 240, 246}
func (i ArchiveOSTypes) String() string {
if i < 0 || i >= ArchiveOSTypes(len(_ArchiveOSTypes_index)-1) {
return "ArchiveOSTypes(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _ArchiveOSTypes_name[_ArchiveOSTypes_index[i]:_ArchiveOSTypes_index[i+1]]
}

View file

@ -0,0 +1,248 @@
package sacloud
import (
"crypto/md5"
"encoding/hex"
"fmt"
)
// PacketFilter パケットフィルタ
type PacketFilter struct {
*Resource // ID
propName // 名称
propDescription // 説明
Expression []*PacketFilterExpression // ルール
Notice string `json:",omitempty"` // Notice
//HACK API呼び出しルートにより数字/文字列が混在する
// PackerFilterのCREATE時は文字列、以外は数値となる。現状利用しないためコメントとしておく
// RequiredHostVersion int `json:",omitempty"`
}
// AllowPacketFilterProtocol パケットフィルタが対応するプロトコルリスト
func AllowPacketFilterProtocol() []string {
return []string{"tcp", "udp", "icmp", "fragment", "ip"}
}
// PacketFilterExpression フィルタリングルール
type PacketFilterExpression struct {
Protocol string `json:",omitempty"` // Protocol プロトコル
Action string `json:",omitempty"` // Action 許可/拒否
SourceNetwork string // SourceNetwork 送信元ネットワーク
SourcePort string // SourcePort 送信元ポート
DestinationPort string // DestinationPort 宛先ポート
propDescription // 説明
}
// Hash 値からハッシュ値を生成
func (e *PacketFilterExpression) Hash() string {
str := fmt.Sprintf("%v", e)
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
// CreateNewPacketFilter パケットフィルタ作成
func CreateNewPacketFilter() *PacketFilter {
return &PacketFilter{
// Expression
Expression: []*PacketFilterExpression{},
}
}
// ClearRules ルールのクリア
func (p *PacketFilter) ClearRules() {
p.Expression = []*PacketFilterExpression{}
}
// FindByHash 指定のハッシュ値を持つPacketFilterExpressionを検索する
func (p *PacketFilter) FindByHash(hash string) *PacketFilterExpression {
for _, e := range p.Expression {
h := e.Hash()
if h == hash {
return e
}
}
return nil
}
// AddTCPRule TCPルール追加
func (p *PacketFilter) AddTCPRule(sourceNetwork string, sourcePort string, destPort string, description string, isAllow bool) (*PacketFilterExpression, error) {
exp := p.createTCPRule(sourceNetwork, sourcePort, destPort, description, isAllow)
p.Expression = append(p.Expression, exp)
return exp, nil
}
// AddTCPRuleAt TCPルール追加
func (p *PacketFilter) AddTCPRuleAt(sourceNetwork string, sourcePort string, destPort string, description string, isAllow bool, index int) (*PacketFilterExpression, error) {
exp := p.createTCPRule(sourceNetwork, sourcePort, destPort, description, isAllow)
p.addRuleAt(exp, index)
return exp, nil
}
func (p *PacketFilter) createTCPRule(sourceNetwork string, sourcePort string, destPort string, description string, isAllow bool) *PacketFilterExpression {
return &PacketFilterExpression{
Protocol: "tcp",
SourceNetwork: sourceNetwork,
SourcePort: sourcePort,
DestinationPort: destPort,
Action: p.getActionString(isAllow),
propDescription: propDescription{Description: description},
}
}
// AddUDPRule UDPルール追加
func (p *PacketFilter) AddUDPRule(sourceNetwork string, sourcePort string, destPort string, description string, isAllow bool) (*PacketFilterExpression, error) {
exp := p.createUDPRule(sourceNetwork, sourcePort, destPort, description, isAllow)
p.Expression = append(p.Expression, exp)
return exp, nil
}
// AddUDPRuleAt UDPルール追加
func (p *PacketFilter) AddUDPRuleAt(sourceNetwork string, sourcePort string, destPort string, description string, isAllow bool, index int) (*PacketFilterExpression, error) {
exp := p.createUDPRule(sourceNetwork, sourcePort, destPort, description, isAllow)
p.addRuleAt(exp, index)
return exp, nil
}
func (p *PacketFilter) createUDPRule(sourceNetwork string, sourcePort string, destPort string, description string, isAllow bool) *PacketFilterExpression {
return &PacketFilterExpression{
Protocol: "udp",
SourceNetwork: sourceNetwork,
SourcePort: sourcePort,
DestinationPort: destPort,
Action: p.getActionString(isAllow),
propDescription: propDescription{Description: description},
}
}
// AddICMPRule ICMPルール追加
func (p *PacketFilter) AddICMPRule(sourceNetwork string, description string, isAllow bool) (*PacketFilterExpression, error) {
exp := p.createICMPRule(sourceNetwork, description, isAllow)
p.Expression = append(p.Expression, exp)
return exp, nil
}
// AddICMPRuleAt ICMPルール追加
func (p *PacketFilter) AddICMPRuleAt(sourceNetwork string, description string, isAllow bool, index int) (*PacketFilterExpression, error) {
exp := p.createICMPRule(sourceNetwork, description, isAllow)
p.addRuleAt(exp, index)
return exp, nil
}
func (p *PacketFilter) createICMPRule(sourceNetwork string, description string, isAllow bool) *PacketFilterExpression {
return &PacketFilterExpression{
Protocol: "icmp",
SourceNetwork: sourceNetwork,
Action: p.getActionString(isAllow),
propDescription: propDescription{Description: description},
}
}
// AddFragmentRule フラグメントルール追加
func (p *PacketFilter) AddFragmentRule(sourceNetwork string, description string, isAllow bool) (*PacketFilterExpression, error) {
exp := p.createFragmentRule(sourceNetwork, description, isAllow)
p.Expression = append(p.Expression, exp)
return exp, nil
}
// AddFragmentRuleAt フラグメントルール追加
func (p *PacketFilter) AddFragmentRuleAt(sourceNetwork string, description string, isAllow bool, index int) (*PacketFilterExpression, error) {
exp := p.createFragmentRule(sourceNetwork, description, isAllow)
p.addRuleAt(exp, index)
return exp, nil
}
func (p *PacketFilter) createFragmentRule(sourceNetwork string, description string, isAllow bool) *PacketFilterExpression {
return &PacketFilterExpression{
Protocol: "fragment",
SourceNetwork: sourceNetwork,
Action: p.getActionString(isAllow),
propDescription: propDescription{Description: description},
}
}
// AddIPRule IPルール追加
func (p *PacketFilter) AddIPRule(sourceNetwork string, description string, isAllow bool) (*PacketFilterExpression, error) {
exp := p.createIPRule(sourceNetwork, description, isAllow)
p.Expression = append(p.Expression, exp)
return exp, nil
}
// AddIPRuleAt IPルール追加
func (p *PacketFilter) AddIPRuleAt(sourceNetwork string, description string, isAllow bool, index int) (*PacketFilterExpression, error) {
exp := p.createIPRule(sourceNetwork, description, isAllow)
p.addRuleAt(exp, index)
return exp, nil
}
func (p *PacketFilter) createIPRule(sourceNetwork string, description string, isAllow bool) *PacketFilterExpression {
return &PacketFilterExpression{
Protocol: "ip",
SourceNetwork: sourceNetwork,
Action: p.getActionString(isAllow),
propDescription: propDescription{Description: description},
}
}
// RemoveRuleAt 指定インデックス(0開始)位置のルールを除去
func (p *PacketFilter) RemoveRuleAt(index int) {
if index >= 0 && index < len(p.Expression) {
p.Expression = append(p.Expression[:index], p.Expression[index+1:]...)
}
}
// RemoveRuleByHash 指定のハッシュ値を持つルールを削除する
func (p *PacketFilter) RemoveRuleByHash(hash string) {
dest := []*PacketFilterExpression{}
for _, e := range p.Expression {
if hash != e.Hash() {
dest = append(dest, e)
}
}
p.Expression = dest
}
func (p *PacketFilter) addRuleAt(rule *PacketFilterExpression, index int) {
if len(p.Expression) == 0 && index == 0 {
p.Expression = []*PacketFilterExpression{rule}
return
}
if !(index < len(p.Expression)) {
index = len(p.Expression)
}
// Grow the slice by one element.
p.Expression = append(p.Expression, nil)
// Use copy to move the upper part of the slice out of the way and open a hole.
copy(p.Expression[index+1:], p.Expression[index:])
// Store the new value.
p.Expression[index] = rule
}
func (p PacketFilter) getActionString(isAllow bool) string {
action := "deny"
if isAllow {
action = "allow"
}
return action
}

View file

@ -0,0 +1,18 @@
package sacloud
// PrivateHost 専有ホスト
type PrivateHost struct {
*Resource // ID
propName // 名称
propDescription // 説明
propPrivateHostPlan // 専有ホストプラン
propHost // ホスト(物理)
propAssignedCPU // 割当済みCPUコア数
propAssignedMemoryMB // 割当済みメモリ(MB)
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
}

View file

@ -0,0 +1,20 @@
package sacloud
// ProductDisk ディスクプラン
type ProductDisk struct {
*Resource // ID
propName // 名称
propDescription // 説明
propStorageClass // ストレージクラス
propAvailability // 有功状態
Size []struct { // サイズ
propAvailability // 有功状態
propSizeMB // サイズ(MB単位)
propServiceClass // サービスクラス
DisplaySize int `json:",omitempty"` // 表示サイズ
DisplaySuffix string `json:",omitempty"` // 表示サフィックス
} `json:",omitempty"`
}

View file

@ -0,0 +1,12 @@
package sacloud
// ProductInternet ルータープラン
type ProductInternet struct {
*Resource // ID
propName // 名称
propAvailability // 有功状態
propServiceClass // サービスクラス
BandWidthMbps int `json:",omitempty"` // 帯域幅
}

View file

@ -0,0 +1,11 @@
package sacloud
// ProductLicense ライセンスプラン
type ProductLicense struct {
*Resource // ID
propName // 名称
propServiceClass // サービスクラス
propCreatedAt // 作成日時
propModifiedAt // 変更日時
TermsOfUse string `json:",omitempty"` // 利用規約
}

View file

@ -0,0 +1,13 @@
package sacloud
// ProductPrivateHost 専有ホストプラン
type ProductPrivateHost struct {
*Resource // ID
propName // 名称
propDescription // 説明
propAvailability // 有功状態
propCPU // CPUコア数
propMemoryMB // メモリサイズ(MB単位)
propClass // クラス
propServiceClass // サービスクラス
}

View file

@ -0,0 +1,12 @@
package sacloud
// ProductServer サーバープラン
type ProductServer struct {
*Resource // ID
propName // 名称
propDescription // 説明
propAvailability // 有功状態
propCPU // CPUコア数
propMemoryMB // メモリサイズ(MB単位)
propServiceClass // サービスクラス
}

View file

@ -0,0 +1,11 @@
package sacloud
// propAssignedCPU CPUコア数内包型
type propAssignedCPU struct {
AssignedCPU int `json:",omitempty"` // CPUコア数
}
// GetAssignedCPU CPUコア数 取得
func (p *propAssignedCPU) GetAssignedCPU() int {
return p.AssignedCPU
}

View file

@ -0,0 +1,19 @@
package sacloud
// propAssignedMemoryMB サイズ(MB)内包型
type propAssignedMemoryMB struct {
AssignedMemoryMB int `json:",omitempty"` // サイズ(MB単位)
}
// GetAssignedMemoryMB サイズ(MB単位) 取得
func (p *propAssignedMemoryMB) GetAssignedMemoryMB() int {
return p.AssignedMemoryMB
}
// GetAssignedMemoryGB サイズ(GB単位) 取得
func (p *propAssignedMemoryMB) GetAssignedMemoryGB() int {
if p.AssignedMemoryMB <= 0 {
return 0
}
return p.AssignedMemoryMB / 1024
}

View file

@ -0,0 +1,26 @@
package sacloud
// propAvailability 有効状態内包型
type propAvailability struct {
Availability EAvailability `json:",omitempty"` // 有効状態
}
// IsAvailable 有効状態が"有効"か判定
func (p *propAvailability) IsAvailable() bool {
return p.Availability.IsAvailable()
}
// IsUploading 有効状態が"アップロード中"か判定
func (p *propAvailability) IsUploading() bool {
return p.Availability.IsUploading()
}
// IsFailed 有効状態が"失敗"か判定
func (p *propAvailability) IsFailed() bool {
return p.Availability.IsFailed()
}
// IsMigrating 有効状態が"マイグレーション中"か判定
func (p *propAvailability) IsMigrating() bool {
return p.Availability.IsMigrating()
}

View file

@ -0,0 +1,27 @@
package sacloud
import "strings"
// BundleInfo バンドル情報
type BundleInfo struct {
HostClass string `json:",omitempty"`
ServiceClass string `json:",omitempty"`
}
// propBundleInfo バンドル情報内包型
type propBundleInfo struct {
BundleInfo *BundleInfo `json:",omitempty"` // バンドル情報
}
// GetBundleInfo バンドル情報 取得
func (p *propBundleInfo) GetBundleInfo() *BundleInfo {
return p.BundleInfo
}
func (p *propBundleInfo) IsSophosUTM() bool {
// SophosUTMであれば編集不可
if p.BundleInfo != nil && strings.Contains(strings.ToLower(p.BundleInfo.ServiceClass), "sophosutm") {
return true
}
return false
}

View file

@ -0,0 +1,11 @@
package sacloud
// propClass クラス内包型
type propClass struct {
Class string `json:",omitempty"` // サービスクラス
}
// GetClass クラス 取得
func (p *propClass) GetClass() string {
return p.Class
}

View file

@ -0,0 +1,45 @@
package sacloud
// propConnectedSwitches 接続先スイッチ内包型
type propConnectedSwitches struct {
ConnectedSwitches []interface{} `json:",omitempty" libsacloud:"requestOnly"` // サーバー作成時の接続先スイッチ指定用パラメーター
}
// GetConnectedSwitches 接続先スイッチ 取得
func (p *propConnectedSwitches) GetConnectedSwitches() []interface{} {
return p.ConnectedSwitches
}
// SetConnectedSwitches 接続先スイッチ 設定
func (p *propConnectedSwitches) SetConnectedSwitches(switches []interface{}) {
p.ConnectedSwitches = switches
}
// ClearConnectedSwitches 接続先スイッチ指定パラメータークリア
func (p *propConnectedSwitches) ClearConnectedSwitches() {
p.ConnectedSwitches = []interface{}{}
}
// AddPublicNWConnectedParam 共有セグメントへ接続したNIC追加
func (p *propConnectedSwitches) AddPublicNWConnectedParam() {
if p.ConnectedSwitches == nil {
p.ClearConnectedSwitches()
}
p.ConnectedSwitches = append(p.ConnectedSwitches, map[string]interface{}{"Scope": "shared"})
}
// AddExistsSwitchConnectedParam スイッチへ接続したNIC追加
func (p *propConnectedSwitches) AddExistsSwitchConnectedParam(switchID string) {
if p.ConnectedSwitches == nil {
p.ClearConnectedSwitches()
}
p.ConnectedSwitches = append(p.ConnectedSwitches, map[string]interface{}{"ID": switchID})
}
// AddEmptyConnectedParam 未接続なNIC追加
func (p *propConnectedSwitches) AddEmptyConnectedParam() {
if p.ConnectedSwitches == nil {
p.ClearConnectedSwitches()
}
p.ConnectedSwitches = append(p.ConnectedSwitches, nil)
}

View file

@ -0,0 +1,56 @@
package sacloud
// propCopySource コピー元情報内包型
type propCopySource struct {
SourceDisk *Disk `json:",omitempty"` // コピー元ディスク
SourceArchive *Archive `json:",omitempty"` // コピー元アーカイブ
}
// SetSourceArchive ソースアーカイブ設定
func (p *propCopySource) SetSourceArchive(sourceID int64) {
if sourceID == EmptyID {
return
}
p.SourceArchive = &Archive{
Resource: &Resource{ID: sourceID},
}
p.SourceDisk = nil
}
// SetSourceDisk ソースディスク設定
func (p *propCopySource) SetSourceDisk(sourceID int64) {
if sourceID == EmptyID {
return
}
p.SourceDisk = &Disk{
Resource: &Resource{ID: sourceID},
}
p.SourceArchive = nil
}
// GetSourceArchive ソースアーカイブ取得
func (p *propCopySource) GetSourceArchive() *Archive {
return p.SourceArchive
}
// GetSourceDisk ソースディスク取得
func (p *propCopySource) GetSourceDisk() *Disk {
return p.SourceDisk
}
// GetSourceArchiveID ソースアーカイブID取得
func (p *propCopySource) GetSourceArchiveID() int64 {
if p.SourceArchive != nil {
return p.SourceArchive.GetID()
}
return EmptyID
}
// GetSourceDiskID ソースディスクID取得
func (p *propCopySource) GetSourceDiskID() int64 {
if p.SourceDisk != nil {
return p.SourceDisk.GetID()
}
return EmptyID
}

View file

@ -0,0 +1,11 @@
package sacloud
// propCPU CPUコア数内包型
type propCPU struct {
CPU int `json:",omitempty"` // CPUコア数
}
// GetCPU CPUコア数 取得
func (p *propCPU) GetCPU() int {
return p.CPU
}

View file

@ -0,0 +1,16 @@
package sacloud
// propDescription 説明内包型
type propDescription struct {
Description string // 説明
}
// GetDescription 説明 取得
func (p *propDescription) GetDescription() string {
return p.Description
}
// SetDescription 説明 設定
func (p *propDescription) SetDescription(desc string) {
p.Description = desc
}

View file

@ -0,0 +1,33 @@
package sacloud
// propDiskConnection ディスク接続情報内包型
type propDiskConnection struct {
Connection EDiskConnection `json:",omitempty"` // ディスク接続方法
ConnectionOrder int `json:",omitempty"` // コネクション順序
}
// GetDiskConnection ディスク接続方法 取得
func (p *propDiskConnection) GetDiskConnection() EDiskConnection {
return p.Connection
}
// SetDiskConnection ディスク接続方法 設定
func (p *propDiskConnection) SetDiskConnection(conn EDiskConnection) {
p.Connection = conn
}
// GetDiskConnectionByStr ディスク接続方法 取得
func (p *propDiskConnection) GetDiskConnectionByStr() string {
return string(p.Connection)
}
// SetDiskConnectionByStr ディスク接続方法 設定
func (p *propDiskConnection) SetDiskConnectionByStr(conn string) {
p.Connection = EDiskConnection(conn)
}
// GetDiskConnectionOrder コネクション順序 取得
func (p *propDiskConnection) GetDiskConnectionOrder() int {
return p.ConnectionOrder
}

View file

@ -0,0 +1,65 @@
package sacloud
// propSizeMB サイズ(MB)内包型
type propSizeMB struct {
SizeMB int `json:",omitempty"` // サイズ(MB単位)
}
// GetSizeMB サイズ(MB単位) 取得
func (p *propSizeMB) GetSizeMB() int {
return p.SizeMB
}
// SetSizeMB サイズ(MB単位) 設定
func (p *propSizeMB) SetSizeMB(size int) {
p.SizeMB = size
}
// GetSizeGB サイズ(GB単位) 取得
func (p *propSizeMB) GetSizeGB() int {
if p.SizeMB <= 0 {
return 0
}
return p.SizeMB / 1024
}
// SetSizeGB サイズ(GB単位) 設定
func (p *propSizeMB) SetSizeGB(size int) {
if size <= 0 {
p.SizeMB = 0
} else {
p.SizeMB = size * 1024
}
}
// propMigratedMB コピー済みデータサイズ(MB単位)内包型
type propMigratedMB struct {
MigratedMB int `json:",omitempty"` // コピー済みデータサイズ(MB単位)
}
// GetMigratedMB サイズ(MB単位) 取得
func (p *propMigratedMB) GetMigratedMB() int {
return p.MigratedMB
}
// SetMigratedMB サイズ(MB単位) 設定
func (p *propMigratedMB) SetMigratedMB(size int) {
p.MigratedMB = size
}
// GetMigratedGB サイズ(GB単位) 取得
func (p *propMigratedMB) GetMigratedGB() int {
if p.MigratedMB <= 0 {
return 0
}
return p.MigratedMB / 1024
}
// SetMigratedGB サイズ(GB単位) 設定
func (p *propMigratedMB) SetMigratedGB(size int) {
if size <= 0 {
p.MigratedMB = 0
} else {
p.MigratedMB = size * 1024
}
}

View file

@ -0,0 +1,22 @@
package sacloud
// propDisks ディスク配列内包型
type propDisks struct {
Disks []Disk `json:",omitempty"` // ディスク
}
// GetDisks ディスク配列 取得
func (p *propDisks) GetDisks() []Disk {
return p.Disks
}
// GetDiskIDs ディスクID配列を返す
func (p *propDisks) GetDiskIDs() []int64 {
ids := []int64{}
for _, disk := range p.Disks {
ids = append(ids, disk.ID)
}
return ids
}

View file

@ -0,0 +1,26 @@
package sacloud
// propDistantFrom ストレージ隔離対象ディスク内包型
type propDistantFrom struct {
DistantFrom []int64 `json:",omitempty"` // ストレージ隔離対象ディスク
}
// GetDistantFrom ストレージ隔離対象ディスク 取得
func (p *propDistantFrom) GetDistantFrom() []int64 {
return p.DistantFrom
}
// SetDistantFrom ストレージ隔離対象ディスク 設定
func (p *propDistantFrom) SetDistantFrom(ids []int64) {
p.DistantFrom = ids
}
// AddDistantFrom ストレージ隔離対象ディスク 追加
func (p *propDistantFrom) AddDistantFrom(id int64) {
p.DistantFrom = append(p.DistantFrom, id)
}
// ClearDistantFrom ストレージ隔離対象ディスク クリア
func (p *propDistantFrom) ClearDistantFrom() {
p.DistantFrom = []int64{}
}

View file

@ -0,0 +1,19 @@
package sacloud
// propHost ホスト(物理)内包型
type propHost struct {
Host *Host `json:",omitempty"` // サービスクラス
}
// GetHost ホスト(物理) 取得
func (p *propHost) GetHost() *Host {
return p.Host
}
// GetHostName ホスト(物理)名称取得
func (p *propHost) GetHostName() string {
if p.Host == nil {
return ""
}
return p.Host.GetName()
}

View file

@ -0,0 +1,11 @@
package sacloud
// propHostName ホスト名内包型
type propHostName struct {
HostName string `json:",omitempty"` // ホスト名 (ディスクの修正実施時に指定した初期ホスト名)
}
// GetHostName (初期)ホスト名 取得
func (p *propHostName) GetHostName() string {
return p.HostName
}

View file

@ -0,0 +1,47 @@
package sacloud
// propIcon アイコン内包型
type propIcon struct {
Icon *Icon // アイコン
}
// GetIcon アイコンを取得
func (p *propIcon) GetIcon() *Icon {
return p.Icon
}
// GetIconID アイコンIDを取得
func (p *propIcon) GetIconID() int64 {
if p.HasIcon() {
return p.Icon.GetID()
}
return -1
}
// GetIconStrID アイコンID(文字列)を取得
func (p *propIcon) GetIconStrID() string {
if p.HasIcon() {
return p.Icon.GetStrID()
}
return ""
}
// HasIcon アイコンがセットされているか
func (p *propIcon) HasIcon() bool {
return p.Icon != nil
}
// SetIconByID 指定のアイコンIDを設定
func (p *propIcon) SetIconByID(id int64) {
p.Icon = &Icon{Resource: NewResource(id)}
}
// SetIcon 指定のアイコンオブジェクトを設定
func (p *propIcon) SetIcon(icon *Icon) {
p.Icon = icon
}
// ClearIcon アイコンをクリア(空IDを持つアイコンオブジェクトをセット)
func (p *propIcon) ClearIcon() {
p.Icon = &Icon{Resource: NewResource(EmptyID)}
}

View file

@ -0,0 +1,59 @@
package sacloud
// propInstance インスタンス内包型
type propInstance struct {
Instance *Instance `json:",omitempty"` // インスタンス
}
// GetInstance インスタンス 取得
func (p *propInstance) GetInstance() *Instance {
return p.Instance
}
// IsUp インスタンスが起動しているか判定
func (p *propInstance) IsUp() bool {
if p.Instance == nil {
return false
}
return p.Instance.IsUp()
}
// IsDown インスタンスがダウンしているか確認
func (p *propInstance) IsDown() bool {
if p.Instance == nil {
return false
}
return p.Instance.IsDown()
}
// GetInstanceStatus ステータス 取得
func (p *propInstance) GetInstanceStatus() string {
if p.Instance == nil {
return ""
}
return p.Instance.GetStatus()
}
// GetInstanceBeforeStatus 以前のステータス 取得
func (p *propInstance) GetInstanceBeforeStatus() string {
if p.Instance == nil {
return ""
}
return p.Instance.GetBeforeStatus()
}
// MaintenanceScheduled メンテナンス予定の有無
func (p *propInstance) MaintenanceScheduled() bool {
if p.Instance == nil {
return false
}
return p.Instance.MaintenanceScheduled()
}
// GetMaintenanceInfoURL メンテナンス情報 URL取得
func (p *propInstance) GetMaintenanceInfoURL() string {
if p.Instance == nil {
return ""
}
return p.Instance.Host.InfoURL
}

View file

@ -0,0 +1,26 @@
package sacloud
// propInterfaceDriver インターフェースドライバ内包型
type propInterfaceDriver struct {
InterfaceDriver EInterfaceDriver `json:",omitempty"` // NIC
}
// SetInterfaceDriver インターフェースドライバ 設定
func (p *propInterfaceDriver) SetInterfaceDriver(v EInterfaceDriver) {
p.InterfaceDriver = v
}
// GetInterfaceDriver インターフェースドライバ 取得
func (p *propInterfaceDriver) GetInterfaceDriver() EInterfaceDriver {
return p.InterfaceDriver
}
// SetInterfaceDriverByString インターフェースドライバ 設定(文字列)
func (p *propInterfaceDriver) SetInterfaceDriverByString(v string) {
p.InterfaceDriver = EInterfaceDriver(v)
}
// GetInterfaceDriverString インターフェースドライバ 取得(文字列)
func (p *propInterfaceDriver) GetInterfaceDriverString() string {
return string(p.InterfaceDriver)
}

View file

@ -0,0 +1,19 @@
package sacloud
// propInterfaces インターフェース(NIC)配列内包型
type propInterfaces struct {
Interfaces []Interface `json:",omitempty"` // インターフェース
}
// GetInterfaces インターフェース(NIC)配列 取得
func (p *propInterfaces) GetInterfaces() []Interface {
return p.Interfaces
}
// GetFirstInterface インターフェース(NIC)配列の先頭要素を返す
func (p *propInterfaces) GetFirstInterface() *Interface {
if len(p.Interfaces) == 0 {
return nil
}
return &p.Interfaces[0]
}

View file

@ -0,0 +1,11 @@
package sacloud
// propJobStatus マイグレーションジョブステータス内包型
type propJobStatus struct {
JobStatus *MigrationJobStatus `json:",omitempty"` // マイグレーションジョブステータス
}
// GetJobStatus マイグレーションジョブステータス 取得
func (p *propJobStatus) GetJobStatus() *MigrationJobStatus {
return p.JobStatus
}

View file

@ -0,0 +1,19 @@
package sacloud
// propMemoryMB サイズ(MB)内包型
type propMemoryMB struct {
MemoryMB int `json:",omitempty"` // サイズ(MB単位)
}
// GetMemoryMB サイズ(MB単位) 取得
func (p *propMemoryMB) GetMemoryMB() int {
return p.MemoryMB
}
// GetMemoryGB サイズ(GB単位) 取得
func (p *propMemoryMB) GetMemoryGB() int {
if p.MemoryMB <= 0 {
return 0
}
return p.MemoryMB / 1024
}

View file

@ -0,0 +1,16 @@
package sacloud
// propName 名称内包型
type propName struct {
Name string `json:",omitempty"` // 名称
}
// GetName 名称 取得
func (p *propName) GetName() string {
return p.Name
}
// SetName 名称 設定
func (p *propName) SetName(name string) {
p.Name = name
}

View file

@ -0,0 +1,39 @@
package sacloud
// ENoteClass スタートアップスクリプトクラス
type ENoteClass string
var (
// NoteClassShell shellクラス
NoteClassShell = ENoteClass("shell")
// NoteClassYAMLCloudConfig yaml_cloud_configクラス
NoteClassYAMLCloudConfig = ENoteClass("yaml_cloud_config")
)
// ENoteClasses 設定可能なスタートアップスクリプトクラス
var ENoteClasses = []ENoteClass{NoteClassShell, NoteClassYAMLCloudConfig}
// propNoteClass スタートアップスクリプトクラス情報内包型
type propNoteClass struct {
Class ENoteClass `json:",omitempty"` // クラス
}
// GetClass クラス 取得
func (p *propNoteClass) GetClass() ENoteClass {
return p.Class
}
// SetClass クラス 設定
func (p *propNoteClass) SetClass(c ENoteClass) {
p.Class = c
}
// GetClassStr クラス 取得(文字列)
func (p *propNoteClass) GetClassStr() string {
return string(p.Class)
}
// SetClassByStr クラス 設定(文字列)
func (p *propNoteClass) SetClassByStr(c string) {
p.Class = ENoteClass(c)
}

View file

@ -0,0 +1,22 @@
package sacloud
// propOriginalArchiveID オリジナルアーカイブID内包型
type propOriginalArchiveID struct {
OriginalArchive *Resource `json:",omitempty"` // オリジナルアーカイブ
}
// GetOriginalArchiveID プランID 取得
func (p *propOriginalArchiveID) GetOriginalArchiveID() int64 {
if p.OriginalArchive == nil {
return -1
}
return p.OriginalArchive.GetID()
}
// GetStrOriginalArchiveID プランID(文字列) 取得
func (p *propOriginalArchiveID) GetStrOriginalArchiveID() string {
if p.OriginalArchive == nil {
return ""
}
return p.OriginalArchive.GetStrID()
}

View file

@ -0,0 +1,22 @@
package sacloud
// propPlanID プランID内包型
type propPlanID struct {
Plan *Resource `json:",omitempty"` // プラン
}
// GetPlanID プランID 取得
func (p *propPlanID) GetPlanID() int64 {
if p.Plan == nil {
return -1
}
return p.Plan.GetID()
}
// GetStrPlanID プランID(文字列) 取得
func (p *propPlanID) GetStrPlanID() string {
if p.Plan == nil {
return ""
}
return p.Plan.GetStrID()
}

View file

@ -0,0 +1,21 @@
package sacloud
// propPrivateHost 専有ホスト内包型
type propPrivateHost struct {
PrivateHost *PrivateHost // 専有ホスト
}
// SetPrivateHostByID 指定のアイコンIDを設定
func (p *propPrivateHost) SetPrivateHostByID(id int64) {
p.PrivateHost = &PrivateHost{Resource: NewResource(id)}
}
// SetPrivateHost 指定のアイコンオブジェクトを設定
func (p *propPrivateHost) SetPrivateHost(icon *PrivateHost) {
p.PrivateHost = icon
}
// ClearPrivateHost アイコンをクリア(空IDを持つアイコンオブジェクトをセット)
func (p *propPrivateHost) ClearPrivateHost() {
p.PrivateHost = &PrivateHost{Resource: NewResource(EmptyID)}
}

View file

@ -0,0 +1,51 @@
package sacloud
// propPrivateHostPlan 専有ホストプラン内包型
type propPrivateHostPlan struct {
Plan *ProductPrivateHost `json:",omitempty"` // 専有ホストプラン
}
// GetPrivateHostPlan 専有ホストプラン取得
func (p *propPrivateHostPlan) GetPrivateHostPlan() *ProductPrivateHost {
return p.Plan
}
// SetPrivateHostPlan 専有ホストプラン設定
func (p *propPrivateHostPlan) SetPrivateHostPlan(plan *ProductPrivateHost) {
p.Plan = plan
}
// SetPrivateHostPlanByID 専有ホストプラン設定
func (p *propPrivateHostPlan) SetPrivateHostPlanByID(planID int64) {
if p.Plan == nil {
p.Plan = &ProductPrivateHost{}
}
p.Plan.Resource = NewResource(planID)
}
// GetCPU CPUコア数 取得
func (p *propPrivateHostPlan) GetCPU() int {
if p.Plan == nil {
return -1
}
return p.Plan.GetCPU()
}
// GetMemoryMB メモリ(MB) 取得
func (p *propPrivateHostPlan) GetMemoryMB() int {
if p.Plan == nil {
return -1
}
return p.Plan.GetMemoryMB()
}
// GetMemoryGB メモリ(GB) 取得
func (p *propPrivateHostPlan) GetMemoryGB() int {
if p.Plan == nil {
return -1
}
return p.Plan.GetMemoryGB()
}

View file

@ -0,0 +1,44 @@
package sacloud
// propRegion リージョン内包型
type propRegion struct {
Region *Region `json:",omitempty"` // リージョン
}
// GetRegion リージョン 取得
func (p *propRegion) GetRegion() *Region {
return p.Region
}
// GetRegionID リージョンID 取得
func (p *propRegion) GetRegionID() int64 {
if p.Region == nil {
return -1
}
return p.Region.GetID()
}
// GetRegionName リージョン名 取得
func (p *propRegion) GetRegionName() string {
if p.Region == nil {
return ""
}
return p.Region.GetName()
}
// GetRegionDescription リージョン説明 取得
func (p *propRegion) GetRegionDescription() string {
if p.Region == nil {
return ""
}
return p.Region.GetDescription()
}
// GetRegionNameServers リージョンのネームサーバー(のIPアドレス)取得
func (p *propRegion) GetRegionNameServers() []string {
if p.Region == nil {
return []string{}
}
return p.Region.GetNameServers()
}

View file

@ -0,0 +1,42 @@
package sacloud
// propScope スコープ内包型
type propScope struct {
Scope string `json:",omitempty"` // スコープ
}
// GetScope スコープ 取得
func (p *propScope) GetScope() string {
return p.Scope
}
// SetScope スコープ 設定
func (p *propScope) SetScope(scope string) {
p.Scope = scope
}
// SetSharedScope 共有スコープに設定
func (p *propScope) SetSharedScope() {
p.Scope = string(ESCopeShared)
}
// SetUserScope ユーザースコープに設定
func (p *propScope) SetUserScope() {
p.Scope = string(ESCopeUser)
}
// IsSharedScope 共有スコープか判定
func (p *propScope) IsSharedScope() bool {
if p == nil {
return false
}
return p.Scope == string(ESCopeShared)
}
// IsUserScope ユーザースコープか判定
func (p *propScope) IsUserScope() bool {
if p == nil {
return false
}
return p.Scope == string(ESCopeUser)
}

View file

@ -0,0 +1,21 @@
package sacloud
// propServer 接続先サーバー内包型
type propServer struct {
Server *Server `json:",omitempty"` // 接続先サーバー
}
// GetServer 接続先サーバー 取得
func (p *propServer) GetServer() *Server {
return p.Server
}
// SetServer 接続先サーバー 設定
func (p *propServer) SetServer(server *Server) {
p.Server = server
}
// SetServerID サーバーIDの設定
func (p *propServer) SetServerID(id int64) {
p.Server = &Server{Resource: &Resource{ID: id}}
}

View file

@ -0,0 +1,51 @@
package sacloud
// propServerPlan サーバープラン内包型
type propServerPlan struct {
ServerPlan *ProductServer `json:",omitempty"` // サーバープラン
}
// GetServerPlan サーバープラン取得
func (p *propServerPlan) GetServerPlan() *ProductServer {
return p.ServerPlan
}
// SetServerPlan サーバープラン設定
func (p *propServerPlan) SetServerPlan(plan *ProductServer) {
p.ServerPlan = plan
}
// SetServerPlanByID サーバープラン設定
func (p *propServerPlan) SetServerPlanByID(planID string) {
if p.ServerPlan == nil {
p.ServerPlan = &ProductServer{}
}
p.ServerPlan.Resource = NewResourceByStringID(planID)
}
// GetCPU CPUコア数 取得
func (p *propServerPlan) GetCPU() int {
if p.ServerPlan == nil {
return -1
}
return p.ServerPlan.GetCPU()
}
// GetMemoryMB メモリ(MB) 取得
func (p *propServerPlan) GetMemoryMB() int {
if p.ServerPlan == nil {
return -1
}
return p.ServerPlan.GetMemoryMB()
}
// GetMemoryGB メモリ(GB) 取得
func (p *propServerPlan) GetMemoryGB() int {
if p.ServerPlan == nil {
return -1
}
return p.ServerPlan.GetMemoryGB()
}

View file

@ -0,0 +1,11 @@
package sacloud
// propServiceClass サービスクラス内包型
type propServiceClass struct {
ServiceClass string `json:",omitempty"` // サービスクラス
}
// GetServiceClass サービスクラス 取得
func (p *propServiceClass) GetServiceClass() string {
return p.ServiceClass
}

View file

@ -0,0 +1,11 @@
package sacloud
// propStorage ストーレジ内包型
type propStorage struct {
Storage *Storage `json:",omitempty"` // ストレージ
}
// GetStorage ストレージ 取得
func (p *propStorage) GetStorage() *Storage {
return p.Storage
}

View file

@ -0,0 +1,11 @@
package sacloud
// propStorageClass ストレージクラス内包型
type propStorageClass struct {
StorageClass string `json:",omitempty"` // ストレージクラス
}
// GetStorageClass ストレージクラス 取得
func (p *propStorageClass) GetStorageClass() string {
return p.StorageClass
}

View file

@ -0,0 +1,21 @@
package sacloud
// propSwitch スイッチ内包型
type propSwitch struct {
Switch *Switch `json:",omitempty"` // スイッチ
}
// GetSwitch スイッチ 取得
func (p *propSwitch) GetSwitch() *Switch {
return p.Switch
}
// SetSwitch スイッチ 設定
func (p *propSwitch) SetSwitch(sw *Switch) {
p.Switch = sw
}
// SetSwitchID スイッチID 設定
func (p *Interface) SetSwitchID(id int64) {
p.Switch = &Switch{Resource: &Resource{ID: id}}
}

View file

@ -0,0 +1,57 @@
package sacloud
// propTags タグ内包型
type propTags struct {
Tags []string // タグ
}
// HasTag 指定のタグを持っているか判定
func (p *propTags) HasTag(target string) bool {
for _, tag := range p.Tags {
if target == tag {
return true
}
}
return false
}
// AppendTag タグを追加
func (p *propTags) AppendTag(target string) {
if p.HasTag(target) {
return
}
p.Tags = append(p.Tags, target)
}
// RemoveTag 指定のタグを削除
func (p *propTags) RemoveTag(target string) {
if !p.HasTag(target) {
return
}
res := []string{}
for _, tag := range p.Tags {
if tag != target {
res = append(res, tag)
}
}
p.Tags = res
}
// ClearTags 全タグを削除
func (p *propTags) ClearTags() {
p.Tags = []string{}
}
// GetTags タグ取得
func (p *propTags) GetTags() []string {
return p.Tags
}
// SetTags タグを設定
func (p *propTags) SetTags(tags []string) {
p.Tags = tags
}

View file

@ -0,0 +1,35 @@
package sacloud
import "time"
// propCreatedAt 作成日時内包型
type propCreatedAt struct {
CreatedAt *time.Time `json:",omitempty"` // 作成日時
}
// GetCreatedAt 作成日時 取得
func (p *propCreatedAt) GetCreatedAt() *time.Time {
return p.CreatedAt
}
// propModifiedAt 変更日時内包型
type propModifiedAt struct {
// ModifiedAt 変更日時
ModifiedAt *time.Time `json:",omitempty"`
}
// GetModifiedAt 変更日時 取得
func (p *propModifiedAt) GetModifiedAt() *time.Time {
return p.ModifiedAt
}
// propUpdatedAt 変更日時内包型
type propUpdatedAt struct {
// UpdatedAt 変更日時
UpdatedAt *time.Time `json:",omitempty"`
}
// GetModifiedAt 変更日時 取得
func (p *propUpdatedAt) GetModifiedAt() *time.Time {
return p.UpdatedAt
}

View file

@ -0,0 +1,118 @@
package sacloud
// PropZone ゾーン内包型
type propZone struct {
Zone *Zone `json:",omitempty"` // ゾーン
}
// GetZone ゾーン 取得
func (p *propZone) GetZone() *Zone {
return p.Zone
}
// GetZoneID ゾーンID 取得
func (p *propZone) GetZoneID() int64 {
if p.Zone == nil {
return -1
}
return p.Zone.GetID()
}
// GetZoneName ゾーン名 取得
func (p *propZone) GetZoneName() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetName()
}
// GetZoneDescription ゾーン説明 取得
func (p *propZone) GetZoneDescription() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetDescription()
}
// GetRegion リージョン 取得
func (p *propZone) GetRegion() *Region {
if p.Zone == nil {
return nil
}
return p.Zone.GetRegion()
}
// GetRegionID リージョンID 取得
func (p *propZone) GetRegionID() int64 {
if p.Zone == nil {
return -1
}
return p.Zone.GetRegionID()
}
// GetRegionName リージョン名 取得
func (p *propZone) GetRegionName() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetRegionName()
}
// GetRegionDescription リージョン説明 取得
func (p *propZone) GetRegionDescription() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetRegionDescription()
}
// GetRegionNameServers リージョンのネームサーバー(のIPアドレス)取得
func (p *propZone) GetRegionNameServers() []string {
if p.Zone == nil {
return []string{}
}
return p.Zone.GetRegionNameServers()
}
// ZoneIsDummy ダミーフラグ 取得
func (p *propZone) ZoneIsDummy() bool {
if p.Zone == nil {
return false
}
return p.Zone.ZoneIsDummy()
}
// GetVNCProxyHostName VNCプロキシホスト名 取得
func (p *propZone) GetVNCProxyHostName() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetVNCProxyHostName()
}
// GetVPCProxyIPAddress VNCプロキシIPアドレス 取得
func (p *propZone) GetVPCProxyIPAddress() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetVPCProxyIPAddress()
}
// GetFTPHostName FTPサーバーホスト名 取得
func (p *propZone) GetFTPHostName() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetFTPHostName()
}
// GetFTPServerIPAddress FTPサーバーIPアドレス 取得
func (p *propZone) GetFTPServerIPAddress() string {
if p.Zone == nil {
return ""
}
return p.Zone.GetFTPServerIPAddress()
}

View file

@ -0,0 +1,18 @@
package sacloud
// PublicPrice 料金
type PublicPrice struct {
DisplayName string `json:",omitempty"` // 表示名
IsPublic bool `json:",omitempty"` // 公開フラグ
ServiceClassID int `json:",omitempty"` // サービスクラスID
ServiceClassName string `json:",omitempty"` // サービスクラス名
ServiceClassPath string `json:",omitempty"` // サービスクラスパス
Price struct { // 価格
Base int `json:",omitempty"` // 基本料金
Daily int `json:",omitempty"` // 日単位料金
Hourly int `json:",omitempty"` // 時間単位料金
Monthly int `json:",omitempty"` // 分単位料金
Zone string `json:",omitempty"` // ゾーン
}
}

18
vendor/github.com/sacloud/libsacloud/sacloud/region.go generated vendored Normal file
View file

@ -0,0 +1,18 @@
package sacloud
// Region リージョン
type Region struct {
*Resource // ID
propName // 名称
propDescription // 説明
NameServers []string `json:",omitempty"` // NameServers ネームサーバー
}
// GetNameServers リージョン内のネームサーバー取得
func (r *Region) GetNameServers() []string {
if r == nil {
return []string{}
}
return r.NameServers
}

145
vendor/github.com/sacloud/libsacloud/sacloud/server.go generated vendored Normal file
View file

@ -0,0 +1,145 @@
package sacloud
import "fmt"
// Server サーバー
type Server struct {
*Resource // ID
propName // 名称
propDescription // 説明
propHostName // ホスト名
propInterfaceDriver // インターフェースドライバ
propAvailability // 有功状態
propServerPlan // サーバープラン
propZone // ゾーン
propServiceClass // サービスクラス
propConnectedSwitches // 接続スイッチ
propDisks // ディスク配列
propInstance // インスタンス
propInterfaces // インターフェース配列
propPrivateHost // 専有ホスト
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
}
// DNSServers サーバの所属するリージョンの推奨ネームサーバリスト
func (s *Server) DNSServers() []string {
return s.Zone.Region.NameServers
}
// IPAddress サーバの1番目のNIC(eth0)のIPアドレス
func (s *Server) IPAddress() string {
// has NIC?
if len(s.Interfaces) == 0 {
return ""
}
ip := s.Interfaces[0].IPAddress
if ip == "" {
ip = s.Interfaces[0].UserIPAddress
}
return ip
}
// Gateway デフォルトゲートウェイアドレス
func (s *Server) Gateway() string {
if len(s.Interfaces) == 0 || s.Interfaces[0].Switch == nil || s.Interfaces[0].Switch.UserSubnet == nil {
return ""
}
return s.Interfaces[0].Switch.UserSubnet.DefaultRoute
}
// DefaultRoute デフォルトゲートウェイアドレス(Gatewayのエイリアス)
func (s *Server) DefaultRoute() string {
return s.Gateway()
}
// NetworkMaskLen サーバの1番目のNIC(eth0)のネットワークマスク長
func (s *Server) NetworkMaskLen() int {
if len(s.Interfaces) == 0 || s.Interfaces[0].Switch == nil || s.Interfaces[0].Switch.UserSubnet == nil {
return 0
}
return s.Interfaces[0].Switch.UserSubnet.NetworkMaskLen
}
// NetworkAddress サーバの1番目のNIC(eth0)のネットワークアドレス
func (s *Server) NetworkAddress() string {
if len(s.Interfaces) == 0 || s.Interfaces[0].Switch == nil || s.Interfaces[0].Switch.Subnet == nil {
return ""
}
return s.Interfaces[0].Switch.Subnet.NetworkAddress
}
// CIDRIPAddress サーバの1番目のNIC(eth0)のIPアドレス+ネットワークマスク長
func (s *Server) CIDRIPAddress() string {
ip, maskLen := s.IPAddress(), s.NetworkMaskLen()
if ip != "" && maskLen > 0 {
return fmt.Sprintf("%s/%d", ip, maskLen)
}
return ""
}
const (
// ServerMaxInterfaceLen サーバーに接続できるNICの最大数
ServerMaxInterfaceLen = 10
// ServerMaxDiskLen サーバーに接続できるディスクの最大数
ServerMaxDiskLen = 4
)
// KeyboardRequest キーボード送信リクエスト
type KeyboardRequest struct {
Keys []string `json:",omitempty"` // キー(複数)
Key string `json:",omitempty"` // キー(単体)
}
// MouseRequest マウス送信リクエスト
type MouseRequest struct {
X *int `json:",omitempty"` // X
Y *int `json:",omitempty"` // Y
Z *int `json:",omitempty"` // Z
Buttons *MouseRequestButtons `json:",omitempty"` // マウスボタン
}
// VNCSnapshotRequest VNCスナップショット取得リクエスト
type VNCSnapshotRequest struct {
ScreenSaverExitTimeMS int `json:",omitempty"` // スクリーンセーバーからの復帰待ち時間
}
// MouseRequestButtons マウスボタン
type MouseRequestButtons struct {
L bool `json:",omitempty"` // 左ボタン
R bool `json:",omitempty"` // 右ボタン
M bool `json:",omitempty"` // 中ボタン
}
// VNCProxyResponse VNCプロキシ取得レスポンス
type VNCProxyResponse struct {
*ResultFlagValue
Status string `json:",omitempty"` // ステータス
Host string `json:",omitempty"` // プロキシホスト
IOServerHost string `json:",omitempty"` // 新プロキシホスト(Hostがlocalhostの場合にこちらを利用する)
Port string `json:",omitempty"` // ポート番号
Password string `json:",omitempty"` // VNCパスワード
VNCFile string `json:",omitempty"` // VNC接続情報ファイル(VNCビューア用)
}
// ActualHost プロキシホスト名(Host or IOServerHost)を返す
func (r *VNCProxyResponse) ActualHost() string {
host := r.Host
if host == "localhost" {
host = r.IOServerHost
}
return host
}
// VNCSizeResponse VNC画面サイズレスポンス
type VNCSizeResponse struct {
Width int `json:",string,omitempty"` // 幅
Height int `json:",string,omitempty"` // 高さ
}
// VNCSnapshotResponse VPCスナップショットレスポンス
type VNCSnapshotResponse struct {
Image string `json:",omitempty"` // スナップショット画像データ
}

111
vendor/github.com/sacloud/libsacloud/sacloud/sim.go generated vendored Normal file
View file

@ -0,0 +1,111 @@
package sacloud
import (
"encoding/json"
"strings"
"time"
)
// SIM SIM(CommonServiceItem)
type SIM struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
propAvailability // 有効状態
Status SIMStatus `json:",omitempty"` // ステータス
Provider SIMProvider `json:",omitempty"` // プロバイダ
Remark *SIMRemark `json:",omitempty"` // Remark
}
// SIMStatus SIMステータス
type SIMStatus struct {
ICCID string `json:",omitempty"` // ICCID
SIMInfo *SIMInfo `json:"sim,omitempty"` // SIM詳細情報
}
// SIMInfo SIM詳細情報
type SIMInfo struct {
ICCID string `json:"iccid,omitempty"`
IMSI []string `json:"imsi,omitempty"`
IP string `json:"ip,omitempty"`
SessionStatus string `json:"session_status,omitempty"`
IMEILock bool `json:"imei_lock,omitempty"`
Registered bool `json:"registered,omitempty"`
Activated bool `json:"activated,omitempty"`
ResourceID string `json:"resource_id,omitempty"`
RegisteredDate *time.Time `json:"registered_date,omitempty"`
ActivatedDate *time.Time `json:"activated_date,omitempty"`
DeactivatedDate *time.Time `json:"deactivated_date,omitempty"`
SIMGroupID string `json:"simgroiup_id,omitempty"`
TrafficBytesOfCurrentMonth *SIMTrafficBytes `json:"traffic_bytes_of_current_month,omitempty"`
ConnectedIMEI string `json:"connected_imei,omitempty"`
}
// SIMTrafficBytes 当月通信量
type SIMTrafficBytes struct {
UplinkBytes int64 `json:"uplink_bytes,omitempty"`
DownlinkBytes int64 `json:"downlink_bytes,omitempty"`
}
// UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
func (s *SIMTrafficBytes) UnmarshalJSON(data []byte) error {
targetData := strings.Replace(strings.Replace(string(data), " ", "", -1), "\n", "", -1)
if targetData == `[]` {
return nil
}
tmp := &struct {
UplinkBytes int64 `json:"uplink_bytes,omitempty"`
DownlinkBytes int64 `json:"downlink_bytes,omitempty"`
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
s.UplinkBytes = tmp.UplinkBytes
s.DownlinkBytes = tmp.DownlinkBytes
return nil
}
// SIMRemark remark
type SIMRemark struct {
PassCode string `json:",omitempty"`
}
// SIMProvider プロバイダ
type SIMProvider struct {
Class string `json:",omitempty"` // クラス
Name string `json:",omitempty"`
ServiceClass string `json:",omitempty"`
}
// SIMLog SIMログ
type SIMLog struct {
Date *time.Time `json:"date,omitempty"`
SessionStatus string `json:"session_status,omitempty"`
ResourceID string `json:"resource_id,omitempty"`
IMEI string `json:"imei,omitempty"`
IMSI string `json:"imsi,omitempty"`
}
// CreateNewSIM SIM作成
func CreateNewSIM(name string, iccID string, passcode string) *SIM {
return &SIM{
Resource: &Resource{},
propName: propName{Name: name},
Provider: SIMProvider{
Class: "sim",
},
Status: SIMStatus{
ICCID: iccID,
},
Remark: &SIMRemark{
PassCode: passcode,
},
}
}

View file

@ -0,0 +1,254 @@
package sacloud
// SimpleMonitor シンプル監視
type SimpleMonitor struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
propModifiedAt // 変更日時
Settings *SimpleMonitorSettings `json:",omitempty"` // 設定
Status *SimpleMonitorStatus `json:",omitempty"` // ステータス
Provider *SimpleMonitorProvider `json:",omitempty"` // プロバイダ
}
// SimpleMonitorSettings シンプル監視設定 リスト
type SimpleMonitorSettings struct {
SimpleMonitor *SimpleMonitorSetting `json:",omitempty"` // シンプル監視設定値
}
// SimpleMonitorSetting シンプル監視設定
type SimpleMonitorSetting struct {
DelayLoop int `json:",omitempty"` // 監視間隔
HealthCheck *SimpleMonitorHealthCheck `json:",omitempty"` // ヘルスチェック
Enabled string `json:",omitempty"` // 有効/無効
NotifyEmail *SimpleMonitorNotify `json:",omitempty"` // Email通知
NotifySlack *SimpleMonitorNotify `json:",omitempty"` // Slack通知
}
// SimpleMonitorStatus シンプル監視ステータス
type SimpleMonitorStatus struct {
Target string `json:",omitempty"` // 対象(IP or FQDN)
}
// SimpleMonitorProvider プロバイダ
type SimpleMonitorProvider struct {
*Resource // ID
propName // 名称
propServiceClass // サービスクラス
Class string `json:",omitempty"` // クラス
}
// SimpleMonitorHealthCheck ヘルスチェック
type SimpleMonitorHealthCheck struct {
Protocol string `json:",omitempty"` // プロトコル
Port string `json:",omitempty"` // ポート
Path string `json:",omitempty"` // HTTP/HTTPS監視の場合のリクエストパス
Status string `json:",omitempty"` // HTTP/HTTPS監視の場合の期待ステータスコード
SNI string `json:",omitempty"` // HTTPS監視時のSNI有効/無効
Host string `json:",omitempty"` // 対象ホスト(IP or FQDN)
QName string `json:",omitempty"` // DNS監視の場合の問い合わせFQDN
ExpectedData string `json:",omitempty"` // 期待値
Community string `json:",omitempty"` // SNMP監視の場合のコミュニティ名
SNMPVersion string `json:",omitempty"` // SNMP監視 SNMPバージョン
OID string `json:",omitempty"` // SNMP監視 OID
RemainingDays int `json:",omitempty"` // SSL証明書 有効残日数
}
// SimpleMonitorNotify シンプル監視通知
type SimpleMonitorNotify struct {
Enabled string `json:",omitempty"` // 有効/無効
HTML string `json:",omitempty"` // メール通知の場合のHTMLメール有効フラグ
IncomingWebhooksURL string `json:",omitempty"` // Slack通知の場合のWebhook URL
}
// CreateNewSimpleMonitor シンプル監視作成
func CreateNewSimpleMonitor(target string) *SimpleMonitor {
return &SimpleMonitor{
propName: propName{Name: target},
Provider: &SimpleMonitorProvider{
Class: "simplemon",
},
Status: &SimpleMonitorStatus{
Target: target,
},
Settings: &SimpleMonitorSettings{
SimpleMonitor: &SimpleMonitorSetting{
HealthCheck: &SimpleMonitorHealthCheck{},
Enabled: "True",
NotifyEmail: &SimpleMonitorNotify{
Enabled: "False",
},
NotifySlack: &SimpleMonitorNotify{
Enabled: "False",
},
},
},
}
}
// AllowSimpleMonitorHealthCheckProtocol シンプル監視対応プロトコルリスト
func AllowSimpleMonitorHealthCheckProtocol() []string {
return []string{"http", "https", "ping", "tcp", "dns", "ssh", "smtp", "pop3", "snmp", "sslcertificate"}
}
func createSimpleMonitorNotifyEmail(withHTML bool) *SimpleMonitorNotify {
n := &SimpleMonitorNotify{
Enabled: "True",
HTML: "False",
}
if withHTML {
n.HTML = "True"
}
return n
}
func createSimpleMonitorNotifySlack(incomingWebhooksURL string) *SimpleMonitorNotify {
return &SimpleMonitorNotify{
Enabled: "True",
IncomingWebhooksURL: incomingWebhooksURL,
}
}
// SetTarget 対象ホスト(IP or FQDN)の設定
func (s *SimpleMonitor) SetTarget(target string) {
s.Name = target
s.Status.Target = target
}
// SetHealthCheckPing pingでのヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckPing() {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "ping",
}
}
// SetHealthCheckTCP TCPでのヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckTCP(port string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "tcp",
Port: port,
}
}
// SetHealthCheckHTTP HTTPでのヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckHTTP(port string, path string, status string, host string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "http",
Port: port,
Path: path,
Status: status,
Host: host,
}
}
// SetHealthCheckHTTPS HTTPSでのヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckHTTPS(port string, path string, status string, host string, sni bool) {
strSNI := "False"
if sni {
strSNI = "True"
}
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "https",
Port: port,
Path: path,
Status: status,
Host: host,
SNI: strSNI,
}
}
// SetHealthCheckDNS DNSクエリでのヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckDNS(qname string, expectedData string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "dns",
QName: qname,
ExpectedData: expectedData,
}
}
// SetHealthCheckSSH SSHヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckSSH(port string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "ssh",
Port: port,
}
}
// SetHealthCheckSMTP SMTPヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckSMTP(port string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "smtp",
Port: port,
}
}
// SetHealthCheckPOP3 POP3ヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckPOP3(port string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "pop3",
Port: port,
}
}
// SetHealthCheckSNMP SNMPヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckSNMP(community string, version string, oid string, expectedData string) {
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "snmp",
Community: community,
SNMPVersion: version,
OID: oid,
ExpectedData: expectedData,
}
}
// SetHealthCheckSSLCertificate SSLサーバ証明書有効期限ヘルスチェック設定
func (s *SimpleMonitor) SetHealthCheckSSLCertificate(remainingDays int) {
// set default
if remainingDays < 0 {
remainingDays = 30
}
s.Settings.SimpleMonitor.HealthCheck = &SimpleMonitorHealthCheck{
Protocol: "sslcertificate",
RemainingDays: remainingDays,
}
}
// EnableNotifyEmail Email通知の有効か
func (s *SimpleMonitor) EnableNotifyEmail(withHTML bool) {
s.Settings.SimpleMonitor.NotifyEmail = createSimpleMonitorNotifyEmail(withHTML)
}
// DisableNotifyEmail Email通知の無効化
func (s *SimpleMonitor) DisableNotifyEmail() {
s.Settings.SimpleMonitor.NotifyEmail = &SimpleMonitorNotify{
Enabled: "False",
}
}
// EnableNofitySlack Slack通知の有効化
func (s *SimpleMonitor) EnableNofitySlack(incomingWebhooksURL string) {
s.Settings.SimpleMonitor.NotifySlack = createSimpleMonitorNotifySlack(incomingWebhooksURL)
}
// DisableNotifySlack Slack通知の無効化
func (s *SimpleMonitor) DisableNotifySlack() {
s.Settings.SimpleMonitor.NotifySlack = &SimpleMonitorNotify{
Enabled: "False",
}
}
// SetDelayLoop 監視間隔の設定
func (s *SimpleMonitor) SetDelayLoop(loop int) {
s.Settings.SimpleMonitor.DelayLoop = loop
}

View file

@ -0,0 +1,38 @@
package sacloud
// SiteToSiteConnectionDetail サイト間VPN接続詳細情報
type SiteToSiteConnectionDetail struct {
ESP struct {
AuthenticationProtocol string
DHGroup string
EncryptionProtocol string
Lifetime string
Mode string
PerfectForwardSecrecy string
}
IKE struct {
AuthenticationProtocol string
EncryptionProtocol string
Lifetime string
Mode string
PerfectForwardSecrecy string
PreSharedSecret string
}
Peer struct {
ID string
InsideNetworks []string
OutsideIPAddress string
}
VPCRouter struct {
ID string
InsideNetworks []string
OutsideIPAddress string
}
}
// SiteToSiteConnectionInfo サイト間VPN接続情報
type SiteToSiteConnectionInfo struct {
Details struct {
Config []SiteToSiteConnectionDetail
}
}

View file

@ -0,0 +1,38 @@
package sacloud
// SSHKey 公開鍵
type SSHKey struct {
*Resource // ID
propName // 名称
propDescription // 説明
propCreatedAt // 作成日時
PublicKey string `json:",omitempty"` // 公開鍵
Fingerprint string `json:",omitempty"` // フィンガープリント
}
// SSHKeyGenerated 公開鍵生成戻り値(秘密鍵のダウンロード用)
type SSHKeyGenerated struct {
SSHKey
PrivateKey string `json:",omitempty"` // 秘密鍵
}
// GetPublicKey 公開鍵取得
func (k *SSHKey) GetPublicKey() string {
return k.PublicKey
}
// SetPublicKey 公開鍵設定
func (k *SSHKey) SetPublicKey(pKey string) {
k.PublicKey = pKey
}
// GetFingerprint フィンガープリント取得
func (k *SSHKey) GetFingerprint() string {
return k.Fingerprint
}
// GetPrivateKey 秘密鍵取得
func (k *SSHKeyGenerated) GetPrivateKey() string {
return k.PrivateKey
}

View file

@ -0,0 +1,18 @@
package sacloud
// Storage ストレージ
type Storage struct {
*Resource // ID
propName // 名称
propDescription // 説明
propZone // ゾーン
Class string `json:",omitempty"` // クラス
DiskPlan struct { // ディスクプラン
*Resource // ID
propName // 名称
propStorageClass // ストレージクラス
} `json:",omitempty"`
//Capacity []string `json:",omitempty"`
}

18
vendor/github.com/sacloud/libsacloud/sacloud/subnet.go generated vendored Normal file
View file

@ -0,0 +1,18 @@
package sacloud
// Subnet IPv4サブネット
type Subnet struct {
*Resource // ID
propServiceClass // サービスクラス
propCreatedAt // 作成日時
DefaultRoute string `json:",omitempty"` // デフォルトルート
IPAddresses []*IPAddress `json:",omitempty"` // IPv4アドレス範囲
NetworkAddress string `json:",omitempty"` // ネットワークアドレス
NetworkMaskLen int `json:",omitempty"` // ネットワークマスク長
ServiceID int64 `json:",omitempty"` // サービスID
StaticRoute string `json:",omitempty"` // スタティックルート
NextHop string `json:",omitempty"` // ネクストホップ
Switch *Switch `json:",omitempty"` // スイッチ
Internet *Internet `json:",omitempty"` // ルーター
}

84
vendor/github.com/sacloud/libsacloud/sacloud/switch.go generated vendored Normal file
View file

@ -0,0 +1,84 @@
package sacloud
import (
"encoding/json"
"fmt"
"net"
)
// Switch スイッチ
type Switch struct {
*Resource // ID
propName // 名称
propDescription // 説明
propServiceClass // サービスクラス
propIcon // アイコン
propTags // タグ
propCreatedAt // 作成日時
ServerCount int `json:",omitempty"` // 接続サーバー数
ApplianceCount int `json:",omitempty"` // 接続アプライアンス数
Scope EScope `json:",omitempty"` // スコープ
Subnet *Subnet `json:",omitempty"` // サブネット
UserSubnet *Subnet `json:",omitempty"` // ユーザー定義サブネット
Subnets []SwitchSubnet `json:",omitempty"` // サブネット
IPv6Nets []IPv6Net `json:",omitempty"` // IPv6サブネットリスト
Internet *Internet `json:",omitempty"` // ルーター
Bridge *struct { // 接続先ブリッジ(Info.Switches配下のIDデータ型HACK)
*Bridge // ブリッジ
Info *struct {
Switches []struct { // 接続スイッチリスト
*Switch // スイッチ
ID json.Number `json:",omitempty"` // HACK
}
}
} `json:",omitempty"`
//HybridConnection //REMARK: !!ハイブリッド接続 not support!!
}
// SwitchSubnet スイッチサブネット
type SwitchSubnet struct {
*Subnet
IPAddresses struct { // IPアドレス範囲
Min string `json:",omitempty"` // IPアドレス開始
Max string `json:",omitempty"` // IPアドレス終了
}
}
// GetDefaultIPAddressesForVPCRouter VPCルーター接続用にサブネットからIPアドレスを3つ取得
func (s *Switch) GetDefaultIPAddressesForVPCRouter() (string, string, string, error) {
if s.Subnets == nil || len(s.Subnets) < 1 {
return "", "", "", fmt.Errorf("switch[%d].Subnets is nil", s.ID)
}
baseAddress := net.ParseIP(s.Subnets[0].IPAddresses.Min).To4()
address1 := net.IPv4(baseAddress[0], baseAddress[1], baseAddress[2], baseAddress[3]+1)
address2 := net.IPv4(baseAddress[0], baseAddress[1], baseAddress[2], baseAddress[3]+2)
return baseAddress.String(), address1.String(), address2.String(), nil
}
// GetIPAddressList IPアドレス範囲内の全てのIPアドレスを取得
func (s *Switch) GetIPAddressList() ([]string, error) {
if s.Subnets == nil || len(s.Subnets) < 1 {
return nil, fmt.Errorf("switch[%d].Subnets is nil", s.ID)
}
//さくらのクラウドの仕様上/24までしか割り当てできないためこのロジックでOK
baseIP := net.ParseIP(s.Subnets[0].IPAddresses.Min).To4()
min := baseIP[3]
max := net.ParseIP(s.Subnets[0].IPAddresses.Max).To4()[3]
var i byte
ret := []string{}
for (min + i) <= max { //境界含む
ip := net.IPv4(baseIP[0], baseIP[1], baseIP[2], baseIP[3]+i)
ret = append(ret, ip.String())
i++
}
return ret, nil
}

View file

@ -0,0 +1,238 @@
package sacloud
import (
"fmt"
"net"
)
// VPCRouter VPCルーター
type VPCRouter struct {
*Appliance // アプライアンス共通属性
Remark *VPCRouterRemark `json:",omitempty"` // リマーク
Settings *VPCRouterSettings `json:",omitempty"` // VPCルーター設定リスト
}
// VPCRouterRemark リマーク
type VPCRouterRemark struct {
*ApplianceRemarkBase
// TODO Zone
//Zone *Resource
}
// VPCRouterSettings VPCルーター設定リスト
type VPCRouterSettings struct {
Router *VPCRouterSetting `json:",omitempty"` // VPCルーター設定
}
// CreateNewVPCRouter VPCルーター作成
func CreateNewVPCRouter() *VPCRouter {
return &VPCRouter{
Appliance: &Appliance{
Class: "vpcrouter",
propPlanID: propPlanID{Plan: &Resource{}},
},
Remark: &VPCRouterRemark{
ApplianceRemarkBase: &ApplianceRemarkBase{
Servers: []interface{}{""},
Switch: &ApplianceRemarkSwitch{},
},
},
Settings: &VPCRouterSettings{
Router: &VPCRouterSetting{},
},
}
}
// InitVPCRouterSetting VPCルーター設定初期化
func (v *VPCRouter) InitVPCRouterSetting() {
settings := &VPCRouterSettings{
Router: &VPCRouterSetting{},
}
if v.Settings != nil && v.Settings.Router != nil && v.Settings.Router.Interfaces != nil {
settings.Router.Interfaces = v.Settings.Router.Interfaces
}
if v.Settings != nil && v.Settings.Router != nil && v.Settings.Router.VRID != nil {
settings.Router.VRID = v.Settings.Router.VRID
}
v.Settings = settings
}
// IsStandardPlan スタンダードプランか判定
func (v *VPCRouter) IsStandardPlan() bool {
return v.Plan.ID == 1
}
// IsPremiumPlan プレミアムプランか判定
func (v *VPCRouter) IsPremiumPlan() bool {
return v.Plan.ID == 2
}
// IsHighSpecPlan ハイスペックプランか判定
func (v *VPCRouter) IsHighSpecPlan() bool {
return v.Plan.ID == 3
}
// SetStandardPlan スタンダードプランへ設定
func (v *VPCRouter) SetStandardPlan() {
v.Plan.SetID(1)
v.Remark.Switch = &ApplianceRemarkSwitch{
// Scope
propScope: propScope{Scope: "shared"},
}
v.Settings = nil
}
// SetPremiumPlan プレミアムプランへ設定
func (v *VPCRouter) SetPremiumPlan(switchID string, virtualIPAddress string, ipAddress1 string, ipAddress2 string, vrid int, ipAliases []string) {
v.Plan.SetID(2)
v.setPremiumServices(switchID, virtualIPAddress, ipAddress1, ipAddress2, vrid, ipAliases)
}
// SetHighSpecPlan ハイスペックプランへ設定
func (v *VPCRouter) SetHighSpecPlan(switchID string, virtualIPAddress string, ipAddress1 string, ipAddress2 string, vrid int, ipAliases []string) {
v.Plan.SetID(3)
v.setPremiumServices(switchID, virtualIPAddress, ipAddress1, ipAddress2, vrid, ipAliases)
}
func (v *VPCRouter) setPremiumServices(switchID string, virtualIPAddress string, ipAddress1 string, ipAddress2 string, vrid int, ipAliases []string) {
v.Remark.Switch = &ApplianceRemarkSwitch{
ID: switchID,
}
v.Remark.Servers = []interface{}{
map[string]string{"IPAddress": ipAddress1},
map[string]string{"IPAddress": ipAddress2},
}
v.Settings = &VPCRouterSettings{
Router: &VPCRouterSetting{
Interfaces: []*VPCRouterInterface{
{
IPAddress: []string{
ipAddress1,
ipAddress2,
},
VirtualIPAddress: virtualIPAddress,
IPAliases: ipAliases,
},
},
VRID: &vrid,
},
}
}
// HasSetting VPCルータ設定を保持しているか
func (v *VPCRouter) HasSetting() bool {
return v.Settings != nil && v.Settings.Router != nil
}
// HasInterfaces NIC設定を保持しているか
func (v *VPCRouter) HasInterfaces() bool {
return v.HasSetting() && v.Settings.Router.HasInterfaces()
}
// HasStaticNAT スタティックNAT設定を保持しているか
func (v *VPCRouter) HasStaticNAT() bool {
return v.HasSetting() && v.Settings.Router.HasStaticNAT()
}
// HasPortForwarding ポートフォワーディング設定を保持しているか
func (v *VPCRouter) HasPortForwarding() bool {
return v.HasSetting() && v.Settings.Router.HasPortForwarding()
}
// HasFirewall ファイアウォール設定を保持しているか
func (v *VPCRouter) HasFirewall() bool {
return v.HasSetting() && v.Settings.Router.HasFirewall()
}
// HasDHCPServer DHCPサーバー設定を保持しているか
func (v *VPCRouter) HasDHCPServer() bool {
return v.HasSetting() && v.Settings.Router.HasDHCPServer()
}
// HasDHCPStaticMapping DHCPスタティックマッピング設定を保持しているか
func (v *VPCRouter) HasDHCPStaticMapping() bool {
return v.HasSetting() && v.Settings.Router.HasDHCPStaticMapping()
}
// HasL2TPIPsecServer L2TP/IPSecサーバを保持しているか
func (v *VPCRouter) HasL2TPIPsecServer() bool {
return v.HasSetting() && v.Settings.Router.HasL2TPIPsecServer()
}
// HasPPTPServer PPTPサーバを保持しているか
func (v *VPCRouter) HasPPTPServer() bool {
return v.HasSetting() && v.Settings.Router.HasPPTPServer()
}
// HasRemoteAccessUsers リモートアクセスユーザー設定を保持しているか
func (v *VPCRouter) HasRemoteAccessUsers() bool {
return v.HasSetting() && v.Settings.Router.HasRemoteAccessUsers()
}
// HasSiteToSiteIPsecVPN サイト間VPN設定を保持しているか
func (v *VPCRouter) HasSiteToSiteIPsecVPN() bool {
return v.HasSetting() && v.Settings.Router.HasSiteToSiteIPsecVPN()
}
// HasStaticRoutes スタティックルートを保持しているか
func (v *VPCRouter) HasStaticRoutes() bool {
return v.HasSetting() && v.Settings.Router.HasStaticRoutes()
}
// RealIPAddress プランに応じて外部向けIPアドレスを返す
//
// Standard: IPAddress1
// Other: VirtualIPAddress
func (v *VPCRouter) RealIPAddress(index int) (string, int) {
if !v.HasInterfaces() {
return "", -1
}
for i, nic := range v.Settings.Router.Interfaces {
if i == index {
if index > 0 && nic == nil {
return "", -1
}
if index == 0 && v.IsStandardPlan() {
return v.Interfaces[0].IPAddress, v.Interfaces[0].Switch.Subnet.NetworkMaskLen
}
nwMask := nic.NetworkMaskLen
if index == 0 {
nwMask = v.Interfaces[0].Switch.Subnet.NetworkMaskLen
}
if v.IsStandardPlan() {
return nic.IPAddress[0], nwMask
}
return nic.VirtualIPAddress, nwMask
}
}
return "", -1
}
// FindBelongsInterface 指定のIPアドレスが所属するIPレンジを持つインターフェースを取得
func (v *VPCRouter) FindBelongsInterface(ip net.IP) (int, *VPCRouterInterface) {
if !v.HasInterfaces() {
return -1, nil
}
for i, nic := range v.Settings.Router.Interfaces {
nicIP, maskLen := v.RealIPAddress(i)
if nicIP != "" {
_, ipv4Net, err := net.ParseCIDR(fmt.Sprintf("%s/%d", nicIP, maskLen))
if err != nil {
return -1, nil
}
if ipv4Net.Contains(ip) {
return i, nic
}
}
}
return -1, nil
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
package sacloud
// VPCRouterStatus VPCルータのステータス情報
type VPCRouterStatus struct {
FirewallReceiveLogs []string
FirewallSendLogs []string
VPNLogs []string
}

View file

@ -0,0 +1,201 @@
package sacloud
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
// EWebAccelDomainType ウェブアクセラレータ ドメイン種別
type EWebAccelDomainType string
const (
// EWebAccelDomainTypeOwn 独自ドメイン
EWebAccelDomainTypeOwn = EWebAccelDomainType("own_domain")
// EWebAccelDomainTypeSubDomain サブドメイン
EWebAccelDomainTypeSubDomain = EWebAccelDomainType("subdomain")
)
// EWebAccelStatus ウェブアクセラレータ ステータス
type EWebAccelStatus string
const (
// EWebAccelStatusEnabled 状態:有効
EWebAccelStatusEnabled = EWebAccelStatus("enabled")
// EWebAccelStatusDisabled 状態:無効
EWebAccelStatusDisabled = EWebAccelStatus("disabled")
)
// WebAccelSite ウェブアクセラレータ サイト
type WebAccelSite struct {
ID string // ID
Name string `json:",omitempty"`
DomainType EWebAccelDomainType `json:",omitempty"`
Domain string `json:",omitempty"`
Subdomain string `json:",omitempty"`
ASCIIDomain string `json:",omitempty"`
Origin string `json:",omitempty"`
HostHeader string
Status EWebAccelStatus `json:",omitempty"`
HasCertificate bool `json:",omitempty"`
HasOldCertificate bool `json:",omitempty"`
GibSentInLastWeek int64 `json:",omitempty"`
CertValidNotBefore int64 `json:",omitempty"`
CertValidNotAfter int64 `json:",omitempty"`
propCreatedAt
}
// SetID ID 設定
func (n *WebAccelSite) SetID(id int64) {
n.ID = fmt.Sprintf("%d", id)
}
// GetID ID 取得
func (n *WebAccelSite) GetID() int64 {
if n == nil {
return -1
}
i, err := strconv.ParseInt(n.ID, 10, 64)
if err != nil {
return -1
}
return i
}
// GetStrID 文字列でID取得
func (n *WebAccelSite) GetStrID() string {
if n == nil {
return ""
}
return n.ID
}
// GetName 名称取得
func (n *WebAccelSite) GetName() string {
if n == nil {
return ""
}
return n.Name
}
// SetName 名称取得
func (n *WebAccelSite) SetName(name string) {
if n == nil {
return
}
n.Name = name
}
// WebAccelCert ウェブアクセラレータ証明書
type WebAccelCert struct {
ID string `json:",omitempty"`
SiteID string `json:",omitempty"`
CertificateChain string `json:",omitempty"`
Key string `json:",omitempty"`
propCreatedAt `json:",omitempty"`
propUpdatedAt `json:",omitempty"`
SerialNumber string `json:",omitempty"`
NotBefore int64 `json:",omitempty"`
NotAfter int64 `json:",omitempty"`
Issuer *struct {
Country string `json:",omitempty"`
Organization string `json:",omitempty"`
OrganizationalUnit string `json:",omitempty"`
CommonName string `json:",omitempty"`
} `json:",omitempty"`
Subject *struct {
Country string `json:",omitempty"`
Organization string `json:",omitempty"`
OrganizationalUnit string `json:",omitempty"`
Locality string `json:",omitempty"`
Province string `json:",omitempty"`
StreetAddress string `json:",omitempty"`
PostalCode string `json:",omitempty"`
SerialNumber string `json:",omitempty"`
CommonName string `json:",omitempty"`
} `json:",omitempty"`
DNSNames []string `json:",omitempty"`
SHA256Fingerprint string `json:",omitempty"`
}
// SetID ID 設定
func (n *WebAccelCert) SetID(id int64) {
n.ID = fmt.Sprintf("%d", id)
}
// GetID ID 取得
func (n *WebAccelCert) GetID() int64 {
if n == nil {
return -1
}
i, err := strconv.ParseInt(n.ID, 10, 64)
if err != nil {
return -1
}
return i
}
// GetStrID 文字列でID取得
func (n *WebAccelCert) GetStrID() string {
if n == nil {
return ""
}
return n.ID
}
// WebAccelCertRequest ウェブアクセラレータ証明書API リクエスト
type WebAccelCertRequest struct {
CertificateChain string
Key string `json:",omitempty"`
}
// WebAccelCertResponse ウェブアクセラレータ証明書API レスポンス
type WebAccelCertResponse struct {
Certificate *WebAccelCertResponseBody `json:",omitempty"`
ResultFlagValue
}
// WebAccelCertResponseBody ウェブアクセラレータ証明書API レスポンスボディ
type WebAccelCertResponseBody struct {
Current *WebAccelCert `json:",omitempty"`
Old []*WebAccelCert `json:",omitempty"`
}
// UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
func (s *WebAccelCertResponse) UnmarshalJSON(data []byte) error {
tmp := &struct {
Certificate *WebAccelCertResponseBody `json:",omitempty"`
ResultFlagValue
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
if tmp.Certificate.Current != nil || len(tmp.Certificate.Old) > 0 {
s.Certificate = tmp.Certificate
}
s.ResultFlagValue = tmp.ResultFlagValue
return nil
}
// UnmarshalJSON JSONアンマーシャル(配列、オブジェクトが混在するためここで対応)
func (s *WebAccelCertResponseBody) UnmarshalJSON(data []byte) error {
targetData := strings.Replace(strings.Replace(string(data), " ", "", -1), "\n", "", -1)
if targetData == `[]` {
return nil
}
tmp := &struct {
Current *WebAccelCert `json:",omitempty"`
Old []*WebAccelCert `json:",omitempty"`
}{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
s.Current = tmp.Current
s.Old = tmp.Old
return nil
}

46
vendor/github.com/sacloud/libsacloud/sacloud/zone.go generated vendored Normal file
View file

@ -0,0 +1,46 @@
package sacloud
// Zone ゾーン
type Zone struct {
*Resource // ID
propName // 名称
propDescription // 説明
propRegion // リージョン
IsDummy bool `json:",omitempty"` // IsDummy ダミーフラグ
VNCProxy struct { // VNCProxy VPCプロキシ
HostName string `json:",omitempty"` // HostName ホスト名
IPAddress string `json:",omitempty"` // IPAddress IPアドレス
} `json:",omitempty"`
FTPServer struct { // FTPServer FTPサーバー
HostName string `json:",omitempty"` // HostName ホスト名
IPAddress string `json:",omitempty"` // IPAddress IPアドレス
} `json:",omitempty"`
}
// ZoneIsDummy ダミーフラグ 取得
func (z *Zone) ZoneIsDummy() bool {
return z.IsDummy
}
// GetVNCProxyHostName VNCプロキシホスト名 取得
func (z *Zone) GetVNCProxyHostName() string {
return z.VNCProxy.HostName
}
// GetVPCProxyIPAddress VNCプロキシIPアドレス 取得
func (z *Zone) GetVPCProxyIPAddress() string {
return z.VNCProxy.IPAddress
}
// GetFTPHostName FTPサーバーホスト名 取得
func (z *Zone) GetFTPHostName() string {
return z.FTPServer.HostName
}
// GetFTPServerIPAddress FTPサーバーIPアドレス 取得
func (z *Zone) GetFTPServerIPAddress() string {
return z.FTPServer.IPAddress
}