def render(self, session, logger, building, dryrun, incremental, **arguments): if building: dbbuilding = get_location(session, building=building) else: dbbuilding = None # --dryrun and --incremental do not mix well if dryrun and incremental: raise ArgumentError("--dryrun and --incremental cannot be given " "simultaneously.") with SyncKey("network", logger=logger): rundir = self.config.get("broker", "rundir") tempdir = mkdtemp(prefix="refresh_network_", dir=rundir) try: args = [self.config.get("broker", "qip_dump_subnetdata"), "--datarootdir", tempdir, "--format", "txt", "--noaudit"] run_command(args, logger=logger) subnetdata = file(os.path.join(tempdir, "subnetdata.txt"), "r") refresher = QIPRefresh(session, logger, dbbuilding, dryrun, incremental) refresher.refresh(subnetdata) session.flush() if dryrun: session.rollback() finally: remove_dir(tempdir, logger=logger)
def render(self, session, logger, dbuser, sandbox, **arguments): sandbox = self.force_my_sandbox(session, logger, dbuser, sandbox) dbsandbox = Sandbox.get_unique(session, sandbox, compel=True) if not dbuser: raise AuthorizationException("Cannot get a sandbox without" " an authenticated connection.") userdir = os.path.join(self.config.get("broker", "templatesdir"), dbuser.name) sandboxdir = os.path.join(userdir, dbsandbox.name) if os.path.exists(sandboxdir): raise ArgumentError("Directory '%s' already exists. Use git " "fetch within the directory to update it." % sandboxdir) if not os.path.exists(userdir): try: logger.client_info("creating %s" % userdir) os.makedirs(userdir, mode=0775) except OSError, e: raise ArgumentError("failed to mkdir %s: %s" % (userdir, e)) args = [self.config.get("broker", "mean")] args.append("chown") args.append("-owner") args.append("%s" % dbuser.name) args.append("-path") args.append("%s" % userdir) try: run_command(args, logger=logger) except ProcessException, e: remove_dir(userdir) raise e
def remove_branch(config, logger, dbbranch): session = object_session(dbbranch) deps = get_branch_dependencies(dbbranch) if deps: raise ArgumentError("\n".join(deps)) session.delete(dbbranch) domain = TemplateDomain(dbbranch, logger=logger) # Can this fail? Is recovery needed? with CompileKey(domain=dbbranch.name, logger=logger): for dir in domain.directories(): remove_dir(dir, logger=logger) kingdir = config.get("broker", "kingdir") try: run_git(["branch", "-D", dbbranch.name], path=kingdir, logger=logger) except ProcessException, e: logger.warning("Error removing branch %s from template-king, " "proceeding anyway: %s", dbbranch.name, e)
command = ["pull", filename, ref] if rebase: command.append("--force") run_git(command, path=temprepo, logger=logger, loglevel=CLIENT_INFO) # FIXME: Run tests before pushing back to template-king if rebase: target_ref = "+" + dbsandbox.name else: target_ref = dbsandbox.name run_git(["push", "origin", target_ref], path=temprepo, logger=logger) except ProcessException, e: raise ArgumentError("\n%s%s" % (e.out, e.err)) finally: remove_file(filename, logger=logger) remove_dir(tempdir, logger=logger) client_command = "git fetch" if not sync or not dbsandbox.autosync: return client_command for domain in dbsandbox.trackers: if not domain.autosync: continue try: sync_domain(domain, logger=logger) except ProcessException, e: logger.warn("Error syncing domain %s: %s" % (domain.name, e)) return client_command
def render(self, session, logger, dbuser, domain, track, start, change_manager, comments, allow_manage, **arguments): if not dbuser: raise AuthorizationException("Cannot create a domain without " "an authenticated connection.") validate_template_name("--domain", domain) Branch.get_unique(session, domain, preclude=True) compiler = self.config.get("panc", "pan_compiler") dbtracked = None if track: dbtracked = Branch.get_unique(session, track, compel=True) if getattr(dbtracked, "tracked_branch", None): raise ArgumentError("Cannot nest tracking. Try tracking " "{0:l} directly.".format(dbtracked.tracked_branch)) start_point = dbtracked if change_manager: raise ArgumentError("Cannot enforce a change manager for " "tracking domains.") else: if not start: start = self.config.get("broker", "default_domain_start") start_point = Branch.get_unique(session, start, compel=True) dbdomain = Domain(name=domain, owner=dbuser, compiler=compiler, tracked_branch=dbtracked, requires_change_manager=bool(change_manager), comments=comments) session.add(dbdomain) if allow_manage is not None: dbdomain.allow_manage = allow_manage session.flush() domainsdir = self.config.get("broker", "domainsdir") clonedir = os.path.join(domainsdir, dbdomain.name) if os.path.exists(clonedir): raise InternalError("Domain directory already exists") kingdir = self.config.get("broker", "kingdir") cmd = ["branch"] if track: cmd.append("--track") else: cmd.append("--no-track") cmd.append(dbdomain.name) cmd.append(start_point.name) run_git(cmd, path=kingdir, logger=logger) # If the branch command above fails the DB will roll back as normal. # If the command below fails we need to clean up from itself and above. try: run_git(["clone", "--branch", dbdomain.name, kingdir, dbdomain.name], path=domainsdir, logger=logger) except ProcessException, e: try: remove_dir(clonedir, logger=logger) run_git(["branch", "-D", dbdomain.name], path=kingdir, logger=logger) except ProcessException, e2: logger.info("Exception while cleaning up: %s", e2)