github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/modelarts/v1/notebook/results.go (about) 1 package notebook 2 3 import ( 4 "strconv" 5 6 "github.com/chnsz/golangsdk/pagination" 7 ) 8 9 const ( 10 StatusInit = "INIT" 11 StatusCreating = "CREATING" 12 StatusStarting = "STARTING" 13 StatusStopping = "STOPPING" 14 StatusDeleting = "DELETING" 15 StatusRunning = "RUNNING" 16 StatusStopped = "STOPPED" 17 StatusSnapshotting = "SNAPSHOTTING" 18 StatusCreateFailed = "CREATE_FAILED" 19 StatusStartFailed = "START_FAILED" 20 StatusDeleteFailed = "DELETE_FAILED" 21 StatusError = "ERROR" 22 StatusDeleted = "DELETED" 23 StatusFrozen = "FROZEN" 24 ) 25 26 type Notebook struct { 27 ActionProgress []JobProgress `json:"action_progress"` 28 Description string `json:"description"` 29 Endpoints []Endpoints `json:"endpoints"` 30 FailReason string `json:"fail_reason"` 31 Feature string `json:"feature"` 32 Flavor string `json:"flavor"` 33 Id string `json:"id"` 34 Image Image `json:"image"` 35 Lease Lease `json:"lease"` 36 Name string `json:"name"` 37 Pool PoolRes `json:"pool"` 38 Status string `json:"status"` 39 Token string `json:"token"` 40 Url string `json:"url"` 41 Volume VolumeRes `json:"volume"` 42 WorkspaceId string `json:"workspace_id"` 43 CreateAt int `json:"create_at"` 44 UpdateAt int `json:"update_at"` 45 } 46 47 type JobProgress struct { 48 NotebookId string `json:"notebook_id"` 49 Status string `json:"status"` 50 Step int `json:"step"` 51 StepDescription string `json:"step_description"` 52 } 53 54 type Endpoints struct { 55 AllowedAccessIps []string `json:"allowed_access_ips"` 56 Service string `json:"service"` 57 KeyPairNames []string `json:"key_pair_names"` 58 Uri string `json:"uri"` 59 } 60 61 type Image struct { 62 Id string `json:"id"` 63 Name string `json:"name"` 64 SwrPath string `json:"swr_path"` 65 Type string `json:"type"` 66 } 67 68 type Lease struct { 69 CreateAt int `json:"create_at"` 70 Duration int `json:"duration"` 71 Enable bool `json:"enable"` 72 UpdateAt int `json:"update_at"` 73 } 74 75 type PoolRes struct { 76 Id string `json:"id"` 77 Name string `json:"name"` 78 } 79 80 type VolumeRes struct { 81 Capacity int `json:"capacity"` 82 Category string `json:"category"` 83 MountPath string `json:"mount_path"` 84 Ownership string `json:"ownership"` 85 Status string `json:"status"` 86 } 87 88 type ListNotebooks struct { 89 Current int `json:"current"` 90 Data []Notebook `json:"data"` 91 Pages int `json:"pages"` 92 Size int `json:"size"` 93 Total int `json:"total"` 94 } 95 96 type ImagesResp struct { 97 Current int `json:"current"` 98 Data []ImageDetail `json:"data"` 99 Pages int `json:"pages"` 100 Size int `json:"size"` 101 Total int `json:"total"` 102 } 103 104 type ImageDetail struct { 105 Id string `json:"id"` 106 Name string `json:"name"` 107 SwrPath string `json:"swr_path"` 108 Type string `json:"type"` 109 Description string `json:"description"` 110 Arch string `json:"arch"` 111 } 112 113 type ImagePage struct { 114 pagination.OffsetPageBase 115 } 116 117 // IsEmpty checks whether a ImagePage struct is empty. 118 func (current ImagePage) IsEmpty() (bool, error) { 119 resp, err := extractImagesResp(current) 120 if err != nil { 121 return false, err 122 } 123 return len(resp.Data) == 0, nil 124 } 125 126 func extractImagesResp(r pagination.Page) (ImagesResp, error) { 127 var s ImagesResp 128 err := (r.(ImagePage)).ExtractInto(&s) 129 return s, err 130 } 131 132 func ExtractImages(r pagination.Page) ([]ImageDetail, error) { 133 var s ImagesResp 134 err := (r.(ImagePage)).ExtractInto(&s) 135 return s.Data, err 136 } 137 138 // NextPageURL generates the URL for the page of results after this one. 139 func (current ImagePage) NextPageURL() (string, error) { 140 next := current.NextOffset() 141 if next == 0 { 142 return "", nil 143 } 144 resp, _ := extractImagesResp(current) 145 currentURL := current.URL 146 q := currentURL.Query() 147 148 if resp.Current+1 >= resp.Pages { 149 // This page is the last page. 150 return "", nil 151 } 152 153 q.Set("offset", strconv.Itoa(next)) 154 currentURL.RawQuery = q.Encode() 155 return currentURL.String(), nil 156 } 157 158 type flavorResp struct { 159 Flavors []Flavor `json:"flavors"` 160 } 161 162 type Flavor struct { 163 Arch string `json:"arch"` 164 Ascend AscendInfo `json:"ascend"` 165 Billing BillingInfo `json:"billing"` 166 Category string `json:"category"` 167 Description string `json:"description"` 168 Feature string `json:"feature"` 169 Free bool `json:"free"` 170 Gpu GPUInfo `json:"gpu"` 171 Id string `json:"id"` 172 Memory int `json:"memory"` 173 Name string `json:"name"` 174 SoldOut bool `json:"sold_out"` 175 Storages []string `json:"storages"` 176 Vcpus int `json:"vcpus"` 177 } 178 179 type AscendInfo struct { 180 Npu int `json:"npu"` 181 NpuMemory string `json:"npu_memory"` 182 Type string `json:"type"` 183 } 184 185 type BillingInfo struct { 186 Code string `json:"code"` 187 UnitNum int `json:"unit_num"` 188 } 189 190 type GPUInfo struct { 191 Gpu int `json:"gpu"` 192 GpuMemory string `json:"gpu_memory"` 193 Type string `json:"type"` 194 } 195 196 type ModelartsError struct { 197 ErrorCode string `json:"error_code"` 198 ErrorMsg string `json:"error_msg"` 199 } 200 201 type MountStorage struct { 202 Category string `json:"category"` 203 Id string `json:"id"` 204 MountPath string `json:"mount_path"` 205 Status string `json:"status"` 206 Uri string `json:"uri"` 207 } 208 209 type MountStorageListResp struct { 210 Current int `json:"current"` 211 Data []MountStorage `json:"data"` 212 Pages int `json:"pages"` 213 Size int `json:"size"` 214 Total int `json:"total"` 215 }