コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
ファイル: guestby1nic.py プロジェクト: goura/karesansui
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
コード例 #7
0
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
コード例 #8
0
ファイル: hostby1logby1.py プロジェクト: goura/karesansui
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
コード例 #9
0
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
コード例 #10
0
ファイル: user.py プロジェクト: goura/karesansui
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
コード例 #11
0
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
コード例 #12
0
ファイル: guestby1snapshot.py プロジェクト: AdUser/karesansui
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
コード例 #13
0
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
コード例 #14
0
ファイル: guestby1cpu.py プロジェクト: goura/karesansui
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
コード例 #15
0
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
コード例 #16
0
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
コード例 #17
0
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
コード例 #18
0
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
コード例 #19
0
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
コード例 #20
0
    def _PUT(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        uni_device = param[1]
        if uni_device is None: return web.notfound()
        device = uni_device.encode("utf-8")

        if not validates_nic(self):
            self.logger.debug("Change nic failed. Did not validate.")
            return web.badrequest(self.view.alert)

        host = findbyhost1(self.orm, host_id)

        modules = ["ifcfg"]
        dop = read_conf(modules, self, host)
        if dop is False:
            self.logger.error("Change nic failed. Failed read conf.")
            return web.internalerror('Internal Server Error. (Read conf)')

        ipaddr = ""
        if is_param(self.input, ipaddr):
            if self.input.ipaddr:
                ipaddr = self.input.ipaddr

        netmask = ""
        if is_param(self.input, netmask):
            if self.input.netmask:
                netmask = self.input.netmask

        bootproto = self.input.bootproto
        onboot = "no"
        if is_param(self.input, 'onboot'):
            onboot = "yes"

        net = NetworkAddress("%s/%s" % (ipaddr,netmask))
        network   = net.network
        broadcast = net.broadcast

        if not dop.get("ifcfg", device):
            self.logger.error("Change nic failed. Target config not found.")
            return web.internalerror('Internal Server Error. (Get conf)')

        dop.set("ifcfg",[device,"ONBOOT"]   ,onboot)
        dop.set("ifcfg",[device,"BOOTPROTO"],bootproto)
        dop.set("ifcfg",[device,"IPADDR"]   ,ipaddr)
        dop.set("ifcfg",[device,"NETMASK"]  ,netmask)
        if network is not None:
            dop.set("ifcfg",[device,"NETWORK"]  ,network)
        if broadcast is not None:
            dop.set("ifcfg",[device,"BROADCAST"],broadcast)

        retval = write_conf(dop, self, host)
        if retval is False:
            self.logger.error("Change nic failed. Failed write conf.")
            return web.internalerror('Internal Server Error. (Adding Task)')

        return web.accepted(url=web.ctx.path)
コード例 #21
0
    def _PUT(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        uni_device = param[1]
        if uni_device is None: return web.notfound()
        device = uni_device.encode("utf-8")

        if not validates_nic(self):
            self.logger.debug("Change nic failed. Did not validate.")
            return web.badrequest(self.view.alert)

        host = findbyhost1(self.orm, host_id)

        modules = ["ifcfg"]
        dop = read_conf(modules, self, host)
        if dop is False:
            self.logger.error("Change nic failed. Failed read conf.")
            return web.internalerror('Internal Server Error. (Read conf)')

        ipaddr = ""
        if is_param(self.input, ipaddr):
            if self.input.ipaddr:
                ipaddr = self.input.ipaddr

        netmask = ""
        if is_param(self.input, netmask):
            if self.input.netmask:
                netmask = self.input.netmask

        bootproto = self.input.bootproto
        onboot = "no"
        if is_param(self.input, 'onboot'):
            onboot = "yes"

        net = NetworkAddress("%s/%s" % (ipaddr, netmask))
        network = net.network
        broadcast = net.broadcast

        if not dop.get("ifcfg", device):
            self.logger.error("Change nic failed. Target config not found.")
            return web.internalerror('Internal Server Error. (Get conf)')

        dop.set("ifcfg", [device, "ONBOOT"], onboot)
        dop.set("ifcfg", [device, "BOOTPROTO"], bootproto)
        dop.set("ifcfg", [device, "IPADDR"], ipaddr)
        dop.set("ifcfg", [device, "NETMASK"], netmask)
        if network is not None:
            dop.set("ifcfg", [device, "NETWORK"], network)
        if broadcast is not None:
            dop.set("ifcfg", [device, "BROADCAST"], broadcast)

        retval = write_conf(dop, self, host)
        if retval is False:
            self.logger.error("Change nic failed. Failed write conf.")
            return web.internalerror('Internal Server Error. (Adding Task)')

        return web.accepted(url=web.ctx.path)
コード例 #22
0
ファイル: guestby1.py プロジェクト: AdUser/karesansui
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
コード例 #23
0
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
コード例 #24
0
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
コード例 #25
0
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
コード例 #26
0
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
コード例 #27
0
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
コード例 #28
0
    def _POST(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None:
            return web.notfound()

        if not validates_network_storage(self):
            self.logger.debug("Network storage add failed. Did not validate.")
            return web.badrequest(self.view.alert)

        hostname = self.input.network_storage_host_name
        port = self.input.network_storage_port_number
        auth = self.input.network_storage_authentication
        user = self.input.network_storage_user
        password = self.input.network_storage_password
        auto_start = False
        if is_param(self.input, "network_storage_auto_start"):
            auto_start = True

        options = {"auth": auth}
        if port:
            options["target"] = "%s:%s" % (hostname, port)
        else:
            options["target"] = hostname

        if auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
            options["user"] = user
            try:
                password_file_name = "/tmp/" + generate_phrase(12, "abcdefghijklmnopqrstuvwxyz")
                create_file(password_file_name, password)
                options["password-file"] = password_file_name
            except Exception, e:
                self.logger.error("Failed to create tmp password file. - file=%s" % (password_file_name))
                options["password"] = password
コード例 #29
0
ファイル: hostby1iptables.py プロジェクト: AdUser/karesansui
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
コード例 #30
0
    def _POST(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if not validates_network_storage(self):
            self.logger.debug("Network storage add failed. Did not validate.")
            return web.badrequest(self.view.alert)

        hostname = self.input.network_storage_host_name
        port = self.input.network_storage_port_number
        auth = self.input.network_storage_authentication
        user = self.input.network_storage_user
        password = self.input.network_storage_password
        auto_start = False
        if is_param(self.input, 'network_storage_auto_start'):
            auto_start = True

        options = {'auth': auth}
        if port:
            options['target'] = "%s:%s" % (hostname, port)
        else:
            options['target'] = hostname

        if auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
            options['user'] = user
            try:
                password_file_name = '/tmp/' + generate_phrase(
                    12, 'abcdefghijklmnopqrstuvwxyz')
                create_file(password_file_name, password)
                options['password-file'] = password_file_name
            except Exception, e:
                self.logger.error(
                    'Failed to create tmp password file. - file=%s' %
                    (password_file_name))
                options['password'] = password
コード例 #31
0
    def _PUT(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if not validates_network_storage(self):
            self.logger.debug("Network storage update failed. Did not validate.")
            return web.badrequest(self.view.alert)

        hostname = self.input.network_storage_host_name
        port = self.input.network_storage_port_number
        iqn = self.input.network_storage_iqn
        auth = self.input.network_storage_authentication
        user = self.input.network_storage_user
        password = self.input.network_storage_password
        auto_start = False
        if is_param(self.input, 'network_storage_auto_start'):
            auto_start = True

        options = {'auth' : auth,
                   'iqn' : iqn,
                   'target' : hostname}
        if port:
            options['port'] = port

        if auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
            options['user'] =  user
            try:
                password_file_name = '/tmp/' + generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')
                create_file(password_file_name, password)
                options['password-file'] = password_file_name
            except Exception, e:
                self.logger.error('Failed to create tmp password file. - file=%s' % (password_file_name))
                options['password'] = password
コード例 #32
0
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
コード例 #33
0
ファイル: guestreplicate.py プロジェクト: goura/karesansui
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
コード例 #34
0
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
コード例 #35
0
ファイル: guestby1memory.py プロジェクト: goura/karesansui
    def _PUT(self, *param, **params):
        """<comment-ja>
        Japanese Comment
        </comment-ja>
        <comment-en>
        TODO: English Comment
        </comment-en>
        """
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None:
            return web.notfound()

        if is_param(self.input, "memory"):
            memory = int(self.input.memory)
        else:
            memory = None
        max_memory = int(self.input.max_memory)

        model = findbyguest1(self.orm, guest_id)

        # virt
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname:
                return web.conflict(web.ctx.path)
            virt = kvc.search_kvg_guests(domname)[0]
            info = virt.get_info()
            # maxMem = info["maxMem"]
            now_memory = info["memory"]
            mem_info = kvc.get_mem_info()
            nodeinfo = kvc.get_nodeinfo()
        finally:
            kvc.close()

        # valid
        # if (mem_info["host_free_mem"] + (now_memory / 1024)) < memory:
        #    return web.badrequest("Memory value is greater than the maximum memory value. - memory=%s" % self.input.memory)

        options = {}
        options["name"] = domname
        options["maxmem"] = max_memory
        if memory is None:
            options["memory"] = max_memory
        else:
            options["memory"] = memory
        _cmd = dict2command("%s/%s" % (karesansui.config["application.bin.dir"], VIRT_COMMAND_SET_MEMORY), options)
        cmdname = "Set memory"
        _jobgroup = JobGroup(cmdname, karesansui.sheconf["env.uniqkey"])
        _jobgroup.jobs.append(Job("%s command" % cmdname, 0, _cmd))
        _machine2jobgroup = m2j_new(
            machine=model,
            jobgroup_id=-1,
            uniq_key=karesansui.sheconf["env.uniqkey"],
            created_user=self.me,
            modified_user=self.me,
        )
        save_job_collaboration(self.orm, self.pysilhouette.orm, _machine2jobgroup, _jobgroup)
        return web.accepted(url=web.ctx.path)
コード例 #36
0
    def _GET(self, *param, **params):
        self.__template__.dir = "hostby1logby1appby1"
        self.__template__.file = "hostby1logby1appby1"
        self.__template__.media = "part"

        appname = param[1]
        filename = param[2]
        log_config = None

        if not validates_log(self):
            self.logger.debug("Get log failed. Did not validate.")
            return web.badrequest(self.view.alert)

        config = LogViewConfigParam(LOG_VIEW_XML_FILE)
        config.load_xml_config()
        app = config.findby1application(appname)

        for log in app["logs"]:
            if log["filename"] == filename:
                log_config = log

        lines = []
        param_value = {}

        if is_param(self.input, "k"):
            param_value["k"] = self.input.k
        else:
            param_value["k"] = ""

        start_day = str2datetime(self.input.s, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0])
        end_day = str2datetime(self.input.e, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0])

        (start_hour, start_minute) = self.input.st.split(":", 2)
        (end_hour, end_minute) = self.input.et.split(":", 2)

        start_time = create_epochsec(start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute))

        end_time = create_epochsec(end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute))
        if int(start_time) > int(end_time):
            self.logger.error("Getting reports failed. Start time > end time.")
            return web.badrequest(_("Getting reports failed. Start time > end time."))

        param_value["start_datetime"] = "%s %s" % (start_day.strftime("%Y/%m/%d"), self.input.st)
        param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et)

        if log_config["view_lotatelog"]:
            try:
                lines = read_log_with_lotate(
                    filename,
                    self.input.m,
                    log_config,
                    param_value["start_datetime"],
                    param_value["end_datetime"],
                    param_value["k"],
                )
                if lines is False:
                    return web.notfound()
            except Exception, e:
                self.logger.warning("log file open error: %s" % e)
コード例 #37
0
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
コード例 #38
0
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug(
                "Failed to get tags. The value of query is invalid.")
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug(
                "Failed to get tags. The value of page is invalid.")
            return web.badrequest(self.view.alert)

        if is_param(self.input, 'q') is True:
            tags = findbyand(self.orm, self.input.q)
            if not tags:
                self.logger.debug(
                    "Failed to get tags. No such tag - query=%s" %
                    self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            tags = findbyall(self.orm)
            self.view.search_value = ""
            if not tags:
                self.logger.debug("Failed to get tag. No tags found.")
                return web.notfound()

        if is_param(self.input, 'p') is True:
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(tags, start, TAG_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug(
                "Failed to get tag. Could not find page - page=%s" %
                self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            self.view.tag = new('')

        self.view.input = self.input
        return True
コード例 #39
0
ファイル: mail.py プロジェクト: goura/karesansui
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
コード例 #40
0
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
コード例 #41
0
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
コード例 #42
0
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
コード例 #43
0
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
コード例 #44
0
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
コード例 #45
0
    def _PUT(self, *param, **params):

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None:
            return web.notfound()

        if not validates_guest_edit(self):
            self.logger.debug(
                "Update Guest OS is failed, Invalid input value.")
            return web.badrequest(self.view.alert)

        guest = findbyguest1(self.orm, guest_id)

        # notebook
        if is_param(self.input, "note_title"):
            guest.notebook.title = self.input.note_title
        if is_param(self.input, "note_value"):
            guest.notebook.value = self.input.note_value

        if is_param(self.input, "m_name"):
            guest.name = self.input.m_name

        # Icon
        icon_filename = None
        if is_param(self.input, "icon_filename", empty=True):
            guest.icon = self.input.icon_filename

        # tag UPDATE
        if is_param(self.input, "tags"):
            _tags = []
            tag_array = comma_split(self.input.tags)
            tag_array = uniq_sort(tag_array)
            for x in tag_array:
                if t_count(self.orm, x) == 0:
                    _tags.append(t_new(x))
                else:
                    _tags.append(t_name(self.orm, x))
            guest.tags = _tags

        guest.modified_user = self.me

        m_update(self.orm, guest)
        return web.seeother(web.ctx.path)
コード例 #46
0
ファイル: guestby1.py プロジェクト: AdUser/karesansui
    def _PUT(self, *param, **params):

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None:
            return web.notfound()

        if not validates_guest_edit(self):
            self.logger.debug("Update Guest OS is failed, Invalid input value.")
            return web.badrequest(self.view.alert)

        guest = findbyguest1(self.orm, guest_id)

        # notebook
        if is_param(self.input, "note_title"):
            guest.notebook.title = self.input.note_title
        if is_param(self.input, "note_value"):
            guest.notebook.value = self.input.note_value

        if is_param(self.input, "m_name"):
            guest.name = self.input.m_name

        # Icon
        icon_filename = None
        if is_param(self.input, "icon_filename", empty=True):
            guest.icon = self.input.icon_filename

        # tag UPDATE
        if is_param(self.input, "tags"):
            _tags = []
            tag_array = comma_split(self.input.tags)
            tag_array = uniq_sort(tag_array)
            for x in tag_array:
                if t_count(self.orm, x) == 0:
                    _tags.append(t_new(x))
                else:
                    _tags.append(t_name(self.orm, x))
            guest.tags = _tags

        guest.modified_user = self.me

        m_update(self.orm, guest)
        return web.seeother(web.ctx.path)
コード例 #47
0
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
コード例 #48
0
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug("Failed to get account. the value of query is invalid. - query=%s" % self.input.q)
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Failed to get account. the value of page is invalid. - page=%s" % self.input.p)
            return web.badrequest(self.view.alert)

        if is_param(self.input, "q"):
            users = findbyand(self.orm, self.input.q)
            if not users:
                self.logger.debug("Failed to get account. No such account. - query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            users = findbyall(self.orm)
            self.view.search_value = ""
            if not users:
                self.logger.debug("Failed to get account. No accounts found.")
                return web.notfound()

        if is_param(self.input, "p"):
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(users, start, USER_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug("Failed to get account. Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            locales = DEFAULT_LANGS.keys()
            self.view.locales = locales
            self.view.user = new('', '', '', '', '')

        self.view.input = self.input
        return True
コード例 #49
0
ファイル: user.py プロジェクト: goura/karesansui
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug("Failed to get account. the value of query is invalid. - query=%s" % self.input.q)
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Failed to get account. the value of page is invalid. - page=%s" % self.input.p)
            return web.badrequest(self.view.alert)

        if is_param(self.input, "q"):
            users = findbyand(self.orm, self.input.q)
            if not users:
                self.logger.debug("Failed to get account. No such account. - query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            users = findbyall(self.orm)
            self.view.search_value = ""
            if not users:
                self.logger.debug("Failed to get account. No accounts found.")
                return web.notfound()

        if is_param(self.input, "p"):
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(users, start, USER_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug("Failed to get account. Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            locales = DEFAULT_LANGS.keys()
            self.view.locales = locales
            self.view.user = new('', '', '', '', '')

        self.view.input = self.input
        return True
コード例 #50
0
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
コード例 #51
0
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
コード例 #52
0
ファイル: tag.py プロジェクト: goura/karesansui
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug("Failed to get tags. The value of query is invalid.")
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Failed to get tags. The value of page is invalid.")
            return web.badrequest(self.view.alert)

        if is_param(self.input, 'q') is True:
            tags = findbyand(self.orm, self.input.q)
            if not tags:
                self.logger.debug("Failed to get tags. No such tag - query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            tags = findbyall(self.orm)
            self.view.search_value = ""
            if not tags:
                self.logger.debug("Failed to get tag. No tags found.")
                return web.notfound()

        if is_param(self.input, 'p') is True:
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(tags, start, TAG_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug("Failed to get tag. Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            self.view.tag = new('')

        self.view.input = self.input
        return True
コード例 #53
0
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
コード例 #54
0
 def is_standalone(self):
     """<comment-ja>
     URLパラメタにstandalone=1が存在するかどうか。
     @rtype: bool
     </comment-ja>
     <comment-en>
     English Comment
     </comment-en>
     """
     if self.is_mode_input() is True or self.is_part() is True and is_param(
             self.input, "standalone") and self.input.standalone == "1":
         return True
     else:
         return False
コード例 #55
0
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
コード例 #56
0
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
コード例 #57
0
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
コード例 #58
0
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
コード例 #59
0
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