github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/server/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 server
    16  
    17  import (
    18  	diskService "github.com/sacloud/libsacloud/v2/helper/service/disk"
    19  	"github.com/sacloud/libsacloud/v2/helper/validate"
    20  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    21  )
    22  
    23  type CreateRequest struct {
    24  	Zone string `request:"-" validate:"required"`
    25  
    26  	Name            string `validate:"required"`
    27  	Description     string `validate:"min=0,max=512"`
    28  	Tags            types.Tags
    29  	IconID          types.ID
    30  	CPU             int
    31  	MemoryGB        int
    32  	GPU             int
    33  	Commitment      types.ECommitment
    34  	Generation      types.EPlanGeneration
    35  	InterfaceDriver types.EInterfaceDriver
    36  
    37  	BootAfterCreate bool
    38  	CDROMID         types.ID
    39  	PrivateHostID   types.ID
    40  
    41  	NetworkInterfaces []*NetworkInterface
    42  	Disks             []*diskService.ApplyRequest
    43  	NoWait            bool
    44  }
    45  
    46  func (req *CreateRequest) Validate() error {
    47  	return validate.Struct(req)
    48  }
    49  
    50  func (req *CreateRequest) ApplyRequest() *ApplyRequest {
    51  	return &ApplyRequest{
    52  		Zone:              req.Zone,
    53  		Name:              req.Name,
    54  		Description:       req.Description,
    55  		Tags:              req.Tags,
    56  		IconID:            req.IconID,
    57  		CPU:               req.CPU,
    58  		MemoryGB:          req.MemoryGB,
    59  		GPU:               req.GPU,
    60  		Commitment:        req.Commitment,
    61  		Generation:        req.Generation,
    62  		InterfaceDriver:   req.InterfaceDriver,
    63  		BootAfterCreate:   req.BootAfterCreate,
    64  		CDROMID:           req.CDROMID,
    65  		PrivateHostID:     req.PrivateHostID,
    66  		NetworkInterfaces: req.NetworkInterfaces,
    67  		Disks:             req.Disks,
    68  		NoWait:            req.NoWait,
    69  	}
    70  }