File: networks_integrations.go

package info (click to toggle)
incus 6.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,392 kB
  • sloc: sh: 16,313; ansic: 3,121; python: 457; makefile: 337; ruby: 51; sql: 50; lisp: 6
file content (78 lines) | stat: -rw-r--r-- 2,745 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build linux && cgo && !agent

package cluster

import (
	"context"
	"database/sql"

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

// Code generation directives.
//
//generate-database:mapper target networks_integrations.mapper.go
//generate-database:mapper reset -i -b "//go:build linux && cgo && !agent"
//
//generate-database:mapper stmt -e network_integration objects
//generate-database:mapper stmt -e network_integration objects-by-Name
//generate-database:mapper stmt -e network_integration objects-by-ID
//generate-database:mapper stmt -e network_integration create struct=NetworkIntegration
//generate-database:mapper stmt -e network_integration id
//generate-database:mapper stmt -e network_integration rename
//generate-database:mapper stmt -e network_integration update struct=NetworkIntegration
//generate-database:mapper stmt -e network_integration delete-by-Name
//
//generate-database:mapper method -i -e network_integration GetMany references=Config
//generate-database:mapper method -i -e network_integration GetOne struct=NetworkIntegration
//generate-database:mapper method -i -e network_integration Exists struct=NetworkIntegration
//generate-database:mapper method -i -e network_integration Create references=Config
//generate-database:mapper method -i -e network_integration ID struct=NetworkIntegration
//generate-database:mapper method -i -e network_integration Rename
//generate-database:mapper method -i -e network_integration DeleteOne-by-Name
//generate-database:mapper method -i -e network_integration Update struct=NetworkIntegration references=Config

const (
	// NetworkIntegrationTypeOVN represents an OVN network integration.
	NetworkIntegrationTypeOVN = iota
)

// NetworkIntegrationTypeNames is a map between DB type to their string representation.
var NetworkIntegrationTypeNames = map[int]string{
	NetworkIntegrationTypeOVN: "ovn",
}

// NetworkIntegration is a value object holding db-related details about a network integration.
type NetworkIntegration struct {
	ID          int
	Name        string
	Description string
	Type        int
}

// ToAPI converts the DB records to an API record.
func (n *NetworkIntegration) ToAPI(ctx context.Context, tx *sql.Tx) (*api.NetworkIntegration, error) {
	// Get the config.
	config, err := GetNetworkIntegrationConfig(ctx, tx, n.ID)
	if err != nil {
		return nil, err
	}

	// Fill in the struct.
	resp := api.NetworkIntegration{
		Name: n.Name,
		Type: NetworkIntegrationTypeNames[n.Type],
		NetworkIntegrationPut: api.NetworkIntegrationPut{
			Description: n.Description,
			Config:      config,
		},
	}

	return &resp, nil
}

// NetworkIntegrationFilter specifies potential query parameter fields.
type NetworkIntegrationFilter struct {
	ID   *int
	Name *string
}