@@ -172,6 +172,7 @@ func handleRequests() {
172172 router .HandleFunc ("/unloadKernelModule" , UnloadKernelModule ).Methods ("POST" )
173173 router .HandleFunc ("/getProcessID" , GetProcessID ).Methods ("POST" )
174174 router .HandleFunc ("/isKernelModuleLoaded" , IsKernelModuleLoaded ).Methods ("POST" )
175+ router .HandleFunc ("/isPackageInstalled" , IsPackageInstalled ).Methods ("POST" )
175176 router .HandleFunc ("/isKernelModulePersistent" , IsKernelModulePersistent ).Methods ("POST" )
176177 router .HandleFunc ("/configureNonPersistentHugePages" , ConfigureNonPersistentHugePages ).Methods ("POST" )
177178 router .HandleFunc ("/isHugePagesPersistent" , IsHugePagesPersistent ).Methods ("POST" )
@@ -351,6 +352,28 @@ func IsKernelModuleLoaded(w http.ResponseWriter, r *http.Request) {
351352 WrapResult (output , ErrNone , w )
352353}
353354
355+ func IsPackageInstalled (w http.ResponseWriter , r * http.Request ) {
356+ var packageName string
357+ d := json .NewDecoder (r .Body )
358+ if err := d .Decode (& packageName ); err != nil {
359+ fmt .Fprint (w , err .Error ())
360+ klog .Error ("failed to read JSON encoded data, Error: " , err )
361+ return
362+ }
363+ klog .Info ("Checking if package is installed " , packageName )
364+ params := fmt .Sprintf ("nsenter --mount=/proc/1/ns/mnt dpkg -s %s >/dev/null 2>&1 && echo 0 || echo 1" , packageName )
365+ klog .Info ("Checking if package is installed" )
366+ output , err := bashLocal (params )
367+ if err != nil {
368+ w .WriteHeader (InternalServerErrorCode )
369+ fmt .Fprint (w , err .Error ())
370+ klog .Error ("failed to check if package is installed:" , packageName , "Error: " , err )
371+ return
372+ }
373+ klog .Info ("Successfully checked if package is installed" )
374+ WrapResult (output , ErrNone , w )
375+ }
376+
354377func IsKernelModulePersistent (w http.ResponseWriter , r * http.Request ) {
355378 var module KernelModule
356379 d := json .NewDecoder (r .Body )
@@ -462,16 +485,8 @@ func GetProcessID(w http.ResponseWriter, r *http.Request) {
462485 klog .Error ("failed to retrieve process ID for:" , process , "Error: " , err )
463486 return
464487 }
465- processBytes , err := base64 .StdEncoding .DecodeString (output )
466- if err != nil {
467- w .WriteHeader (InternalServerErrorCode )
468- fmt .Fprint (w , err .Error ())
469- klog .Error ("failed to decode process ID for:" , process , "Error: " , err )
470- return
471- }
472- process = string (processBytes )
473488 klog .Info ("Successfully retrieved process ID" )
474- WrapResult (process , ErrNone , w )
489+ WrapResult (output , ErrNone , w )
475490}
476491
477492func createFaultyDevice (w http.ResponseWriter , r * http.Request ) {
0 commit comments