Skip to content

Commit

Permalink
Merge pull request #12662 from MusicDin/feature/member-virt-indication
Browse files Browse the repository at this point in the history
Indicate supported instance types when querying /1.0
  • Loading branch information
tomponline authored Jan 19, 2024
2 parents a50a2b3 + f3e2858 commit 4d5ac96
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/api-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2340,3 +2340,9 @@ This API extension provides the ability to configure storage volumes in preseed
## `metrics_instances_count`

This extends the metrics to include the containers and virtual machines counts. Instances are counted irrespective of their state.

## `server_instance_type_info`

This API extension enables querying a server's supported instance types.
When querying the `/1.0` endpoint, a new field named `instance_types` is added to the retrieved data.
This field indicates which instance types are supported by the server.
9 changes: 9 additions & 0 deletions doc/rest-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5292,6 +5292,15 @@ definitions:
example: nftables
type: string
x-go-name: Firewall
instance_types:
description: List of supported instance types
example:
- container
- virtual-machine
items:
type: string
type: array
x-go-name: InstanceTypes
kernel:
description: OS kernel name
example: Linux
Expand Down
6 changes: 6 additions & 0 deletions lxd/api_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ func api10Get(d *Daemon, r *http.Request) response.Response {
} else {
env.DriverVersion = driver.Info.Version
}

// Add supported instance types.
instType := driver.Info.Type.String()
if !shared.ValueInSlice(instType, env.InstanceTypes) {
env.InstanceTypes = append(env.InstanceTypes, instType)
}
}

if s.OS.LXCFeatures != nil {
Expand Down
6 changes: 6 additions & 0 deletions shared/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ type ServerEnvironment struct {
// Example: 4.0.7 | 5.2.0
DriverVersion string `json:"driver_version" yaml:"driver_version"`

// List of supported instance types
// Example: ["container", "virtual-machine"]
//
// API extension: server_instance_type_info
InstanceTypes []string `json:"instance_types" yaml:"instance_types"`

// Current firewall driver
// Example: nftables
//
Expand Down
1 change: 1 addition & 0 deletions shared/version/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ var APIExtensions = []string{
"ovn_ssl_config",
"init_preseed_storage_volumes",
"metrics_instances_count",
"server_instance_type_info",
}

// APIExtensionsCount returns the number of available API extensions.
Expand Down
1 change: 1 addition & 0 deletions test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ if [ "${1:-"all"}" != "cluster" ]; then
run_test test_oidc "OpenID Connect"
run_test test_certificate_edit "Certificate edit"
run_test test_basic_usage "basic usage"
run_test test_server_info "server info"
run_test test_remote_url "remote url handling"
run_test test_remote_admin "remote administration"
run_test test_remote_usage "remote usage"
Expand Down
5 changes: 5 additions & 0 deletions test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,8 @@ test_basic_usage() {
remaining_instances="$(lxc list --format csv)"
[ -z "${remaining_instances}" ]
}

test_server_info() {
# Ensure server always reports support for containers.
lxc query /1.0 | jq -e '.environment.instance_types | contains(["container"])'
}

0 comments on commit 4d5ac96

Please sign in to comment.