Ejemplo n.º 1
0
    def render(self, session, logger, hostname, **arguments):
        dbhost = hostname_to_host(session, hostname)
        if dbhost.status.name == 'ready':
            raise ArgumentError("{0:l} is in ready status, "
                                "advertised status can be reset only "
                                "when host is in non ready state."
                                .format(dbhost))

        dbhost.advertise_status = False

        session.flush()

        td = TemplateDomain(dbhost.branch, dbhost.sandbox_author, logger=logger)
        plenary = Plenary.get_plenary(dbhost, logger=logger)
        # Force a host lock as pan might overwrite the profile...
        with plenary.get_key():
            try:
                plenary.write(locked=True)
                td.compile(session, only=plenary.object_templates, locked=True)
            except IncompleteError:
                raise ArgumentError("Run aq make for host %s first." %
                                    dbhost.fqdn)
            except:
                plenary.restore_stash()
                raise

        return
Ejemplo n.º 2
0
    def render(self, session, logger, cluster, buildstatus, **arguments):
        dbcluster = Cluster.get_unique(session, cluster, compel=True)
        dbstatus = ClusterLifecycle.get_instance(session, buildstatus)

        if not dbcluster.status.transition(dbcluster, dbstatus):
            return

        if not dbcluster.personality.archetype.is_compileable:
            return

        session.flush()

        plenaries = PlenaryCollection(logger=logger)
        plenaries.append(Plenary.get_plenary(dbcluster))

        for dbhost in dbcluster.hosts:
            plenaries.append(Plenary.get_plenary(dbhost))

        td = TemplateDomain(dbcluster.branch, dbcluster.sandbox_author,
                            logger=logger)
        # Force a host lock as pan might overwrite the profile...
        with plenaries.get_key():
            plenaries.stash()
            try:
                plenaries.write(locked=True)
                td.compile(session, only=plenaries.object_templates,
                           locked=True)
            except:
                plenaries.restore_stash()
                raise
        return
Ejemplo n.º 3
0
 def render(self, session, logger, hostname,
            pancinclude, pancexclude, pancdebug, cleandeps,
            **arguments):
     dbhost = hostname_to_host(session, hostname)
     if pancdebug:
         pancinclude = r'.*'
         pancexclude = r'components/spma/functions'
     dom = TemplateDomain(dbhost.branch, dbhost.sandbox_author,
                          logger=logger)
     plenary = Plenary.get_plenary(dbhost, logger=logger)
     with plenary.get_key():
         dom.compile(session, only=plenary.object_templates,
                     panc_debug_include=pancinclude,
                     panc_debug_exclude=pancexclude,
                     cleandeps=cleandeps, locked=True)
     return
Ejemplo n.º 4
0
    def render(self, session, logger, domain, sandbox, archetype, personality,
               pancinclude, pancexclude, pancdebug, cleandeps,
               **arguments):
        dbdomain = None
        dbauthor = None
        if domain or sandbox:
            (dbdomain, dbauthor) = get_branch_and_author(session, logger,
                                                         domain=domain,
                                                         sandbox=sandbox,
                                                         compel=True)

        dbpersonality = Personality.get_unique(session, name=personality,
                                               archetype=archetype, compel=True)
        if pancdebug:
            pancinclude = r'.*'
            pancexclude = r'components/spma/functions'

        q = session.query(Host)
        q = q.filter_by(personality=dbpersonality)
        if dbdomain:
            q = q.filter_by(branch=dbdomain)
        if dbauthor:
            q = q.filter_by(sandbox_author=dbauthor)

        host_list = q.all()

        if not host_list:
            return

        # If the domain was not specified, set it to the domain of first host
        dbdomain, dbauthor = validate_branch_author(host_list)

        plenaries = PlenaryCollection(logger=logger)
        for host in host_list:
            plenaries.append(Plenary.get_plenary(host))

        dom = TemplateDomain(dbdomain, dbauthor, logger=logger)
        with plenaries.get_key():
            dom.compile(session, only=plenaries.object_templates,
                        panc_debug_include=pancinclude,
                        panc_debug_exclude=pancexclude,
                        cleandeps=cleandeps, locked=True)
        return
Ejemplo n.º 5
0
    def render(self, session, logger, list, **arguments):
        check_hostlist_size(self.command, self.config, list)
        dbhosts = hostlist_to_hosts(session, list)

        dbbranch, dbauthor = validate_branch_author(dbhosts)

        failed = []
        compileable = []
        # Do any cross-list or dependency checks
        for dbhost in dbhosts:
            if dbhost.status.name == 'ready':
                failed.append("{0:l} is in ready status, "
                              "advertised status can be reset only "
                              "when host is in non ready state.".format(dbhost))
        if failed:
            raise ArgumentError("Cannot modify the following hosts:\n%s" %
                                "\n".join(failed))

        plenaries = PlenaryCollection(logger=logger)
        for dbhost in dbhosts:
            dbhost.advertise_status = False
            plenaries.append(Plenary.get_plenary(dbhost))

        session.flush()

        td = TemplateDomain(dbbranch, dbauthor, logger=logger)
        with plenaries.get_key():
            plenaries.stash()
            try:
                plenaries.write(locked=True)
                td.compile(session, only=compileable, locked=True)
            except:
                plenaries.restore_stash()
                raise

        return
Ejemplo n.º 6
0
    def render(self, session, logger, hostname, buildstatus, **arguments):
        dbhost = hostname_to_host(session, hostname)
        dbstatus = HostLifecycle.get_instance(session, buildstatus)
        changed = dbhost.status.transition(dbhost, dbstatus)

        if not changed or not dbhost.archetype.is_compileable:
            return

        session.flush()

        td = TemplateDomain(dbhost.branch, dbhost.sandbox_author, logger=logger)
        plenary = Plenary.get_plenary(dbhost, logger=logger)
        # Force a host lock as pan might overwrite the profile...
        with plenary.get_key():
            plenary.stash()
            try:
                plenary.write(locked=True)
                td.compile(session, only=plenary.object_templates, locked=True)
            except IncompleteError:
                raise ArgumentError("Run aq make for host %s first." % dbhost.fqdn)
            except:
                plenary.restore_stash()
                raise
        return
Ejemplo n.º 7
0
        logger.info("reconfigure_hostlist processing: %s" %
                    ",".join([str(dbhost.fqdn) for dbhost in dbhosts]))

        if not choosers:
            return

        plenaries = PlenaryCollection(logger=logger)

        # chooser.plenaries is a PlenaryCollection - this flattens
        # that top level.
        plenary_set = set()
        for chooser in choosers:
            plenary_set.update(chooser.plenaries.plenaries)
        plenaries.extend(plenary_set)

        td = TemplateDomain(dbbranch, dbauthor, logger=logger)

        # Don't bother locking until every possible check before the
        # actual writing and compile is done.  This will allow for fast
        # turnaround on errors (no need to wait for a lock if there's
        # a missing service map entry or something).
        with plenaries.get_key():
            plenaries.stash()
            try:
                errors = []
                for template in plenaries.plenaries:
                    try:
                        template.write(locked=True)
                    except IncompleteError, err:
                        # Ignore IncompleteError for hosts added indirectly,
                        # e.g. servers of service instances. It is debatable