kopia lustrzana https://github.com/OpenDroneMap/WebODM
update_node_info is now able to update django models with external info from node-OpenDroneMap
rodzic
98b66013fe
commit
804193b9a1
|
@ -0,0 +1 @@
|
|||
default_app_config = 'nodeodm.apps.NodeodmConfig'
|
|
@ -2,28 +2,33 @@
|
|||
A wrapper around Bravado to communicate with a node-OpenDroneMap node.
|
||||
"""
|
||||
from bravado.client import SwaggerClient
|
||||
|
||||
def check_client(func):
|
||||
def check(self, *args, **kwargs):
|
||||
"""
|
||||
Makes sure that the client has been instantiated.
|
||||
Sometimes this will fail (rest endpoint might be offline),
|
||||
so we need to handle it gracefully...
|
||||
"""
|
||||
if not self.client:
|
||||
try:
|
||||
self.client = SwaggerClient.from_url('http://{}:{}/swagger.json'.format(host, port))
|
||||
except ConnectionError as err:
|
||||
print("ProcessingNode {}:{} seems offline: {}".format(self.host, self.port, err))
|
||||
return None
|
||||
|
||||
return func(self, *args, **kwargs)
|
||||
from requests import ConnectionError
|
||||
|
||||
class ApiClient:
|
||||
def check_client(func):
|
||||
def check(self, *args, **kwargs):
|
||||
"""
|
||||
Makes sure that the client has been instantiated.
|
||||
Sometimes this will fail (rest endpoint might be offline),
|
||||
so we need to handle it gracefully...
|
||||
"""
|
||||
if not hasattr(self, 'client'):
|
||||
try:
|
||||
self.client = SwaggerClient.from_url('http://{}:{}/swagger.json'.format(self.host, self.port))
|
||||
except ConnectionError as err:
|
||||
print("{}:{} seems offline: {}".format(self.host, self.port, err))
|
||||
return None
|
||||
return func(self, *args, **kwargs)
|
||||
return check
|
||||
|
||||
def __init__(self, host, port):
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
||||
@check_client
|
||||
def info(self):
|
||||
return self.client.server.get_info().result()
|
||||
return self.client.server.get_info().result()
|
||||
|
||||
@check_client
|
||||
def options(self):
|
||||
return self.client.server.get_options().result()
|
|
@ -2,6 +2,6 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class NodeodmConfig(AppConfig):
|
||||
name = 'nodeodm'
|
||||
verbose_name = 'Node Management'
|
||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.db import models
|
||||
from django.contrib.postgres import fields
|
||||
from django.utils import timezone
|
||||
from .api_client import ApiClient
|
||||
|
||||
class ProcessingNode(models.Model):
|
||||
|
@ -16,19 +17,24 @@ class ProcessingNode(models.Model):
|
|||
super(ProcessingNode, self).__init__(*args, **kwargs)
|
||||
|
||||
# Initialize api client
|
||||
if self.hostname != None and self.port != None:
|
||||
print("HI!")
|
||||
self.api_client = ApiClient(self.hostname, self.port)
|
||||
self.api_client = ApiClient(self.hostname, self.port)
|
||||
|
||||
def __str__(self):
|
||||
print("OH!");
|
||||
self.update_info()
|
||||
return '{}:{}'.format(self.hostname, self.port)
|
||||
|
||||
|
||||
def update_info(self):
|
||||
def update_node_info(self):
|
||||
"""
|
||||
Retrieves information from the node
|
||||
Retrieves information and options from the node
|
||||
and saves it into the database
|
||||
"""
|
||||
print(self.api_client.info())
|
||||
info = self.api_client.info()
|
||||
if info != None:
|
||||
self.api_version = info['version']
|
||||
self.queue_count = info['taskQueueCount']
|
||||
|
||||
options = self.api_client.options()
|
||||
if options != None:
|
||||
self.available_options = options
|
||||
self.last_refreshed = timezone.now()
|
||||
|
||||
self.save()
|
||||
|
|
Ładowanie…
Reference in New Issue