def datagramReceived(self, datagram, address): request = SsdpRequest(datagram) addr = ipaddress.ip_address(str(address[0])) # Since we really only need to support queries from clients based on # pdtools, we can be choosy about what requests we will respond to. # # 1. Only reply to M-SEARCH requests. # 2. The search target (ST) must match our URN or one of the common # wildcard targets. # 3. The recipient MUST be a private IP address. if not request.error_code and \ request.command == "M-SEARCH" and \ request.path == "*" and \ request.headers['ST'] in ["ssdp:all", "upnp:rootdevice", PARADROP_URN] and \ request.headers['MAN'] == '"ssdp:discover"' and \ addr.is_private: os_ver = system_info.getOSVersion() pd_ver = system_info.getPackageVersion("paradrop") message = "\r\n".join([ "HTTP/1.1 200 OK", "CACHE-CONTROL: max-age=60", "LOCATION: http://{domain}", "SERVER: OS/{os_ver} UPnP/1.1 Paradrop/{pd_ver}", "ST: {urn}" ]).format(domain=settings.LOCAL_DOMAIN, os_ver=os_ver, pd_ver=pd_ver, urn=PARADROP_URN) self.transport.write(message, address)
def __init__(self): self.vendor = pdos.read_sys_file( '/sys/devices/virtual/dmi/id/sys_vendor') self.board = pdos.read_sys_file('/sys/devices/virtual/dmi/id/product_name', default='') \ + ' ' + pdos.read_sys_file('/sys/devices/virtual/dmi/id/product_version', default='') self.cpu = platform.processor() self.memory = virtual_memory().total self.wifi = [] devices = detectSystemDevices() for wifiDev in devices['wifi']: self.wifi.append({ 'id': wifiDev['id'], 'macAddr': wifiDev['mac'], 'vendorId': wifiDev['vendor'], 'deviceId': wifiDev['device'], 'slot': wifiDev['slot'] }) self.biosVendor = pdos.read_sys_file( '/sys/devices/virtual/dmi/id/bios_vendor') self.biosVersion = pdos.read_sys_file( '/sys/devices/virtual/dmi/id/bios_version') self.biosDate = pdos.read_sys_file( '/sys/devices/virtual/dmi/id/bios_date') self.osVersion = getOSVersion() self.kernelVersion = platform.system() + '-' + platform.release() self.pdVersion = getPackageVersion('paradrop') self.uptime = int( float(pdos.read_sys_file('/proc/uptime', default='0').split()[0]))
def __init__(self): self.vendor = pdos.read_sys_file('/sys/devices/virtual/dmi/id/sys_vendor') self.board = pdos.read_sys_file('/sys/devices/virtual/dmi/id/product_name', default='') \ + ' ' + pdos.read_sys_file('/sys/devices/virtual/dmi/id/product_version', default='') self.cpu = platform.processor() self.memory = virtual_memory().total self.wifi = [] devices = detectSystemDevices() for wifiDev in devices['wifi']: self.wifi.append({ 'id': wifiDev['id'], 'macAddr': wifiDev['mac'], 'vendorId': wifiDev['vendor'], 'deviceId': wifiDev['device'], 'slot': wifiDev['slot'] }) self.biosVendor = pdos.read_sys_file('/sys/devices/virtual/dmi/id/bios_vendor') self.biosVersion = pdos.read_sys_file('/sys/devices/virtual/dmi/id/bios_version') self.biosDate = pdos.read_sys_file('/sys/devices/virtual/dmi/id/bios_date') self.osVersion = getOSVersion() self.kernelVersion = platform.system() + '-' + platform.release() self.pdVersion = getPackageVersion('paradrop') self.uptime = int(float(pdos.read_sys_file('/proc/uptime', default='0').split()[0]))
def prepare(self): report = StateReport() report.name = nexus.core.info.pdid report.osVersion = system_info.getOSVersion() # We can get the paradrop version from the installed python package. report.paradropVersion = system_info.getPackageVersion('paradrop') # TODO: Get pdinstall version - we will have to work with snappy or # devise some other mechanism, since it installs as a completely # separate snap. report.chutes = [] chuteStore = ChuteStorage() chutes = chuteStore.getChuteList() allocation = resource.computeResourceAllocation(chutes) for chute in chutes: container = ChuteContainer(chute.name) report.chutes.append({ 'name': chute.name, 'desired': chute.state, 'state': container.getStatus(), 'warning': chute.warning, 'version': getattr(chute, 'version', None), 'allocation': allocation.get(chute.name, None), 'environment': getattr(chute, 'environment', None), 'external': getattr(chute, 'external', None), 'resources': getattr(chute, 'resources', None) }) report.devices = devices.listSystemDevices() report.hostConfig = hostconfig.prepareHostConfig(write=False) client = SnapdClient() report.snaps = client.listSnaps() report.zerotierAddress = zerotier.getAddress() report.dmi = system_info.getDMI() # Add CPU, memory, disk, and network interface information. This gives # the controller useful debugging information such as high memory or # disk utilization and IP addresses. status_source = SystemStatus() report.status = status_source.getStatus(max_age=None) return report.__dict__
def prepare(self): report = StateReport() report.name = nexus.core.info.pdid report.osVersion = system_info.getOSVersion() # We can get the paradrop version from the installed python package. report.paradropVersion = system_info.getPackageVersion('paradrop') report.chutes = [] chuteStore = ChuteStorage() chutes = chuteStore.getChuteList() allocation = resource.computeResourceAllocation(chutes) for chute in chutes: service_info = {} for service in chute.get_services(): container_name = service.get_container_name() container = ChuteContainer(container_name) service_info[service.name] = { 'allocation': allocation.get(container_name, None), 'state': container.getStatus() } # Use the default service (e.g. "main") to report the chute's # current state. service = chute.get_default_service() container = ChuteContainer(service.get_container_name()) report.chutes.append({ 'name': chute.name, 'desired': chute.state, 'state': container.getStatus(), 'services': service_info, 'warning': None, 'version': getattr(chute, 'version', None), 'allocation': None, # deprecated 'environment': getattr(chute, 'environment', None), 'external': getattr(chute, 'external', None), 'resources': getattr(chute, 'resources', None) }) report.devices = devices.listSystemDevices() report.hostConfig = hostconfig.prepareHostConfig(write=False) if GovernorClient.isAvailable(): client = GovernorClient() report.snaps = client.listSnaps() report.zerotierAddress = zerotier.getAddress() report.dmi = system_info.getDMI() # Add CPU, memory, disk, and network interface information. This gives # the controller useful debugging information such as high memory or # disk utilization and IP addresses. status_source = SystemStatus() report.status = status_source.getStatus(max_age=None) return report.__dict__