forked from Juniper/contrail
/
service.go
64 lines (55 loc) · 2.04 KB
/
service.go
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
package types
import (
"context"
"github.com/Juniper/asf/pkg/models"
"github.com/Juniper/asf/pkg/services/baseservices"
"github.com/Juniper/contrail/pkg/services"
"github.com/Juniper/contrail/pkg/types/ipam"
)
const (
// VirtualNetworkIDPoolKey identifies the int pool of virtual network IDs.
VirtualNetworkIDPoolKey = "virtual_network_id"
// SecurityGroupIDPoolKey identifies the int pool of security group IDs.
SecurityGroupIDPoolKey = "security_group_id"
)
// InTransactionDoer executes do function atomically.
type InTransactionDoer interface {
DoInTransaction(ctx context.Context, do func(context.Context) error) error
}
// IntPoolAllocator (de)allocates integers in an integer pool.
type IntPoolAllocator interface {
CreateIntPool(context.Context, string, int64, int64) error
GetIntOwner(context.Context, string, int64) (string, error)
DeleteIntPool(context.Context, string) error
AllocateInt(context.Context, string, string) (int64, error)
SetInt(context.Context, string, int64, string) error
DeallocateInt(context.Context, string, int64) error
}
//MetadataGetter provides getter for metadata.
type MetadataGetter interface {
GetMetadata(ctx context.Context, requested models.Metadata) (*models.Metadata, error)
ListMetadata(ctx context.Context, requested []*models.Metadata) ([]*models.Metadata, error)
}
// ContrailTypeLogicService is a service for implementing type specific logic
type ContrailTypeLogicService struct {
services.BaseService
ReadService services.ReadService
InTransactionDoer InTransactionDoer
AddressManager ipam.AddressManager
IntPoolAllocator IntPoolAllocator
MetadataGetter baseservices.MetadataGetter
WriteService services.WriteService
defaultGSCUUID string
}
// FQNameToUUID translates fqName to UUID.
func (sv *ContrailTypeLogicService) FQNameToUUID(
ctx context.Context,
fqName []string,
resourceType string,
) (string, error) {
metadata, err := sv.MetadataGetter.GetMetadata(ctx, models.Metadata{Type: resourceType, FQName: fqName})
if err != nil {
return "", err
}
return metadata.UUID, nil
}