github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/fgs/v2/function/results.go (about) 1 package function 2 3 import ( 4 "strconv" 5 6 "github.com/chnsz/golangsdk" 7 "github.com/chnsz/golangsdk/pagination" 8 ) 9 10 type Function struct { 11 Id string `json:"-"` 12 FuncId string `json:"-"` 13 FuncUrn string `json:"func_urn"` 14 FuncName string `json:"func_name"` 15 DomainId string `json:"domain_id"` 16 Namespace string `json:"namespace"` 17 ProjectName string `json:"project_name"` 18 Package string `json:"package"` 19 Runtime string `json:"runtime"` 20 Timeout int `json:"timeout"` 21 Handler string `json:"handler"` 22 MemorySize int `json:"memory_size"` 23 Cpu int `json:"cpu"` 24 CodeType string `json:"code_type"` 25 CodeUrl string `json:"code_url"` 26 CodeFileName string `json:"code_filename"` 27 CodeSize int64 `json:"code_size"` 28 CustomImage CustomImage `json:"custom_image"` 29 UserData string `json:"user_data"` 30 EncryptedUserData string `json:"encrypted_user_data"` 31 Digest string `json:"digest"` 32 Version string `json:"version"` 33 ImageName string `json:"image_name"` 34 Xrole string `json:"xrole"` 35 AppXrole string `json:"app_xrole"` 36 Description string `json:"description"` 37 VersionDescription string `json:"version_description"` 38 LastmodifiedUtc int64 `json:"-"` 39 LastModified string `json:"last_modified"` 40 FuncCode FunctionCode `json:"func_code"` 41 FuncVpc FuncVpc `json:"func_vpc"` 42 MountConfig MountConfig `json:"mount_config,omitempty"` 43 Concurrency int `json:"-"` 44 DependList []string `json:"depend_list"` // Deprecated 45 DependVersionList []string `json:"depend_version_list"` 46 StrategyConfig StrategyConfig `json:"strategy_config"` 47 ExtendConfig string `json:"extend_config"` 48 Dependencies []*Dependency `json:"dependencies"` 49 InitializerTimeout int `json:"initializer_timeout,omitempty"` 50 InitializerHandler string `json:"initializer_handler,omitempty"` 51 EnterpriseProjectID string `json:"enterprise_project_id"` 52 Type string `json:"type"` 53 // GPU memory. 54 // Range: 1024 to 16,384, and the value is a multiple of 1024. 55 GPUMemory int `json:"gpu_memory"` 56 // GPU type. 57 GPUType string `json:"gpu_type"` 58 // Ephemeral storage size, the maximum value is 10 GB. Defaults to 512 MB. 59 EphemeralStorage int `json:"ephemeral_storage"` 60 // Whether to allow a long timeout. 61 LongTime bool `json:"long_time"` 62 // Log group ID. 63 LogGroupId string `json:"log_group_id"` 64 // Log stream ID. 65 LogStreamId string `json:"log_stream_id"` 66 // Network configuration. 67 NetworkController NetworkControlConfig `json:"network_controller"` 68 // Whether stateful functions are supported. 69 IsStatefulFunction bool `json:"is_stateful_function"` 70 // Whether to enable dynamic memory allocation. 71 EnableDynamicMemory bool `json:"enable_dynamic_memory"` 72 // Whether to allow authentication information in the request header. 73 EnableAuthInHeader bool `json:"enable_auth_in_header"` 74 // Private domain name. 75 DomainNames string `json:"domain_names"` 76 // The pre-stop handler of the function. 77 PreStopHandler string `json:"pre_stop_handler"` 78 // Maximum duration the function can be initialized. 79 PreStopTimeout int `json:"pre_stop_timeout"` 80 } 81 82 type FuncMount struct { 83 Id string `json:"id,omitempty"` 84 MountType string `json:"mount_type" required:"true"` 85 MountResource string `json:"mount_resource" required:"true"` 86 MountSharePath string `json:"mount_share_path" required:"true"` 87 LocalMountPath string `json:"local_mount_path" required:"true" description:"local file path in function runtime environment"` 88 UserGroupId *int `json:"-"` 89 UserId *int `json:"-"` 90 Status string `json:"status,omitempty"` //ACTIVE或DISABLED,和触发器类似。如果已经存在的配置不可用了processrouter不会挂载。 91 ProjectId string `json:"-"` 92 FuncVersions []*FunctionVersion `json:"-"` 93 SaveType int `json:"-"` //仅仅在数据处理时用到,如果需要保存新的映射关系,则将其置为1,如要删除老的,将其置为2 94 } 95 96 // noinspection GoNameStartsWithPackageName 97 type FunctionVersion struct { 98 Id string `json:"-"` 99 FuncId string `json:"-"` 100 Runtime string `json:"runtime"` 101 Timeout int `json:"timeout"` 102 Handler string `json:"handler"` 103 MemorySize int `json:"memory_size"` 104 Cpu int `json:"cpu"` 105 CodeType string `json:"code_type"` 106 CodeUrl string `json:"code_url"` 107 CodeFileName string `json:"code_file_name"` 108 CodeSize int64 `json:"code_size"` 109 UserData string `json:"user_data"` 110 EncryptedUserData string `json:"encrypted_user_data"` 111 ImageName string `json:"image_name"` 112 Digest string `json:"digest"` 113 Version string `json:"version"` 114 Xrole string `json:"xrole"` 115 AppXrole string `json:"app_xrole"` 116 Description string `json:"description"` 117 VersionDescription string `json:"version_description"` 118 LastModified int64 `json:"last_modified"` 119 Concurrency int `json:"concurrency"` 120 ExtendConfig string `json:"extend_config"` 121 Dependencies []*Dependency `json:"dependencies"` 122 FuncBase *FunctionBase `json:"func_base"` 123 FuncVpcId string `json:"-"` 124 FuncMounts []*FuncMount 125 MountConfig *MountConfig `json:"mount_config"` 126 Vpc *FuncVpc `json:"vpc"` 127 InitializerTimeout int 128 InitializerHandler string `description:"the function initializer handler"` 129 } 130 131 // dependency 132 type Dependency struct { 133 Id string `json:"id"` 134 Owner string `json:"owner"` 135 Namespace string `json:"-"` 136 Link string `json:"link"` 137 Runtime string `json:"runtime"` 138 ETag string `json:"etag"` 139 Size int64 `json:"size"` 140 Name string `json:"name"` 141 Description string `json:"description"` 142 FileName string `json:"file_name,omitempty"` 143 FuncVersions []*FunctionVersion `json:"-"` 144 SaveType int `json:"-"` 145 } 146 147 type MountUser struct { 148 UserId int `json:"user_id" required:"true"` 149 UserGroupId int `json:"user_group_id" required:"true"` 150 } 151 152 type MountConfig struct { 153 MountUser MountUser `json:"mount_user" required:"true"` 154 FuncMounts []FuncMount `json:"func_mounts" required:"true"` 155 } 156 157 // noinspection GoNameStartsWithPackageName 158 type FunctionCode struct { 159 File string `json:"file"` 160 Link string `json:"link"` 161 } 162 163 // noinspection GoNameStartsWithPackageName 164 type FunctionBase struct { 165 Id string `json:"-"` 166 FuncName string `json:"func_name"` 167 DomainId string `description:"domain id"` 168 Namespace string `json:"namespace"` 169 ProjectName string `json:"project_name"` 170 Package string `json:"package"` 171 } 172 173 type FuncVpc struct { 174 Id string `json:"-"` 175 DomainId string `json:"-" validate:"regexp=^[a-zA-Z0-9-]+$" description:"domain id"` 176 Namespace string `json:"-"` 177 VpcName string `json:"vpc_name,omitempty"` 178 VpcId string `json:"vpc_id,omitempty"` 179 SubnetName string `json:"subnet_name,omitempty"` 180 SubnetId string `json:"subnet_id,omitempty"` 181 Cidr string `json:"cidr,omitempty"` 182 Gateway string `json:"gateway,omitempty"` 183 } 184 185 type commonResult struct { 186 golangsdk.Result 187 } 188 189 type GetResult struct { 190 commonResult 191 } 192 193 type CreateResult struct { 194 commonResult 195 } 196 197 type DeleteResult struct { 198 golangsdk.ErrResult 199 } 200 201 type UpdateResult struct { 202 commonResult 203 } 204 205 type FunctionPage struct { 206 pagination.SinglePageBase 207 } 208 209 func (r commonResult) Extract() (*Function, error) { 210 var f Function 211 err := r.ExtractInto(&f) 212 return &f, err 213 } 214 215 // noinspection GoNameStartsWithPackageName 216 type FunctionList struct { 217 Functions []Function `json:"functions"` 218 NextMarker int `json:"next_marker"` 219 } 220 221 func ExtractList(r pagination.Page) (FunctionList, error) { 222 var s FunctionList 223 err := (r.(FunctionPage)).ExtractInto(&s) 224 return s, err 225 } 226 227 func (r commonResult) ExtractInvoke() (interface{}, error) { 228 return r.Body, r.Err 229 } 230 231 type Versions struct { 232 Versions []Function `json:"versions"` 233 NextMarker int `json:"next_marker"` 234 } 235 236 func ExtractVersionlist(r pagination.Page) (Versions, error) { 237 var s Versions 238 err := (r.(FunctionPage)).ExtractInto(&s) 239 return s, err 240 } 241 242 type AliasResult struct { 243 Name string `json:"name"` 244 Version string `json:"version"` 245 Description string `json:"description"` 246 LastModified string `json:"last_modified"` 247 AliasUrn string `json:"alias_urn"` 248 } 249 250 func (r commonResult) ExtractAlias() (*AliasResult, error) { 251 var s AliasResult 252 err := r.ExtractInto(&s) 253 return &s, err 254 } 255 256 func ExtractAliasList(r pagination.Page) ([]AliasResult, error) { 257 var s []AliasResult 258 err := (r.(FunctionPage)).ExtractInto(&s) 259 return s, err 260 } 261 262 // AsyncInvokeConfig is the structure that represents the asynchronous invocation. 263 type AsyncInvokeConfig struct { 264 // Function URN. 265 FunctionUrn string `json:"func_urn"` 266 // Maximum validity period of a message. Value range: 60–86,400. Unit: second. 267 MaxAsyncEventAgeInSeconds int `json:"max_async_event_age_in_seconds"` 268 // Maximum number of retry attempts to be made if asynchronous invocation fails. Default value: 3. Value range: 0–8. 269 MaxAsyncRetryAttempts int `json:"max_async_retry_attempts"` 270 // Asynchronous invocation target. 271 DestinationConfig DestinationConfig `json:"destination_config"` 272 // Time when asynchronous execution notification was configured. 273 CreatedAt string `json:"created_time"` 274 // Time when the asynchronous execution notification settings were last modified. 275 UpdatedAt string `json:"last_modified"` 276 // Whether to enable asynchronous invocation status persistence. 277 EnableAsyncStatusLog bool `json:"enable_async_status_log"` 278 } 279 280 // ReservedInstanceConfigResp is the structure that represents the response of the GetReservedInstanceConfig method. 281 type ReservedInstanceConfigResp struct { 282 // The list of reserved instance policy. 283 ReservedInstances []ReservedInstancePolicy `json:"reserved_instances"` 284 // The page information. 285 PageInfo PageInfoObj `json:"page_info"` 286 // Number of function. 287 Count int `json:"count"` 288 } 289 290 // ReservedInstancePolicy is the structure that represents the reserved instance policy configuration. 291 type ReservedInstancePolicy struct { 292 // Function URN. 293 FunctionUrn string `json:"function_urn"` 294 // Limited type, the supported values are version and alias. 295 QualifierType string `json:"qualifier_type"` 296 // The value of the limited type. 297 QualifierName string `json:"qualifier_name"` 298 // The number of instance reserved. 299 MinCount int `json:"min_count"` 300 // Whether to enable the idle mode configuration. 301 IdleMode bool `json:"idle_mode"` 302 // The auto scaling policy configuration. 303 TacticsConfig TacticsConfigObj `json:"tactics_config"` 304 } 305 306 // PageInfoObj is the structure that represents pagination information of the function reserved instance. 307 type PageInfoObj struct { 308 // Next record location. 309 NextMarker int `json:"next_marker"` 310 // Last record location. 311 PreviousMarker int `json:"previous_marker"` 312 // Total number of current page. 313 CurrentCount int `json:"current_count"` 314 } 315 316 // ReservedInstanceConfigPage represents the response pages of the GetReservedInstanceConfig method. 317 type ReservedInstanceConfigPage struct { 318 pagination.MarkerPageBase 319 } 320 321 // IsEmpty returns true if no reserved instance. 322 func (r ReservedInstanceConfigPage) IsEmpty() (bool, error) { 323 resp, err := extractReservedInstanceConfigs(r) 324 return len(resp) == 0, err 325 } 326 327 // LastMarker returns the last marker index in reserved instance list. 328 func (r ReservedInstanceConfigPage) LastMarker() (string, error) { 329 resp, err := extractPageInfo(r) 330 if err != nil { 331 return "", err 332 } 333 334 if resp.CurrentCount == 0 { 335 return "", nil 336 } 337 return strconv.Itoa(resp.NextMarker), nil 338 } 339 340 // extractPageInfo is a method which to extract the response of the page information. 341 func extractPageInfo(r pagination.Page) (*PageInfoObj, error) { 342 var s ReservedInstanceConfigResp 343 err := r.(ReservedInstanceConfigPage).Result.ExtractInto(&s) 344 345 return &s.PageInfo, err 346 } 347 348 // extractReservedInstanceConfigs is a method which to extract the response to reserved instance configuration list. 349 func extractReservedInstanceConfigs(p pagination.Page) ([]ReservedInstancePolicy, error) { 350 var resp ReservedInstanceConfigResp 351 err := p.(ReservedInstanceConfigPage).Result.ExtractInto(&resp) 352 353 return resp.ReservedInstances, err 354 }