summaryrefslogtreecommitdiffstats
path: root/kernel/arch/x86/boot/.gitignore
blob: e3cf9f682be55e5d07617a7ba921bead05a218e1 (plain)
1
2
3
4
5
6
7
8
9
bootsect
bzImage
cpustr.h
mkcpustr
voffset.h
zoffset.h
setup
setup.bin
setup.elf
8888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
# Copyright 2014 Huawei Technologies Co. Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Validator methods."""
import logging
import netaddr
import re
import socket

from compass.utils import setting_wrapper as setting
from compass.utils import util


def is_valid_ip(name, ip_addr, **kwargs):
    """Valid the format of an IP address."""
    if isinstance(ip_addr, list):
        return all([
            is_valid_ip(name, item, **kwargs) for item in ip_addr
        ])
    try:
        netaddr.IPAddress(ip_addr)
    except Exception:
        logging.debug('%s invalid ip addr %s', name, ip_addr)
        return False
    return True


def is_valid_network(name, ip_network, **kwargs):
    """Valid the format of an Ip network."""
    if isinstance(ip_network, list):
        return all([
            is_valid_network(name, item, **kwargs) for item in ip_network
        ])
    try:
        netaddr.IPNetwork(ip_network)
    except Exception:
        logging.debug('%s invalid network %s', name, ip_network)
        return False
    return True


def is_valid_netmask(name, ip_addr, **kwargs):
    """Valid the format of a netmask."""
    if isinstance(ip_addr, list):
        return all([
            is_valid_netmask(name, item, **kwargs) for item in ip_addr
        ])
    if not is_valid_ip(ip_addr):
        return False
    ip = netaddr.IPAddress(ip_addr)
    if ip.is_netmask():
        return True
    logging.debug('%s invalid netmask %s', name, ip_addr)
    return False


def is_valid_gateway(name, ip_addr, **kwargs):
    """Valid the format of gateway."""
    if isinstance(ip_addr, list):
        return all([
            is_valid_gateway(name, item, **kwargs) for item in ip_addr
        ])
    if not is_valid_ip(ip_addr):
        return False
    ip = netaddr.IPAddress(ip_addr)
    if ip.is_private() or ip.is_public():
        return True
    logging.debug('%s invalid gateway %s', name, ip_addr)
    return False


def is_valid_dns(name, dns, **kwargs):
    """Valid the format of DNS."""
    if isinstance(dns, list):
        return all([is_valid_dns(name, item, **kwargs) for item in dns])
    if is_valid_ip(dns):
        return True
    try:
        socket.gethostbyname_ex(dns)
    except Exception:
        logging.debug('%s invalid dns name %s', name, dns)
        return False
    return True


def is_valid_url(name, url, **kwargs):
    """Valid the format of url."""
    if isinstance(url, list):
        return all([
            is_valid_url(name, item, **kwargs) for item in url
        ])
    if re.match(
        r'^(http|https|ftp)://([0-9A-Za-z_-]+)(\.[0-9a-zA-Z_-]+)*'
        r'(:\d+)?(/[0-9a-zA-Z_-]+)*$',
        url
    ):
        return True
    logging.debug(
        '%s invalid url %s', name, url
    )
    return False


def is_valid_domain(name, domain, **kwargs):
    """Validate the format of domain."""
    if isinstance(domain, list):
        return all([
            is_valid_domain(name, item, **kwargs) for item in domain
        ])
    if re.match(
        r'^([0-9a-zA-Z_-]+)(\.[0-9a-zA-Z_-]+)*$',
        domain
    ):
        return True
    logging.debug(
        '%s invalid domain %s', name, domain
    )
    return False


def is_valid_username(name, username, **kwargs):
    """Valid the format of username."""
    if bool(username):
        return True
    logging.debug(
        '%s username is empty', name
    )


def is_valid_password(name, password, **kwargs):
    """Valid the format of password."""
    if bool(password):
        return True
    logging.debug('%s password is empty', name)
    return False


def is_valid_partition(name, partition, **kwargs):
    """Valid the format of partition name."""
    if name != 'swap' and not name.startswith('/'):
        logging.debug(
            '%s is not started with / or swap', name
        )
        return False
    if 'size' not in partition and 'percentage' not in partition:
        logging.debug(
            '%s partition does not contain sie or percentage',
            name
        )
        return False
    return True


def is_valid_percentage(name, percentage, **kwargs):
    """Valid the percentage."""
    if 0 <= percentage <= 100:
        return True
    logging.debug('%s invalid percentage %s', name, percentage)


def is_valid_port(name, port, **kwargs):
    """Valid the format of port."""
    if 0 < port < 65536:
        return True
    logging.debug('%s invalid port %s', name, port)


def is_valid_size(name, size, **kwargs):
    if re.match(r'^(\d+)(K|M|G|T)$', size):
        return True
    logging.debug('%s invalid size %s', name, size)
    return False


VALIDATOR_GLOBALS = globals()
VALIDATOR_LOCALS = locals()
VALIDATOR_CONFIGS = util.load_configs(
    setting.VALIDATOR_DIR,
    config_name_suffix='.py',
    env_globals=VALIDATOR_GLOBALS,
    env_locals=VALIDATOR_LOCALS
)
for validator_config in VALIDATOR_CONFIGS:
    VALIDATOR_LOCALS.update(validator_config)