github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/disk/create_request.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 "fmt" 19 20 "github.com/sacloud/libsacloud/v2/helper/validate" 21 "github.com/sacloud/libsacloud/v2/sacloud/ostype" 22 "github.com/sacloud/libsacloud/v2/sacloud/types" 23 ) 24 25 // CreateRequest ディスク作成リクエスト 26 type CreateRequest struct { 27 Zone string `request:"-" validate:"required"` 28 29 Name string `validate:"required"` 30 Description string `validate:"min=0,max=512"` 31 Tags types.Tags 32 IconID types.ID 33 DiskPlanID types.ID `validate:"oneof=4 2"` 34 Connection types.EDiskConnection `validate:"oneof=virtio ide"` 35 SourceDiskID types.ID 36 SourceArchiveID types.ID 37 ServerID types.ID 38 SizeGB int `request:"SizeMB,filters=gb_to_mb"` 39 DistantFrom []types.ID 40 OSType ostype.ArchiveOSType 41 EditParameter *EditParameter 42 43 NoWait bool 44 } 45 46 func (req *CreateRequest) Validate() error { 47 if req.OSType != ostype.Custom { 48 if !req.SourceDiskID.IsEmpty() || !req.SourceArchiveID.IsEmpty() { 49 return fmt.Errorf("SourceDiskID or SourceArchiveID must be empty if OSType has a value") 50 } 51 } 52 return validate.Struct(req) 53 } 54 55 func (req *CreateRequest) ApplyRequest() *ApplyRequest { 56 return &ApplyRequest{ 57 Zone: req.Zone, 58 Name: req.Name, 59 Description: req.Description, 60 Tags: req.Tags, 61 IconID: req.IconID, 62 DiskPlanID: req.DiskPlanID, 63 Connection: req.Connection, 64 SourceDiskID: req.SourceArchiveID, 65 SourceArchiveID: req.SourceArchiveID, 66 ServerID: req.ServerID, 67 SizeGB: req.SizeGB, 68 DistantFrom: req.DistantFrom, 69 OSType: req.OSType, 70 EditParameter: req.EditParameter, 71 NoWait: req.NoWait, 72 } 73 }