コード例 #1
0
ファイル: dns.py プロジェクト: MarioCarrilloA/config
def _check_dns_data(dns):
    # Get data
    nameservers = dns['nameservers']
    idns_nameservers_list = []
    dns_nameservers = ""

    MAX_S = 3

    if 'forisystemid' in dns.keys():
        ntp_list = pecan.request.dbapi.intp_get_by_isystem(dns['forisystemid'])
    else:
        ntp_list = pecan.request.dbapi.intp_get_by_isystem(dns['isystem_uuid'])

    if nameservers:
        for nameservers in [n.strip() for n in nameservers.split(',')]:
            # Semantic check each server as IP
            try:
                idns_nameservers_list.append(str(IPAddress(nameservers)))
            except (AddrFormatError, ValueError):

                if nameservers == 'NC':
                    idns_nameservers_list.append(str(""))
                    break

                raise wsme.exc.ClientSideError(
                    _("Invalid DNS nameserver target address %s "
                      "Please configure a valid DNS "
                      "address.") % (nameservers))

    if len(idns_nameservers_list) == 0 or idns_nameservers_list == [""]:
        if ntp_list:
            if hasattr(ntp_list[0], 'ntpservers'):
                if ntp_list[0].ntpservers:
                    for ntpserver in [
                            n.strip()
                            for n in ntp_list[0].ntpservers.split(',')
                    ]:
                        try:
                            str(IPAddress(ntpserver))

                        except (AddrFormatError, ValueError):
                            if utils.is_valid_hostname(ntpserver):
                                raise wsme.exc.ClientSideError(
                                    _("At least  one DNS server must be used "
                                      "when any NTP server address is using "
                                      "FQDN. Alternatively, use IPv4 or IPv6 for"
                                      "NTP server address and then delete DNS "
                                      "servers."))

    if len(idns_nameservers_list) > MAX_S:
        raise wsme.exc.ClientSideError(
            _("Maximum DNS nameservers supported: %s but provided: %s. "
              "Please configure a valid list of DNS nameservers." %
              (MAX_S, len(idns_nameservers_list))))

    dns_nameservers = ",".join(idns_nameservers_list)

    dns['nameservers'] = dns_nameservers

    return dns
コード例 #2
0
def _check_ntp_data(op, ntp):
    # Get data
    ntpservers = ntp['ntpservers']
    intp_ntpservers_list = []
    idns_nameservers_list = []

    MAX_S = 3

    dns_list = pecan.request.dbapi.idns_get_by_isystem(ntp['forisystemid'])

    if dns_list:
        if hasattr(dns_list[0], 'nameservers'):
            if dns_list[0].nameservers:
                idns_nameservers_list = dns_list[0].nameservers.split(',')

    if ntpservers:
        for ntpserver in [n.strip() for n in ntpservers.split(',')]:
            # Semantic check each server as IP
            try:
                intp_ntpservers_list.append(str(IPAddress(ntpserver)))

            except (AddrFormatError, ValueError):
                if utils.is_valid_hostname(ntpserver):
                    # If server address in FQDN, and no DNS servers,
                    # raise error
                    if len(idns_nameservers_list) == 0 and ntpserver != 'NC':
                        raise wsme.exc.ClientSideError(
                            _("A DNS server must be configured prior to "
                              "configuring any NTP server address as FQDN. "
                              "Alternatively, specify the NTP server as an IP"
                              " address"))
                    else:
                        if ntpserver == 'NC':
                            intp_ntpservers_list.append(str(""))
                        else:
                            intp_ntpservers_list.append(str(ntpserver))
                else:
                    raise wsme.exc.ClientSideError(
                        _("Invalid NTP server %s "
                          "Please configure a valid NTP "
                          "IP address or hostname.") % ntpserver)

    if len(intp_ntpservers_list) == 0:
        raise wsme.exc.ClientSideError(_("No NTP parameters provided."))

    if len(intp_ntpservers_list) > MAX_S:
        raise wsme.exc.ClientSideError(
            _("Maximum NTP servers supported: %s but provided: %s. "
              "Please configure a valid list of NTP servers." %
              (MAX_S, len(intp_ntpservers_list))))

    ntp_ntpservers = ",".join(intp_ntpservers_list)

    ntp['ntpservers'] = ntp_ntpservers

    return ntp
コード例 #3
0
 def _validate_name(self):
     if self.name:
         # follows the same naming convention as a host name since it
         # typically contains the hostname with a network type suffix
         utils.is_valid_hostname(self.name)