Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Moxa status query #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion api/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from schemas import IPCallSchema, NumberCallSchema, MOXACallSchema
from jobs import call_using_custom_wrapper

import socket
import subprocess


# Python 2 and python3 compat for str type assertions
try:
basestring
Expand Down Expand Up @@ -195,11 +199,37 @@ def put(self):
})


class MoxaStatus(Resource):

def test_moxa(self, public_ip, moxa_port=950):
status = False
if public_ip:
status = subprocess.call('/bin/ping -c 1 {}'.format(public_ip), shell=True) == 0
if not status and moxa_port:
s = socket.socket()
s.settimeout(10.0)
error_moxa_conn = s.connect_ex((public_ip, moxa_port))
s.close()
status = error_moxa_conn == 0
return status

def get(self, address):
'''
Tests moxa
* ping
'''
is_alive = self.test_moxa(address)
return jsonify({
'is_alive': is_alive,
}
)

resources = [
(CallEnqueue, '/call/'),
(CallStatus, '/call/<string:job_id>'),
(UserToken, '/get_token'),
(UserTokenValid, '/is_token_valid'),
(UserPassword, '/user/password'),
(ApiCatchall, '/<path:path>/')
(ApiCatchall, '/<path:path>/'),
(MoxaStatus, '/moxa/<string:address>'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquest ha d'anar abans del catchall sinó no serà accessible pq el catchall fa match abans

]