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

Introduce network integrations (and OVN inter-connect support) #655

Merged
merged 33 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9096adc
api: network_integrations
stgraber Jan 4, 2024
5d9747b
shared/api: Add type and target_integration fields to NetworkPeersPost
stgraber Jan 4, 2024
243b1b5
incusd/db/cluster: Add networks_integrations
stgraber Jan 4, 2024
964aee7
incusd/db/cluster: Re-generate schema
stgraber Jan 4, 2024
8eab1bc
incusd/db/cluster: Add generated DB code for network integrations
stgraber Jan 11, 2024
612cd78
incusd/db: Update network peer DB query functions
stgraber Jan 8, 2024
c59cf79
client: Add check for network_integrations in CreateNetworkPeer
stgraber Jan 11, 2024
833ea14
incus/network/peer: Add support for network peer types
stgraber Jan 11, 2024
44f4c72
shared/api: Add network integrations
stgraber Jan 11, 2024
3938689
client: Add network integration functions
stgraber Jan 11, 2024
f85e5c2
incus/network: Introduce support for integrations
stgraber Jan 11, 2024
32df268
incusd/auth: Add network integration functions
stgraber Jan 12, 2024
996d943
shared/api: Add lifecycle events for network integrations
stgraber Jan 12, 2024
c8a7ecc
incusd/lifecycle: Add network integration events
stgraber Jan 12, 2024
20ac73f
incusd: Add network integration API
stgraber Jan 12, 2024
7126922
incusd/db: Add GetNetworkPeersURLByIntegration
stgraber Jan 15, 2024
b02a646
incusd/network_integration: Add UsedBy field
stgraber Jan 15, 2024
ecde076
incusd/network_integrations: Add validator
stgraber Jan 18, 2024
baaeeb4
incusd/network/ovn: Add support for peering with OVN IC
stgraber Mar 6, 2024
3a145b6
incusd/project: Add restricted.networks.integrations
stgraber Mar 25, 2024
2debae2
incusd/project: Add NetworkIntegrationAllowed
stgraber Mar 25, 2024
9283edc
incusd/network/integrations: Respect project restrictions
stgraber Mar 25, 2024
59fdf33
incusd/network/ovn: Add support for integration restrictions
stgraber Mar 25, 2024
7f806fc
incusd/auth/openfga: Update the model
stgraber Mar 25, 2024
3788589
incusd/auth/openfga: Update the generated model
stgraber Mar 25, 2024
8754d52
incusd/auth/openfga: Handle model updates
stgraber Mar 25, 2024
4d9166c
incusd: Remove openfga.store.model_id
stgraber Mar 25, 2024
fed766f
incusd/db/cluster: Remove openfga.store.model_id
stgraber Mar 25, 2024
0a9e669
doc/ovn_peers: Add remote peering
stgraber Mar 25, 2024
d8cc514
doc: Add documentation for network integrations
stgraber Mar 25, 2024
5710e83
doc/rest-api: Refresh swagger YAML
stgraber Jan 18, 2024
4587f85
i18n: Update translation templates
stgraber Feb 22, 2024
886e616
doc: Update configs
stgraber Mar 25, 2024
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
121 changes: 121 additions & 0 deletions client/incus_network_integrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package incus

import (
"fmt"
"net/url"

"github.com/lxc/incus/shared/api"
)

// GetNetworkIntegrationNames returns a list of network integration names.
func (r *ProtocolIncus) GetNetworkIntegrationNames() ([]string, error) {
if !r.HasExtension("network_integrations") {
return nil, fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

// Fetch the raw URL values.
urls := []string{}
baseURL := "/network-integrations"
_, err := r.queryStruct("GET", baseURL, nil, "", &urls)
if err != nil {
return nil, err
}

// Parse it.
return urlsToResourceNames(baseURL, urls...)
}

// GetNetworkIntegrations returns a list of network integration structs.
func (r *ProtocolIncus) GetNetworkIntegrations() ([]api.NetworkIntegration, error) {
if !r.HasExtension("network_integrations") {
return nil, fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

integrations := []api.NetworkIntegration{}

// Fetch the raw value.
_, err := r.queryStruct("GET", "/network-integrations?recursion=1", nil, "", &integrations)
if err != nil {
return nil, err
}

return integrations, nil
}

// GetNetworkIntegration returns a network integration entry.
func (r *ProtocolIncus) GetNetworkIntegration(name string) (*api.NetworkIntegration, string, error) {
if !r.HasExtension("network_integrations") {
return nil, "", fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

integration := api.NetworkIntegration{}

// Fetch the raw value.
etag, err := r.queryStruct("GET", fmt.Sprintf("/network-integrations/%s", url.PathEscape(name)), nil, "", &integration)
if err != nil {
return nil, "", err
}

return &integration, etag, nil
}

// CreateNetworkIntegration defines a new network integration using the provided struct.
// Returns true if the integration connection has been mutually created. Returns false if integrationing has been only initiated.
func (r *ProtocolIncus) CreateNetworkIntegration(integration api.NetworkIntegrationsPost) error {
if !r.HasExtension("network_integrations") {
return fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

// Send the request.
_, _, err := r.query("POST", "/network-integrations", integration, "")
if err != nil {
return err
}

return nil
}

// UpdateNetworkIntegration updates the network integration to match the provided struct.
func (r *ProtocolIncus) UpdateNetworkIntegration(name string, integration api.NetworkIntegrationPut, ETag string) error {
if !r.HasExtension("network_integrations") {
return fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

// Send the request.
_, _, err := r.query("PUT", fmt.Sprintf("/network-integrations/%s", url.PathEscape(name)), integration, ETag)
if err != nil {
return err
}

return nil
}

// RenameNetworkIntegration renames an existing network integration entry.
func (r *ProtocolIncus) RenameNetworkIntegration(name string, network api.NetworkIntegrationPost) error {
if !r.HasExtension("network_integrations") {
return fmt.Errorf("The server is missing the required \"network_integrations\" API extension")
}

// Send the request
_, _, err := r.query("POST", fmt.Sprintf("/network-integrations/%s", url.PathEscape(name)), network, "")
if err != nil {
return err
}

return nil
}

// DeleteNetworkIntegration deletes an existing network integration.
func (r *ProtocolIncus) DeleteNetworkIntegration(name string) error {
if !r.HasExtension("network_integrations") {
return fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

// Send the request.
_, _, err := r.query("DELETE", fmt.Sprintf("/network-integrations/%s", url.PathEscape(name)), nil, "")
if err != nil {
return err
}

return nil
}
4 changes: 4 additions & 0 deletions client/incus_network_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (r *ProtocolIncus) CreateNetworkPeer(networkName string, peer api.NetworkPe
return fmt.Errorf(`The server is missing the required "network_peer" API extension`)
}

if peer.Type != "" && peer.Type != "local" && !r.HasExtension("network_integrations") {
return fmt.Errorf(`The server is missing the required "network_integrations" API extension`)
}

// Send the request.
_, _, err := r.query("POST", fmt.Sprintf("/networks/%s/peers", url.PathEscape(networkName)), peer, "")
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ type InstanceServer interface {
UpdateNetworkZoneRecord(zone string, name string, record api.NetworkZoneRecordPut, ETag string) (err error)
DeleteNetworkZoneRecord(zone string, name string) (err error)

// Network integrations functions ("network_integrations" API extension)
GetNetworkIntegrationNames() (names []string, err error)
GetNetworkIntegrations() (integrations []api.NetworkIntegration, err error)
GetNetworkIntegration(name string) (integration *api.NetworkIntegration, ETag string, err error)
CreateNetworkIntegration(integration api.NetworkIntegrationsPost) (err error)
UpdateNetworkIntegration(name string, integration api.NetworkIntegrationPut, ETag string) (err error)
RenameNetworkIntegration(name string, integration api.NetworkIntegrationPost) (err error)
DeleteNetworkIntegration(name string) (err error)

// Operation functions
GetOperationUUIDs() (uuids []string, err error)
GetOperations() (operations []api.Operation, err error)
Expand Down
4 changes: 4 additions & 0 deletions cmd/incus/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (c *cmdNetwork) Command() *cobra.Command {
networkForwardCmd := cmdNetworkForward{global: c.global}
cmd.AddCommand(networkForwardCmd.Command())

// Integration
networkIntegrationCmd := cmdNetworkIntegration{global: c.global}
cmd.AddCommand(networkIntegrationCmd.Command())

// Load Balancer
networkLoadBalancerCmd := cmdNetworkLoadBalancer{global: c.global}
cmd.AddCommand(networkLoadBalancerCmd.Command())
Expand Down
Loading
Loading