github.com/sacloud/iaas-api-go@v1.12.0/fake/ops_auto_scale.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 fake 16 17 import ( 18 "context" 19 20 "github.com/sacloud/iaas-api-go" 21 "github.com/sacloud/iaas-api-go/types" 22 ) 23 24 // Find is fake implementation 25 func (o *AutoScaleOp) Find(ctx context.Context, conditions *iaas.FindCondition) (*iaas.AutoScaleFindResult, error) { 26 results, _ := find(o.key, iaas.APIDefaultZone, conditions) 27 var values []*iaas.AutoScale 28 for _, res := range results { 29 dest := &iaas.AutoScale{} 30 copySameNameField(res, dest) 31 values = append(values, dest) 32 } 33 return &iaas.AutoScaleFindResult{ 34 Total: len(results), 35 Count: len(results), 36 From: 0, 37 AutoScale: values, 38 }, nil 39 } 40 41 // Create is fake implementation 42 func (o *AutoScaleOp) Create(ctx context.Context, param *iaas.AutoScaleCreateRequest) (*iaas.AutoScale, error) { 43 result := &iaas.AutoScale{} 44 copySameNameField(param, result) 45 fill(result, fillID, fillCreatedAt) 46 result.Availability = types.Availabilities.Available 47 48 // TODO core logic is not implemented 49 50 putAutoScale(iaas.APIDefaultZone, result) 51 return result, nil 52 } 53 54 // Read is fake implementation 55 func (o *AutoScaleOp) Read(ctx context.Context, id types.ID) (*iaas.AutoScale, error) { 56 value := getAutoScaleByID(iaas.APIDefaultZone, id) 57 if value == nil { 58 return nil, newErrorNotFound(o.key, id) 59 } 60 dest := &iaas.AutoScale{} 61 copySameNameField(value, dest) 62 return dest, nil 63 } 64 65 // Update is fake implementation 66 func (o *AutoScaleOp) Update(ctx context.Context, id types.ID, param *iaas.AutoScaleUpdateRequest) (*iaas.AutoScale, error) { 67 value, err := o.Read(ctx, id) 68 if err != nil { 69 return nil, err 70 } 71 copySameNameField(param, value) 72 fill(value, fillModifiedAt) 73 74 putAutoScale(iaas.APIDefaultZone, value) 75 return value, nil 76 } 77 78 // UpdateSettings is fake implementation 79 func (o *AutoScaleOp) UpdateSettings(ctx context.Context, id types.ID, param *iaas.AutoScaleUpdateSettingsRequest) (*iaas.AutoScale, error) { 80 value, err := o.Read(ctx, id) 81 if err != nil { 82 return nil, err 83 } 84 copySameNameField(param, value) 85 fill(value, fillModifiedAt) 86 87 putAutoScale(iaas.APIDefaultZone, value) 88 return value, nil 89 } 90 91 // Delete is fake implementation 92 func (o *AutoScaleOp) Delete(ctx context.Context, id types.ID) error { 93 _, err := o.Read(ctx, id) 94 if err != nil { 95 return err 96 } 97 98 ds().Delete(o.key, iaas.APIDefaultZone, id) 99 return nil 100 } 101 102 func (o *AutoScaleOp) Status(ctx context.Context, id types.ID) (*iaas.AutoScaleStatus, error) { 103 _, err := o.Read(ctx, id) 104 if err != nil { 105 return nil, err 106 } 107 108 return &iaas.AutoScaleStatus{ 109 LatestLogs: []string{"log1", "log2"}, 110 ResourcesText: "...", 111 }, nil 112 } 113 114 func (o *AutoScaleOp) ScaleUp(ctx context.Context, id types.ID) error { 115 return nil 116 } 117 118 func (o *AutoScaleOp) ScaleDown(ctx context.Context, id types.ID) error { 119 return nil 120 }