def validates_disk(obj): checker = Checker() check = True _ = obj._ checker.errors = [] """ TODO # sparse # disk if is_param(obj.input, 'disk_size'): check = checker.check_number(_('Disk Size (MB)'), obj.input.disk_size, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, min = DISK_MIN_SIZE, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Disk Size (MB)')) """ obj.view.alert = checker.errors return check
def validates_uriguest_status(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, "status"): check = ( checker.check_status( _("Status"), obj.input.status, CHECK_EMPTY | CHECK_VALID, [ GUEST_ACTION_CREATE, GUEST_ACTION_SHUTDOWN, GUEST_ACTION_DESTROY, GUEST_ACTION_SUSPEND, GUEST_ACTION_RESUME, GUEST_ACTION_REBOOT, GUEST_ACTION_ENABLE_AUTOSTART, GUEST_ACTION_DISABLE_AUTOSTART, ], ) and check ) else: check = False checker.add_error(_('"%s" is required.') % _("Status")) obj.view.alert = checker.errors return check
def validates_mail(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'hostname'): check = False checker.add_error(_('"%s" is required.') % _('Server Name')) else: check_server = checker.check_domainname(_('Server Name'), obj.input.hostname, CHECK_VALID, ) or \ checker.check_ipaddr(_('Server Name'), obj.input.hostname, CHECK_VALID, ) check = check_server and check if not is_param(obj.input, 'port'): check = False checker.add_error(_('"%s" is required.') % _('Port Number')) else: check = checker.check_number( _('Port Number'), obj.input.port, CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check obj.view.alert = checker.errors return check
def validates_src_id(obj): """<comment-ja> ゲストOSコピー元のチェッカー @param obj: karesansui.lib.rest.Rest オブジェクト @type obj: karesansui.lib.rest.Rest @return: check @rtype: bool </comment-ja> <comment-en> TODO: English Comment </comment-en> """ checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'src_id'): check = False checker.add_error(_('"%s" is required.') % _('Copy Source')) else: check = checker.check_number(_('Copy Source'), obj.input.src_id, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, ID_MIN_LENGTH, ID_MAX_LENGTH ) and check obj.view.alert = checker.errors return check
def validates_nic(obj): checker = Checker() check = True _ = obj._ checker.errors = [] # nic_type - [phydev, virnet] if is_param(obj.input, 'nic_type'): if (obj.input.nic_type in ['phydev', 'virnet']) is False: check = False checker.add_error(_("")) else: check = False checker.add_error(_('"%s" is required.') % _('Interface Type')) # mac_address if is_param(obj.input, 'mac_address'): check = checker.check_macaddr(_('MAC Address'), obj.input.mac_address, CHECK_EMPTY | CHECK_VALID) and check else: check = False checker.add_error(_('"%s" is required.') % _('MAC Address')) obj.view.alert = checker.errors return check
def validates_snapshot(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'title'): check = checker.check_string( _('Title'), obj.input.title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min = NOTE_TITLE_MIN_LENGTH, max = NOTE_TITLE_MAX_LENGTH, ) and check if is_param(obj.input, 'value'): check = checker.check_string( _('Note'), obj.input.value, CHECK_ONLYSPACE, None, None, None, ) and check obj.view.alert = checker.errors return check
def validates_snapshot(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'title'): check = checker.check_string( _('Title'), obj.input.title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min=NOTE_TITLE_MIN_LENGTH, max=NOTE_TITLE_MAX_LENGTH, ) and check if is_param(obj.input, 'value'): check = checker.check_string( _('Note'), obj.input.value, CHECK_ONLYSPACE, None, None, None, ) and check obj.view.alert = checker.errors return check
def validates_guest_import(obj): checker = Checker() check = True _ = obj._ checker.errors = [] # TODO UUID check obj.view.alert = checker.errors return check
def validates_mail(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'hostname'): check = False checker.add_error(_('"%s" is required.') % _('Server Name')) else: check_server = checker.check_domainname(_('Server Name'), obj.input.hostname, CHECK_VALID, ) or \ checker.check_ipaddr(_('Server Name'), obj.input.hostname, CHECK_VALID, ) check = check_server and check if not is_param(obj.input, 'port'): check = False checker.add_error(_('"%s" is required.') % _('Port Number')) else: check = checker.check_number(_('Port Number'), obj.input.port, CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check obj.view.alert = checker.errors return check
def validates_nic(obj): checker = Checker() check = True _ = obj._ checker.errors = [] # nic_type - [phydev, virnet] if is_param(obj.input, 'nic_type'): if (obj.input.nic_type in ['phydev', 'virnet']) is False: check = False checker.add_error(_("")) else: check = False checker.add_error(_('"%s" is required.') % _('Interface Type')) # mac_address if is_param(obj.input, 'mac_address'): check = checker.check_macaddr( _('MAC Address'), obj.input.mac_address, CHECK_EMPTY | CHECK_VALID ) and check else: check = False checker.add_error(_('"%s" is required.') % _('MAC Address')) obj.view.alert = checker.errors return check
def validates_staticroute(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'target'): check = False checker.add_error(_('Specify target address for the route.')) else: check = checker.check_ipaddr( _('Target'), obj.input.target, CHECK_EMPTY | CHECK_VALID, ) and check if not is_param(obj.input, 'gateway'): check = False checker.add_error(_('Specify gateway address for the route.')) else: check = checker.check_ipaddr( _('Gateway'), obj.input.gateway, CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def compare_password(obj, user): checker = Checker() check = True _ = obj._ checker.errors = [] if not sha1compare(user.password, obj.input.password, user.salt): check = False checker.add_error(_('%s is mismatched.') % _('Current Password')) obj.view.alert = checker.errors return check
def validates_nicby1(obj): checker = Checker() check = True _ = obj._ checker.errors = [] # mac_address if is_param(obj.input, "mac_address"): check = checker.check_macaddr(_("MAC Address"), obj.input.mac_address, CHECK_EMPTY | CHECK_VALID) and check obj.view.alert = checker.errors return check
def validates_jobsearch(obj): checker = Checker() _ = obj._ checker.errors = [] check = True edit = False if is_param(obj.input, "name", True) is True: edit = True check = checker.check_string( _('Machine Name'), obj.input.name, CHECK_LENGTH | CHECK_ONLYSPACE | CHECK_VALID, '[%_]', min = MACHINE_NAME_MIN_LENGTH, max = MACHINE_NAME_MAX_LENGTH, ) and check if is_param(obj.input, "user", True) is True: edit = True check = checker.check_string( _('Create User'), obj.input.user, CHECK_LENGTH | CHECK_ONLYSPACE | CHECK_VALID, '[%_]', min = USER_MIN_LENGTH, max = USER_MAX_LENGTH, ) and check if is_param(obj.input, "status", True) is True: edit = True check = checker.check_status( _('Status'), obj.input.status, CHECK_VALID, JOBGROUP_STATUS.values() ) and check if is_param(obj.input, "start", True) is True: edit = True check = checker.check_datetime_string( _('Created'), obj.input.start, CHECK_VALID, obj.me.languages ) and check if is_param(obj.input, "end", True) is True: edit = True check = checker.check_datetime_string( _('Created'), obj.input.end, CHECK_VALID, obj.me.languages ) and check obj.view.alert = checker.errors return check, edit
def validates_guest_edit(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'm_name'): check = False checker.add_error(_('Parameter m_name does not exist.')) else: check = checker.check_string( _('Machine Name'), obj.input.m_name, CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE, None, min=MACHINE_NAME_MIN_LENGTH, max=MACHINE_NAME_MAX_LENGTH, ) and check if is_param(obj.input, 'note_title'): check = checker.check_string( _('Title'), obj.input.note_title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min=NOTE_TITLE_MIN_LENGTH, max=NOTE_TITLE_MAX_LENGTH, ) and check if is_param(obj.input, 'note_value'): check = checker.check_string( _('Note'), obj.input.note_value, CHECK_ONLYSPACE, None, None, None, ) and check if is_param(obj.input, 'tags'): for tag in comma_split(obj.input.tags): check = checker.check_string( _('Tag'), tag, CHECK_LENGTH | CHECK_ONLYSPACE, None, min=TAG_MIN_LENGTH, max=TAG_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_tag(obj): checker = Checker() check = True _ = obj._ checker.errors = [] check = check and checker.check_length( _('Tag'), obj.input.name, TAG_MIN_LENGTH, TAG_MAX_LENGTH, ) obj.view.alert = checker.errors return check
def validates_param_id(obj, user_id): checker = Checker() check = True _ = obj._ checker.errors = [] check = checker.check_number( _('User ID'), user_id, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, min = ID_MIN_LENGTH, max = ID_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_param_id(obj, tag_id): checker = Checker() check = True _ = obj._ checker.errors = [] check = checker.check_number( _('Tag ID'), tag_id, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, min=ID_MIN_LENGTH, max=ID_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_iptables_save(obj, host): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'iptables_save'): check = False checker.add_error(_('"%s" is required.') % _('Rule')) else: check = checker.check_string( _('Rule'), obj.input.iptables_save, CHECK_EMPTY | CHECK_VALID, '[^-a-zA-Z0-9_\,\.\@\$\%\!\#\*\[\]\:\/\r\n\+ ]+', None, None, ) and check if check is True: ret = iptables_lint_contents(obj.input.iptables_save, obj, host) if str(ret) != "": check = False checker.add_error(ret) """ m = re.match(".* line (?P<line>[0-9]+).*",str(ret)) if m: checker.add_error("LINE:"+m.group("line")) """ obj.view.alert = checker.errors return check
def validates_cpu(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'max_vcpus'): check = checker.check_number( _('Maximum Allocatable Virtual CPUs'), obj.input.max_vcpus, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, min=VCPUS_MIN_SIZE, ) and check else: check = False checker.add_error( _('"%s" is required.') % _('Maximum Allocatable Virtual CPUs')) if is_param(obj.input, 'vcpus'): check = checker.check_number( _("Number of Virtual CPUs to Allocate"), obj.input.vcpus, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, min=VCPUS_MIN_SIZE, ) and check obj.view.alert = checker.errors return check
def validates_storage_pool(obj, uuid=None): checker = Checker() check = True _ = obj._ checker.errors = [] if uuid: check = checker.check_unique_key(_('Target UUID'), uuid, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Target UUID')) obj.view.alert = checker.errors return check
def validates_page(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'p'): check = checker.check_number( _('Page Number'), obj.input.p, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, min = PAGE_MIN_SIZE, max = PAGE_MAX_SIZE, ) and check obj.view.alert = checker.errors return check
def validates_icon(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'multi_icon'): check = checker.check_image( _('Machine Icon'), obj.input.multi_icon.value, CHECK_EMPTY | CHECK_VALID, None, None, ) and check obj.view.alert = checker.errors return check
def validates_query(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'q'): check = checker.check_string(_('Search Query'), obj.input.q, CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID, '[%_]', min = SEARCH_MIN_LENGTH, max = SEARCH_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_page(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'p'): check = checker.check_number( _('Page Number'), obj.input.p, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, min=PAGE_MIN_SIZE, max=PAGE_MAX_SIZE, ) and check obj.view.alert = checker.errors return check
def validates_guest_edit(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'm_name'): check = False checker.add_error(_('Parameter m_name does not exist.')) else: check = checker.check_string( _('Machine Name'), obj.input.m_name, CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE, None, min = MACHINE_NAME_MIN_LENGTH, max = MACHINE_NAME_MAX_LENGTH, ) and check if is_param(obj.input, 'note_title'): check = checker.check_string( _('Title'), obj.input.note_title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min = NOTE_TITLE_MIN_LENGTH, max = NOTE_TITLE_MAX_LENGTH, ) and check if is_param(obj.input, 'note_value'): check = checker.check_string( _('Note'), obj.input.note_value, CHECK_ONLYSPACE, None, None, None, ) and check if is_param(obj.input, 'tags'): for tag in comma_split(obj.input.tags): check = checker.check_string( _('Tag'), tag, CHECK_LENGTH | CHECK_ONLYSPACE, None, min = TAG_MIN_LENGTH, max = TAG_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_nicby1(obj): checker = Checker() check = True _ = obj._ checker.errors = [] # mac_address if is_param(obj.input, 'mac_address'): check = checker.check_macaddr( _('MAC Address'), obj.input.mac_address, CHECK_EMPTY | CHECK_VALID ) and check obj.view.alert = checker.errors return check
def validates_nw_status(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, "status"): status = int(obj.input.status) check = ( checker.check_status(_("Status"), status, CHECK_EMPTY | CHECK_VALID, [NETWORK_ACTIVE, NETWORK_INACTIVE]) and check ) else: check = False checker.add_error(_('"%s" is required.') % _("Status")) obj.view.alert = checker.errors return check
def validates_sid(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'sid'): check = False checker.add_error(_('"%s" is required.') % _('Copy Source')) else: check = checker.check_number(_('Copy Source'), obj.input.sid, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, ID_MIN_LENGTH, ID_MAX_LENGTH ) and check obj.view.alert = checker.errors return check
def validates_iptables_status(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'status'): check = checker.check_status( _('Status'), obj.input.status, CHECK_EMPTY | CHECK_VALID, IPTABLES_STATUS.values() ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Status')) obj.view.alert = checker.errors return check
def validates_log(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, "s"): check = ( checker.check_datetime_string(_("Start Date"), obj.input.s, CHECK_EMPTY | CHECK_VALID, obj.me.languages) and check ) if is_param(obj.input, "e"): check = ( checker.check_datetime_string(_("End Date"), obj.input.e, CHECK_EMPTY | CHECK_VALID, obj.me.languages) and check ) if is_param(obj.input, "st"): check = checker.check_time_string(_("Start Time"), obj.input.st, CHECK_EMPTY | CHECK_VALID) and check if is_param(obj.input, "et"): check = checker.check_time_string(_("End Time"), obj.input.et, CHECK_EMPTY | CHECK_VALID) and check obj.view.alert = checker.errors return check
def validates_report(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'report_start_day'): check = checker.check_datetime_string(_('Start Date'), obj.input.report_start_day, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'report_end_day'): check = checker.check_datetime_string(_('End Date'), obj.input.report_end_day, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'report_start_time'): check = checker.check_time_string(_('Start Time'), obj.input.report_start_time, CHECK_EMPTY | CHECK_VALID, ) and check if is_param(obj.input, 'report_end_time'): check = checker.check_time_string(_('End Time'), obj.input.report_end_time, CHECK_EMPTY | CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def validates_uriguest_status(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'status'): check = checker.check_status( _('Status'), obj.input.status, CHECK_EMPTY | CHECK_VALID, [GUEST_ACTION_CREATE, GUEST_ACTION_SHUTDOWN, GUEST_ACTION_DESTROY, GUEST_ACTION_SUSPEND, GUEST_ACTION_RESUME, GUEST_ACTION_REBOOT, GUEST_ACTION_ENABLE_AUTOSTART, GUEST_ACTION_DISABLE_AUTOSTART] ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Status')) obj.view.alert = checker.errors return check
def validates_log(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 's'): check = checker.check_datetime_string(_('Start Date'), obj.input.s, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'e'): check = checker.check_datetime_string(_('End Date'), obj.input.e, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'st'): check = checker.check_time_string(_('Start Time'), obj.input.st, CHECK_EMPTY | CHECK_VALID, ) and check if is_param(obj.input, 'et'): check = checker.check_time_string(_('End Time'), obj.input.et, CHECK_EMPTY | CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def validates_cpu(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'max_vcpus'): check = checker.check_number( _('Maximum Allocatable Virtual CPUs'), obj.input.max_vcpus, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, min = VCPUS_MIN_SIZE, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Maximum Allocatable Virtual CPUs')) if is_param(obj.input, 'vcpus'): check = checker.check_number( _("Number of Virtual CPUs to Allocate"), obj.input.vcpus, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, min = VCPUS_MIN_SIZE, ) and check; obj.view.alert = checker.errors return check
def validates_guest_export(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'export_title'): check = False checker.add_error(_('Parameter export_title does not exist.')) else: check = checker.check_string( _('Title'), obj.input.export_title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min = NOTE_TITLE_MIN_LENGTH, max = NOTE_TITLE_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_watch(obj, target, lang): checker = Checker() check = True _ = obj._ checker.errors = [] if target not in WATCH_PLUGINS.values(): check = False checker.add_error(_('"%s" is not watch target.') % _(target)) if lang not in DEFAULT_LANGS: check = False checker.add_error(_('"%s" is not supported language.') % _(lang)) obj.view.alert = checker.errors return check
def validates_watch(obj, target, lang): checker = Checker() check = True _ = obj._ checker.errors = [] if target not in WATCH_PLUGINS.values(): check = False checker.add_error(_('"%s" is not watch target.') %_(target)) if lang not in DEFAULT_LANGS: check = False checker.add_error(_('"%s" is not supported language.') %_(lang)) obj.view.alert = checker.errors return check
def validates_sid(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'sid'): check = False checker.add_error(_('"%s" is required.') % _('Copy Source')) else: check = checker.check_number( _('Copy Source'), obj.input.sid, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, ID_MIN_LENGTH, ID_MAX_LENGTH) and check obj.view.alert = checker.errors return check
def validates_fw_status(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'status'): check = checker.check_status(_('Status'), obj.input.status, CHECK_EMPTY | CHECK_VALID, FIREWALL_STATUS.values()) and check else: check = False checker.add_error(_('"%s" is required.') % _('Status')) obj.view.alert = checker.errors return check
def validates_log(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 's'): check = checker.check_datetime_string( _('Start Date'), obj.input.s, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'e'): check = checker.check_datetime_string( _('End Date'), obj.input.e, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'st'): check = checker.check_time_string( _('Start Time'), obj.input.st, CHECK_EMPTY | CHECK_VALID, ) and check if is_param(obj.input, 'et'): check = checker.check_time_string( _('End Time'), obj.input.et, CHECK_EMPTY | CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def validates_report(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'report_start_day'): check = checker.check_datetime_string( _('Start Date'), obj.input.report_start_day, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'report_end_day'): check = checker.check_datetime_string( _('End Date'), obj.input.report_end_day, CHECK_EMPTY | CHECK_VALID, obj.me.languages, ) and check if is_param(obj.input, 'report_start_time'): check = checker.check_time_string( _('Start Time'), obj.input.report_start_time, CHECK_EMPTY | CHECK_VALID, ) and check if is_param(obj.input, 'report_end_time'): check = checker.check_time_string( _('End Time'), obj.input.report_end_time, CHECK_EMPTY | CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def validates_nw_status(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'status'): status = int(obj.input.status) check = checker.check_status( _('Status'), status, CHECK_EMPTY | CHECK_VALID, [NETWORK_ACTIVE, NETWORK_INACTIVE]) and check else: check = False checker.add_error(_('"%s" is required.') % _('Status')) obj.view.alert = checker.errors return check
def validates_storage_pool(obj, uuid=None): checker = Checker() check = True _ = obj._ checker.errors = [] if uuid: check = checker.check_unique_key( _('Target UUID'), uuid, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Target UUID')) obj.view.alert = checker.errors return check
def validates_guest_export(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'export_title'): check = False checker.add_error(_('Parameter export_title does not exist.')) else: check = checker.check_string( _('Title'), obj.input.export_title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min=NOTE_TITLE_MIN_LENGTH, max=NOTE_TITLE_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_nic(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'bootproto'): if obj.input.bootproto == "static": if is_param(obj.input, 'ipaddr'): check = checker.check_ipaddr(_('IP Address'), obj.input.ipaddr, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('IP Address')) if is_param(obj.input, 'netmask'): check = checker.check_netmask(_('Netmask'), obj.input.netmask, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Netmask')) else: if is_param(obj.input, 'ipaddr'): check = checker.check_ipaddr(_('IP Address'), obj.input.ipaddr, CHECK_VALID, ) and check if is_param(obj.input, 'netmask'): check = checker.check_netmask(_('Netmask'), obj.input.netmask, CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Boot-time Protocol')) obj.view.alert = checker.errors return check
def validates_rule(obj, is_newrule=False): checker = Checker() check = True _ = obj._ checker.errors = [] obj.view.error_msg = checker.errors if is_newrule: kit = KaresansuiIpTables() rule_id_max_length = 1 if os.path.exists(kit.firewall_xml_file) is False: check = False checker.add_error(_('Has not been initialized. Please initialize.')) else: kit.firewall_xml = kit.read_firewall_xml() rule_id_max_length += len(kit.get_rules()) if not is_param(obj.input, 'rule_id'): check = False checker.add_error(_('"%s" is required.') % _('ID')) else: check = checker.check_number( _('ID'), obj.input.rule_id, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, min = ID_MIN_LENGTH, max = rule_id_max_length, ) and check if not is_param(obj.input, 'target'): check = False checker.add_error(_('"%s" is required.') % _('Target')) else: check = checker.check_firewall_policy( _('Target'), obj.input.target, CHECK_EMPTY | CHECK_VALID, ) and check if not is_param(obj.input, 'protocol'): check = False checker.add_error(_('"%s" is required.') % _('Protocol')) else: check = checker.check_firewall_protocol( _('Protocol'), obj.input.protocol, CHECK_VALID, ) and check if not is_param(obj.input, 'source'): check = False checker.add_error(_('"%s" is required.') % _('Source Address')) else: check = checker.check_ipaddr( _('Source Address'), obj.input.source, CHECK_VALID, ) and check if not is_param(obj.input, 'sport'): check = False checker.add_error(_('"%s" is required.') % _('Source Port')) else: if obj.input.protocol == 'tcp' or obj.input.protocol == 'udp': check = checker.check_number( _('Source Port'), obj.input.sport, CHECK_VALID | CHECK_MIN | CHECK_MAX, min = PORT_MIN_NUMBER, max = PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'destination'): check = False checker.add_error(_('"%s" is required.') % _('Destination Address')) else: check = checker.check_ipaddr( _('Destination Address'), obj.input.destination, CHECK_VALID, ) and check if not is_param(obj.input, 'dport'): check = False checker.add_error(_('"%s" is required.') % _('Destination Port')) else: if obj.input.protocol == 'tcp' or obj.input.protocol == 'udp': check = checker.check_number( _('Destination Port'), obj.input.dport, CHECK_VALID | CHECK_MIN | CHECK_MAX, min = PORT_MIN_NUMBER, max = PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'inif'): check = False checker.add_error(_('"%s" is required.') % _('In Interface')) else: check = checker.check_firewall_if( _('In Interface'), obj.input.inif, CHECK_EXIST, ) and check if not is_param(obj.input, 'outif'): check = False checker.add_error(_('"%s" is required.') % _('Out Interface')) else: check = checker.check_firewall_if( _('Out Interface'), obj.input.outif, CHECK_EXIST, ) and check obj.view.alert = checker.errors return check
def validates_proxy(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'proxy_status'): check = False checker.add_error(_('"%s" is required.') % _('Proxy Settings')) else: if obj.input.proxy_status == PROXY_ENABLE: if not is_param(obj.input, 'proxy_server'): check = False checker.add_error(_('"%s" is required.') % _('Proxy Server')) else: check = checker.check_domainname( _('Proxy Server'), obj.input.proxy_server, CHECK_EMPTY | CHECK_VALID, None, None, ) and check if not is_param(obj.input, 'proxy_port'): check = False checker.add_error(_('"%s" is required.') % _('Proxy Port Number')) else: check = checker.check_number( _('Port Number'), obj.input.proxy_port, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'proxy_user'): check = False checker.add_error(_('"%s" is required.') % _('Proxy User Name')) else: check = checker.check_username( _('Proxy User Name'), obj.input.proxy_user, CHECK_VALID | CHECK_ONLYSPACE, None, None, ) and check if not is_param(obj.input, 'proxy_password'): check = False checker.add_error(_('"%s" is required.') % _('Proxy Password')) else: check = checker.check_password( _('Proxy Password'), obj.input.proxy_password, obj.input.proxy_password, CHECK_VALID, ) and check; elif obj.input.proxy_status == PROXY_DISABLE: check = True and check else: check = False checker.add_error(_('"%s" is in invalid format.') % _('Proxy Status')) obj.view.alert = checker.errors return check
def validates_user(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'nickname'): check = False checker.add_error(_('"%s" is required.') % _('User Name')) else: check = checker.check_username( _('User Name'), obj.input.nickname, CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE, min = USER_MIN_LENGTH, max = USER_MAX_LENGTH, ) and check if not is_param(obj.input, 'email'): check = False checker.add_error(_('"%s" is required.') % _('Mail Address')) else: check = checker.check_mailaddress( _('Mail Address'), obj.input.email, CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID, min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH, ) and check _password_flag = True if not is_param(obj.input, 'password'): check = False _password_flag = False checker.add_error(_('"%s" is required.') % _('Password')) if not is_param(obj.input, 'retype'): check = False _password_flag = False checker.add_error(_('"%s" is required.') % _('Retype')) if _password_flag == True: if not is_empty(obj.input.password) or \ not is_empty(obj.input.retype): check = checker.check_password( _('Password'), obj.input.password, obj.input.password, CHECK_EMPTY | CHECK_LENGTH, min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH, ) and check check = checker.check_languages( _('Language'), obj.input.languages, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH, min = LANGUAGES_MIN_LENGTH, max = LANGUAGES_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_network(obj, network_name=None): checker = Checker() check = True _ = obj._ checker.errors = [] if not network_name: check = False checker.add_error(_('Specify network name.')) if not is_param(obj.input, 'cidr'): check = False checker.add_error(_('Specify bridge IP address for the network.')) else: check = checker.check_ipaddr( _('Bridge IP Address/Netmask'), obj.input.cidr, CHECK_EMPTY | CHECK_VALID, ) and check if not is_param(obj.input, 'bridge'): check = False checker.add_error(_('Specify bridge name to create for the network.')) else: check = checker.check_netdev_name( _('Bridge Device Name'), obj.input.bridge, CHECK_EMPTY | CHECK_VALID, ) and check A = is_param(obj.input, 'dhcp_start') B = is_param(obj.input, 'dhcp_end') #if not ( ((not A) and (not B)) or (A and B)): if not (A and B): check = False checker.add_error( _('Specify both %s and %s') % (_('DHCP Start Address'), _('DHCP End Address'))) if is_param(obj.input, 'dhcp_start'): check = checker.check_ipaddr( _('DHCP Start Address'), obj.input.dhcp_start, CHECK_EMPTY | CHECK_ONLYSPACE | CHECK_VALID, ) and check if is_param(obj.input, 'dhcp_end'): check = checker.check_ipaddr( _('DHCP End Address'), obj.input.dhcp_end, CHECK_EMPTY | CHECK_ONLYSPACE | CHECK_VALID, ) and check check = checker.check_if_ips_are_in_network([ _('DHCP Start Address'), _('DHCP End Address'), _('Bridge IP Address/Netmask') ], [obj.input.dhcp_start, obj.input.dhcp_end], obj.input.cidr, CHECK_VALID | CHECK_UNIQUE) and check check = checker.check_ip_range([ _('DHCP Start Address'), _('DHCP End Address'), _('Bridge IP Address/Netmask') ], [obj.input.dhcp_start, obj.input.dhcp_end, obj.input.cidr], CHECK_VALID) and check check = checker.check_virt_network_address_conflict( _('Bridge IP Address/Netmask'), obj.input.cidr, [network_name], # names to ignore CHECK_VALID) and check if is_param(obj.input, 'forward_mode'): check = checker.check_forward_mode( _('Forward Mode'), obj.input.forward_mode, CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def validates_host_edit(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'm_name'): check = False checker.add_error(_('Parameter m_name does not exist.')) else: check = checker.check_string( _('Machine Name'), obj.input.m_name, CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE, None, min=MACHINE_NAME_MIN_LENGTH, max=MACHINE_NAME_MAX_LENGTH, ) and check if not is_param(obj.input, 'm_connect_type'): check = False checker.add_error(_('Parameter m_connect_type does not exist.')) else: if obj.input.m_connect_type == "karesansui": if not is_param(obj.input, 'm_hostname'): check = False checker.add_error(_('"%s" is required.') % _('FQDN')) else: m_hostname_parts = obj.input.m_hostname.split(":") if len(m_hostname_parts) > 2: check = False checker.add_error( _('%s contains too many colon(:)s.') % _('FQDN')) else: check = checker.check_domainname( _('FQDN'), m_hostname_parts[0], CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID, min=FQDN_MIN_LENGTH, max=FQDN_MAX_LENGTH, ) and check try: check = checker.check_number( _('Port Number'), m_hostname_parts[1], CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check except IndexError: # when reach here, 'm_hostname' has only host name pass if obj.input.m_connect_type == "libvirt": if not is_param(obj.input, 'm_uri'): check = False checker.add_error(_('"%s" is required.') % _('URI')) else: pass if is_param(obj.input, 'm_auth_user') and obj.input.m_auth_user != "": check = checker.check_username( _('User Name'), obj.input.m_auth_user, CHECK_LENGTH | CHECK_ONLYSPACE, min=USER_MIN_LENGTH, max=USER_MAX_LENGTH, ) and check if is_param(obj.input, 'note_title'): check = checker.check_string( _('Title'), obj.input.note_title, CHECK_LENGTH | CHECK_ONLYSPACE, None, min=NOTE_TITLE_MIN_LENGTH, max=NOTE_TITLE_MAX_LENGTH, ) and check if is_param(obj.input, 'note_value'): check = checker.check_string( _('Note'), obj.input.note_value, CHECK_ONLYSPACE, None, None, None, ) and check if is_param(obj.input, 'tags'): for tag in comma_split(obj.input.tags): check = checker.check_string( _('Tag'), tag, CHECK_LENGTH | CHECK_ONLYSPACE, None, min=TAG_MIN_LENGTH, max=TAG_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check