Skip to content

Commit

Permalink
Merge pull request #13036 from hamistao/issue12550/add_list_all_volum…
Browse files Browse the repository at this point in the history
…es_endpoint

API: Add list all volumes endpoint
  • Loading branch information
tomponline authored Mar 27, 2024
2 parents c83a912 + ae3176d commit e6f9af1
Show file tree
Hide file tree
Showing 55 changed files with 5,148 additions and 4,327 deletions.
4 changes: 4 additions & 0 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ type InstanceServer interface {
UpdateStoragePoolBucketKey(poolName string, bucketName string, keyName string, key api.StorageBucketKeyPut, ETag string) (err error)
DeleteStoragePoolBucketKey(poolName string, bucketName string, keyName string) (err error)

// List all volumes functions ("storage_volumes_all" API extension)
GetVolumesWithFilter(filters []string) (volumes []api.StorageVolume, err error)
GetVolumesWithFilterAllProjects(filters []string) (volumes []api.StorageVolume, err error)

// Storage volume functions ("storage" API extension)
GetStoragePoolVolumeNames(pool string) (names []string, err error)
GetStoragePoolVolumeNamesAllProjects(pool string) (names map[string][]string, err error)
Expand Down
60 changes: 60 additions & 0 deletions client/lxd_storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,66 @@ func (r *ProtocolLXD) GetStoragePoolVolumesAllProjects(pool string) ([]api.Stora
return volumes, nil
}

// GetVolumesWithFilter returns a filtered list of StorageVolume entries for all storage pools.
func (r *ProtocolLXD) GetVolumesWithFilter(filters []string) ([]api.StorageVolume, error) {
err := r.CheckExtension("storage")
if err != nil {
return nil, err
}

err = r.CheckExtension("storage_volumes_all")
if err != nil {
return nil, err
}

volumes := []api.StorageVolume{}

url := api.NewURL().Path("storage-volumes").
WithQuery("recursion", "1").
WithQuery("filter", parseFilters(filters))

// Fetch the raw value
_, err = r.queryStruct(http.MethodGet, url.String(), nil, "", &volumes)
if err != nil {
return nil, err
}

return volumes, nil
}

// GetVolumesWithFilterAllProjects returns a filtered list of StorageVolume entries for all storage pools and for all projects.
func (r *ProtocolLXD) GetVolumesWithFilterAllProjects(filters []string) ([]api.StorageVolume, error) {
err := r.CheckExtension("storage")
if err != nil {
return nil, err
}

err = r.CheckExtension("storage_volumes_all_projects")
if err != nil {
return nil, err
}

err = r.CheckExtension("storage_volumes_all")
if err != nil {
return nil, err
}

volumes := []api.StorageVolume{}

url := api.NewURL().Path("storage-volumes").
WithQuery("recursion", "1").
WithQuery("filter", parseFilters(filters)).
WithQuery("all-projects", "true")

// Fetch the raw value.
_, err = r.queryStruct(http.MethodGet, url.String(), nil, "", &volumes)
if err != nil {
return nil, err
}

return volumes, nil
}

// GetStoragePoolVolumesWithFilter returns a filtered list of StorageVolume entries for the provided pool.
func (r *ProtocolLXD) GetStoragePoolVolumesWithFilter(pool string, filters []string) ([]api.StorageVolume, error) {
err := r.CheckExtension("storage")
Expand Down
4 changes: 4 additions & 0 deletions doc/api-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2388,3 +2388,7 @@ For more information on access control for OIDC clients, see {ref}`fine-grained-
## `vm_disk_io_limits`

Adds the ability to limit disk I/O for virtual machines.

## `storage_volumes_all`

This API extension adds support for listing storage volumes from all storage pools via `/1.0/storage-volumes` or `/1.0/storage-volumes/{type}` to filter by volume type. Also adds a `pool` field to storage volumes.
239 changes: 239 additions & 0 deletions doc/rest-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6202,6 +6202,11 @@ definitions:
example: foo
type: string
x-go-name: Name
pool:
description: Name of the pool the volume is using
example: '"default"'
type: string
x-go-name: Pool
project:
description: Project containing the volume.
example: default
Expand Down Expand Up @@ -16234,6 +16239,240 @@ paths:
summary: Get the storage pools
tags:
- storage
/1.0/storage-volumes:
get:
description: Returns a list of storage volumes (URLs).
operationId: storage_volumes_get
parameters:
- description: Project name
example: default
in: query
name: project
type: string
- description: Indicates whether volumes from all projects should be returned
example: true
in: query
name: all-projects
type: bool
- description: Cluster member name
example: lxd01
in: query
name: target
type: string
- description: Collection filter
example: default
in: query
name: filter
type: string
produces:
- application/json
responses:
"200":
description: API endpoints
schema:
description: Sync response
properties:
metadata:
description: List of endpoints
example: |-
[
"/1.0/storage-pools/local/volumes/container/a1",
"/1.0/storage-pools/local/volumes/container/a2",
"/1.0/storage-pools/local/volumes/custom/backups",
"/1.0/storage-pools/local/volumes/custom/images"
]
items:
type: string
type: array
status:
description: Status description
example: Success
type: string
status_code:
description: Status code
example: 200
type: integer
type:
description: Response type
example: sync
type: string
type: object
"403":
$ref: '#/responses/Forbidden'
"500":
$ref: '#/responses/InternalServerError'
summary: Get the storage volumes
tags:
- storage
/1.0/storage-volumes/{type}:
get:
description: Returns a list of storage volumes (URLs) (type specific endpoint).
operationId: storage_pool_volumes_type_get
parameters:
- description: Project name
example: default
in: query
name: project
type: string
- description: Indicates whether volumes from all projects should be returned
example: true
in: query
name: all-projects
type: bool
- description: Cluster member name
example: lxd01
in: query
name: target
type: string
produces:
- application/json
responses:
"200":
description: API endpoints
schema:
description: Sync response
properties:
metadata:
description: List of endpoints
example: |-
[
"/1.0/storage-pools/local/volumes/custom/backups",
"/1.0/storage-pools/local/volumes/custom/images"
]
items:
type: string
type: array
status:
description: Status description
example: Success
type: string
status_code:
description: Status code
example: 200
type: integer
type:
description: Response type
example: sync
type: string
type: object
"403":
$ref: '#/responses/Forbidden'
"500":
$ref: '#/responses/InternalServerError'
summary: Get the storage volumes
tags:
- storage
/1.0/storage-volumes/{type}?recursion=1:
get:
description: Returns a list of storage volumes (structs) (type specific endpoint).
operationId: storage_pool_volumes_type_get_recursion1
parameters:
- description: Project name
example: default
in: query
name: project
type: string
- description: Indicates whether volumes from all projects should be returned
example: true
in: query
name: all-projects
type: bool
- description: Cluster member name
example: lxd01
in: query
name: target
type: string
produces:
- application/json
responses:
"200":
description: API endpoints
schema:
description: Sync response
properties:
metadata:
description: List of storage volumes
items:
$ref: '#/definitions/StorageVolume'
type: array
status:
description: Status description
example: Success
type: string
status_code:
description: Status code
example: 200
type: integer
type:
description: Response type
example: sync
type: string
type: object
"403":
$ref: '#/responses/Forbidden'
"500":
$ref: '#/responses/InternalServerError'
summary: Get the storage volumes
tags:
- storage
/1.0/storage-volumes?recursion=1:
get:
description: Returns a list of storage volumes (structs).
operationId: storage_pool_volumes_get_recursion1
parameters:
- description: Project name
example: default
in: query
name: project
type: string
- description: Indicates whether volumes from all projects should be returned
example: true
in: query
name: all-projects
type: bool
- description: Cluster member name
example: lxd01
in: query
name: target
type: string
- description: Collection filter
example: default
in: query
name: filter
type: string
produces:
- application/json
responses:
"200":
description: API endpoints
schema:
description: Sync response
properties:
metadata:
description: List of storage volumes
items:
$ref: '#/definitions/StorageVolume'
type: array
status:
description: Status description
example: Success
type: string
status_code:
description: Status code
example: 200
type: integer
type:
description: Response type
example: sync
type: string
type: object
"403":
$ref: '#/responses/Forbidden'
"500":
$ref: '#/responses/InternalServerError'
summary: Get the storage volumes
tags:
- storage
/1.0/warnings:
get:
description: Returns a list of warnings.
Expand Down
Loading

0 comments on commit e6f9af1

Please sign in to comment.