Skip to content

Commit

Permalink
feat(models): add created_at and updated_at timestamps
Browse files Browse the repository at this point in the history
Working on #278

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Oct 24, 2023
1 parent ae6a0dc commit 695ff86
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pkg/models/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ package models
import (
// "encoding/binary"
"net"
"time"

pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
)

// Bridge object, separate from protobuf for decoupling
type Bridge struct {
Name string
Vni uint32
VlanID uint32
VtepIP net.IPNet
Name string
Vni uint32
VlanID uint32
VtepIP net.IPNet
CreatedAt time.Time
UpdatedAt time.Time
}

// build time check that struct implements interface
Expand All @@ -28,7 +31,7 @@ func NewBridge(in *pb.LogicalBridge) *Bridge {
// binary.BigEndian.PutUint32(vtepip, in.Spec.VtepIpPrefix.Addr.GetV4Addr())
// vip := net.IPNet{IP: vtepip, Mask: net.CIDRMask(int(in.Spec.VtepIpPrefix.Len), 32)}
// TODO: Vni: *in.Spec.Vni
return &Bridge{VlanID: in.Spec.VlanId}
return &Bridge{VlanID: in.Spec.VlanId, CreatedAt: time.Now()}
}

// ToPb transforms SVI object to protobuf message
Expand Down
10 changes: 9 additions & 1 deletion pkg/models/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package models

import (
"net"
"time"

pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
)
Expand All @@ -28,6 +29,8 @@ type Port struct {
Ptype BridgePortType
MacAddress net.HardwareAddr
LogicalBridgeRefKeys []string
CreatedAt time.Time
UpdatedAt time.Time
}

// build time check that struct implements interface
Expand All @@ -36,7 +39,12 @@ var _ EvpnObject[*pb.BridgePort] = (*Port)(nil)
// NewPort creates new SVI object from protobuf message
func NewPort(in *pb.BridgePort) *Port {
mac := net.HardwareAddr(in.Spec.MacAddress)
return &Port{Ptype: BridgePortType(in.Spec.Ptype), MacAddress: mac, LogicalBridgeRefKeys: in.Spec.LogicalBridges}
return &Port{
Ptype: BridgePortType(in.Spec.Ptype),
MacAddress: mac,
LogicalBridgeRefKeys: in.Spec.LogicalBridges,
CreatedAt: time.Now(),
}
}

// ToPb transforms SVI object to protobuf message
Expand Down
4 changes: 4 additions & 0 deletions pkg/models/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package models
import (
"encoding/binary"
"net"
"time"

pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
)
Expand All @@ -20,6 +21,8 @@ type Svi struct {
GwIP []net.IPNet
EnableBgp bool
RemoteAs uint32
CreatedAt time.Time
UpdatedAt time.Time
}

// build time check that struct implements interface
Expand All @@ -42,6 +45,7 @@ func NewSvi(in *pb.Svi) *Svi {
GwIP: gwIPList,
EnableBgp: in.Spec.EnableBgp,
RemoteAs: in.Spec.RemoteAs,
CreatedAt: time.Now(),
}
return svi
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/models/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package models
import (
"encoding/binary"
"net"
"time"

pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
)
Expand All @@ -20,6 +21,8 @@ type Vrf struct {
LocalAs int
RoutingTable uint32
MacAddress net.HardwareAddr
CreatedAt time.Time
UpdatedAt time.Time
}

// build time check that struct implements interface
Expand All @@ -34,7 +37,7 @@ func NewVrf(in *pb.Vrf) *Vrf {
// vtepip := make(net.IP, 4)
// binary.BigEndian.PutUint32(vtepip, in.Spec.VtepIpPrefix.Addr.GetV4Addr())
// vip := net.IPNet{IP: vtepip, Mask: net.CIDRMask(int(in.Spec.VtepIpPrefix.Len), 32)}
return &Vrf{LoopbackIP: lip, MacAddress: mac, RoutingTable: in.Status.RoutingTable}
return &Vrf{LoopbackIP: lip, MacAddress: mac, RoutingTable: in.Status.RoutingTable, CreatedAt: time.Now()}
}

// ToPb transforms VRF object to protobuf message
Expand Down

0 comments on commit 695ff86

Please sign in to comment.