github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/vpcrouter/create_standard_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 vpcrouter
    16  
    17  import (
    18  	"github.com/sacloud/libsacloud/v2/helper/validate"
    19  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    20  )
    21  
    22  type CreateStandardRequest struct {
    23  	Zone string `request:"-" validate:"required"`
    24  
    25  	Name        string `validate:"required"`
    26  	Description string `validate:"min=0,max=512"`
    27  	Tags        types.Tags
    28  	IconID      types.ID
    29  
    30  	Version int
    31  
    32  	AdditionalNICSettings []*AdditionalStandardNICSetting
    33  	RouterSetting         *RouterSetting
    34  	NoWait                bool
    35  	BootAfterCreate       bool
    36  }
    37  
    38  func (req *CreateStandardRequest) Validate() error {
    39  	return validate.Struct(req)
    40  }
    41  
    42  func (req *CreateStandardRequest) ApplyRequest() *ApplyRequest {
    43  	var additionalNICs []AdditionalNICSettingHolder
    44  	for _, nic := range req.AdditionalNICSettings {
    45  		additionalNICs = append(additionalNICs, nic)
    46  	}
    47  	return &ApplyRequest{
    48  		Zone:                  req.Zone,
    49  		Name:                  req.Name,
    50  		Description:           req.Description,
    51  		Tags:                  req.Tags,
    52  		IconID:                req.IconID,
    53  		PlanID:                types.VPCRouterPlans.Standard,
    54  		Version:               req.Version,
    55  		NICSetting:            &StandardNICSetting{},
    56  		AdditionalNICSettings: additionalNICs,
    57  		RouterSetting:         req.RouterSetting,
    58  		NoWait:                req.NoWait,
    59  		BootAfterCreate:       req.BootAfterCreate,
    60  	}
    61  }