示例#1
0
文件: views.py 项目: senglobe/ignite
 def post(self, request, format=None):
     me = RequestValidator(request.META)
     if request.data['match']!='serial_id':
         serializer = DiscoveryRuleSerializer(data=request.data)
         if serializer.is_valid():
             rule_object = DiscoveryRule()
             rule_object.name = serializer.data['name']
             rule_object.priority = serializer.data['priority']
             rule_object.user_id = me.user_is_exist().user_id
             rule_object.config_id = serializer.data['config_id']
             rule_object.subrules = json.dumps(serializer.data['subrules'])
             rule_object.match = serializer.data['match'].lower()
             rule_object.save()
             serializer = DiscoveryRuleGetSerializer(rule_object)
             return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         serializer = DiscoveryRuleSerialIDSerializer(data=request.data)
         if serializer.is_valid():
             rule_object = DiscoveryRule()
             rule_object.name = serializer.data['name']
             rule_object.priority = serializer.data['priority']
             rule_object.user_id = me.user_is_exist().user_id
             rule_object.config_id = serializer.data['config_id']
             for i in range(len(serializer.data['subrules'])):
                 serializer.data['subrules'][i]=str(serializer.data['subrules'][i])
             rule_object.subrules = str(serializer.data['subrules'])
             rule_object.match = serializer.data['match']
             rule_object.save()
             serializer = DiscoveryRuleGetSerializer(rule_object)
             return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#2
0
 def post(self, request, format=None):
     me = RequestValidator(request.META)
     if request.data['match'] != 'serial_id':
         serializer = DiscoveryRuleSerializer(data=request.data)
         if serializer.is_valid():
             rule_object = DiscoveryRule()
             rule_object.name = serializer.data['name']
             rule_object.priority = serializer.data['priority']
             rule_object.user_id = me.user_is_exist().user_id
             rule_object.config_id = serializer.data['config_id']
             rule_object.subrules = json.dumps(serializer.data['subrules'])
             rule_object.match = serializer.data['match'].lower()
             rule_object.save()
             serializer = DiscoveryRuleGetSerializer(rule_object)
             return Response(serializer.data,
                             status=status.HTTP_201_CREATED)
     else:
         serializer = DiscoveryRuleSerialIDSerializer(data=request.data)
         if serializer.is_valid():
             rule_object = DiscoveryRule()
             rule_object.name = serializer.data['name']
             rule_object.priority = serializer.data['priority']
             rule_object.user_id = me.user_is_exist().user_id
             rule_object.config_id = serializer.data['config_id']
             for i in range(len(serializer.data['subrules'])):
                 serializer.data['subrules'][i] = str(
                     serializer.data['subrules'][i])
             rule_object.subrules = str(serializer.data['subrules'])
             rule_object.match = serializer.data['match']
             rule_object.save()
             serializer = DiscoveryRuleGetSerializer(rule_object)
             return Response(serializer.data,
                             status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#3
0
def add_discoveryrule(data, username):
    config_obj = get_profile(data[CONFIG])
    image = image_profile.get_profile(data[IMAGE])
    rule_object = DiscoveryRule()
    if data[WORKFLOW]:
        wf = get_workflow(data[WORKFLOW])
        rule_object.workflow = wf
    rule_object.name = data[NAME]
    rule_object.match = data[MATCH].lower()
    if str(data[MATCH]) == SERIAL_NUM:
        find_repeat_serial_num(data[SUBRULES])
        find_duplicate(data[SUBRULES])
    rule_object.priority = data[PRIORITY]
    rule_object.config = config_obj
    rule_object.image = image
    rule_object.subrules = data[SUBRULES]
    rule_object.updated_by = username
    rule_object.save()
    return rule_object
示例#4
0
def add_discoveryrule(data, username):
    config_obj = get_profile(data[CONFIG])
    image = image_profile.get_profile(data[IMAGE])
    rule_object = DiscoveryRule()
    if data[WORKFLOW]:
        wf = get_workflow(data[WORKFLOW])
        rule_object.workflow = wf
    rule_object.name = data[NAME]
    rule_object.match = data[MATCH].lower()
    if str(data[MATCH]) == SERIAL_NUM:
        find_repeat_serial_num(data[SUBRULES])
        find_duplicate(data[SUBRULES])
    rule_object.priority = data[PRIORITY]
    rule_object.config = config_obj
    rule_object.image = image
    rule_object.subrules = data[SUBRULES]
    rule_object.updated_by = username
    rule_object.save()
    return rule_object