github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/vpcrouter/apply_nic_settings.go (about) 1 // Copyright 2016-2022 The Libsacloud Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package vpcrouter 16 17 import ( 18 "github.com/sacloud/libsacloud/v2/sacloud" 19 "github.com/sacloud/libsacloud/v2/sacloud/types" 20 ) 21 22 // NICSettingHolder VPCルータのeth0の設定 SharedNICSettingまたはRouterNICSettingを指定する 23 type NICSettingHolder interface { 24 connectedSwitch() *sacloud.ApplianceConnectedSwitch 25 ipAddresses() []string 26 interfaceSetting() *sacloud.VPCRouterInterfaceSetting 27 } 28 29 // StandardNICSetting VPCルータのeth0を共有セグメントに接続するためのSetting(スタンダードプラン) 30 type StandardNICSetting struct{} 31 32 func (s *StandardNICSetting) connectedSwitch() *sacloud.ApplianceConnectedSwitch { 33 return &sacloud.ApplianceConnectedSwitch{Scope: types.Scopes.Shared} 34 } 35 36 func (s *StandardNICSetting) ipAddresses() []string { 37 return nil 38 } 39 40 func (s *StandardNICSetting) interfaceSetting() *sacloud.VPCRouterInterfaceSetting { 41 return nil 42 } 43 44 // PremiumNICSetting VPCルータのeth0をスイッチ+ルータに接続するためのSetting(プレミアム/ハイスペックプラン) 45 type PremiumNICSetting struct { 46 SwitchID types.ID 47 IPAddresses []string 48 VirtualIPAddress string 49 IPAliases []string 50 } 51 52 func (s *PremiumNICSetting) connectedSwitch() *sacloud.ApplianceConnectedSwitch { 53 return &sacloud.ApplianceConnectedSwitch{ID: s.SwitchID} 54 } 55 56 func (s *PremiumNICSetting) ipAddresses() []string { 57 return s.IPAddresses 58 } 59 60 func (s *PremiumNICSetting) interfaceSetting() *sacloud.VPCRouterInterfaceSetting { 61 return &sacloud.VPCRouterInterfaceSetting{ 62 IPAddress: s.IPAddresses, 63 VirtualIPAddress: s.VirtualIPAddress, 64 IPAliases: s.IPAliases, 65 Index: 0, 66 } 67 } 68 69 // AdditionalNICSettingHolder VPCルータのeth1-eth7の設定 70 type AdditionalNICSettingHolder interface { 71 switchInfo() (switchID types.ID, index int) 72 interfaceSetting() *sacloud.VPCRouterInterfaceSetting 73 } 74 75 // AdditionalStandardNICSetting VPCルータのeth1-eth7の設定(スタンダードプラン向け) 76 type AdditionalStandardNICSetting struct { 77 SwitchID types.ID 78 IPAddress string 79 NetworkMaskLen int 80 Index int 81 } 82 83 func (s *AdditionalStandardNICSetting) switchInfo() (switchID types.ID, index int) { 84 return s.SwitchID, s.Index 85 } 86 87 func (s *AdditionalStandardNICSetting) interfaceSetting() *sacloud.VPCRouterInterfaceSetting { 88 return &sacloud.VPCRouterInterfaceSetting{ 89 IPAddress: []string{s.IPAddress}, 90 NetworkMaskLen: s.NetworkMaskLen, 91 Index: s.Index, 92 } 93 } 94 95 // AdditionalPremiumNICSetting VPCルータのeth1-eth7の設定(プレミアム/ハイスペックプラン向け) 96 type AdditionalPremiumNICSetting struct { 97 SwitchID types.ID 98 IPAddresses []string 99 VirtualIPAddress string 100 NetworkMaskLen int 101 Index int 102 } 103 104 func (s *AdditionalPremiumNICSetting) switchInfo() (switchID types.ID, index int) { 105 return s.SwitchID, s.Index 106 } 107 108 func (s *AdditionalPremiumNICSetting) interfaceSetting() *sacloud.VPCRouterInterfaceSetting { 109 return &sacloud.VPCRouterInterfaceSetting{ 110 IPAddress: s.IPAddresses, 111 VirtualIPAddress: s.VirtualIPAddress, 112 NetworkMaskLen: s.NetworkMaskLen, 113 Index: s.Index, 114 } 115 }