github.com/sacloud/iaas-api-go@v1.12.0/internal/define/nfs.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  	nfsAPIName     = "NFS"
    27  	nfsAPIPathName = "appliance"
    28  )
    29  
    30  var nfsAPI = &dsl.Resource{
    31  	Name:       nfsAPIName,
    32  	PathName:   nfsAPIPathName,
    33  	PathSuffix: dsl.CloudAPISuffix,
    34  	Operations: dsl.Operations{
    35  		// find
    36  		ops.FindAppliance(nfsAPIName, nfsNakedType, findParameter, nfsView),
    37  
    38  		// create
    39  		ops.CreateAppliance(nfsAPIName, nfsNakedType, nfsCreateParam, nfsView),
    40  
    41  		// read
    42  		ops.ReadAppliance(nfsAPIName, nfsNakedType, nfsView),
    43  
    44  		// update
    45  		ops.UpdateAppliance(nfsAPIName, nfsNakedType, nfsUpdateParam, nfsView),
    46  
    47  		// delete
    48  		ops.Delete(nfsAPIName),
    49  
    50  		// power management(boot/shutdown/reset)
    51  		ops.Boot(nfsAPIName),
    52  		ops.Shutdown(nfsAPIName),
    53  		ops.Reset(nfsAPIName),
    54  
    55  		// monitor
    56  		ops.MonitorChild(nfsAPIName, "CPU", "cpu",
    57  			monitorParameter, monitors.cpuTimeModel()),
    58  		ops.MonitorChild(nfsAPIName, "FreeDiskSize", "database",
    59  			monitorParameter, monitors.freeDiskSizeModel()),
    60  		ops.MonitorChild(nfsAPIName, "Interface", "interface",
    61  			monitorParameter, monitors.interfaceModel()),
    62  	},
    63  }
    64  
    65  var (
    66  	nfsNakedType = meta.Static(naked.NFS{})
    67  
    68  	nfsView = &dsl.Model{
    69  		Name:      nfsAPIName,
    70  		NakedType: nfsNakedType,
    71  		Fields: []*dsl.FieldDesc{
    72  			fields.ID(),
    73  			fields.Name(),
    74  			fields.Description(),
    75  			fields.Tags(),
    76  			fields.Availability(),
    77  			fields.Class(),
    78  			// instance
    79  			fields.InstanceHostName(),
    80  			fields.InstanceHostInfoURL(),
    81  			fields.InstanceStatus(),
    82  			fields.InstanceStatusChangedAt(),
    83  			// interfaces
    84  			fields.Interfaces(),
    85  			// plan
    86  			fields.AppliancePlanID(),
    87  			// switch
    88  			fields.ApplianceSwitchID(),
    89  			// fields.Switch(),
    90  			// remark
    91  			fields.RemarkDefaultRoute(),
    92  			fields.RemarkNetworkMaskLen(),
    93  			fields.RemarkServerIPAddress(),
    94  			fields.RemarkZoneID(),
    95  			// other
    96  			fields.IconID(),
    97  			fields.CreatedAt(),
    98  			fields.ModifiedAt(),
    99  			fields.Def("SwitchName", meta.TypeString, mapConvTag("Switch.Name")),
   100  		},
   101  	}
   102  
   103  	nfsCreateParam = &dsl.Model{
   104  		Name:      names.CreateParameterName(nfsAPIName),
   105  		NakedType: nfsNakedType,
   106  		ConstFields: []*dsl.ConstFieldDesc{
   107  			{
   108  				Name:  "Class",
   109  				Type:  meta.TypeString,
   110  				Value: `"nfs"`,
   111  			},
   112  		},
   113  		Fields: []*dsl.FieldDesc{
   114  			fields.ApplianceSwitchID(),
   115  			fields.AppliancePlanID(),
   116  			fields.ApplianceIPAddresses(),
   117  			fields.RemarkNetworkMaskLen(),
   118  			fields.RemarkDefaultRoute(),
   119  			fields.Name(),
   120  			fields.Description(),
   121  			fields.Tags(),
   122  			fields.IconID(),
   123  		},
   124  	}
   125  
   126  	nfsUpdateParam = &dsl.Model{
   127  		Name:      names.UpdateParameterName(nfsAPIName),
   128  		NakedType: nfsNakedType,
   129  		Fields: []*dsl.FieldDesc{
   130  			fields.Name(),
   131  			fields.Description(),
   132  			fields.Tags(),
   133  			fields.IconID(),
   134  		},
   135  	}
   136  )