github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/server/api_client.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 server 16 17 import ( 18 "context" 19 20 "github.com/sacloud/libsacloud/v2/helper/query" 21 "github.com/sacloud/libsacloud/v2/sacloud" 22 "github.com/sacloud/libsacloud/v2/sacloud/types" 23 ) 24 25 // APIClient builderが利用するAPIクライアント群 26 type APIClient struct { 27 Disk DiskHandler 28 Interface InterfaceHandler 29 PacketFilter PacketFilterReader 30 Server CreateServerHandler 31 ServerPlan query.ServerPlanFinder 32 Switch SwitchReader 33 } 34 35 // DiskHandler ディスクの接続/切断のためのインターフェース 36 type DiskHandler interface { 37 ConnectToServer(ctx context.Context, zone string, id types.ID, serverID types.ID) error 38 DisconnectFromServer(ctx context.Context, zone string, id types.ID) error 39 } 40 41 // SwitchReader スイッチ参照のためのインターフェース 42 type SwitchReader interface { 43 Read(ctx context.Context, zone string, id types.ID) (*sacloud.Switch, error) 44 } 45 46 // InterfaceHandler NIC操作のためのインターフェース 47 type InterfaceHandler interface { 48 Create(ctx context.Context, zone string, param *sacloud.InterfaceCreateRequest) (*sacloud.Interface, error) 49 Update(ctx context.Context, zone string, id types.ID, param *sacloud.InterfaceUpdateRequest) (*sacloud.Interface, error) 50 Delete(ctx context.Context, zone string, id types.ID) error 51 ConnectToSharedSegment(ctx context.Context, zone string, id types.ID) error 52 ConnectToSwitch(ctx context.Context, zone string, id types.ID, switchID types.ID) error 53 DisconnectFromSwitch(ctx context.Context, zone string, id types.ID) error 54 ConnectToPacketFilter(ctx context.Context, zone string, id types.ID, packetFilterID types.ID) error 55 DisconnectFromPacketFilter(ctx context.Context, zone string, id types.ID) error 56 } 57 58 // PacketFilterReader パケットフィルタ参照のためのインターフェース 59 type PacketFilterReader interface { 60 Read(ctx context.Context, zone string, id types.ID) (*sacloud.PacketFilter, error) 61 } 62 63 // CreateServerHandler サーバ操作のためのインターフェース 64 type CreateServerHandler interface { 65 Create(ctx context.Context, zone string, param *sacloud.ServerCreateRequest) (*sacloud.Server, error) 66 Update(ctx context.Context, zone string, id types.ID, param *sacloud.ServerUpdateRequest) (*sacloud.Server, error) 67 Read(ctx context.Context, zone string, id types.ID) (*sacloud.Server, error) 68 InsertCDROM(ctx context.Context, zone string, id types.ID, insertParam *sacloud.InsertCDROMRequest) error 69 EjectCDROM(ctx context.Context, zone string, id types.ID, ejectParam *sacloud.EjectCDROMRequest) error 70 Boot(ctx context.Context, zone string, id types.ID) error 71 BootWithVariables(ctx context.Context, zone string, id types.ID, param *sacloud.ServerBootVariables) error 72 Shutdown(ctx context.Context, zone string, id types.ID, shutdownOption *sacloud.ShutdownOption) error 73 ChangePlan(ctx context.Context, zone string, id types.ID, plan *sacloud.ServerChangePlanRequest) (*sacloud.Server, error) 74 } 75 76 // NewBuildersAPIClient APIクライアントの作成 77 func NewBuildersAPIClient(caller sacloud.APICaller) *APIClient { 78 return &APIClient{ 79 Disk: sacloud.NewDiskOp(caller), 80 Interface: sacloud.NewInterfaceOp(caller), 81 PacketFilter: sacloud.NewPacketFilterOp(caller), 82 Server: sacloud.NewServerOp(caller), 83 ServerPlan: sacloud.NewServerPlanOp(caller), 84 Switch: sacloud.NewSwitchOp(caller), 85 } 86 }