Skip to content

Commit

Permalink
Merge pull request #655 from stgraber/ovn-ic
Browse files Browse the repository at this point in the history
Introduce network integrations (and OVN inter-connect support)
  • Loading branch information
hallyn committed Mar 25, 2024
2 parents 8792dfa + 886e616 commit db3115e
Show file tree
Hide file tree
Showing 51 changed files with 10,508 additions and 5,172 deletions.
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

0 comments on commit db3115e

Please sign in to comment.