def Run(self, args: rdf_cloud.CloudMetadataRequests): bios_version = None services = None if platform.system() == "Linux": bios_version = subprocess.check_output( self.LINUX_BIOS_VERSION_COMMAND) bios_version = bios_version.decode("utf-8") elif platform.system() == "Windows": services = subprocess.check_output(self.WINDOWS_SERVICES_COMMAND) services = services.decode("utf-8") else: # Interrogate shouldn't call this client action on OS X machines at all, # so raise. raise RuntimeError("Only linux and windows cloud vms supported.") result_list = [] instance_type = None for request in args.requests: if self.IsCloud(request, bios_version, services): instance_type = request.instance_type result_list.append(self.GetMetaData(request)) if result_list: self.SendReply( rdf_cloud.CloudMetadataResponses(responses=result_list, instance_type=instance_type))
def Run(self, args): bios_version = None services = None if platform.system() == "Linux": bios_version = subprocess.check_output(self.BIOS_VERSION_COMMAND) elif platform.system() == "Windows": cmd = [ "%s\\System32\\sc.exe" % os.environ.get("SYSTEMROOT", r"C:\Windows"), "query" ] services = subprocess.check_output(cmd) else: # Interrogate shouldn't call this client action on OS X machines at all, # so raise. raise RuntimeError("Only linux and windows cloud vms supported.") result_list = [] instance_type = None for request in args.requests: if self.IsCloud(request, bios_version, services): instance_type = request.instance_type result_list.append(self.GetMetaData(request)) if result_list: self.SendReply( rdf_cloud.CloudMetadataResponses( responses=result_list, instance_type=instance_type))
def Run(self, args: rdf_cloud.CloudMetadataRequests): bios_version = None services = None # The output of commands is not guaranteed to contain valid Unicode text but # it should most of the time. Since we are just searching for a particular # pattern it is safe to replace spurious bytes with '�' as they simply have # no significance for search results. if platform.system() == "Linux": bios_version = subprocess.check_output(self.LINUX_BIOS_VERSION_COMMAND) bios_version = bios_version.decode("utf-8", "replace") elif platform.system() == "Windows": services = subprocess.check_output(self.WINDOWS_SERVICES_COMMAND) services = services.decode("utf-8", "replace") else: # Interrogate shouldn't call this client action on OS X machines at all, # so raise. raise RuntimeError("Only linux and windows cloud vms supported.") result_list = [] instance_type = None for request in args.requests: if self.IsCloud(request, bios_version, services): instance_type = request.instance_type result_list.append(self.GetMetaData(request)) if result_list: self.SendReply( rdf_cloud.CloudMetadataResponses( responses=result_list, instance_type=instance_type))
def GetCloudVMMetadata(self, args): result_list = [] for request in args.requests: result_list.append( rdf_cloud.CloudMetadataResponse( label=request.label or request.url, text=request.label)) return [ rdf_cloud.CloudMetadataResponses( responses=result_list, instance_type="GOOGLE") ]