github.com/sacloud/iaas-api-go@v1.12.0/internal/define/subnet.go (about)

     1  // Copyright 2022-2023 The sacloud/iaas-api-go 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 define
    16  
    17  import (
    18  	"github.com/sacloud/iaas-api-go/internal/define/ops"
    19  	"github.com/sacloud/iaas-api-go/internal/dsl"
    20  	"github.com/sacloud/iaas-api-go/internal/dsl/meta"
    21  	"github.com/sacloud/iaas-api-go/naked"
    22  )
    23  
    24  const (
    25  	subnetAPIName     = "Subnet"
    26  	subnetAPIPathName = "subnet"
    27  )
    28  
    29  var subnetAPI = &dsl.Resource{
    30  	Name:       subnetAPIName,
    31  	PathName:   subnetAPIPathName,
    32  	PathSuffix: dsl.CloudAPISuffix,
    33  	Operations: dsl.Operations{
    34  		// find
    35  		ops.Find(subnetAPIName, subnetNakedType, findParameter, subnetView),
    36  		// read
    37  		ops.Read(subnetAPIName, subnetNakedType, subnetView),
    38  	},
    39  }
    40  var (
    41  	subnetNakedType = meta.Static(naked.Subnet{})
    42  
    43  	subnetView = &dsl.Model{
    44  		Name:      subnetAPIName,
    45  		NakedType: subnetNakedType,
    46  		Fields: []*dsl.FieldDesc{
    47  			fields.ID(),
    48  			fields.SwitchID(),
    49  			fields.Def("InternetID", meta.TypeID, mapConvTag("Switch.Internet.ID,omitempty")),
    50  			fields.DefaultRoute(),
    51  			fields.NextHop(),
    52  			fields.StaticRoute(),
    53  			fields.NetworkAddress(),
    54  			fields.NetworkMaskLen(),
    55  			{
    56  				Name: "IPAddresses",
    57  				Type: &dsl.Model{
    58  					Name:      "SubnetIPAddress",
    59  					NakedType: ipNakedType,
    60  					IsArray:   true,
    61  					Fields: []*dsl.FieldDesc{
    62  						fields.HostName(),
    63  						fields.IPAddress(),
    64  					},
    65  				},
    66  				Tags: mapConvTag("[]IPAddresses,recursive"),
    67  			},
    68  		},
    69  	}
    70  )