-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Initial code for mesos-manager - defined a mesos-manager serve…
…r - fixed mesos server code to run - handle CNI input data"
- Loading branch information
Showing
6 changed files
with
253 additions
and
21 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. | ||
# | ||
|
||
_WEB_HOST = '127.0.0.1' | ||
_WEB_PORT = 6991 | ||
_CASSANDRA_HOST = '127.0.0.1' | ||
_CASSANDRA_PORT = 9160 | ||
_CASSANDRA_MAX_RETRIES = 5 | ||
_CASSANDRA_TIMEOUT = 0.5 | ||
_ZK_HOST = '127.0.0.1' | ||
_ZK_PORT = 2181 | ||
DEFAULT_VERSION='1.0' | ||
|
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
194 changes: 194 additions & 0 deletions
194
src/container/mesos-manager/mesos_manager/mesos_server.py
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,194 @@ | ||
# | ||
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. | ||
# | ||
|
||
""" | ||
MESOS CNI Server | ||
""" | ||
|
||
import bottle | ||
import json | ||
from cfgm_common.rest import LinkObject | ||
from vnc_api.vnc_api import * | ||
|
||
class MesosServer(object): | ||
|
||
def __init__(self, args=None, logger=None, q=None): | ||
self._args = args | ||
self.logger = logger | ||
|
||
self._homepage_links = [] | ||
self._cni_data = {} | ||
|
||
self._base_url = "http://%s:%s" % (self._args.listen_ip_addr, | ||
self._args.listen_port) | ||
self._pipe_start_app = None | ||
bottle.route('/', 'GET', self.homepage_http_get) | ||
|
||
# Add CNI information | ||
bottle.route('/add_cni_info', 'POST', self.add_cni_info) | ||
self._homepage_links.append( | ||
LinkObject( | ||
'action', | ||
self._base_url , '/add_cni_info', 'Add CNI information')) | ||
|
||
# Get CNI information | ||
bottle.route('/get_cni_info', 'GET', self.get_cni_info_all) | ||
self._homepage_links.append( | ||
LinkObject( | ||
'action', | ||
self._base_url , '/get_cni_info', 'get all CNI information')) | ||
|
||
# get a specific CNI information | ||
bottle.route('/get_cni_info/<container_id>', 'GET', self.get_cni_info_all) | ||
|
||
# show config | ||
bottle.route('/config', 'GET', self.show_config) | ||
self._homepage_links.append( | ||
LinkObject( | ||
'action', | ||
self._base_url , '/config', 'show cni config')) | ||
|
||
# show debug | ||
bottle.route('/stats', 'GET', self.show_stats) | ||
self._homepage_links.append( | ||
LinkObject( | ||
'action', | ||
self._base_url , '/stats', 'show cni debug stats')) | ||
|
||
# cleanup | ||
bottle.route('/cleanup', 'GET', self.cleanup_http_get) | ||
self._homepage_links.append(LinkObject('action', | ||
self._base_url , '/cleanup', 'Purge deleted cni')) | ||
|
||
if not self._pipe_start_app: | ||
self._pipe_start_app = bottle.app() | ||
|
||
def process_cni_data(self, container_id, data): | ||
event = json.loads(data) | ||
print event | ||
self.q.put(event) | ||
pass | ||
|
||
def create_cni_data(self, container_id, data): | ||
if not container_id in self._cni_data: | ||
self._cni_data[container_id] = {} | ||
self._cni_data[container_id] = data | ||
self.process_cni_data(container_id, data) | ||
return self._cni_data[container_id] | ||
# end | ||
|
||
def delete_cni_data(self, container_id): | ||
if container_id in self._cni_data: | ||
del self._cni_data[container_id] | ||
# end | ||
|
||
def get_cni_data(self, container_id, service_type): | ||
if container_id in self._cni_data: | ||
return self._cni_data[container_id] | ||
return None | ||
# end | ||
|
||
# Public Methods | ||
def get_args(self): | ||
return self._args | ||
# end get_args | ||
|
||
def get_ip_addr(self): | ||
return self._args.listen_ip_addr | ||
# end get_ip_addr | ||
|
||
def get_port(self): | ||
return self._args.listen_port | ||
# end get_port | ||
|
||
def get_pipe_start_app(self): | ||
return self._pipe_start_app | ||
# end get_pipe_start_app | ||
|
||
def add_cni_info(self): | ||
json_req = {} | ||
ctype = bottle.request.headers['content-type'] | ||
try: | ||
if 'application/json' in ctype: | ||
data = bottle.request.json | ||
elif 'application/xml' in ctype: | ||
data = xmltodict.parse(bottle.request.body.read()) | ||
except Exception as e: | ||
self.syslog('Unable to parse publish request') | ||
self.syslog(bottle.request.body.buf) | ||
bottle.abort(415, 'Unable to parse publish request') | ||
|
||
for key, value in data.items(): | ||
json_req[key] = value | ||
print json_req | ||
|
||
cid = json_req['cid'] | ||
self.create_cni_data(cid, json_req) | ||
|
||
return json_req | ||
# end add_cni_info | ||
|
||
def get_cni_info_all(self): | ||
return self._cni_data | ||
# end get_cni_info_all | ||
|
||
# purge expired cni | ||
def cleanup_http_get(self): | ||
return "Cleanup" | ||
# end cleanup_http_get | ||
|
||
def show_config(self): | ||
rsp = "" | ||
|
||
rsp += '<table border="1" cellpadding="1" cellspacing="0">\n' | ||
rsp += '<tr><th colspan="2">Defaults CONFIGG</th></tr>' | ||
for k in sorted(self._args.__dict__.iterkeys()): | ||
v = self._args.__dict__[k] | ||
rsp += '<tr><td>%s</td><td>%s</td></tr>' % (k, v) | ||
rsp += '</table>' | ||
rsp += '<br>' | ||
|
||
return rsp | ||
# end show_config | ||
|
||
def show_stats(self): | ||
|
||
rsp = "" | ||
rsp += ' <table border="1" cellpadding="1" cellspacing="0">\n' | ||
for k in sorted(stats.iterkeys()): | ||
rsp += ' <tr>\n' | ||
rsp += ' <td>%s</td>\n' % (k) | ||
rsp += ' <td>STATSSS</td>\n' | ||
rsp += ' </tr>\n' | ||
return rsp | ||
# end show_stats | ||
|
||
def homepage_http_get(self): | ||
json_links = [] | ||
url = bottle.request.url[:-1] | ||
for link in self._homepage_links: | ||
json_links.append({'link': link.to_dict(with_url=url)}) | ||
|
||
json_body = \ | ||
{"href": self._base_url, | ||
"links": json_links | ||
} | ||
|
||
return json_body | ||
# end homepage_http_get | ||
|
||
def start_server(self): | ||
self.logger.info("Starting server.") | ||
|
||
pipe_start_app = self.get_pipe_start_app() | ||
|
||
try: | ||
bottle.run(app=pipe_start_app, host=self.get_ip_addr(), | ||
port=self.get_port(), server='gevent') | ||
except Exception as e: | ||
import pdb; pdb.set_trace() | ||
self.cleanup() | ||
# start_server | ||
|
||
# end class MesosServer |