-
Notifications
You must be signed in to change notification settings - Fork 33
/
route_table.go
67 lines (56 loc) · 2.26 KB
/
route_table.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
65
66
67
package types
import (
"fmt"
"github.com/multycloud/multy/api/proto/commonpb"
"github.com/multycloud/multy/resources/common"
"github.com/multycloud/multy/api/errors"
"github.com/multycloud/multy/api/proto/resourcespb"
"github.com/multycloud/multy/resources"
"github.com/multycloud/multy/validate"
)
/*
Notes:
AWS: Internet route to IGW
Azure: Internet route nextHop Internet
*/
type RouteTable struct {
resources.ChildResourceWithId[*VirtualNetwork, *resourcespb.RouteTableArgs]
VirtualNetwork *VirtualNetwork `mhcl:"ref=virtual_network"`
}
func (r *RouteTable) Create(resourceId string, args *resourcespb.RouteTableArgs, others *resources.Resources) error {
return NewRouteTable(r, resourceId, args, others)
}
func (r *RouteTable) Update(args *resourcespb.RouteTableArgs, others *resources.Resources) error {
return NewRouteTable(r, r.ResourceId, args, others)
}
func (r *RouteTable) Import(resourceId string, args *resourcespb.RouteTableArgs, others *resources.Resources) error {
return NewRouteTable(r, resourceId, args, others)
}
func (r *RouteTable) Export(_ *resources.Resources) (*resourcespb.RouteTableArgs, bool, error) {
return r.Args, true, nil
}
func NewRouteTable(rt *RouteTable, resourceId string, args *resourcespb.RouteTableArgs, others *resources.Resources) error {
vn, err := resources.Get[*VirtualNetwork](resourceId, others, args.VirtualNetworkId)
if err != nil {
return errors.ValidationError(resources.NewError(err, rt.ResourceId, "virtual_network_id"))
}
rt.ChildResourceWithId = resources.NewChildResource(resourceId, vn, args)
rt.Parent = vn
rt.VirtualNetwork = vn
return nil
}
func (r *RouteTable) Validate(ctx resources.MultyContext) (errs []validate.ValidationError) {
if len(r.Args.Routes) > 20 {
errs = append(errs, r.NewValidationError(fmt.Errorf("\"%d\" exceeds routes limit is 20", len(r.Args.Routes)), "routes"))
}
for _, route := range r.Args.Routes {
if route.Destination == resourcespb.RouteDestination_UNKNOWN_DESTINATION {
errs = append(errs, r.NewValidationError(fmt.Errorf("unknown route destination"), "route"))
}
// if route.CidrBlock valid CIDR
}
return errs
}
func (r *RouteTable) ParseCloud(args *resourcespb.RouteTableArgs) commonpb.CloudProvider {
return common.ParseCloudFromResourceId(args.VirtualNetworkId)
}