@@ -184,6 +184,18 @@ func (p *execClient) ExecutePowershellCommand(command string) (string, error) {
184184
185185// SetSdnRemoteArpMacAddress sets the regkey for SDNRemoteArpMacAddress needed for multitenancy if hns is enabled
186186func SetSdnRemoteArpMacAddress (ctx context.Context ) error {
187+ if err := setSDNRemoteARPRegKey (); err != nil {
188+ return err
189+ }
190+ log .Printf ("SDNRemoteArpMacAddress regKey set successfully" )
191+ if err := restartHNS (ctx ); err != nil {
192+ return err
193+ }
194+ log .Printf ("HNS service restarted successfully" )
195+ return nil
196+ }
197+
198+ func setSDNRemoteARPRegKey () error {
187199 log .Printf ("Setting SDNRemoteArpMacAddress regKey" )
188200 // open the registry key
189201 k , err := registry .OpenKey (registry .LOCAL_MACHINE , `SYSTEM\CurrentControlSet\Services\hns\State` , registry .READ | registry .SET_VALUE )
@@ -202,7 +214,10 @@ func SetSdnRemoteArpMacAddress(ctx context.Context) error {
202214 if err = k .SetStringValue ("SDNRemoteArpMacAddress" , SDNRemoteArpMacAddress ); err != nil {
203215 return errors .Wrap (err , "could not set registry key" )
204216 }
205- log .Printf ("SDNRemoteArpMacAddress regKey set successfully" )
217+ return nil
218+ }
219+
220+ func restartHNS (ctx context.Context ) error {
206221 log .Printf ("Restarting HNS service" )
207222 // connect to the service manager
208223 m , err := mgr .Connect ()
@@ -216,24 +231,16 @@ func SetSdnRemoteArpMacAddress(ctx context.Context) error {
216231 return errors .Wrap (err , "could not access service" )
217232 }
218233 defer service .Close ()
219- if err := restartService (ctx , service ); err != nil {
220- return errors .Wrap (err , "could not restart service" )
221- }
222- log .Printf ("HNS service restarted successfully" )
223- return nil
224- }
225-
226- func restartService (ctx context.Context , s * mgr.Service ) error {
227234 // Stop the service
228- _ , err := s .Control (svc .Stop )
235+ _ , err = service .Control (svc .Stop )
229236 if err != nil {
230237 return errors .Wrap (err , "could not stop service" )
231238 }
232239 // Wait for the service to stop
233240 ticker := time .NewTicker (500 * time .Millisecond ) //nolint:gomnd // 500ms
234241 defer ticker .Stop ()
235242 for { // hacky cancellable do-while
236- status , err := s .Query ()
243+ status , err := service .Query ()
237244 if err != nil {
238245 return errors .Wrap (err , "could not query service status" )
239246 }
@@ -247,7 +254,7 @@ func restartService(ctx context.Context, s *mgr.Service) error {
247254 }
248255 }
249256 // Start the service again
250- if err := s .Start (); err != nil {
257+ if err := service .Start (); err != nil {
251258 return errors .Wrap (err , "could not start service" )
252259 }
253260 return nil
0 commit comments