-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #655 from stgraber/ovn-ic
Introduce network integrations (and OVN inter-connect support)
- Loading branch information
Showing
51 changed files
with
10,508 additions
and
5,172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.