This repository was archived by the owner on Feb 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,42 @@ func (m *DHClientManager) Get(_ context.Context, args *godhcpd.DHClientManagedId
104104 return nil , status .Errorf (codes .NotFound , msg )
105105}
106106
107+ // Delete deletes a dhcp client.
108+ func (m * DHClientManager ) Delete (_ context.Context , args * godhcpd.DHClientManagedId ) (* godhcpd.DHClientManagedId , error ) {
109+ id := args .GetId ()
110+
111+ DHClient := m .DHClientsManaged [id ]
112+ if DHClient == nil {
113+ msg := "dhcp client not found"
114+
115+ log .Error (msg )
116+
117+ return nil , status .Errorf (codes .NotFound , msg )
118+ }
119+
120+ log .Info ("Stopping dhcp client" )
121+
122+ if err := DHClient .DisableAutoRestart (); err != nil { // Manually disable auto restart; disables crash recovery even if process is not running
123+ log .Error (err .Error ())
124+
125+ return nil , status .Errorf (codes .Unknown , err .Error ())
126+ }
127+
128+ if DHClient .IsRunning () {
129+ if err := DHClient .Stop (); err != nil { // Stop is sync, so no need to `.Wait()`
130+ log .Error (err .Error ())
131+
132+ return nil , status .Errorf (codes .Unknown , err .Error ())
133+ }
134+ }
135+
136+ delete (m .DHClientsManaged , id )
137+
138+ return & godhcpd.DHClientManagedId {
139+ Id : id ,
140+ }, nil
141+ }
142+
107143// Extract extracts the ISC DHCP client binary.
108144func (m * DHClientManager ) Extract () error {
109145 statikFS , err := fs .New ()
You can’t perform that action at this time.
0 commit comments