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 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_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_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_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_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_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_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 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_user(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'nickname'): check = False checker.add_error(_('"%s" is required.') % _('Nickname')) else: check = checker.check_username( _('Nickname'), 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, 'new_password'): _password_flag = False checker.add_error(_('"%s" is required.') % _('New Password')) if not is_param(obj.input, 'retype'): check = False _password_flag = False checker.add_error(_('"%s" is required.') % _('Retype')) if _password_flag == True: check = checker.check_password( _('Password'), obj.input.new_password, obj.input.retype, CHECK_VALID | CHECK_LENGTH | CHECK_EMPTY, 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_storage(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'network_storage_host_name'): check = checker.check_domainname(_('Target Hostname'), obj.input.network_storage_host_name, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Target Hostname')) if is_param(obj.input, 'network_storage_port_number'): check = checker.check_number(_('Target Port Number'), obj.input.network_storage_port_number, CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check if is_param(obj.input, 'network_storage_authentication'): check = checker.check_empty(_('iSCSI Authentication Type'), obj.input.network_storage_authentication, ) and check if obj.input.network_storage_authentication == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP: if is_param(obj.input, 'network_storage_user'): check = checker.check_username_with_num(_('iSCSI Authentication User'), obj.input.network_storage_user, CHECK_VALID | CHECK_LENGTH, CHAP_USER_MIN_LENGTH, CHAP_USER_MAX_LENGTH, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('iSCSI Authentication User')) if is_param(obj.input, 'network_storage_password'): check = checker.check_password(_('iSCSI Authentication Password'), obj.input.network_storage_password, obj.input.network_storage_password, CHECK_LENGTH, CHAP_PASSWORD_MIN_LENGTH, CHAP_PASSWORD_MAX_LENGTH, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('iSCSI Authentication Password')) else: check = False checker.add_error(_('"%s" is required.') %_('iSCSI Authentication Type')) 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_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_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_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_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_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_policy(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'input_policy'): check = False checker.add_error(_('"%s" is required.') % _('INPUT Chain')) else: check = checker.check_firewall_policy( _('INPUT Chain'), obj.input.input_policy, CHECK_EMPTY | CHECK_VALID) and check if not is_param(obj.input, 'output_policy'): check = False checker.add_error(_('"%s" is required.') % _('OUTPUT Chain')) else: check = checker.check_firewall_policy( _('OUTPUT Chain'), obj.input.output_policy, CHECK_EMPTY | CHECK_VALID) and check if not is_param(obj.input, 'forward_policy'): check = False checker.add_error(_('"%s" is required.') % _('FORWARD Chain')) else: check = checker.check_firewall_policy( _('FORWARD Chain'), obj.input.input_policy, CHECK_EMPTY | CHECK_VALID) and check obj.view.alert = checker.errors return check
def validates_policy(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, "input_policy"): check = False checker.add_error(_('"%s" is required.') % _("INPUT Chain")) else: check = ( checker.check_firewall_policy(_("INPUT Chain"), obj.input.input_policy, CHECK_EMPTY | CHECK_VALID) and check ) if not is_param(obj.input, "output_policy"): check = False checker.add_error(_('"%s" is required.') % _("OUTPUT Chain")) else: check = ( checker.check_firewall_policy(_("OUTPUT Chain"), obj.input.output_policy, CHECK_EMPTY | CHECK_VALID) and check ) if not is_param(obj.input, "forward_policy"): check = False checker.add_error(_('"%s" is required.') % _("FORWARD Chain")) else: check = ( checker.check_firewall_policy(_("FORWARD Chain"), obj.input.input_policy, CHECK_EMPTY | CHECK_VALID) 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_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_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_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_general(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'gateway'): check = checker.check_ipaddr( _('Default Gateway'), obj.input.gateway, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Default Gateway')) if is_param(obj.input, 'fqdn'): check = checker.check_domainname( _('FQDN'), obj.input.fqdn, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH, FQDN_MIN_LENGTH, FQDN_MAX_LENGTH, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('FQDN')) if is_param(obj.input, 'nameserver'): nameservers = obj.input.nameserver.strip().split() if len(nameservers) != 0: for name_server in nameservers: if name_server == "": continue check = checker.check_ipaddr( _('Nameserver'), name_server, CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Nameserver')) else: check = False checker.add_error(_('"%s" is required.') % _('Nameserver')) obj.view.alert = checker.errors return check
def validates_general(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'gateway'): check = checker.check_ipaddr(_('Default Gateway'), obj.input.gateway, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Default Gateway')) if is_param(obj.input, 'fqdn'): check = checker.check_domainname(_('FQDN'), obj.input.fqdn, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH, FQDN_MIN_LENGTH, FQDN_MAX_LENGTH, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('FQDN')) if is_param(obj.input, 'nameserver'): nameservers = obj.input.nameserver.strip().split() if len(nameservers) != 0: for name_server in nameservers: if name_server == "": continue check = checker.check_ipaddr(_('Nameserver'), name_server, CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Nameserver')) else: check = False checker.add_error(_('"%s" is required.') %_('Nameserver')) 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_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_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_bonding(obj, target_regex): checker = Checker() check = True _ = obj._ checker.errors = [] count = 0 for input in obj.input: m = target_regex.match(input) if m: count += 1 check = checker.check_netdev_name( _('Target Device Name'), m.group('dev'), CHECK_EMPTY | CHECK_VALID, ) and check if count < 2: check = False checker.add_error(_('Not enough target devices for bonding.')) if is_param(obj.input, 'bonding_target_dev_primary'): check = checker.check_netdev_name( _('Primary Device Name'), obj.input.bonding_target_dev_primary, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Primary Device Name')) if is_param(obj.input, 'bonding_mode'): if obj.input.bonding_mode not in BONDING_MODE: check = False checker.add_error(_('Unknown bonding mode.')) else: check = False checker.add_error(_('"%s" is required.') % _('Bonding Mode')) 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_bonding(obj, target_regex): checker = Checker() check = True _ = obj._ checker.errors = [] count = 0 for input in obj.input: m = target_regex.match(input) if m: count += 1 check = checker.check_netdev_name(_('Target Device Name'), m.group('dev'), CHECK_EMPTY | CHECK_VALID, ) and check if count < 2: check = False checker.add_error(_('Not enough target devices for bonding.')) if is_param(obj.input, 'bonding_target_dev_primary'): check = checker.check_netdev_name(_('Primary Device Name'), obj.input.bonding_target_dev_primary, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Primary Device Name')) if is_param(obj.input, 'bonding_mode'): if obj.input.bonding_mode not in BONDING_MODE: check = False checker.add_error(_('Unknown bonding mode.')) else: check = False checker.add_error(_('"%s" is required.') %_('Bonding Mode')) obj.view.alert = checker.errors return check
def validates_mail(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'server'): check = False checker.add_error(_('"%s" is required.') % _('Mail Server Name')) else: check_server = checker.check_domainname(_('Mail Server Name'), obj.input.server, CHECK_EMPTY | CHECK_VALID, ) or \ checker.check_ipaddr(_('Mail Server Name'), obj.input.server, CHECK_EMPTY | 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_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'email'): check = False checker.add_error(_('"%s" is required.') % _('Recipient Mail Address')) else: check = checker.check_mailaddress(_('Recipient Mail Address'), obj.input.email, CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH, min = EMAIL_MIN_LENGTH, max = EMAIL_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_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_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_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_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_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_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_network_storage(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'network_storage_host_name'): check = checker.check_domainname( _('Target Hostname'), obj.input.network_storage_host_name, CHECK_EMPTY | CHECK_VALID, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Target Hostname')) if is_param(obj.input, 'network_storage_port_number'): check = checker.check_number( _('Target Port Number'), obj.input.network_storage_port_number, CHECK_VALID | CHECK_MIN | CHECK_MAX, PORT_MIN_NUMBER, PORT_MAX_NUMBER, ) and check if is_param(obj.input, 'network_storage_authentication'): check = checker.check_empty( _('iSCSI Authentication Type'), obj.input.network_storage_authentication, ) and check if obj.input.network_storage_authentication == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP: if is_param(obj.input, 'network_storage_user'): check = checker.check_username_with_num( _('iSCSI Authentication User'), obj.input.network_storage_user, CHECK_VALID | CHECK_LENGTH, CHAP_USER_MIN_LENGTH, CHAP_USER_MAX_LENGTH, ) and check else: check = False checker.add_error( _('"%s" is required.') % _('iSCSI Authentication User')) if is_param(obj.input, 'network_storage_password'): check = checker.check_password( _('iSCSI Authentication Password'), obj.input.network_storage_password, obj.input.network_storage_password, CHECK_LENGTH, CHAP_PASSWORD_MIN_LENGTH, CHAP_PASSWORD_MAX_LENGTH, ) and check else: check = False checker.add_error( _('"%s" is required.') % _('iSCSI Authentication Password')) else: check = False checker.add_error( _('"%s" is required.') % _('iSCSI Authentication Type')) 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_graphics(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if not is_param(obj.input, 'port'): check = False checker.add_error(_('"%s" is required.') % _('Graphics Port Number')) else: check = checker.check_number( _('Graphics Port Number'), obj.input.port, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, min=GRAPHICS_PORT_MIN_NUMBER, max=GRAPHICS_PORT_MAX_NUMBER, ) and check if not is_param(obj.input, 'listen'): check = False checker.add_error( _('"%s" is required.') % _('Graphics Listen Address')) else: check = checker.check_empty(_('Graphics Listen Address'), obj.input.listen) and check if check is True: if not obj.input.listen in ["0.0.0.0", "127.0.0.1"]: checker.add_error( _('%s is in invalid format.') % (_('Graphics Listen Address'))) check = False else: check = True if not is_param(obj.input, 'change_passwd'): check = False checker.add_error(_('"%s" is required.') % _('Graphics Password')) else: check = checker.check_empty(_('Graphics Password'), obj.input.change_passwd) and check if check is True: if not obj.input.change_passwd in ["random", "empty", "keep"]: checker.add_error( _('%s is in invalid format.') % (_('Graphics Password'))) check = False else: check = True hypervisor = "KVM" if obj.input.VMType == 'XEN': hypervisor = "XEN" elif obj.input.VMType == 'KVM': hypervisor = "KVM" if not is_param(obj.input, 'keymap'): check = False checker.add_error(_('"%s" is required.') % _('Graphics Keymap')) else: check = checker.check_keymap(_('Graphics Keymap'), obj.input.keymap, CHECK_EMPTY | CHECK_EXIST, hypervisor) 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_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