github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/disk/apply_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  	diskBuilder "github.com/sacloud/libsacloud/v2/helper/builder/disk"
    19  	"github.com/sacloud/libsacloud/v2/helper/service"
    20  	"github.com/sacloud/libsacloud/v2/helper/validate"
    21  	"github.com/sacloud/libsacloud/v2/sacloud"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/ostype"
    23  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    24  )
    25  
    26  type ApplyRequest struct {
    27  	Zone string   `request:"-" validate:"required"`
    28  	ID   types.ID `request:"-"` // TODO Builderを更新対応させる(変更できない値の場合はエラーにするとか)
    29  
    30  	Name            string `validate:"required"`
    31  	Description     string `validate:"min=0,max=512"`
    32  	Tags            types.Tags
    33  	IconID          types.ID
    34  	DiskPlanID      types.ID
    35  	Connection      types.EDiskConnection
    36  	SourceDiskID    types.ID
    37  	SourceArchiveID types.ID
    38  	ServerID        types.ID
    39  	SizeGB          int
    40  	DistantFrom     []types.ID
    41  
    42  	OSType        ostype.ArchiveOSType
    43  	EditParameter *EditParameter
    44  
    45  	NoWait bool
    46  }
    47  
    48  // EditParameter ディスクの修正用パラメータ
    49  type EditParameter struct {
    50  	HostName string
    51  	Password string
    52  
    53  	DisablePWAuth       bool
    54  	EnableDHCP          bool
    55  	ChangePartitionUUID bool
    56  
    57  	IPAddress      string
    58  	NetworkMaskLen int
    59  	DefaultRoute   string
    60  
    61  	SSHKeys   []string
    62  	SSHKeyIDs []types.ID
    63  
    64  	// IsSSHKeysEphemeral trueの場合、SSHキーを生成する場合に生成したSSHキーリソースをサーバ作成後に削除する
    65  	IsSSHKeysEphemeral bool
    66  
    67  	IsNotesEphemeral bool
    68  	NoteContents     []string
    69  	Notes            []*sacloud.DiskEditNote
    70  }
    71  
    72  func (req *ApplyRequest) Validate() error {
    73  	return validate.Struct(req)
    74  }
    75  
    76  func (req *ApplyRequest) Builder(caller sacloud.APICaller) (diskBuilder.Builder, error) {
    77  	var editParameter *diskBuilder.EditRequest
    78  
    79  	if req.EditParameter != nil {
    80  		editParameter = &diskBuilder.EditRequest{}
    81  		if err := service.RequestConvertTo(req.EditParameter, editParameter); err != nil {
    82  			return nil, err
    83  		}
    84  	}
    85  
    86  	director := &diskBuilder.Director{
    87  		OSType:          req.OSType,
    88  		Name:            req.Name,
    89  		SizeGB:          req.SizeGB,
    90  		DistantFrom:     req.DistantFrom,
    91  		PlanID:          req.DiskPlanID,
    92  		Connection:      req.Connection,
    93  		Description:     req.Description,
    94  		Tags:            req.Tags,
    95  		IconID:          req.IconID,
    96  		DiskID:          req.ID,
    97  		SourceDiskID:    req.SourceDiskID,
    98  		SourceArchiveID: req.SourceArchiveID,
    99  		EditParameter:   editParameter,
   100  		NoWait:          req.NoWait,
   101  		Client:          diskBuilder.NewBuildersAPIClient(caller),
   102  	}
   103  	return director.Builder(), nil
   104  }