コード例 #1
0
def generate_system_facts(name=None):
    """Generate random system facts for registration.

    :param str name: A valid FQDN for a system. If one is not
        provided, then a random value will be generated.
    :return: A dictionary with random system facts
    :rtype: dict
    """
    if name is None:
        name = u"{0}.example.net".format(FauxFactory.generate_alpha().lower())

    # Make a copy of the system facts 'template'
    new_facts = copy.deepcopy(SYSTEM_FACTS)
    # Select a random RHEL version...
    distro = FauxFactory.generate_choice(DISTRO_IDS)

    # ...and update our facts
    new_facts["distribution.id"] = distro["id"]
    new_facts["distribution.version"] = distro["version"]
    new_facts["dmi.bios.relase_date"] = _bios_date().strftime("%m/%d/%Y")
    new_facts["dmi.memory.maximum_capacity"] = FauxFactory.generate_choice(MEMORY_CAPACITY)
    new_facts["dmi.memory.size"] = FauxFactory.generate_choice(MEMORY_SIZE)
    new_facts["dmi.system.uuid"] = FauxFactory.generate_uuid()
    new_facts["dmi.system.version"] = u"RHEL"
    new_facts["lscpu.architecture"] = distro["architecture"]
    new_facts["net.interface.eth1.hwaddr"] = FauxFactory.generate_mac()
    new_facts["net.interface.eth1.ipaddr"] = FauxFactory.generate_ipaddr()
    new_facts["network.hostname"] = name
    new_facts["network.ipaddr"] = new_facts["net.interface.eth1.ipaddr"]
    new_facts["uname.machine"] = distro["architecture"]
    new_facts["uname.nodename"] = name
    new_facts["uname.release"] = distro["kernel"]
    new_facts["virt.uuid"] = new_facts["dmi.system.uuid"]

    return new_facts
コード例 #2
0
 def get_value(self):
     """Return a value suitable for a :class:`StringField`."""
     return _get_value(
         self,
         lambda: FauxFactory.generate_string(
             FauxFactory.generate_choice(self.str_type),
             FauxFactory.generate_integer(1, self.max_len)
         )
     )
コード例 #3
0
    def _generate_name(self):
        """
        Generates a random name string.

        :return: A random string of random length.
        :rtype: str
        """

        name = unicode(FauxFactory.generate_string(
            FauxFactory.generate_choice(['alpha', 'cjk', 'latin1', 'utf8']),
            FauxFactory.generate_integer(1, 30)))

        return name
コード例 #4
0
def _get_value(field, default):
    """Return a value for ``field``.

    Use the following strategies, in order, to find a value for ``field``:

    1. If ``field`` has a default value, return that value.
    2. If ``field`` provides choices, randomly return one of those choices.
    3. If ``default`` is callable, return ``default()``.
    4. Finally, fall back to returning ``default``.

    :param field: A :class:`Field`, or one of its more specialized brethren.
    :param default: A callable which yields a value.
    :return: A value appropriate for that field.

    """
    if 'default' in field.options.keys():
        return field.options['default']
    elif 'choices' in field.options.keys():
        return FauxFactory.generate_choice(field.options['choices'])
    elif callable(default):
        return default()
    else:
        return default
コード例 #5
0
    # Today is...
    today = datetime.date.today()
    # and 10 years ago (~365 days * 10 years) is
    ten_years_ago = today - datetime.timedelta(3650)
    return FauxFactory.generate_date(ten_years_ago, today)


ARCHITECTURES = [u"i386", u"x86_64", u"ppc", u"s390x"]

# https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux#Version_history
DISTRO_IDS = [
    {
        u"id": u"Maipo",
        u"version": u"7.0",
        # There is no 'i386' for RHEL 7
        u"architecture": FauxFactory.generate_choice(ARCHITECTURES[1:]),
        u"kernel": u"3.10.0-123.el7",
    },
    {
        u"id": u"Santiago",
        u"version": u"6.{0}".format(FauxFactory.generate_integer(1, 5)),
        u"architecture": FauxFactory.generate_choice(ARCHITECTURES),
        u"kernel": u"2.6.32-431.el6",
    },
    {
        u"id": u"Tikanga",
        u"version": u"5.{0}".format(FauxFactory.generate_integer(1, 10)),
        u"architecture": FauxFactory.generate_choice(ARCHITECTURES),
        u"kernel": u"2.6.18-371.el5",
    },
    {