コード例 #1
0
ファイル: project.py プロジェクト: xueqiu/warden
 def GET(self, group_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     rows = ProjectModel().rows(group_id)
     return self.resp(data=rows)
コード例 #2
0
ファイル: environment.py プロジェクト: xueqiu/warden
 def POST(self, group_name, proj_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     project = ProjectModel().load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id = project['id']
     all_envs = EnvironmentModel().rows(project_id)
     all_env_names = [ env['name'] for env in all_envs ]
     if len(all_envs) == 0:
         return self.resp(errno=3, errmsg='no environment in this project')
     param_keys = web.input().keys()
     if param_keys == None or len(param_keys) == 0:
         return self.resp(errno=4, errmsg='no envoronment and uid_rate param in request body')
     for param_key in param_keys:
         if param_key not in all_env_names:
             return self.resp(errno=5, errmsg='%s is not in project environment, please check, all env names is:%s' % (
                 param_key, str(all_env_names) ))
     if len(param_keys) != len(all_envs):
         return self.resp(errno=6, errmsg="param count is not equal to this project's environment name count, all env names is:%s" % (
             str(all_env_names) ))
     param_val_sum = 0
     param_vals = web.input().values()
     for param_val in param_vals:
         if '.' in param_val:
             return self.resp(errno=7, errmsg='uid_rate should be interger not float')
         try:
             param_val = int(param_val)
         except Exception, ex:
             return self.resp(errno=8, errmsg='uid_rate should be interger not float')
         if param_val < 0:
             return self.resp(errno=9, errmsg='uid_rate should be more than or equal 0')
         param_val_sum = param_val_sum + param_val
コード例 #3
0
ファイル: openresty.py プロジェクト: xueqiu/warden
 def DELETE(self, group_name, host, port):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     OpenrestyModel().delete(group_id, host, port)
     return self.resp()
コード例 #4
0
def upstream_check():
    groupModel = GroupModel()
    groups = groupModel.rows()
    for group in groups:
        #这里返回ip,port去重后的结果
        all_upstreams = groupModel.allUpstreams(group['id'])
        #协程批量curl,填充请求结果
        all_upstreams = batch_check(all_upstreams)
        for upstream in all_upstreams:
            key = cache.gen_upstream_key(upstream['host'], upstream['port'])
            status = cache.get(key)
            if status == '':
                if upstream['status'] == 'failed':
                    do_offline(group, upstream)
                    log.info('set upstream %s:%s status to %s' %
                             (upstream['host'], upstream['port'],
                              upstream['status']))
            else:
                if status == upstream['status']:
                    continue
                if upstream['status'] == 'failed':
                    do_offline(group, upstream)
                else:
                    do_online(group, upstream)
                log.info('set upstream %s:%s status from %s to %s' %
                         (upstream['host'], upstream['port'], status,
                          upstream['status']))
コード例 #5
0
ファイル: project.py プロジェクト: xueqiu/warden
 def DELETE(self, group_name, project_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     ProjectModel().delete(group_id, project_name)
     return self.resp()
コード例 #6
0
ファイル: project.py プロジェクト: xueqiu/warden
 def PUT(self, group_name, project_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     try:
         ProjectModel().add(group_id, project_name)
     except Exception, ex:
         return self.resp(errno=2, errmsg=str(ex))
コード例 #7
0
ファイル: environment.py プロジェクト: xueqiu/warden
 def DELETE(self, group_name, proj_name, env_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     project = ProjectModel().load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id =project['id']
     EnvironmentModel().delete(project_id, env_name)
     return self.resp()
コード例 #8
0
ファイル: environment.py プロジェクト: xueqiu/warden
 def GET(self, group_name, proj_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     project = ProjectModel().load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id =project['id']
     rows = EnvironmentModel().rows(project_id)
     return self.resp(data=rows)
コード例 #9
0
ファイル: util.py プロジェクト: kyleslight/wutong
    def __init__(self, number):
        self.number = number
        self.db = db_test
        self.user = UserModel(self.db)
        self.group = GroupModel(self.db)
        self.article = ArticleModel(self.db)
        self.admin = {
            'email': '*****@*****.**',
            'penname': 'wutong',
            'password': '******',
        }

        self.gen_test_data()
コード例 #10
0
ファイル: environment.py プロジェクト: xueqiu/warden
 def PUT(self, group_name, proj_name, env_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     project = ProjectModel().load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id =project['id']
     try:
         EnvironmentModel().add(project_id, env_name)
     except Exception, ex:
         return self.resp(errno=3, errmsg=str(ex))
コード例 #11
0
ファイル: openresty.py プロジェクト: xueqiu/warden
 def PUT(self, group_name, host, port):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     if self.isValidIp(host) == False:
         return self.resp(errno=2, errmsg='%s is invalid ip' % host)
     if self.isValidPort(port) == False:
         return self.resp(errno=3, errmsg='%s is invalid port' % port)
     try:
         OpenrestyModel().add(group_id, host, port)
     except Exception, ex:
         return self.resp(errno=4, errmsg=str(ex))
コード例 #12
0
ファイル: upstream.py プロジェクト: xueqiu/warden
 def DELETE(self, group_name, proj_name, env_name, host, port):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     project = ProjectModel().load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id =project['id']
     environment = EnvironmentModel().load(project_id, env_name)
     if environment == None:
         return self.resp(errno=3, errmsg='no this environment')
     env_id = environment['id']
     UpstreamModel().delete(env_id, host, port)
     return self.resp()
コード例 #13
0
ファイル: no_uid.py プロジェクト: xueqiu/warden
 def PUT(self, group_name, proj_name, no_uid_env_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     projModel = ProjectModel()
     project = projModel.load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id = project['id']
     all_envs = EnvironmentModel().rows(project_id)
     all_env_names = [env['name'] for env in all_envs]
     if no_uid_env_name not in all_env_names:
         if no_uid_env_name != '':
             return self.resp(errno=3, errmsg='no this env, please call api set')
     projModel.setNoUidEnv(project_id, no_uid_env_name)
     return self.resp()
コード例 #14
0
def batch_set_resty_upstream(group, upstream, oper):
    if group == None or upstream == None: return
    if oper not in ['up', 'down']: return
    all_openresty = GroupModel().allOpenrestys(group['id'])
    if len(all_openresty) == 0:
        log.error('group:%s has no openresty', group['name'])
        return
    from gevent import monkey
    monkey.patch_socket()
    import gevent
    greenlets = [
        gevent.spawn(set_resty_upstream, openresty, upstream, oper)
        for openresty in all_openresty
    ]
    gevent.joinall(greenlets)
    key = cache.gen_upstream_key(upstream['host'], upstream['port'])
    cache.set(key, upstream['status'])
    log.info('set cache finish')
コード例 #15
0
    def setUpClass(cls):
        cls.db = util.db_test
        cls.tearDownClass()

        cls.uid = cls.db.getfirstfield("""
            insert into "user"
                   (email, penname, password, is_activated)
            values ('*****@*****.**', 'test', 'test', true)
            returning uid
        """)

        cls.model = GroupModel(util.db_test)
        cls.name = 'test_group'

        sql = """insert into "group"
                        (uid, name)
                 values (%s, %s)
                 returning gid"""
        cls.gid = cls.db.getfirstfield(sql, cls.uid, cls.name)
コード例 #16
0
ファイル: special_uid.py プロジェクト: xueqiu/warden
 def PUT(self, group_name, proj_name, spec_uid_str):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     projModel = ProjectModel()
     project = projModel.load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this priject')
     project_id = project['id']
     spec_uid_list = list(
         set([spec_uid.strip() for spec_uid in spec_uid_str.split(',')]))
     try:
         spec_uid_list.remove('')
     except:
         pass
     spec_uid_str = ','.join(spec_uid_list)
     ProjectModel().setSpecUid(project_id, spec_uid_str)
     return self.resp()
コード例 #17
0
ファイル: upstream.py プロジェクト: xueqiu/warden
 def PUT(self, group_name, proj_name, env_name, host, port):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     project = ProjectModel().load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this project')
     project_id =project['id']
     environment = EnvironmentModel().load(project_id, env_name)
     if environment == None:
         return self.resp(errno=3, errmsg='no this environment')
     env_id = environment['id']
     if self.isValidIp(host) == False:
         return self.resp(errno=4, errmsg = '%s is invalid ip' % host)
     if self.isValidPort(port) == False:
         return self.resp(errno=5, errmsg='%s is invalid port' % port)
     try:
         UpstreamModel().add(env_id, host, port)
     except Exception, ex:
         return self.resp(errno=6, errmsg=str(ex))
コード例 #18
0
 def PUT(self, group_name, proj_name, spec_env_name):
     group = GroupModel().load(group_name)
     if group == None:
         return self.resp(errno=1, errmsg='no this group')
     group_id = group['id']
     projModel = ProjectModel()
     project = projModel.load(group_id, proj_name)
     if project == None:
         return self.resp(errno=2, errmsg='no this priject')
     project_id = project['id']
     all_envs = EnvironmentModel().rows(project_id)
     if len(all_envs) == 0:
         return self.resp(
             errno=3,
             errmsg='now this project has no environment, please add')
     all_env_names = [env['name'] for env in all_envs]
     if spec_env_name not in all_env_names and spec_env_name != '':
         return self.resp(
             errno=4,
             errmsg="special env name is not in this project's environment")
     projModel.setSpecialEnv(project_id, spec_env_name)
     return self.resp()
コード例 #19
0
ファイル: group.py プロジェクト: xueqiu/warden
 def DELETE(self, group_name):
     try:
         GroupModel().delete(group_name)
     except Exception, ex:
         return self.resp(errno=1, errmsg=str(ex))
コード例 #20
0
ファイル: group.py プロジェクト: xueqiu/warden
 def PUT(self, group_name):
     try:
         GroupModel().add(group_name)
     except Exception, ex:
         return self.resp(errno=1, errmsg=str(ex))
コード例 #21
0
ファイル: group.py プロジェクト: xueqiu/warden
 def GET(self):
     return self.resp(data=GroupModel().rows())