github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/disk/director.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 "github.com/sacloud/libsacloud/v2/sacloud/ostype" 19 "github.com/sacloud/libsacloud/v2/sacloud/types" 20 ) 21 22 // Director パラメータに応じて適切なDiskBuilderを構築する 23 type Director struct { 24 OSType ostype.ArchiveOSType 25 26 Name string 27 SizeGB int 28 DistantFrom []types.ID 29 PlanID types.ID 30 Connection types.EDiskConnection 31 Description string 32 Tags types.Tags 33 IconID types.ID 34 35 DiskID types.ID 36 SourceDiskID types.ID 37 SourceArchiveID types.ID 38 39 EditParameter *EditRequest 40 41 NoWait bool 42 Client *APIClient 43 } 44 45 // Builder パラメータに応じて適切なDiskBuilderを返す 46 func (d *Director) Builder() Builder { 47 switch { 48 case d.OSType == ostype.Custom: 49 switch { 50 case !d.DiskID.IsEmpty(): 51 return &ConnectedDiskBuilder{ 52 ID: d.DiskID, 53 Name: d.Name, 54 Description: d.Description, 55 Tags: d.Tags, 56 IconID: d.IconID, 57 Connection: d.Connection, 58 EditParameter: d.EditParameter.ToUnixDiskEditRequest(), 59 NoWait: d.NoWait, 60 Client: d.Client, 61 } 62 case !d.SourceDiskID.IsEmpty(), !d.SourceArchiveID.IsEmpty(): 63 return &FromDiskOrArchiveBuilder{ 64 SourceDiskID: d.SourceDiskID, 65 SourceArchiveID: d.SourceArchiveID, 66 Name: d.Name, 67 SizeGB: d.SizeGB, 68 DistantFrom: d.DistantFrom, 69 PlanID: d.PlanID, 70 Connection: d.Connection, 71 Description: d.Description, 72 Tags: d.Tags, 73 IconID: d.IconID, 74 EditParameter: d.EditParameter.ToUnixDiskEditRequest(), 75 NoWait: d.NoWait, 76 Client: d.Client, 77 } 78 default: 79 return &BlankBuilder{ 80 Name: d.Name, 81 SizeGB: d.SizeGB, 82 DistantFrom: d.DistantFrom, 83 PlanID: d.PlanID, 84 Connection: d.Connection, 85 Description: d.Description, 86 Tags: d.Tags, 87 IconID: d.IconID, 88 NoWait: d.NoWait, 89 Client: d.Client, 90 } 91 } 92 case d.OSType.IsSupportDiskEdit(): 93 return &FromUnixBuilder{ 94 OSType: d.OSType, 95 Name: d.Name, 96 SizeGB: d.SizeGB, 97 DistantFrom: d.DistantFrom, 98 PlanID: d.PlanID, 99 Connection: d.Connection, 100 Description: d.Description, 101 Tags: d.Tags, 102 IconID: d.IconID, 103 EditParameter: d.EditParameter.ToUnixDiskEditRequest(), 104 NoWait: d.NoWait, 105 Client: d.Client, 106 } 107 case d.OSType.IsWindows(): 108 return &FromWindowsBuilder{ 109 OSType: d.OSType, 110 Name: d.Name, 111 SizeGB: d.SizeGB, 112 DistantFrom: d.DistantFrom, 113 PlanID: d.PlanID, 114 Connection: d.Connection, 115 Description: d.Description, 116 Tags: d.Tags, 117 IconID: d.IconID, 118 EditParameter: d.EditParameter.ToWindowsDiskEditRequest(), 119 NoWait: d.NoWait, 120 Client: d.Client, 121 } 122 default: 123 // 現在はOSTypeにディスクの修正不可のアーカイブはないためここには到達しない 124 return &FromFixedArchiveBuilder{ 125 OSType: d.OSType, 126 Name: d.Name, 127 SizeGB: d.SizeGB, 128 DistantFrom: d.DistantFrom, 129 PlanID: d.PlanID, 130 Connection: d.Connection, 131 Description: d.Description, 132 Tags: d.Tags, 133 IconID: d.IconID, 134 NoWait: d.NoWait, 135 Client: d.Client, 136 } 137 } 138 }