kopia lustrzana https://github.com/OpenDroneMap/WebODM
Moved ProcessingNode to nodeodm module
rodzic
6a4f02fc27
commit
98b66013fe
|
@ -252,7 +252,7 @@
|
|||
</li>
|
||||
{% endfor %}
|
||||
<li>
|
||||
<a href="/admin/app/processingnode/add/"><span class="fa fa-plus-circle"></span> Add New</a>
|
||||
<a href="/admin/nodeodm/processingnode/add/"><span class="fa fa-plus-circle"></span> Add New</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- /.nav-second-level -->
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
from api_client import *
|
|
@ -3,9 +3,27 @@ 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)
|
||||
|
||||
class ApiClient:
|
||||
def __init__(self, host, port):
|
||||
# TODO
|
||||
client = SwaggerClient.from_url('http://{}:{}/swagger.json'.format(host, port))
|
||||
print client.server.get_info().result()
|
||||
print dir(client)
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
||||
@check_client
|
||||
def info(self):
|
||||
return self.client.server.get_info().result()
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.db import models
|
||||
from django.contrib.postgres import fields
|
||||
from .api_client import ApiClient
|
||||
|
||||
class ProcessingNode(models.Model):
|
||||
hostname = models.CharField(max_length=255, help_text="Hostname where the node is located (can be an internal hostname as well)")
|
||||
|
@ -10,5 +11,24 @@ class ProcessingNode(models.Model):
|
|||
last_refreshed = models.DateTimeField(null=True, help_text="When was the information about this node last retrieved?")
|
||||
queue_count = models.PositiveIntegerField(default=0, help_text="Number of tasks currently being processed by this node (as reported by the node itself)")
|
||||
available_options = fields.JSONField(default=dict(), help_text="Description of the options that can be used for processing")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
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)
|
||||
|
||||
def __str__(self):
|
||||
print("OH!");
|
||||
self.update_info()
|
||||
return '{}:{}'.format(self.hostname, self.port)
|
||||
|
||||
|
||||
def update_info(self):
|
||||
"""
|
||||
Retrieves information from the node
|
||||
and saves it into the database
|
||||
"""
|
||||
print(self.api_client.info())
|
Ładowanie…
Reference in New Issue