github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/disk/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 disk 16 17 import ( 18 "context" 19 20 "github.com/sacloud/libsacloud/v2/sacloud" 21 "github.com/sacloud/libsacloud/v2/sacloud/types" 22 ) 23 24 // APIClient builderが利用するAPIクライアント群 25 type APIClient struct { 26 Archive ArchiveFinder 27 Disk CreateDiskHandler 28 DiskPlan PlanReader 29 Note NoteHandler 30 SSHKey SSHKeyHandler 31 } 32 33 // ArchiveFinder アーカイブ検索のためのインターフェース 34 type ArchiveFinder interface { 35 Find(ctx context.Context, zone string, conditions *sacloud.FindCondition) (*sacloud.ArchiveFindResult, error) 36 Read(ctx context.Context, zone string, id types.ID) (*sacloud.Archive, error) 37 } 38 39 // CreateDiskHandler ディスク操作のためのインターフェース 40 type CreateDiskHandler interface { 41 Create(ctx context.Context, zone string, createParam *sacloud.DiskCreateRequest, distantFrom []types.ID) (*sacloud.Disk, error) 42 CreateWithConfig( 43 ctx context.Context, 44 zone string, 45 createParam *sacloud.DiskCreateRequest, 46 editParam *sacloud.DiskEditRequest, 47 bootAtAvailable bool, 48 distantFrom []types.ID, 49 ) (*sacloud.Disk, error) 50 Update(ctx context.Context, zone string, id types.ID, updateParam *sacloud.DiskUpdateRequest) (*sacloud.Disk, error) 51 Config(ctx context.Context, zone string, id types.ID, editParam *sacloud.DiskEditRequest) error 52 Read(ctx context.Context, zone string, id types.ID) (*sacloud.Disk, error) 53 ConnectToServer(ctx context.Context, zone string, id types.ID, serverID types.ID) error 54 } 55 56 // PlanReader ディスクプラン取得のためのインターフェース 57 type PlanReader interface { 58 Read(ctx context.Context, zone string, id types.ID) (*sacloud.DiskPlan, error) 59 } 60 61 // NoteHandler スタートアップスクリプト参照のためのインターフェース 62 type NoteHandler interface { 63 Read(ctx context.Context, id types.ID) (*sacloud.Note, error) 64 Create(ctx context.Context, param *sacloud.NoteCreateRequest) (*sacloud.Note, error) 65 Delete(ctx context.Context, id types.ID) error 66 } 67 68 // SSHKeyHandler SSHKey参照のためのインターフェース 69 type SSHKeyHandler interface { 70 Read(ctx context.Context, id types.ID) (*sacloud.SSHKey, error) 71 Generate(ctx context.Context, param *sacloud.SSHKeyGenerateRequest) (*sacloud.SSHKeyGenerated, error) 72 Delete(ctx context.Context, id types.ID) error 73 } 74 75 // NewBuildersAPIClient APIクライアントの作成 76 func NewBuildersAPIClient(caller sacloud.APICaller) *APIClient { 77 return &APIClient{ 78 Archive: sacloud.NewArchiveOp(caller), 79 Disk: sacloud.NewDiskOp(caller), 80 DiskPlan: sacloud.NewDiskPlanOp(caller), 81 Note: sacloud.NewNoteOp(caller), 82 SSHKey: sacloud.NewSSHKeyOp(caller), 83 } 84 }