github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/icd/icdv4/scaling.go (about) 1 package icdv4 2 3 import ( 4 "fmt" 5 6 "github.com/IBM-Cloud/bluemix-go/client" 7 "github.com/IBM-Cloud/bluemix-go/utils" 8 ) 9 10 type GroupList struct { 11 Groups []Group `json:"groups"` 12 } 13 14 type Group struct { 15 Id string `json:"id"` 16 Count int `json:"count"` 17 Members Members `json:"members"` 18 Memory Memory `json:"memory"` 19 Cpu Cpu `json:"cpu"` 20 Disk Disk `json:"disk"` 21 } 22 23 type Members struct { 24 Units string `json:"units"` 25 AllocationCount int `json:"allocation_count"` 26 MinimumCount int `json:"minimum_count"` 27 MaximumCount int `json:"maximum_count"` 28 StepSizeCount int `json:"step_size_count"` 29 IsAdjustable bool `json:"is_adjustable"` 30 IsOptional bool `json:"is_optional"` 31 CanScaleDown bool `json:"can_scale_down"` 32 } 33 34 type Memory struct { 35 Units string `json:"units"` 36 AllocationMb int `json:"allocation_mb"` 37 MinimumMb int `json:"minimum_mb"` 38 MaximumMb int `json:"maximum_mb"` 39 StepSizeMb int `json:"step_size_mb"` 40 IsAdjustable bool `json:"is_adjustable"` 41 IsOptional bool `json:"is_optional"` 42 CanScaleDown bool `json:"can_scale_down"` 43 } 44 45 type Cpu struct { 46 Units string `json:"units"` 47 AllocationCount int `json:"allocation_count"` 48 MinimumCount int `json:"minimum_count"` 49 MaximumCount int `json:"maximum_count"` 50 StepSizeCount int `json:"step_size_count"` 51 IsAdjustable bool `json:"is_adjustable"` 52 IsOptional bool `json:"is_optional"` 53 CanScaleDown bool `json:"can_scale_down"` 54 } 55 56 type Disk struct { 57 Units string `json:"units"` 58 AllocationMb int `json:"allocation_mb"` 59 MinimumMb int `json:"minimum_mb"` 60 MaximumMb int `json:"maximum_mb"` 61 StepSizeMb int `json:"step_size_mb"` 62 IsAdjustable bool `json:"is_adjustable"` 63 IsOptional bool `json:"is_optional"` 64 CanScaleDown bool `json:"can_scale_down"` 65 } 66 67 type GroupReq struct { 68 GroupBdy GroupBdy `json:"group"` 69 } 70 71 type GroupBdy struct { 72 Members *MembersReq `json:"members,omitempty"` 73 Memory *MemoryReq `json:"memory,omitempty"` 74 Cpu *CpuReq `json:"cpu,omitempty"` 75 Disk *DiskReq `json:"disk,omitempty"` 76 } 77 78 type MembersReq struct { 79 AllocationCount int `json:"allocation_count,omitempty"` 80 } 81 type MemoryReq struct { 82 AllocationMb int `json:"allocation_mb,omitempty"` 83 } 84 type CpuReq struct { 85 AllocationCount int `json:"allocation_count"` 86 } 87 type DiskReq struct { 88 AllocationMb int `json:"allocation_mb,omitempty"` 89 } 90 91 type Groups interface { 92 GetDefaultGroups(groupType string) (GroupList, error) 93 GetGroups(icdId string) (GroupList, error) 94 UpdateGroup(icdId string, groupId string, groupReq GroupReq) (Task, error) 95 } 96 97 type groups struct { 98 client *client.Client 99 } 100 101 func newGroupAPI(c *client.Client) Groups { 102 return &groups{ 103 client: c, 104 } 105 } 106 107 func (r *groups) GetDefaultGroups(groupType string) (GroupList, error) { 108 groupList := GroupList{} 109 rawURL := fmt.Sprintf("/v4/ibm/deployables/%s/groups", groupType) 110 _, err := r.client.Get(rawURL, &groupList) 111 if err != nil { 112 return groupList, err 113 } 114 return groupList, nil 115 } 116 117 func (r *groups) GetGroups(icdId string) (GroupList, error) { 118 groupList := GroupList{} 119 rawURL := fmt.Sprintf("/v4/ibm/deployments/%s/groups", utils.EscapeUrlParm(icdId)) 120 _, err := r.client.Get(rawURL, &groupList) 121 if err != nil { 122 return groupList, err 123 } 124 return groupList, nil 125 } 126 127 func (r *groups) UpdateGroup(icdId string, groupId string, groupReq GroupReq) (Task, error) { 128 taskResult := TaskResult{} 129 rawURL := fmt.Sprintf("/v4/ibm/deployments/%s/groups/%s", utils.EscapeUrlParm(icdId), groupId) 130 _, err := r.client.Patch(rawURL, &groupReq, &taskResult) 131 if err != nil { 132 return taskResult.Task, err 133 } 134 return taskResult.Task, nil 135 }