def deploy(params, topdir=None, cache_only=None): if cache_only: return (0, "no-ops for caching", {}) action_type = 'configfiles.deploy' if not _local_permission_check(action_type): log_to_file(0, "permissions error: " + str(action_type)) return _perm_error(action_type) _init() files = params.get('files') or [] dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0) for file in files: dep_trans.add(file) try: dep_trans.deploy() #5/3/05 wregglej - 135415 Adding stuff for missing user info except cfg_exceptions.UserNotFound, e: try: dep_trans.rollback() except FailedRollback: log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound, f: log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
def deploy(params, topdir=None, cache_only=None): if cache_only: return (0, "no-ops for caching", {}) action_type = 'configfiles.deploy' if not _local_permission_check(action_type): log_to_file(0, "permissions error: " + str(action_type)) return _perm_error(action_type) _init() files = params.get('files') or [] dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0) for file in files: dep_trans.add(file) try: dep_trans.deploy() #5/3/05 wregglej - 135415 Adding stuff for missing user info except cfg_exceptions.UserNotFound: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],)) return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {}) else: log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) except cfg_exceptions.GroupNotFound: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ) ) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],)) return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {}) else: log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (e[0], )) return (51, "Failed deployment and rollback, group '%s' could not be found" % (e[0], ), {}) except cfg_exceptions.FileEntryIsDirectory: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file(0, "Failed deployment and rollback, %s already exists as a directory" % (e[0], )) return (44, "Failed deployment and rollback, %s already exists as a directory" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],)) return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {}) else: log_to_file(0, "Failed deployment, %s already exists as a directory" % (e[0], )) return (45, "Failed deployment, %s already exists as a directory" % (e[0], ), {}) except cfg_exceptions.DirectoryEntryIsFile: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file(0, "Failed deployment and rollback, %s already exists as a file" % (e[0], )) return (46, "Failed deployment and rollback, %s already exists as a file" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding exceptions for missing user except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],)) return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {}) else: log_to_file(0, "Failed deployment, %s already exists as a file" % (e[0], )) return (47, "Failed deployment, %s already exists as a file" % (e[0], ), {}) except Exception: e = sys.exc_info()[1] print(e) try: dep_trans.rollback() except FailedRollback: e2 = sys.exc_info()[1] log_to_file(0, "Failed deployment, failed rollback: %s" % e2) return (48, "Failed deployment, failed rollback: %s" % e2, {}) #5/3/05 wregglej - 135415 Add exception handling for missing user. except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0])) return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0]), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],)) return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {}) else: log_to_file(0, "Failed deployment, rolled back: %s" % e) return (49, "Failed deployment, rolled back: %s" % e, {}) extras = {} log_to_file(0, "Files successfully deployed: %s %s" % (format_file_string(files, create_key_list()), str(extras))) return 0, "Files successfully deployed", extras
def run(self): log_debug(2) r = self.repository channel = self.options.channel if not channel: die(6, "Config channel not specified") topdir = self.options.topdir if topdir: if not os.path.isdir(self.options.topdir): die( 8, "--topdir specified, but `%s' not a directory" % self.options.topdir) if not self.args: die(7, "No files specified") revision = self.options.revision if revision: if len(self.args) > 1: die(9, "--revision specified with multiple files") dep_trans = None if topdir: dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploying_mesg_callback) for f in self.args: try: directory = topdir or tempfile.gettempdir() #5/11/05 wregglej - 157066 dirs_created is returned from get_file_info. (temp_file, info, dirs_created) = r.get_file_info(channel, f, revision=revision, auto_delete=0, dest_directory=directory) except cfg_exceptions.RepositoryFileMissingError: if revision is not None: die( 2, "Error: file %s (revision %s) not in config " "channel %s" % (f, revision, channel)) else: die( 2, "Error: file %s not in config channel %s" % (f, channel)) if topdir: #5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed. dep_trans.add_preprocessed(f, temp_file, info, dirs_created, strict_ownership=0) continue elif info.get('filetype') == 'symlink': print("%s -> %s" % (info['path'], info['symlink'])) continue elif info.get('filetype') == 'directory': print("%s is a directory entry, nothing to get" % info['path']) continue else: print(open(temp_file).read()) os.unlink(temp_file) if topdir: try: dep_trans.deploy() except Exception: try: dep_trans.rollback() except FailedRollback: raise_with_tb(FailedRollback("FAILED ROLLBACK: "), sys.exc_info()[2]) #5/3/05 wregglej - 136415 Added exception stuff for missing user info. except cfg_exceptions.UserNotFound: raise #5/5/05 wregglej - 136415 Added exception handling for unknown group. except cfg_exceptions.GroupNotFound: raise else: raise_with_tb( Exception("Deploy failed, rollback successful: "), sys.exc_info()[2])
def deploy(params, topdir=None, cache_only=None): if cache_only: return (0, "no-ops for caching", {}) action_type = 'configfiles.deploy' if not _local_permission_check(action_type): log_to_file(0, "permissions error: " + str(action_type)) return _perm_error(action_type) _init() files = params.get('files') or [] dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0) for file in files: dep_trans.add(file) try: dep_trans.deploy() #5/3/05 wregglej - 135415 Adding stuff for missing user info except cfg_exceptions.UserNotFound: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return ( 44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return ( 50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, group '%s' could not be found" % (f[0], )) return ( 51, "Failed deployment and rollback, group '%s' could not be found" % (f[0], ), {}) else: log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return ( 50, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) except cfg_exceptions.GroupNotFound: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], )) return ( 44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return ( 50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, group '%s' could not be found" % (f[0], )) return ( 51, "Failed deployment and rollback, group '%s' could not be found" % (f[0], ), {}) else: log_to_file( 0, "Failed deployment and rollback, group '%s' could not be found" % (e[0], )) return ( 51, "Failed deployment and rollback, group '%s' could not be found" % (e[0], ), {}) except cfg_exceptions.FileEntryIsDirectory: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file( 0, "Failed deployment and rollback, %s already exists as a directory" % (e[0], )) return ( 44, "Failed deployment and rollback, %s already exists as a directory" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding some more exceptions to handle except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return ( 50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, group '%s' could not be found" % (f[0], )) return ( 51, "Failed deployment and rollback, group '%s' could not be found" % (f[0], ), {}) else: log_to_file( 0, "Failed deployment, %s already exists as a directory" % (e[0], )) return (45, "Failed deployment, %s already exists as a directory" % (e[0], ), {}) except cfg_exceptions.DirectoryEntryIsFile: e = sys.exc_info()[1] try: dep_trans.rollback() except FailedRollback: log_to_file( 0, "Failed deployment and rollback, %s already exists as a file" % (e[0], )) return ( 46, "Failed deployment and rollback, %s already exists as a file" % (e[0], ), {}) #5/3/05 wregglej - 136415 Adding exceptions for missing user except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], )) return ( 50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, group '%s' could not be found" % (f[0], )) return ( 51, "Failed deployment and rollback, group '%s' could not be found" % (f[0], ), {}) else: log_to_file( 0, "Failed deployment, %s already exists as a file" % (e[0], )) return (47, "Failed deployment, %s already exists as a file" % (e[0], ), {}) except Exception: e = sys.exc_info()[1] print(e) try: dep_trans.rollback() except FailedRollback: e2 = sys.exc_info()[1] log_to_file(0, "Failed deployment, failed rollback: %s" % e2) return (48, "Failed deployment, failed rollback: %s" % e2, {}) #5/3/05 wregglej - 135415 Add exception handling for missing user. except cfg_exceptions.UserNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0])) return ( 50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0]), {}) #5/5/05 wregglej - 136415 Adding exception handling for unknown group, except cfg_exceptions.GroupNotFound: f = sys.exc_info()[1] log_to_file( 0, "Failed deployment and rollback, group '%s' could not be found" % (f[0], )) return ( 51, "Failed deployment and rollback, group '%s' could not be found" % (f[0], ), {}) else: log_to_file(0, "Failed deployment, rolled back: %s" % e) return (49, "Failed deployment, rolled back: %s" % e, {}) extras = {} log_to_file( 0, "Files successfully deployed: %s %s" % (format_file_string(files, create_key_list()), str(extras))) return 0, "Files successfully deployed", extras
def run(self): log_debug(2) r = self.repository channel = self.options.channel if not channel: die(6, "Config channel not specified") topdir = self.options.topdir if topdir: if not os.path.isdir(self.options.topdir): die(8, "--topdir specified, but `%s' not a directory" % self.options.topdir) if not self.args: die(7, "No files specified") revision = self.options.revision if revision: if len(self.args) > 1: die(9, "--revision specified with multiple files") dep_trans = None if topdir: dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploying_mesg_callback) for f in self.args: try: directory = topdir or tempfile.gettempdir() # 5/11/05 wregglej - 157066 dirs_created is returned from get_file_info. (temp_file, info, dirs_created) = r.get_file_info( channel, f, revision=revision, auto_delete=0, dest_directory=directory ) except cfg_exceptions.RepositoryFileMissingError: if revision is not None: die(2, "Error: file %s (revision %s) not in config " "channel %s" % (f, revision, channel)) else: die(2, "Error: file %s not in config channel %s" % (f, channel)) if topdir: # 5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed. dep_trans.add_preprocessed(f, temp_file, info, dirs_created, strict_ownership=0) continue elif info.get("filetype") == "symlink": print "%s -> %s" % (info["path"], info["symlink"]) continue elif info.get("filetype") == "directory": print "%s is a directory entry, nothing to get" % info["path"] continue else: print open(temp_file).read() os.unlink(temp_file) if topdir: try: dep_trans.deploy() except Exception, e: try: dep_trans.rollback() except FailedRollback, e2: raise e2, "FAILED ROLLBACK: ", sys.exc_info()[2] # 5/3/05 wregglej - 136415 Added exception stuff for missing user info. except cfg_exceptions.UserNotFound, f: raise