Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

file head format

  • Loading branch information...
commit 1e46d45eebee1d227ef428a172b3281ec73d7a5a 1 parent 2587219
@hokerffb hokerffb authored
View
4 bin/api-client
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
@@ -28,7 +27,6 @@ from collections import OrderedDict
from kanyun.client import api_client
from kanyun.common import const
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-4-5
def show_result(rs, cf_str):
for i in rs:
View
3  bin/api-server
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
3  bin/listip
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
5 bin/server
@@ -1,9 +1,6 @@
#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-3-19
-
# Copyright 2012 Sina Corporation
# All Rights Reserved.
# Author: YuWei Peng <pengyuwei@gmail.com>
View
3  bin/worker
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
0  common/__init__.py
No changes.
View
206 common/protocol.py
@@ -1,206 +0,0 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
-#
-# Copyright 2012 Sina Corporation
-# All Rights Reserved.
-# Author:
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-"""
-msg_type = 'lb'
-msg_id = str(uuid.uuid1())
-
-======== client -> server ==============
-
-# 'create_lb'
-msg_body = {'cmd': 'create_lb',
- 'msg': {'user_name': 'myUser',
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- # http, tcp
- 'protocol': http,
- 'listen_port': 80,
- 'instance_port': 80,
- # round_robin, source_binding
- 'balancing_method': 'round_robin',
- 'health_check_timeout_ms': 5,
- 'health_check_interval_ms': 0.5,
- # if http
- 'health_check_target_path': '/',
- 'health_check_fail_count': 2,
- # elif tcp
- 'health_check_healthy_treshold':10,
- 'health_check_unhealthy_treshold':2,
- # end if
- 'instance_uuids': ["a-uuid", "b-uuid", "c-uuid"],
- 'http_server_names': ['www.abc.com', 'www.xyz.com'],
- }
- }
-
-# 'delete_lb' or 'read_lb'
-message = {'cmd': 'delete_lb',
- 'msg': {'user_name': 'myUser',
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- }
- }
-
-# 'read_lb_list'
-message = {'cmd': 'read_lb_list',
- 'msg': {'user_name': 'myUser'
- 'tenant': 'myTenant'
- }
- }
-
-# After you create a load balancer, you can modify any of the settings,
-# except for Load Balancer Name and Port Configuration.
-
-# To rename a load balancer or change its port configuration,
-# create a replacement load balancer.
-
-# 'update_lb_config'
-message = {'cmd': 'update_lb_config',
- 'msg': {'user_name': 'myUser',
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- # round_robin, source_binding
- 'balancing_method': 'round_robin',
- 'health_check_timeout_ms': 5,
- 'health_check_interval_ms': 0.5,
- # if http
- 'health_check_target_path': '/',
- 'health_check_fail_count': 2,
- # elif tcp
- 'health_check_healthy_treshold':10,
- 'health_check_unhealthy_treshold':2,
- }
- }
-
-# 'update_lb_instances'
-message = {'cmd': 'update_lb_instances',
- 'msg': {'user_name': 12,
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- 'instance_uuids': ["a-uuid", "b-uuid", "c-uuid"],
- }
- }
-
-# 'update_lb_http_server_names'
-message = {'cmd': 'update_lb_http_server_names',
- 'msg': {'user_name': 12,
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- 'http_server_names': ['www.abc.com', 'www.xyz.com'],
- }
- }
-
-======== server -> client ==============
-
-# 'create_lb', 'update_lb', 'delete_lb'
-to_client = {'cmd': <cmd>,
- 'msg' {'desc': 'message string'
- # 200 or 500
- 'code': 200,
- }
- }
-
-# 'read_lb'
-to_client = {'cmd': <cmd>,
- 'msg': {'user_name': 'myUser',
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- # round_robin, source_binding
- 'balancing_method': 'round_robin',
- 'health_check_timeout_ms': 5,
- 'health_check_interval_ms': 0.5,
- # if http
- 'health_check_target_path': '/',
- 'health_check_fail_count': 2,
- # elif tcp
- 'health_check_healthy_treshold':10,
- 'health_check_unhealthy_treshold':2,
- # end if
- 'instance_uuids': ["a-uuid", "b-uuid", "c-uuid"],
- 'http_server_names': ['www.abc.com', 'www.xyz.com'],
- }
- }
-
-# 'read_lb_list'
-to_client = {'cmd': <cmd>,
- 'msg': {'user_name': 'myUser',
- 'tenant': 'myTenant',
- 'load_balancer_list': [{'load_balancer_id': 'myLB',
- # http, tcp
- 'protocol': http,
- 'listen_port': 80,
- 'instance_port': 80,
- },
- {'load_balancer_id': 'myLB',
- # http, tcp
- 'protocol': http,
- 'listen_port': 80,
- 'instance_port': 80,
- },
- ],
- }
- }
-
-======== server -> worker ==============
-
-# 'create_lb', 'update_lb' -> all data of lb must be sent to worker
-to_worker = {'cmd': 'create_lb',
- 'msg': {'user_name': 'myUser',
- 'tenant': 'myTenant',
- 'load_balancer_id': 'myLB',
- # http, tcp
- 'protocol': 'http',
- 'listen_port': 80,
- 'instance_port': 80,
- # round_robin, source_binding
- 'balancing_method': 'round_robin',
- 'health_check_timeout_ms': 5,
- 'health_check_interval_ms': 0.5,
- # if http
- 'health_check_target_path': '/',
- 'health_check_fail_count': 2,
- # elif tcp
- 'health_check_healthy_treshold':10,
- 'health_check_unhealthy_treshold':2,
- # end if
- 'instance_uuids': ["a-uuid", "b-uuid", "c-uuid"],
- # add instance fixed ips and send to worker
- 'instance_ips': ['10.4.5.6', '10.3.4.5', '10.8.8.8']
- 'http_server_names': ['www.abc.com', 'www.xyz.com'],
- }
- }
-
-# 'delete_lb'
-to_worker= {'cmd': 'delete_lb',
- 'msg': {'user_name': 'myUser'
- 'tenant': 'myTenant'
- 'load_balancer_id': 'myLB',
- }
- }
-
-======== worker -> server ==============
-
-from_worker = {'cmd': <cmd>,
- 'msg' {'worker_id': 2,
- # 200 or 500
- 'code': 200,
- 'desc': 'message string'
- }
- }
-"""
View
5 kanyun/client/api_client.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
@@ -26,7 +24,6 @@
from kanyun.common.const import *
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-4-5
"""
protocol:
View
6 kanyun/common/const.py
@@ -1,8 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
-#
-# Last update: Yuwei Peng<pengyuwei@gmail.com> 2012-4-6
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
8 kanyun/database/cassadb.py
@@ -1,9 +1,5 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
-
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-3-28
-
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
# Author: YuWei Peng <pengyuwei@gmail.com>
View
69 kanyun/server/api_server.py
@@ -1,8 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
-#
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-3-28
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
@@ -137,11 +133,11 @@ def api_getdata(row_id, cf_str, scf_str, time_from=0, time_to=0):
param type: UnicodeType and IntType
return: recordset, count, bool(count > limit?)
"""
- if not type(row_id) is types.UnicodeType \
- or not type(cf_str) is types.UnicodeType \
- or not type(scf_str) is types.UnicodeType \
- or not type(time_from) is types.IntType \
- or not type(time_to) is types.IntType:
+ if not isinstanceof(row_id, unicode)
+ or not isinstanceof(cf_str, unicode)
+ or not isinstanceof(scf_str, unicode)
+ or not isinstanceof(time_from, int)
+ or not isinstanceof(time_to, int):
return None, 0, True
db = get_db()
@@ -149,7 +145,8 @@ def api_getdata(row_id, cf_str, scf_str, time_from=0, time_to=0):
if time_to == 0:
time_to = time.time()
- rs = db.get(cf_str, row_id, super_column=scf_str, column_start=time_from, column_finish=time_to, column_count=20000)
+ rs = db.get(cf_str, row_id, super_column=scf_str,
+ column_start=time_from, column_finish=time_to, column_count=20000)
count = 0 if rs is None else len(rs)
return rs, count, False if (count == 20000) else True
@@ -159,7 +156,9 @@ def analyize_data(rs, period, statistic):
"""[private func]analyize the data
period: minutes
"""
- if rs is None or not type(period) is types.IntType or not type(statistic) is types.IntType:
+ if rs is None
+ or not isinstanceof(period, int)
+ or not isinstanceof(statistic, int):
return None
t = 0
key_time = 0
@@ -168,7 +167,8 @@ def analyize_data(rs, period, statistic):
for timestmp, value in rs.iteritems():
rt = time.gmtime(timestmp)
- key = rt.tm_min + rt.tm_hour*100 + rt.tm_mday*10000 + rt.tm_mon*1000000 + rt.tm_year*100000000
+ key = rt.tm_min + rt.tm_hour*100 + rt.tm_mday*10000 + \
+ rt.tm_mon*1000000 + rt.tm_year*100000000
if t == 0:
print '\tget first value'
st.clean()
@@ -180,7 +180,9 @@ def analyize_data(rs, period, statistic):
t = timestmp
key_time = time.gmtime(timestmp)
st.update(float(value))
- key2 = time.mktime((key_time.tm_year, key_time.tm_mon, key_time.tm_mday, key_time.tm_hour, key_time.tm_min,0,0,0,0))
+ key2 = time.mktime(
+ (key_time.tm_year, key_time.tm_mon, key_time.tm_mday,
+ key_time.tm_hour, key_time.tm_min,0,0,0,0))
this_period[key2] = st.get_value(statistic)
print '\tcompute time=%d, value=%s(%f) "update(%s)=%d"' % \
(key, value, float(value), key2, this_period[key2])
@@ -189,15 +191,16 @@ def analyize_data(rs, period, statistic):
print statistic, ":each period(", period, "):"
for m, val in this_period.iteritems():
rt = time.gmtime(m)
- key = rt.tm_min + rt.tm_hour*100 + rt.tm_mday*10000 + rt.tm_mon*1000000 + rt.tm_year*100000000
+ key = rt.tm_min + rt.tm_hour*100 + rt.tm_mday*10000 + \
+ rt.tm_mon*1000000 + rt.tm_year*100000000
print '\t', key, m, val
return this_period
-############################# public API interface #############################
+############################# public API interface ############################
def api_get_instances_list(cf_str):
- if not type(cf_str) is types.UnicodeType:
+ if not isinstanceof(cf_str) is types.UnicodeType:
print 'param types error'
return None
ret = list()
@@ -215,8 +218,8 @@ def api_get_instances_list(cf_str):
def api_get_by_instance_id(row_id, cf_str):
- if not type(row_id) is types.UnicodeType \
- or not type(cf_str) is types.UnicodeType:
+ if not isinstanceof(row_id, unicode)
+ or not isinstanceof(cf_str) is types.UnicodeType:
print 'param types error'
return None, 0, True
db = get_db()
@@ -231,10 +234,10 @@ def api_getbykey(row_id, cf_str, scf_str, limit=20000):
example:cf=u'vmnetwork',scf=u'10.0.0.1',key=u'instance-0000002'
return: recordset, count, bool(count > limit?)
"""
- if not type(row_id) is types.UnicodeType \
- or not type(cf_str) is types.UnicodeType \
- or not type(scf_str) is types.UnicodeType \
- or not type(limit) is types.IntType:
+ if not isinstanceof(row_id, unicode)
+ or not isinstanceof(cf_str, unicode)
+ or not isinstanceof(scf_str, unicode)
+ or not isinstanceof(limit, int):
print 'param types error'
return None, 0, True
db = get_db()
@@ -244,22 +247,24 @@ def api_getbykey(row_id, cf_str, scf_str, limit=20000):
return rs, count, False if (count == 20000) else True
-def api_statistic(row_id, cf_str, scf_str, statistic, period=5, time_from=0, time_to=0):
+def api_statistic(row_id, cf_str, scf_str,
+ statistic, period=5, time_from=0, time_to=0):
"""statistic is STATISTIC enum
period default=5 minutes
time_to default=0(now)"""
- if not type(row_id) is types.UnicodeType \
- or not type(cf_str) is types.UnicodeType \
- or not type(scf_str) is types.UnicodeType \
- or not type(statistic) is types.IntType \
- or not type(period) is types.IntType \
- or not type(time_from) is types.IntType \
- or not type(time_to) is types.IntType:
+ if (not isinstanceof(row_id, unicode)
+ or not isinstanceof(cf_str, unicode)
+ or not isinstanceof(scf_str, unicode)
+ or not isinstanceof(statistic, int)
+ or not isinstanceof(period, int)
+ or not isinstanceof(time_from, int)
+ or not isinstanceof(time_to, int)):
print 'param types error'
return None, 0, True
ret_len = 0
- rs, count, all_data = api_getdata(row_id, cf_str, scf_str, time_from, time_to)
+ rs, count, all_data = api_getdata(row_id, cf_str, scf_str,
+ time_from, time_to)
if not rs is None and count > 0:
buf = analyize_data(rs, 1, statistic)
ret = analyize_data(buf, period, statistic)
View
6 kanyun/server/data_server.py
@@ -1,9 +1,5 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
-# Last update: Peng Yuwei<yuwei5@staff.sina.com.cn> 2012-3-19
-
# Copyright 2012 Sina Corporation
# All Rights Reserved.
# Author: YuWei Peng <pengyuwei@gmail.com>
View
6 kanyun/server/plugin_agent_srv.py
@@ -1,9 +1,5 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-3-23
-
# Copyright 2012 Sina Corporation
# All Rights Reserved.
# Author: YuWei Peng <pengyuwei@gmail.com> 2012-3-23
View
8 kanyun/worker/monitor_worker.conf
@@ -1,8 +0,0 @@
-[Worker]
-id: 1
-log: /tmp/worker.log
-broadcast_host: *
-broadcast_port: 5558
-feedback_host: localhost
-feedback_port: 5559
-worker_timeout: 60
View
5 kanyun/worker/plugin_agent.py
@@ -1,7 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
-# Last update: Yuwei Peng<yuwei5@staff.sina.com.cn> 2012-3-28
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
4 kanyun/worker/plugin_traffic_accounting.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
4 kanyun/worker/worker.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
25 setup.py
@@ -1,12 +1,21 @@
#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space
-
-# Author: Peng Yuwei<yuwei5@staff.sina.com.cn> 2012-4-6
-# Last update: Peng Yuwei<yuwei5@staff.sina.com.cn> 2012-4-6
-
-# python setup.py develop
-# python setup.py install
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2012 Sina Corporation
+# All Rights Reserved.
+# Author: YuWei Peng <pengyuwei@gmail.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
import sys
from setuptools import setup, find_packages
View
4 tests/test_api_server.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
4 tests/test_call_plugin_agent.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
11 tests/test_cassadb.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
@@ -33,7 +31,8 @@ def insert(self, cf_str, key, values):
def get_range(self, cf_str):
pass
- def get(self, cf_str, key, super_column, column_start, column_finish, column_count = 20000):
+ def get(self, cf_str, key, super_column, column_start,
+ column_finish, column_count = 20000):
pass
def getbykey(self, cf_str, key):
@@ -71,7 +70,9 @@ def GetTest(self):
pool = pycassa.ConnectionPool('data', server_list=['127.0.0.1'])
cf = pycassa.ColumnFamily(pool, cf_str)
- rs = cf.get(key=key, super_column=super_column, column_start=column_start, column_finish=column_finish, column_reversed=True, column_count=column_count)
+ rs = cf.get(key=key, super_column=super_column,
+ column_start=column_start, column_finish=column_finish,
+ column_reversed=True, column_count=column_count)
print rs
View
4 tests/test_client.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
4 tests/test_data_server.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
4 tests/test_plugin_agent.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
4 tests/test_plugin_traffic_accounting.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
View
7 tests/test_worker.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# TAB char: space[4]
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Sina Corporation
# All Rights Reserved.
@@ -175,7 +173,8 @@ def test_istime_to_work(self):
sys.stdout.flush()
time.sleep(1)
now = time.localtime()
- print '\n%02d:%02d:%02d working success finished.' % (now[3], now[4], now[5])
+ print '\n%02d:%02d:%02d working success finished.' % \
+ (now[3], now[4], now[5])
w.update_time()
#if only test the first working timepoint, break here.
Please sign in to comment.
Something went wrong with that request. Please try again.