2016-05-29 18:56:50 +02:00
|
|
|
class NodeInit(object):
|
|
|
|
def __init__(self, NodeJsonObject):
|
|
|
|
self.__jsonObject__ = NodeJsonObject
|
|
|
|
self.nodeID = self.__jsonObject__['nodeinfo']['node_id']
|
|
|
|
self.interfaces = self.__getInterfaces__()
|
|
|
|
self.hostname = self.__jsonObject__['nodeinfo']['hostname']
|
2017-04-23 23:09:31 +02:00
|
|
|
self.isGateway = self.__jsonObject__['nodeinfo']['isGateway']
|
2016-05-29 18:56:50 +02:00
|
|
|
self.geo = self.__getGeo__()
|
|
|
|
self.isAutoupdaterEnabled = self.__getAutoupdaterStatus__()
|
|
|
|
self.autoupdaterBranch = self.__getBranch__()
|
2017-04-23 23:09:31 +02:00
|
|
|
self.isOnline = self.__jsonObject__['nodeinfo']['isOnline']
|
2016-05-29 18:56:50 +02:00
|
|
|
self.publicIPv6Addresses = self.__getPublicAddresses__()
|
2017-08-19 23:25:30 +02:00
|
|
|
self.domName = self.__getSiteCode__()
|
2016-05-29 18:56:50 +02:00
|
|
|
|
|
|
|
def __getInterfaces__(self):
|
|
|
|
try:
|
|
|
|
return self.__jsonObject__['nodeinfo']['network']['mesh']['bat0']['interfaces']
|
|
|
|
except:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def __getAutoupdaterStatus__(self):
|
2017-08-18 22:07:40 +02:00
|
|
|
try:
|
2016-05-29 18:56:50 +02:00
|
|
|
return self.__jsonObject__['nodeinfo']['software']['autoupdater']['enabled']
|
2017-08-18 22:07:40 +02:00
|
|
|
except:
|
2016-05-29 18:56:50 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
def __getBranch__(self):
|
2017-08-18 22:07:40 +02:00
|
|
|
try:
|
|
|
|
return self.__jsonObject__['nodeinfo']['software']['autoupdater']['branch']
|
|
|
|
except:
|
|
|
|
return None
|
2016-05-29 18:56:50 +02:00
|
|
|
|
|
|
|
def __getGeo__(self):
|
2017-08-19 23:25:30 +02:00
|
|
|
try:
|
|
|
|
return {
|
|
|
|
'lat' : self.__jsonObject__['nodeinfo']['location']['latitude'],
|
|
|
|
'lon' : self.__jsonObject__['nodeinfo']['location']['longitude']
|
|
|
|
}
|
|
|
|
except:
|
|
|
|
return None
|
2016-05-29 18:56:50 +02:00
|
|
|
|
|
|
|
def __getPublicAddresses__(self):
|
|
|
|
addresses = []
|
2017-08-19 23:25:30 +02:00
|
|
|
try:
|
2016-05-29 18:56:50 +02:00
|
|
|
for address in self.__jsonObject__['nodeinfo']['network']['addresses']:
|
2016-05-29 20:12:47 +02:00
|
|
|
if not address.startswith('fe80'):
|
2016-05-29 18:56:50 +02:00
|
|
|
addresses.append(address)
|
2017-08-19 23:25:30 +02:00
|
|
|
except:
|
|
|
|
pass
|
2016-05-29 18:56:50 +02:00
|
|
|
return addresses
|
|
|
|
|
|
|
|
def __getSiteCode__(self):
|
|
|
|
try:
|
|
|
|
return self.__jsonObject__['nodeinfo']['system']['site_code']
|
|
|
|
except:
|
|
|
|
return None
|