示例#1
0
文件: __init__.py 项目: RobWC/doit
  def group_vars_by_group(group):
    domain_name = request.args.get('domain')
    domain = Domain(domain_name)
    myDoit = DOIT(domain)
    domainList = myDoit.get_domain_list()
    groupObj = myDoit.get_group_by_name(group)
    groupObj = myDoit.get_group_vars(groupObj)
    try:
      groupVars = groupObj.toDict()[group]['vars']
    except KeyError:
      groupVars = {}

    title = "{0} Variables".format(group)
    return render_template('group_vars_list.j2',title=title,groupVars=groupVars,domainList=domainList,domain_name=domain_name)
示例#2
0
文件: __init__.py 项目: RobWC/doit
  def api(type,name,action):
    reqMethod = request.method
    domain_name = request.args.get('domain')
    group_name = request.args.get('group')
    value = request.args.get('value')
    response = Response()
    #contentType = request.headers['content-type']
    domain = Domain(domain_name)
    myDoit = DOIT(domain)
    #content = request.json['content']

    if type == 'host':
      #handle host requests

      #require domain be set
      if domain_name == None:
        abort(500)

      if action == 'create' and reqMethod == 'POST':
        response.data = json.dumps(myDoit.add_host(name).toDict())
      elif action == 'delete' and reqMethod == 'DELETE':
        response.data = json.dumps(myDoit.delete_host_by_name(name).toDict())
      #elif action == 'update' and reqMethod == 'PUT':
        #response.data = json.dumps(myDoit.update_host_by_name().toDict())
      elif action == 'list' and reqMethod == 'GET':
        response.data = json.dumps(myDoit.get_host_by_name(name).toDict())
      else:
        abort(500)
    elif type == 'group':
      #handle group requests
      if action == 'create' and reqMethod == 'POST':
        response.data = json.dumps(myDoit.add_group(name).toDict())
      elif action == 'delete' and reqMethod == 'DELETE':
        response.data = json.dumps(myDoit.delete_group_by_name(name).toDict())
      #elif action == 'update' and reqMethod == 'PUT':
        #response.data = json.dumps(myDoit.update_host_by_name().toDict())
      elif action == 'list' and reqMethod == 'GET':
        response.data = json.dumps(myDoit.get_group_by_name(name).toDict())
      else:
        abort(500)
    elif type == 'domain':
      #handle domain requests
      if action == 'create' and reqMethod == 'POST':
        response.data = json.dumps(myDoit.add_domain(name).toDict())
      elif action == 'delete' and reqMethod == 'DELETE':
        response.data = json.dumps(myDoit.delete_domain_by_name(name).toDict())
      #elif action == 'update' and reqMethod == 'PUT':
        #response.data = json.dumps(myDoit.update_host_by_name().toDict())
      elif action == 'list' and reqMethod == 'GET':
        response.data = json.dumps(myDoit.get_domain_by_name(name).toDict())
      else:
        abort(500)
    elif type == 'group_var':
      # Add group var requires group query item
      if group_name == None:
        abort(500)
      #handle group_var requests
      if action == 'create' and reqMethod == 'POST':
        response.data = json.dumps(myDoit.add_group_var(name,value,group_name).toDict())
      elif action == 'delete' and reqMethod == 'DELETE':
        response.data = json.dumps(myDoit.delete_group_var(name,group_name).toDict())
      #elif action == 'update' and reqMethod == 'PUT':
        #response.data = json.dumps(myDoit.update_host_by_name().toDict())
      elif action == 'list' and reqMethod == 'GET':
        response.data = json.dumps(myDoit.get_domain_by_name(name).toDict())
      else:
        abort(500)
    elif type == 'host_var':
      #add host var api
      print 'host_var'

    response.headers['Content-Type'] = 'application/json'
    return response