Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: LXD: Add services APIs and support for copying across services of type lxd (clusters) #14884

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3952900
api: Add `services` extension
kadinsayani Jan 17, 2025
ffca96f
lxd/db/cluster: Update schema for services API
kadinsayani Jan 17, 2025
b916d23
lxd/db/cluster: Update schema
kadinsayani Jan 17, 2025
5f597b7
lxd/db/cluster: Add database types for `services`
kadinsayani Jan 17, 2025
47096aa
lxd/db/cluster: Update schema
kadinsayani Feb 14, 2025
0e2719d
shared/api: Add `Service` API type
kadinsayani Jan 20, 2025
52048df
lxd/db/cluster: Add database methods for `Service`
kadinsayani Feb 14, 2025
ddfd94b
lxd/db/cluster: Add `GetPendingTLSIdentityByName` function
kadinsayani Jan 29, 2025
d19f96b
lxd/lifecycle: Add service lifecycle events
kadinsayani Jan 29, 2025
848a98a
lxd: Add services APIs
kadinsayani Jan 29, 2025
0dd323c
doc/rest-api: Refresh swagger YAML
kadinsayani Jan 29, 2025
7a16547
client: Add service client functions
kadinsayani Jan 29, 2025
7f3f92f
lxc/service: Add `service` command and `service add` subcommand
kadinsayani Feb 10, 2025
a039977
lxc/service: Add `service list` command
kadinsayani Feb 13, 2025
7e0b5cd
lxc/completion: Add `cmpServices` completion function
kadinsayani Feb 13, 2025
8515a6b
lxc/service: Add `service remove` command
kadinsayani Feb 13, 2025
3e61866
lxc/service: Add `service edit` command
kadinsayani Feb 14, 2025
262063d
lxc/service: Add `service get`, `service set`, `service show` and `se…
kadinsayani Feb 14, 2025
9281066
lxd/service: Add `service` package and `Connect` function
kadinsayani Feb 5, 2025
42d947c
i18n: Update translation templates.
kadinsayani Feb 19, 2025
05cd8c5
i18n: Update translations.
kadinsayani Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ type InstanceServer interface {
UpdateClusterGroup(name string, group api.ClusterGroupPut, ETag string) error
GetClusterGroup(name string) (*api.ClusterGroup, string, error)

// Service functions ("services" API extension)
GetService(name string) (service *api.Service, ETag string, err error)
GetServices() (services []api.Service, err error)
AddService(service api.ServicePost) error
UpdateService(name string, service api.ServicePut, ETag string) error
DeleteService(name string) error

// Warning functions
GetWarningUUIDs() (uuids []string, err error)
GetWarnings() (warnings []api.Warning, err error)
Expand Down
89 changes: 89 additions & 0 deletions client/lxd_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package lxd

import (
"net/http"

"github.com/canonical/lxd/shared/api"
)

// GetServices returns all services.
func (r *ProtocolLXD) GetServices() ([]api.Service, error) {
err := r.CheckExtension("services")
if err != nil {
return nil, err
}

services := []api.Service{}
u := api.NewURL().Path("services")
_, err = r.queryStruct(http.MethodGet, u.String(), nil, "", &services)
if err != nil {
return nil, err
}

return services, nil
}

// GetService returns information about a service.
func (r *ProtocolLXD) GetService(name string) (*api.Service, string, error) {
err := r.CheckExtension("services")
if err != nil {
return nil, "", err
}

service := &api.Service{}
u := api.NewURL().Path("services", name)
etag, err := r.queryStruct(http.MethodGet, u.String(), nil, "", &service)
if err != nil {
return nil, "", err
}

return service, etag, nil
}

// AddService requests add a new service.
func (r *ProtocolLXD) AddService(service api.ServicePost) error {
err := r.CheckExtension("services")
if err != nil {
return err
}

u := api.NewURL().Path("service", "add")
_, _, err = r.query(http.MethodPost, u.String(), service, "")
if err != nil {
return err
}

return nil
}

// UpdateService updates a service.
func (r *ProtocolLXD) UpdateService(name string, service api.ServicePut, ETag string) error {
err := r.CheckExtension("services")
if err != nil {
return err
}

u := api.NewURL().Path("services", name)
_, _, err = r.query(http.MethodPut, u.String(), service, ETag)
if err != nil {
return err
}

return nil
}

// DeleteService deletes a service.
func (r *ProtocolLXD) DeleteService(name string) error {
err := r.CheckExtension("services")
if err != nil {
return err
}

u := api.NewURL().Path("services", name)
_, _, err = r.query(http.MethodDelete, u.String(), nil, "")
if err != nil {
return err
}

return nil
}
14 changes: 14 additions & 0 deletions doc/api-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2618,3 +2618,17 @@ Note that the `openid` and `email` scopes are always required.
## `project_default_network_and_storage`

Adds flags --network and --storage. The --network flag adds a network device connected to the specified network to the default profile. The --storage flag adds a root disk device using the specified storage pool to the default profile.

## services

This introduces the services API to enable services (server-side remotes).

This includes the following new endpoints (see [RESTful API](rest-api.md) for details):

* `GET /1.0/services/<name>` - returns information about a specific service.
* `GET /1.0/services` - returns a combined view of self-created and delegated services (if any).
* `PUT /1.0/services/<name>` - allows for modification of a specific service.
* `POST /1.0/service/add` - adds a specific service using a provided trust token.
* `DELETE /1.0/services/<name>` - deletes a service.

This also includes the new `services` and `services_config` database tables and their corresponding functions.
Loading
Loading