github.com/sacloud/iaas-api-go@v1.12.0/internal/define/ipaddress.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  	"net/http"
    19  
    20  	"github.com/sacloud/iaas-api-go/internal/define/names"
    21  	"github.com/sacloud/iaas-api-go/internal/dsl"
    22  	"github.com/sacloud/iaas-api-go/internal/dsl/meta"
    23  	"github.com/sacloud/iaas-api-go/naked"
    24  )
    25  
    26  const (
    27  	ipAPIName     = "IPAddress"
    28  	ipAPIPathName = "ipaddress"
    29  )
    30  
    31  var ipAPI = &dsl.Resource{
    32  	Name:       ipAPIName,
    33  	PathName:   ipAPIPathName,
    34  	PathSuffix: dsl.CloudAPISuffix,
    35  	Operations: dsl.Operations{
    36  		// find
    37  		{
    38  			ResourceName:     ipAPIName,
    39  			Name:             "List",
    40  			PathFormat:       dsl.DefaultPathFormat,
    41  			Method:           http.MethodGet,
    42  			UseWrappedResult: true,
    43  			ResponseEnvelope: dsl.ResponseEnvelopePlural(&dsl.EnvelopePayloadDesc{
    44  				Type: ipNakedType,
    45  				Name: ipAPIName,
    46  			}),
    47  			Results: dsl.Results{
    48  				{
    49  					SourceField: ipAPIName,
    50  					DestField:   names.ResourceFieldName(ipAPIName, dsl.PayloadForms.Plural),
    51  					IsPlural:    true,
    52  					Model:       ipView,
    53  				},
    54  			},
    55  		},
    56  		// read
    57  		{
    58  			ResourceName: ipAPIName,
    59  			Name:         "Read",
    60  			PathFormat:   dsl.DefaultPathFormat + "/{{.ipAddress}}",
    61  			Method:       http.MethodGet,
    62  			Arguments: dsl.Arguments{
    63  				{
    64  					Name: "ipAddress",
    65  					Type: meta.TypeString,
    66  				},
    67  			},
    68  			ResponseEnvelope: dsl.ResponseEnvelope(&dsl.EnvelopePayloadDesc{
    69  				Type: ipNakedType,
    70  				Name: ipAPIName,
    71  			}),
    72  			Results: dsl.Results{
    73  				{
    74  					SourceField: ipAPIName,
    75  					DestField:   ipAPIName,
    76  					IsPlural:    false,
    77  					Model:       ipView,
    78  				},
    79  			},
    80  		},
    81  
    82  		// set reverse
    83  		{
    84  			ResourceName: ipAPIName,
    85  			Name:         "UpdateHostName",
    86  			PathFormat:   dsl.DefaultPathFormat + "/{{.ipAddress}}",
    87  			Method:       http.MethodPut,
    88  			RequestEnvelope: dsl.RequestEnvelope(&dsl.EnvelopePayloadDesc{
    89  				Type: ipNakedType,
    90  				Name: ipAPIName,
    91  			}),
    92  			Arguments: dsl.Arguments{
    93  				{
    94  					Name: "ipAddress",
    95  					Type: meta.TypeString,
    96  				},
    97  				{
    98  					Name:       "hostName",
    99  					Type:       meta.TypeString,
   100  					MapConvTag: "IPAddress.HostName",
   101  				},
   102  			},
   103  			ResponseEnvelope: dsl.ResponseEnvelope(&dsl.EnvelopePayloadDesc{
   104  				Type: ipNakedType,
   105  				Name: ipAPIName,
   106  			}),
   107  			Results: dsl.Results{
   108  				{
   109  					SourceField: ipAPIName,
   110  					DestField:   ipAPIName,
   111  					IsPlural:    false,
   112  					Model:       ipView,
   113  				},
   114  			},
   115  		},
   116  	},
   117  }
   118  var (
   119  	ipNakedType = meta.Static(naked.IPAddress{})
   120  
   121  	ipView = &dsl.Model{
   122  		Name:      ipAPIName,
   123  		NakedType: ipNakedType,
   124  		Fields: []*dsl.FieldDesc{
   125  			fields.HostName(),
   126  			fields.IPAddress(),
   127  			fields.InterfaceID(),
   128  			fields.SubnetID(),
   129  			// Note: InterfaceとSubnetはIDにのみ対応。その他のフィールドは今後必要になったら対応を検討する。
   130  		},
   131  	}
   132  )