class ElasticGroupConfigValidator(serializers.Serializer): security = serializers.CharField(max_length=100) nets = serializers.ListField(child=serializers.CharField(max_length=100), allow_empty=False) flavor = serializers.CharField(max_length=100) image = serializers.CharField(max_length=100) volumes = serializers.ListField(child=serializers.CharField( max_length=100)) biz = serializers.CharField(max_length=100, allow_blank=True) compute = serializers.CharField(max_length=100)
class CreateMonitorRemoteBusinessValidator(serializers.Serializer): type = serializers.CharField(max_length=128) business = serializers.CharField(max_length=128) targets = serializers.ListField(child=serializers.CharField( max_length=128)) executor = serializers.CharField(max_length=128) cycle = serializers.IntegerField(min_value=0, default=60, required=False) tries = serializers.IntegerField(min_value=0, default=5, required=False) when = serializers.ListField(child=serializers.CharField(max_length=128)) who = serializers.CharField(max_length=128) how = serializers.ListField(child=serializers.CharField(max_length=128))
class DetachJumperAuthorizationUserSerializer(serializers.Serializer): jumper_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(_(u"堡垒机IP"))) host_id = serializers.IntegerField( required=True, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) user_ids = serializers.ListField( required=True, error_messages=serializers.CommonErrorMessages(_(u"用户ID"))) rule_ids = serializers.ListField(required=False)
class DescribeInstancesValidator(serializers.Serializer): """ Describe the instance information if instance_id not not provided, this will show all user's instances """ instance_id = serializers.CharField(required=False, max_length=11) instance_ids = serializers.ListField( required=False, child=serializers.CharField(max_length=11), ) sort_key = serializers.CharField( required=False, validators=[helper.instance_sort_key_valiator]) page = serializers.IntegerField(required=False, min_value=0) count = serializers.IntegerField(required=False, min_value=0) zone = serializers.CharField(required=False) owner = serializers.CharField(required=False) group_id = serializers.IntegerField(required=False, min_value=0) app_system_id = serializers.IntegerField(required=False, min_value=0) limit = serializers.IntegerField(required=False, min_value=0) offset = serializers.IntegerField(required=False, min_value=0) vhost_type = serializers.CharField(required=False, max_length=15) search_instance = serializers.CharField(required=False, max_length=15, allow_blank=True)
class JoinRouterValidator(serializers.Serializer): action = serializers.CharField( max_length=40, required=True, error_messages=serializers.CommonErrorMessages(_(u"执行动作")) ) owner = serializers.CharField( max_length=40, required=True, error_messages=serializers.CommonErrorMessages(_(u"owner")) ) zone = serializers.CharField( max_length=40, required=True, error_messages=serializers.CommonErrorMessages(_(u"zone")) ) router_id = serializers.CharField( max_length=40, required=True, error_messages=serializers.CommonErrorMessages(_(u"路由号")) ) subnet_list = serializers.ListField( child=serializers.CharField(max_length=50, error_messages=serializers.CommonErrorMessages(_(u"子网号")) ) )
class DetachInstanceDisksSerializer(InstanceIDSerializer): disks = serializers.ListField(child=serializers.CharField( max_length=20, required=True, validators=[disk_id_validator])) disk_type = serializers.CharField( required=False, max_length=100, )
class CreateBoardFrameValidator(ValidatorBase): owner = serializers.CharField( max_length=32, error_messages=serializers.CommonErrorMessages('owner') ) board_id = serializers.CharField( max_length=32, error_messages=serializers.CommonErrorMessages('board_id') ) frame_infos = serializers.ListField( error_messages=serializers.CommonErrorMessages('frame_infos') ) def handler(self, validated_data): board = BoardModel.objects.get_board(validated_data['board_id']) frame_infos = validated_data['frame_infos'] result_set = list() for frame_info in frame_infos: ref_action = frame_info.get("ref_action") meta_data = frame_info.get("meta_data") frame = FrameModel.objects.create_frame( board, ref_action, meta_data, ) serializer = FrameSerializer(frame) result_set.append(serializer.data) return ConsoleResponse(ret_set=result_set)
class UpdateCmdbValidator(serializers.Serializer): type = serializers.ChoiceField( choices=CFG_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) cfg_items = serializers.ListField( error_messages=serializers.CommonErrorMessages('cfg_items'))
class DeleteBoardFrameValidator(ValidatorBase): owner = serializers.CharField( max_length=32, error_messages=serializers.CommonErrorMessages('owner') ) frame_ids = serializers.ListField( error_messages=serializers.CommonErrorMessages('frame_id') ) def handler(self, validated_data): direction = 'down' ret = True # (删除模块相当于每次下移一步,直到无法下移时将其删除) frame_ids = validated_data['frame_ids'], logger.debug("%s", frame_ids) for frame_id in frame_ids[0]: while ret: ret = FrameModel.objects.arrange_frame( validated_data['owner'], frame_id, direction ) FrameModel.objects.delete_frame( validated_data['owner'], frame_id ) ret = True return ConsoleResponse(code=ret) pass
class DescribeDisksValidator(serializers.Serializer): # 硬盘的唯一id, 非api disk id disk_id = serializers.CharField(required=False, max_length=11, validators=[disk_id_validator]) # 特定的要展示的硬盘id disks = serializers.ListField(required=False, validators=[disk_id_validator]) sort_key = serializers.CharField(required=False, max_length=20, validators=[disk_sort_key_valiator]) limit = serializers.IntegerField(required=False, min_value=0) offset = serializers.IntegerField(required=False, min_value=0) availability_zone = serializers.CharField(required=False, max_length=64) search_key = serializers.CharField(required=False, max_length=64, allow_blank=True) status = serializers.ChoiceField( required=False, choices=(('available', u'available'), ('in-use', u'in-use'), ('creating', u'creating'), ('deleting', u'deleting'), ('attaching', u'attaching'), ('detaching', u'detaching'), ('error', u'error'), ('error_deleting', u'error_deleting'), ('backing-up', u'backing-up'), ('restoring-backup', u'restoring-backup')))
class JoinNetsValidator(serializers.Serializer): nets = serializers.ListField(required=True, child=serializers.CharField(max_length=100), validators=[net_list_validator]) instance_id = serializers.CharField(max_length=60, required=True, validators=[instance_id_validator])
class CreateNoticeValidator(serializers.Serializer): title = serializers.CharField( error_messages=serializers.CommonErrorMessages('title')) content = serializers.CharField( error_messages=serializers.CommonErrorMessages('content')) notice_list = serializers.ListField( error_messages=serializers.CommonErrorMessages('notice_list'))
class DescribeMonitorVMInfoValidator(serializers.Serializer): num = serializers.IntegerField( required=False, min_value=0, error_messages=serializers.CommonErrorMessages('num')) sort = serializers.ChoiceField( required=False, choices=SORT_METHOD, error_messages=serializers.CommonErrorMessages('sort')) format = serializers.ChoiceField( required=False, choices=PERIOD_CHOICE, error_messages=serializers.CommonErrorMessages('format')) poolname = serializers.CharField( required=False, error_messages=serializers.CommonErrorMessages('poolname')) items = serializers.ListField( required=False, child=serializers.ChoiceField(required=False, choices=VM_ITEM), error_messages=serializers.CommonErrorMessages('items')) timestamp = serializers.IntegerField(required=False, validators=[]) point_num = serializers.IntegerField(required=False, validators=[]) VM_type = serializers.ChoiceField( required=False, choices=('KVM', 'VMWARE'), )
class DeleteCmdbValidator(serializers.Serializer): type = serializers.ChoiceField( choices=CFG_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) ids = serializers.ListField( error_messages=serializers.CommonErrorMessages('ids'))
class DeleteBackupsValidator(serializers.Serializer): """ 删除备份 """ # 备份的ID backups = serializers.ListField(required=True, allow_empty=False, validators=[backup_id_validator])
class JoinNetValidator(serializers.Serializer): net_id = serializers.CharField( required=True, max_length=100, ) instances = serializers.ListField( child=serializers.CharField(max_length=60), required=True, validators=[instance_list_validator])
class UpdateMonitorTemplateNotificationValidator(serializers.Serializer): id = serializers.CharField(max_length=128) when = serializers.CharField(max_length=128, default='touch', required=False) how = serializers.CharField(max_length=128, default='email', required=False) who = serializers.ListField(child=serializers.CharField(max_length=128))
class DescribeLoadbalancersSerializer(serializers.Serializer): lb_id = serializers.CharField(required=False, max_length=20, validators=[lb_id_validator]) features = serializers.ListField( child=serializers.CharField(max_length=57), allow_empty=True, required=False, default=list())
class CreateSecurityGroupRuleSerializer(serializers.Serializer): type = serializers.ChoiceField( default='instance', choices=SECURITY_GROUP_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) rules = serializers.ListField( required=True, validators=[], error_messages=serializers.CommonErrorMessages('rules'))
class EditNoticeValidator(serializers.Serializer): msgid = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages('msgid')) title = serializers.CharField( error_messages=serializers.CommonErrorMessages('title')) content = serializers.CharField( error_messages=serializers.CommonErrorMessages('content')) notice_list = serializers.ListField( error_messages=serializers.CommonErrorMessages('notice_list'))
class CreateWafServiceSerializer(SmcBaseSerializer): """ 增加站点 """ domain = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"站点域名")) ips = serializers.ListField( required=True, error_messages=serializers.CommonErrorMessages(u"站点回源IP"))
class GetMonitorDataValidator(serializers.Serializer): type = serializers.CharField(max_length=128) subtype = serializers.CharField(max_length=128, default=None, required=False) option = serializers.CharField(max_length=128) targets = serializers.ListField(child=serializers.CharField( max_length=100)) cycle = serializers.IntegerField(min_value=1, default=1, required=False) sort = serializers.CharField(max_length=1, default='-', required=False)
class ChangeDepartmentValidator(serializers.Serializer): member_list = serializers.ListField(required=True, child=serializers.CharField( max_length=20, validators=[username_validator]), error_messages=error_message('成员ID列表')) department_id = serializers.CharField( max_length=20, required=True, validators=[department_validator], error_messages=error_message('所在部门id'))
class AddJumperAuthorizationUserOrDetachSerializer(serializers.Serializer): jumper_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(_(u"堡垒机IP"))) host_id = serializers.IntegerField( required=True, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) data = serializers.ListField( required=True, error_messages=serializers.CommonErrorMessages(_(u"操作详情")))
class ApprovalCmdbTicketValidator(serializers.Serializer): ticket_id = serializers.CharField( error_messages=serializers.CommonErrorMessages('ticket_id')) type = serializers.ChoiceField( choices=CFG_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) applicant = serializers.CharField( error_messages=serializers.CommonErrorMessages('applicant')) approve = serializers.CharField( error_messages=serializers.CommonErrorMessages('approve')) cfg_diffs = serializers.ListField( error_messages=serializers.CommonErrorMessages('cfg_diffs'))
class RemoveJumperHostAccountSerializer(serializers.Serializer): jumper_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(_(u"堡垒机IP"))) host_id = serializers.IntegerField( required=True, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) account_ids = serializers.ListField( required=True, error_messages=serializers.CommonErrorMessages(_(u"账户ID")))
class DropJumperSerializer(serializers.Serializer): owner = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(_('用户'))) zone = serializers.ChoiceField( required=True, choices=['dev', 'test', 'prod'], error_messages=serializers.CommonErrorMessages(_('区域'))) jumper_ids = serializers.ListField( required=True, error_messages=serializers.CommonErrorMessages(_('堡垒机ID'))) isSuperUser = serializers.BooleanField(required=False, default=False)
class MergedSecurityGroupRuleSerializer(serializers.Serializer): type = serializers.ChoiceField( default='instance', choices=SECURITY_GROUP_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) sgr_ids = serializers.ListField( required=True, validators=[], error_messages=serializers.CommonErrorMessages('sgr_ids')) sg_id = serializers.CharField( required=True, max_length=60, validators=[], error_messages=serializers.CommonErrorMessages('sg_id'))
class RestoreTrashJumperSerializer(serializers.Serializer): owner = serializers.CharField( required=True, max_length=30, error_messages=serializers.CommonErrorMessages(_(u"用户"))) zone = serializers.ChoiceField( required=True, choices=["dev", "test", "prod"], error_messages=serializers.CommonErrorMessages(_(u"区域"))) jumper_ids = serializers.ListField( required=True, error_messages=serializers.CommonErrorMessages(_('堡垒机ID')))
class CreateAlarmValidator(serializers.Serializer): alarm_name = serializers.CharField(required=True, max_length=100, validators=[]) resource_type = serializers.ChoiceField(required=True, choices=resource_type_choice, validators=[]) period = serializers.IntegerField(required=True, min_value=1, validators=[]) trigger_condition = serializers.ListField(child=serializers.DictField(), required=True, validators=[]) resource = serializers.ListField(required=True, validators=[]) notify_at = serializers.CharField(required=True, max_length=100, validators=[]) notify_group_id = serializers.CharField(required=True, max_length=20, validators=[group_id_validator]) notify_method = serializers.CharField(required=True, max_length=100, validators=[])