Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 5652b6d

Browse files
committed
feat: Add Get RPC to dhclientd (#10)
1 parent bc21468 commit 5652b6d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pkg/svc/dhclient.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/rakyll/statik/fs"
88
uuid "github.com/satori/go.uuid"
99
"gitlab.com/bloom42/libs/rz-go/log"
10+
"google.golang.org/grpc/codes"
11+
"google.golang.org/grpc/status"
1012
"os"
1113
)
1214

@@ -75,6 +77,33 @@ func (m *DHClientManager) List(_ context.Context, args *godhcpd.DHClientManagerL
7577
}, nil
7678
}
7779

80+
// Get gets one of the managed dhcp clients.
81+
func (m *DHClientManager) Get(_ context.Context, args *godhcpd.DHClientManagedId) (*godhcpd.DHClientManaged, error) {
82+
log.Info("Getting dhcp client")
83+
84+
var DHClientManaged *godhcpd.DHClientManaged
85+
86+
for id, DHClient := range m.DHClientsManaged {
87+
if id == args.GetId() {
88+
DHClientManaged = &godhcpd.DHClientManaged{
89+
Id: id,
90+
Device: DHClient.Device,
91+
}
92+
break
93+
}
94+
}
95+
96+
if DHClientManaged != nil {
97+
return DHClientManaged, nil
98+
}
99+
100+
msg := "dhcp client not found"
101+
102+
log.Error(msg)
103+
104+
return nil, status.Errorf(codes.NotFound, msg)
105+
}
106+
78107
// Extract extracts the ISC DHCP client binary.
79108
func (m *DHClientManager) Extract() error {
80109
statikFS, err := fs.New()

pkg/svc/dhcpd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (m *DHCPDManager) Get(_ context.Context, args *godhcpd.DHCPDManagedId) (*go
141141
return DHCPDManaged, nil
142142
}
143143

144-
msg := "dhcp server not not found"
144+
msg := "dhcp server not found"
145145

146146
log.Error(msg)
147147

0 commit comments

Comments
 (0)