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_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_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_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_pool_iscsi(obj, now_pools): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, "pool_name"): check = ( checker.check_string(_("Storage Pool Name"), obj.input.pool_name, CHECK_EMPTY | CHECK_ONLYSPACE, None) and check ) if obj.input.pool_name in now_pools: check = False checker.add_error(_('%s "%s" already exists.') % (_("Storage Pool Name"), obj.input.pool_name)) else: check = False checker.add_error(_('"%s" is required.') % _("Storage Pool Name")) if is_param(obj.input, "pool_target_iscsi"): check = ( checker.check_string(_("iSCSI Target"), obj.input.pool_target_iscsi, CHECK_EMPTY | CHECK_ONLYSPACE, None) and check ) try: kvc = KaresansuiVirtConnection() for pool_name in now_pools: pool_iqn = kvc.get_storage_pool_sourcedevicepath(pool_name) if obj.input.pool_target_iscsi == pool_iqn: check = False checker.add_error( _('Storagepool iSCSI target IQN "%s" is already being used.') % (obj.input.pool_target_iscsi) ) finally: kvc.close() else: check = False checker.add_error(_('"%s" is required.') % _("iSCSI Target")) obj.view.alert = checker.errors return check
def validates_pool_iscsi(obj, now_pools): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'pool_name'): check = checker.check_string(_('Storage Pool Name'), obj.input.pool_name, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check if obj.input.pool_name in now_pools: check = False checker.add_error(_('%s "%s" already exists.') % (_('Storage Pool Name'), obj.input.pool_name)) else: check = False checker.add_error(_('"%s" is required.') %_('Storage Pool Name')) if is_param(obj.input, 'pool_target_iscsi'): check = checker.check_string(_('iSCSI Target'), obj.input.pool_target_iscsi, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check try: kvc = KaresansuiVirtConnection() for pool_name in now_pools: pool_iqn = kvc.get_storage_pool_sourcedevicepath(pool_name) if obj.input.pool_target_iscsi == pool_iqn: check = False checker.add_error(_('Storagepool iSCSI target IQN "%s" is already being used.') % (obj.input.pool_target_iscsi)) finally: kvc.close() else: check = False checker.add_error(_('"%s" is required.') %_('iSCSI Target')) obj.view.alert = checker.errors return check
def validates_network_storage(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'iqn'): check = checker.check_string( _('Target IQN'), obj.input.iqn, CHECK_EMPTY | CHECK_ONLYSPACE, None, None, None, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Target IQN')) if is_param(obj.input, 'status'): check = checker.check_empty( _('Action Status'), obj.input.status, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Action Status')) if is_param(obj.input, 'host'): check = checker.check_domainname( _('Target Hostname'), obj.input.host, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Target Hostname')) if is_param(obj.input, 'port'): check = checker.check_number( _('Target Port Number'), obj.input.port, CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Target Port Number')) obj.view.alert = checker.errors return check
def validates_network_storage(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'iqn'): check = checker.check_string(_('Target IQN'), obj.input.iqn, CHECK_EMPTY | CHECK_ONLYSPACE, None, None, None, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Target IQN')) if is_param(obj.input, 'status'): check = checker.check_empty(_('Action Status'), obj.input.status, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Action Status')) if is_param(obj.input, 'host'): check = checker.check_domainname(_('Target Hostname'), obj.input.host, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Target Hostname')) if is_param(obj.input, 'port'): check = checker.check_number(_('Target Port Number'), obj.input.port, CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Target Port Number')) obj.view.alert = checker.errors return check
def validates_pool_dir(obj, now_pools): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, "pool_name"): check = ( checker.check_string(_("Storage Pool Name"), obj.input.pool_name, CHECK_EMPTY | CHECK_ONLYSPACE, None) and check ) if obj.input.pool_name in now_pools: check = False checker.add_error(_('%s "%s" already exists.') % (_("Storage Pool Name"), obj.input.pool_name)) else: check = False checker.add_error(_('"%s" is required.') % _("Storage Pool Name")) if is_param(obj.input, "pool_target_path"): check = ( checker.check_directory( _("Directory Path"), obj.input.pool_target_path, CHECK_EMPTY | CHECK_STARTROOT | CHECK_NOTROOT ) and check ) try: kvc = KaresansuiVirtConnection() for pool_name in now_pools: target_path = kvc.get_storage_pool_targetpath(pool_name) if obj.input.pool_target_path == target_path: check = False checker.add_error( _('Storagepool target path "%s" is already being used.') % (obj.input.pool_target_path) ) finally: kvc.close() else: check = False checker.add_error(_('"%s" is required.') % _("Directory Path")) 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_pool_dir(obj, now_pools): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'pool_name'): check = checker.check_string(_('Storage Pool Name'), obj.input.pool_name, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check if obj.input.pool_name in now_pools: check = False checker.add_error(_('%s "%s" already exists.') % (_('Storage Pool Name'), obj.input.pool_name)) else: check = False checker.add_error(_('"%s" is required.') %_('Storage Pool Name')) if is_param(obj.input, 'pool_target_path'): check = checker.check_directory(_('Directory Path'), obj.input.pool_target_path, CHECK_EMPTY | CHECK_STARTROOT | CHECK_NOTROOT ) and check try: kvc = KaresansuiVirtConnection() for pool_name in now_pools: target_path = kvc.get_storage_pool_targetpath(pool_name) if obj.input.pool_target_path == target_path: check = False checker.add_error(_('Storagepool target path "%s" is already being used.') % (obj.input.pool_target_path)) finally: kvc.close() else: check = False checker.add_error(_('"%s" is required.') %_('Directory Path')) 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_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_guest_replicate(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 if not is_param(obj.input, 'domain_dest_name'): check = False checker.add_error(_('Parameter domain_dest_name does not exist.')) else: check = checker.check_string( _('Destination Domain Name'), obj.input.domain_dest_name, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH, '[^-a-zA-Z0-9_\.]+', DOMAIN_NAME_MIN_LENGTH, DOMAIN_NAME_MAX_LENGTH, ) and check if not is_param(obj.input, 'vm_vncport'): check = False checker.add_error(_('Parameter vm_vncport does not exist.')) else: check = checker.check_number( _('VNC Port Number'), obj.input.vm_vncport, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, VNC_PORT_MIN_NUMBER, VNC_PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'vm_mac'): check = False checker.add_error(_('Parameter vm_mac does not exist.')) else: check = checker.check_macaddr( _('MAC Address'), obj.input.vm_mac, CHECK_EMPTY | 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
def validates_watch(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'watch_name'): check = checker.check_string( _('Watch Name'), obj.input.watch_name, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Watch Name')) if is_param(obj.input, 'continuation_count'): check = checker.check_number( _('Alert Trigger Count'), obj.input.continuation_count, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, CONTINUATION_COUNT_MIN, CONTINUATION_COUNT_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Alert Trigger Count')) if is_param(obj.input, 'prohibition_period'): check = checker.check_number( _('Silent Period'), obj.input.prohibition_period, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PROHIBITION_PERIOD_MIN, PROHIBITION_PERIOD_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Silent Period')) if is_param(obj.input, 'threshold_fraction'): fraction = int(obj.input.threshold_fraction) else: fraction = 0 if is_param(obj.input, 'threshold_val1'): if fraction == 0: check = checker.check_number( _('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction( _('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Threshold Value')) if is_param(obj.input, 'threshold_val2'): if fraction == 0: check = checker.check_number( _('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction( _('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Threshold Value')) if not is_param(obj.input, 'threshold_type'): check = False checker.add_error(_('"%s" is required.') % _('Threshold Type')) if is_param(obj.input, 'notify_mail_to'): if obj.input.notify_mail_to != "": check = checker.check_mailaddress( _('Mail To'), obj.input.notify_mail_to, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check if is_param(obj.input, 'notify_mail_from'): if obj.input.notify_mail_from != "": check = checker.check_mailaddress( _('Mail From'), obj.input.notify_mail_from, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_host_add(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_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 not is_param(obj.input, 'm_uuid'): check = False checker.add_error(_('"%s" is required.') % _('Unique Key')) else: check = checker.check_unique_key( _('Unique Key'), obj.input.m_uuid, CHECK_EMPTY | CHECK_VALID ) 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_guest_add(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 if not is_param(obj.input, 'm_hypervisor'): check = False checker.add_error(_('Parameter m_hypervisor does not exist.')) else: check = checker.check_hypervisor( _('Hypervisor'), obj.input.m_hypervisor, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, HYPERVISOR_MIN_SIZE, HYPERVISOR_MAX_SIZE, ) and check if not is_param(obj.input, 'domain_name'): check = False checker.add_error(_('Parameter domain_name does not exist.')) else: check = checker.check_string( _('Domain Name'), obj.input.domain_name, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH | CHECK_ONLYSPACE, '[^-a-zA-Z0-9_\.]+', DOMAIN_NAME_MIN_LENGTH, DOMAIN_NAME_MAX_LENGTH, ) and check if obj.input.domain_name in get_dom_list(): dom_type = get_dom_type(obj.input.domain_name) checker.add_error( _("The same domain name already exists for hypervisor '%s'.") % dom_type.upper()) check = False if is_param(obj.input, 'vm_mem_size'): check = checker.check_number( _('Memory Size (MB)'), obj.input.vm_mem_size, CHECK_VALID | CHECK_MIN | CHECK_EMPTY, MEMORY_MIN_SIZE, None, ) and check if is_param(obj.input, 'pool_type'): if obj.input.pool_type != "block": if is_param(obj.input, 'vm_disk_size'): check = checker.check_number( _('Disk Size (MB)'), obj.input.vm_disk_size, CHECK_VALID | CHECK_MIN | CHECK_EMPTY, DISK_MIN_SIZE, None, ) and check if not is_param(obj.input, 'boot_image'): check = False checker.add_error(_('Parameter boot_image does not exist.')) else: if obj.input.boot_image == "kernel": if not is_param(obj.input, 'vm_kernel'): check = False checker.add_error(_('Parameter vm_kernel does not exist.')) else: check = checker.check_startfile( _('Kernel Image'), obj.input.vm_kernel, CHECK_EMPTY | CHECK_VALID | CHECK_EXIST, ) and check if not is_param(obj.input, 'vm_initrd'): check = False checker.add_error(_('Parameter vm_initrd does not exist.')) else: check = checker.check_startfile( _('Initrd Image'), obj.input.vm_initrd, CHECK_EMPTY | CHECK_VALID | CHECK_EXIST, ) and check if obj.input.boot_image == "iso": if not is_param(obj.input, 'vm_iso'): check = False checker.add_error(_('Parameter vm_iso does not exist.')) else: check = checker.check_startfile( _('ISO Image'), obj.input.vm_iso, CHECK_EMPTY | CHECK_VALID | CHECK_EXIST, ) and check if check: check = is_iso9660_filesystem_format(obj.input.vm_iso) checker.add_error( _('"%s" is not valid ISO 9660 CD-ROM filesystem data.') % obj.input.vm_iso) if not is_param(obj.input, 'keymap'): check = False checker.add_error(_('"%s" is required.') % _('Graphics Keymap')) else: hypervisor = "KVM" if int(obj.input.m_hypervisor) == MACHINE_HYPERVISOR['XEN']: hypervisor = "XEN" elif int(obj.input.m_hypervisor) == MACHINE_HYPERVISOR['KVM']: hypervisor = "KVM" check = checker.check_keymap(_('Graphics Keymap'), obj.input.keymap, CHECK_EMPTY | CHECK_EXIST, hypervisor) and check if not is_param(obj.input, 'vm_graphics_port'): check = False checker.add_error(_('Parameter vm_graphics_port does not exist.')) else: check = checker.check_number( _('Graphics Port Number'), obj.input.vm_graphics_port, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, GRAPHICS_PORT_MIN_NUMBER, GRAPHICS_PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'vm_mac'): check = False checker.add_error(_('Parameter vm_mac does not exist.')) else: check = checker.check_macaddr( _('MAC Address'), obj.input.vm_mac, CHECK_EMPTY | CHECK_VALID, ) and check obj.view.alert = checker.errors return check
def validates_watch(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'watch_name'): check = checker.check_string(_('Name'), obj.input.watch_name, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Name')) if is_param(obj.input, 'watch_target'): check = checker.check_string(_('Watch Target'), obj.input.watch_target, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check if obj.input.watch_target not in WATCH_PLUGINS.values(): check = False # TRANSLATORS: # %sは監視対象ではありません。 checker.add_error(_('"%s" is not watch target.') %_(obj.input.watch_target)) else: check = False checker.add_error(_('"%s" is required.') %_('Watch Target')) if is_param(obj.input, 'continuation_count'): check = checker.check_number(_('Alert Trigger Count'), obj.input.continuation_count, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, CONTINUATION_COUNT_MIN, CONTINUATION_COUNT_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Alert Trigger Count')) if is_param(obj.input, 'prohibition_period'): check = checker.check_number(_('Silent Period'), obj.input.prohibition_period, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PROHIBITION_PERIOD_MIN, PROHIBITION_PERIOD_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Silent Period')) if is_param(obj.input, 'threshold_fraction'): fraction = int(obj.input.threshold_fraction) else: fraction = 0 if is_param(obj.input, 'threshold_val1'): if fraction == 0: check = checker.check_number(_('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction(_('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Threshold Value')) if is_param(obj.input, 'threshold_val2'): if fraction == 0: check = checker.check_number(_('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction(_('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Threshold Value')) if not is_param(obj.input, 'threshold_type'): check = False checker.add_error(_('"%s" is required.') %_('Threshold Type')) if is_param(obj.input, 'notify_mail_to'): if obj.input.notify_mail_to != "": check = checker.check_mailaddress(_('Mail To'), obj.input.notify_mail_to, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check if is_param(obj.input, 'notify_mail_from'): if obj.input.notify_mail_from != "": check = checker.check_mailaddress(_('Mail From'), obj.input.notify_mail_from, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_guest_add(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 if not is_param(obj.input, 'm_hypervisor'): check = False checker.add_error(_('Parameter m_hypervisor does not exist.')) else: check = checker.check_hypervisor( _('Hypervisor'), obj.input.m_hypervisor, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, HYPERVISOR_MIN_SIZE, HYPERVISOR_MAX_SIZE, ) and check if not is_param(obj.input, 'domain_name'): check = False checker.add_error(_('Parameter domain_name does not exist.')) else: check = checker.check_string( _('Domain Name'), obj.input.domain_name, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH | CHECK_ONLYSPACE, '[^-a-zA-Z0-9_\.]+', DOMAIN_NAME_MIN_LENGTH, DOMAIN_NAME_MAX_LENGTH, ) and check if obj.input.domain_name in get_dom_list(): dom_type = get_dom_type(obj.input.domain_name) checker.add_error(_("The same domain name already exists for hypervisor '%s'.") % dom_type.upper()) check = False if is_param(obj.input, 'vm_mem_size'): check = checker.check_number( _('Memory Size (MB)'), obj.input.vm_mem_size, CHECK_VALID | CHECK_MIN | CHECK_EMPTY, MEMORY_MIN_SIZE, None, ) and check if is_param(obj.input, 'pool_type'): if obj.input.pool_type != "block": if is_param(obj.input, 'vm_disk_size'): check = checker.check_number( _('Disk Size (MB)'), obj.input.vm_disk_size, CHECK_VALID | CHECK_MIN | CHECK_EMPTY, DISK_MIN_SIZE, None, ) and check if not is_param(obj.input, 'boot_image'): check = False checker.add_error(_('Parameter boot_image does not exist.')) else: if obj.input.boot_image == "kernel": if not is_param(obj.input, 'vm_kernel'): check = False checker.add_error(_('Parameter vm_kernel does not exist.')) else: check = checker.check_startfile( _('Kernel Image'), obj.input.vm_kernel, CHECK_EMPTY | CHECK_VALID | CHECK_EXIST, ) and check if not is_param(obj.input, 'vm_initrd'): check = False checker.add_error(_('Parameter vm_initrd does not exist.')) else: check = checker.check_startfile( _('Initrd Image'), obj.input.vm_initrd, CHECK_EMPTY | CHECK_VALID | CHECK_EXIST, ) and check if obj.input.boot_image == "iso": if not is_param(obj.input, 'vm_iso'): check = False checker.add_error(_('Parameter vm_iso does not exist.')) else: check = checker.check_startfile( _('ISO Image'), obj.input.vm_iso, CHECK_EMPTY | CHECK_VALID | CHECK_EXIST, ) and check if check: check = is_iso9660_filesystem_format(obj.input.vm_iso) checker.add_error(_('"%s" is not valid ISO 9660 CD-ROM filesystem data.') % obj.input.vm_iso) if not is_param(obj.input, 'keymap'): check = False checker.add_error(_('"%s" is required.') % _('Graphics Keymap')) else: hypervisor = "KVM" if int(obj.input.m_hypervisor) == MACHINE_HYPERVISOR['XEN']: hypervisor = "XEN" elif int(obj.input.m_hypervisor) == MACHINE_HYPERVISOR['KVM']: hypervisor = "KVM" check = checker.check_keymap( _('Graphics Keymap'), obj.input.keymap, CHECK_EMPTY | CHECK_EXIST, hypervisor ) and check if not is_param(obj.input, 'vm_graphics_port'): check = False checker.add_error(_('Parameter vm_graphics_port does not exist.')) else: check = checker.check_number( _('Graphics Port Number'), obj.input.vm_graphics_port, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, GRAPHICS_PORT_MIN_NUMBER, GRAPHICS_PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'vm_mac'): check = False checker.add_error(_('Parameter vm_mac does not exist.')) else: check = checker.check_macaddr( _('MAC Address'), obj.input.vm_mac, CHECK_EMPTY | CHECK_VALID, ) and check obj.view.alert = checker.errors return check