github.com/sacloud/iaas-api-go@v1.12.0/internal/define/private_host.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/names"
    19  	"github.com/sacloud/iaas-api-go/internal/define/ops"
    20  	"github.com/sacloud/iaas-api-go/internal/dsl"
    21  	"github.com/sacloud/iaas-api-go/internal/dsl/meta"
    22  	"github.com/sacloud/iaas-api-go/naked"
    23  )
    24  
    25  const (
    26  	privateHostAPIName     = "PrivateHost"
    27  	privateHostAPIPathName = "privatehost"
    28  )
    29  
    30  var privateHostAPI = &dsl.Resource{
    31  	Name:       privateHostAPIName,
    32  	PathName:   privateHostAPIPathName,
    33  	PathSuffix: dsl.CloudAPISuffix,
    34  	Operations: dsl.Operations{
    35  		// find
    36  		ops.Find(privateHostAPIName, privateHostNakedType, findParameter, privateHostView),
    37  
    38  		// create
    39  		ops.Create(privateHostAPIName, privateHostNakedType, privateHostCreateParam, privateHostView),
    40  
    41  		// read
    42  		ops.Read(privateHostAPIName, privateHostNakedType, privateHostView),
    43  
    44  		// update
    45  		ops.Update(privateHostAPIName, privateHostNakedType, privateHostUpdateParam, privateHostView),
    46  
    47  		// delete
    48  		ops.Delete(privateHostAPIName),
    49  	},
    50  }
    51  
    52  var (
    53  	privateHostNakedType = meta.Static(naked.PrivateHost{})
    54  
    55  	privateHostView = &dsl.Model{
    56  		Name:      privateHostAPIName,
    57  		NakedType: privateHostNakedType,
    58  		Fields: []*dsl.FieldDesc{
    59  			fields.ID(),
    60  			fields.Name(),
    61  			fields.Description(),
    62  			fields.Tags(),
    63  			fields.IconID(),
    64  			fields.CreatedAt(),
    65  			fields.PrivateHostPlanID(),
    66  			{
    67  				Name: "PlanName",
    68  				Type: meta.TypeString,
    69  				Tags: &dsl.FieldTags{
    70  					MapConv: "Plan.Name",
    71  				},
    72  			},
    73  			{
    74  				Name: "PlanClass",
    75  				Type: meta.TypeString,
    76  				Tags: &dsl.FieldTags{
    77  					MapConv: "Plan.Class",
    78  				},
    79  			},
    80  			{
    81  				Name: "CPU",
    82  				Type: meta.TypeInt,
    83  				Tags: &dsl.FieldTags{
    84  					MapConv: "Plan.CPU",
    85  				},
    86  			},
    87  			{
    88  				Name: "MemoryMB",
    89  				Type: meta.TypeInt,
    90  				Tags: &dsl.FieldTags{
    91  					MapConv: "Plan.MemoryMB",
    92  				},
    93  				Methods: []*dsl.MethodDesc{
    94  					{
    95  						Name:        "GetMemoryGB",
    96  						ResultTypes: []meta.Type{meta.TypeInt},
    97  					},
    98  					{
    99  						Name: "SetMemoryGB",
   100  						Arguments: dsl.Arguments{
   101  							{
   102  								Name: "memory",
   103  								Type: meta.TypeInt,
   104  							},
   105  						},
   106  					},
   107  				},
   108  			},
   109  			fields.Def("AssignedCPU", meta.TypeInt),
   110  			{
   111  				Name: "AssignedMemoryMB",
   112  				Type: meta.TypeInt,
   113  				Methods: []*dsl.MethodDesc{
   114  					{
   115  						Name:        "GetAssignedMemoryGB",
   116  						ResultTypes: []meta.Type{meta.TypeInt},
   117  					},
   118  					{
   119  						Name: "SetAssignedMemoryGB",
   120  						Arguments: dsl.Arguments{
   121  							{
   122  								Name: "memory",
   123  								Type: meta.TypeInt,
   124  							},
   125  						},
   126  					},
   127  				},
   128  			},
   129  			fields.PrivateHostHostName(),
   130  		},
   131  	}
   132  
   133  	privateHostCreateParam = &dsl.Model{
   134  		Name:      names.CreateParameterName(privateHostAPIName),
   135  		NakedType: privateHostNakedType,
   136  		Fields: []*dsl.FieldDesc{
   137  			fields.Name(),
   138  			fields.Description(),
   139  			fields.Tags(),
   140  			fields.IconID(),
   141  			fields.PrivateHostPlanID(),
   142  		},
   143  	}
   144  
   145  	privateHostUpdateParam = &dsl.Model{
   146  		Name:      names.UpdateParameterName(privateHostAPIName),
   147  		NakedType: privateHostNakedType,
   148  		Fields: []*dsl.FieldDesc{
   149  			fields.Name(),
   150  			fields.Description(),
   151  			fields.Tags(),
   152  			fields.IconID(),
   153  		},
   154  	}
   155  )