<commit_before>#!/ms/dist/python/PROJ/core/2.5.0/bin/python
# ex: set expandtab softtabstop=4 shiftwidth=4: -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# $Header$
# $Change$
# $DateTime$
# $Author$
# Copyright (C) 2008 <NAME>
#
# This module is part of Aquilon
"""Contains the logic for `aq add host`."""


from aquilon.exceptions_ import ArgumentError
from aquilon.server.broker import (format_results, add_transaction, az_check,
                                   BrokerCommand)
from aquilon.server.dbwrappers.domain import verify_domain
from aquilon.server.dbwrappers.status import get_status
from aquilon.server.dbwrappers.machine import get_machine
from aquilon.server.dbwrappers.archetype import get_archetype
from aquilon.server.dbwrappers.host import hostname_to_domain_and_string
from aquilon.aqdb.sy.host import Host
from aquilon.server.templates import PlenaryMachineInfo
from aquilon.server.processes import DSDBRunner


class CommandAddHost(BrokerCommand):

    required_parameters = ["hostname", "machine", "archetype", "domain",
            "status"]

    @add_transaction
    @az_check
    def render(self, session, hostname, machine, archetype, domain, status,
            user, **arguments):
        dbdomain = verify_domain(session, domain,
                self.config.get("broker", "servername"))
        dbstatus = get_status(session, status)
        dbmachine = get_machine(session, machine)
        dbarchetype = get_archetype(session, archetype)

        if dbmachine.model.machine_type not in [
                'blade', 'workstation', 'rackmount']:
            raise ArgumentError("Machine is of type %s, and must be a blade, workstation, or rackmount to add a host." %
                    (dbmachine.model.machine_type))

        if not dbmachine.interfaces:
            raise ArgumentError("Machine '%s' has no interfaces." % machine)
        found_boot = False
        for interface in dbmachine.interfaces:
            if interface.boot:
                if found_boot:
                    # FIXME: Is this actually a problem?
                    raise ArgumentError("Multiple interfaces on machine '%s' are marked bootable" % machine)
                found_boot = True
        if not found_boot:
            raise ArgumentError("Machine '%s' requires a bootable interface." % machine)<commit_msg>Add a refresh before checking to see if the machine has interfaces. This was necessary when testing parallel execution under sqlite, and may not be relevant when backed by oracle.<commit_after>#!/ms/dist/python/PROJ/core/2.5.0/bin/python
# ex: set expandtab softtabstop=4 shiftwidth=4: -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# $Header$
# $Change$
# $DateTime$
# $Author$
# Copyright (C) 2008 <NAME>
#
# This module is part of Aquilon
"""Contains the logic for `aq add host`."""


from aquilon.exceptions_ import ArgumentError
from aquilon.server.broker import (format_results, add_transaction, az_check,
                                   BrokerCommand)
from aquilon.server.dbwrappers.domain import verify_domain
from aquilon.server.dbwrappers.status import get_status
from aquilon.server.dbwrappers.machine import get_machine
from aquilon.server.dbwrappers.archetype import get_archetype
from aquilon.server.dbwrappers.host import hostname_to_domain_and_string
from aquilon.aqdb.sy.host import Host
from aquilon.server.templates import PlenaryMachineInfo
from aquilon.server.processes import DSDBRunner


class CommandAddHost(BrokerCommand):

    required_parameters = ["hostname", "machine", "archetype", "domain",
            "status"]

    @add_transaction
    @az_check
    def render(self, session, hostname, machine, archetype, domain, status,
            user, **arguments):
        dbdomain = verify_domain(session, domain,
                self.config.get("broker", "servername"))
        dbstatus = get_status(session, status)
        dbmachine = get_machine(session, machine)
        dbarchetype = get_archetype(session, archetype)

        if dbmachine.model.machine_type not in [
                'blade', 'workstation', 'rackmount']:
            raise ArgumentError("Machine is of type %s, and must be a blade, workstation, or rackmount to add a host." %
                    (dbmachine.model.machine_type))

        session.refresh(dbmachine)
        if not dbmachine.interfaces:
            raise ArgumentError("Machine '%s' has no interfaces." % machine)
        found_boot = False
        for interface in dbmachine.interfaces:
            if interface.boot:
                if found_boot:
                    # FIXME: Is this actually a problem?
                    raise ArgumentError("Multiple interfaces on machine '%s' are marked bootable" % machine)
                found_boot = True
        if not found_boot:
            raise ArgumentError("Machine '%s' requires a bootable interface." % machine)
{'fraction_non_alphanumeric': 0.0908530318602261, 'fraction_numerical': 0.0041109969167523125, 'mean_word_length': 2.9950738916256157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4041613', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1333, 'n_words': 395}