Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 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))
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
 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))
Ejemplo n.º 11
0
 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()
Ejemplo n.º 12
0
 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))