-
Notifications
You must be signed in to change notification settings - Fork 140
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
Issue#706 websockets #724
Merged
Merged
Issue#706 websockets #724
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
41879cc
Environ issues
gkadillak 5e198bf
Kernel info, uptime being sent to dashboard
gkadillak d467c3b
Added styling, removed polling for kernel version
gkadillak 8def48e
Use handler map to set abstract socket connections
gkadillak e8a1b82
Forgot end of comment
gkadillak ae3741e
Change the server port number
gkadillak b71bfcb
Merge branch 'master' of https://github.com/rockstor/rockstor-core in…
gkadillak ac3e490
update buildout for new changes in library update process. #706
schakrava fbf3d91
Kernel version, uptime displayed
gkadillak b2622bd
Merge branch 'issue#706-websockets' of github.com:gkadillak/rockstor-…
gkadillak e346186
simplify gunicorn parts in buildout.
schakrava 718361d
simplify supervisord config part in buildout. #706
schakrava 57e0b30
simplify django settings part in buildout. #706
schakrava b922cea
Merge branch 'issue#706-websockets' of https://github.com/gkadillak/r…
schakrava 7540876
Use /run(which is tmpfs) for gunicorn and supervisord pids. #660
schakrava 54eb94c
Fixes to dashboard (null error), socket handler
gkadillak 11f0bb1
Merge branch 'issue#706-websockets' of github.com:gkadillak/rockstor-…
gkadillak 9723c83
dc2 supervisord function got lost in translation
gkadillak 1ec51bd
Log connections, write disconnect code
gkadillak 5c92337
Polling removed from services
gkadillak 998bec8
Update each model in collection via websockets
gkadillak d2e4160
update jslibs with socketio. #706
schakrava 2c52ee5
Updated frontend to point to shop
gkadillak 6d3ff21
Clean up, remove console.logs
gkadillak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Kernel info, uptime being sent to dashboard
- Loading branch information
commit 5e198bfb4addbca2442f01fde909e40efa44403c
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from gevent import monkey | ||
monkey.patch_all() | ||
import gevent | ||
from socketio.server import SocketIOServer | ||
from socketio import socketio_manage | ||
from socketio.namespace import BaseNamespace | ||
from socketio.mixins import BroadcastMixin | ||
|
||
from django.conf import settings | ||
from system.osi import (uptime, kernel_info) | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DashboardNamespace(BaseNamespace, BroadcastMixin): | ||
def initialize(self): | ||
pass | ||
|
||
|
||
class SysinfoNamespace(BaseNamespace, BroadcastMixin): | ||
start = False | ||
supported_kernel = settings.SUPPORTED_KERNEL_VERSION | ||
|
||
def initialize(self): | ||
self.emit("sysinfo", {"sysinfo": "connected"}) | ||
self.start = True | ||
gevent.spawn(self.send_uptime) | ||
gevent.spawn(self.send_kernel_info) | ||
|
||
def recv_disconnect(self): | ||
self.start = False | ||
self.disconnect(silent=True) | ||
|
||
def send_uptime(self): | ||
|
||
while self.start: | ||
if not self.start: | ||
break | ||
self.emit('uptime', {'uptime': uptime()}) | ||
# seconds not displayed | ||
gevent.sleep(30) | ||
|
||
def send_kernel_info(self): | ||
while self.start: | ||
if not self.start: | ||
break | ||
try: | ||
self.emit('kernel_info', {'kernel_info': | ||
kernel_info(self.supported_kernel)}) | ||
except: | ||
self.error('unsupported_kernel', 'the kernel is bad') | ||
# kernel information doesn't change that much | ||
gevent.sleep(1000) | ||
|
||
|
||
class Application(object): | ||
def __init__(self): | ||
self.buffer = [] | ||
|
||
def __call__(self, environ, start_response): | ||
path = environ['PATH_INFO'].strip('/') or 'index.html' | ||
|
||
if path.startswith('/static') or path == 'index.html': | ||
try: | ||
data = open(path).read() | ||
except Exception: | ||
return not_found(start_response) | ||
|
||
if path.endswith(".js"): | ||
content_type = "text/javascript" | ||
elif path.endswith(".css"): | ||
content_type = "text/css" | ||
elif path.endswith(".swf"): | ||
content_type = "application/x-shockwave-flash" | ||
else: | ||
content_type = "text/html" | ||
|
||
start_response('200 OK', [('Content-Type', content_type)]) | ||
return [data] | ||
if path.startswith("socket.io"): | ||
socketio_manage(environ, {'/sysinfo': SysinfoNamespace}) | ||
socketio_manage(environ, {'/dashboard': DashboardNamespace}) | ||
|
||
|
||
def not_found(start_response): | ||
start_response('404 Not Found', []) | ||
return ['<h1>Not found</h1>'] | ||
|
||
|
||
def main(): | ||
logger.debug('Listening on port http://127.0.0.1:8080 and on port 10843 (flash policy server)') | ||
server = SocketIOServer(('127.0.0.1', 8080), Application(), | ||
resource="socket.io", policy_server=True).serve_forever() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkadillak Sorry if I've got the wrong end of the stick but shouldn't we copy this library "socket.io.min.js" to our local stash (/static/js/lib/) as what if someone is on a network with limited / or no internet access?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is merely me being lazy, @phillxnet. Once the code gets pushed to production, the hard copy of the file will be referenced.