Skip to content

Commit

Permalink
Merge pull request #107 from gmacf/resolve
Browse files Browse the repository at this point in the history
Add additional fields to EntityLookup: IP address and hardware model.
  • Loading branch information
gmacf authored Dec 4, 2023
2 parents 2ea6d44 + 599d3e7 commit afc4082
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions server/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"crypto"
"crypto/tls"
"crypto/x509"
"net"

"github.com/openconfig/gnmi/errlist"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

Expand Down Expand Up @@ -61,6 +63,8 @@ type SecurityArtifacts struct {
type EntityLookup struct {
Manufacturer string
SerialNumber string
PartNumber string
IPAddress string
}

// EntityManager maintains the entities and their states.
Expand All @@ -81,6 +85,11 @@ func (s *Service) GetBootstrapData(ctx context.Context, req *bpb.GetBootstrapDat
log.Infof("=============================================================================")
log.Infof("==================== Received request for bootstrap data ====================")
log.Infof("=============================================================================")
peerAddr, err := peerAddressFromContext(ctx)
if err != nil {
return nil, err
}
log.Infof("Received GetBootstrapData request from %v", peerAddr)
fixedChasis := true
ccSerial := ""
chassisDesc := req.GetChassisDescriptor()
Expand All @@ -92,6 +101,8 @@ func (s *Service) GetBootstrapData(ctx context.Context, req *bpb.GetBootstrapDat
lookup := &EntityLookup{
Manufacturer: chassisDesc.GetManufacturer(),
SerialNumber: chassisDesc.GetSerialNumber(),
PartNumber: chassisDesc.GetPartNumber(),
IPAddress: peerAddr,
}
// Validate the chassis can be serviced
chassis, err := s.em.ResolveChassis(ctx, lookup, ccSerial)
Expand Down Expand Up @@ -181,6 +192,18 @@ func (s *Service) SetDeviceConfiguration(ctx context.Context) error {
return status.Errorf(codes.Unimplemented, "Unimplemented")
}

func peerAddressFromContext(ctx context.Context) (string, error) {
p, ok := peer.FromContext(ctx)
if !ok {
return "", status.Error(codes.InvalidArgument, "no peer information found in request context")
}
a, ok := p.Addr.(*net.TCPAddr)
if !ok {
return "", status.Errorf(codes.InvalidArgument, "peer address type must be TCP")
}
return a.IP.String(), nil
}

// New creates a new service.
func New(em EntityManager) *Service {
return &Service{
Expand Down

0 comments on commit afc4082

Please sign in to comment.