def commit_config(self):
<EOL>self._gen_rollback_cfg()<EOL>if self.config_replace:<EOL><INDENT>filename = self.candidate_cfg<EOL>cfg_file = self._gen_full_path(filename)<EOL>if not self._check_file_exists(cfg_file):<EOL><INDENT>raise ReplaceConfigException("<STR_LIT>")<EOL><DEDENT>if self.auto_rollback_on_error:<EOL><INDENT>cmd = '<STR_LIT>'.format(cfg_file)<EOL><DEDENT>else:<EOL><INDENT>cmd = '<STR_LIT>'.format(cfg_file)<EOL><DEDENT>output = self._commit_hostname_handler(cmd)<EOL>if ('<STR_LIT>' in output) or('<STR_LIT:error>' in output.lower()) or('<STR_LIT>' in output.lower()):<EOL><INDENT>msg = "<STR_LIT>".format(output)<EOL>raise ReplaceConfigException(msg)<EOL><DEDENT>elif '<STR_LIT>' in output:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ReplaceConfigException(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filename = self.merge_cfg<EOL>cfg_file = self._gen_full_path(filename)<EOL>if not self._check_file_exists(cfg_file):<EOL><INDENT>raise MergeConfigException("<STR_LIT>")<EOL><DEDENT>cmd = '<STR_LIT>'.format(cfg_file)<EOL>self._disable_confirm()<EOL>output = self._commit_hostname_handler(cmd)<EOL>self._enable_confirm()<EOL>if '<STR_LIT>' in output:<EOL><INDENT>self.rollback()<EOL>err_header = "<STR_LIT>"<EOL>merge_error = "<STR_LIT>".format(err_header, output)<EOL>raise MergeConfigException(merge_error)<EOL><DEDENT><DEDENT>output += self.device.send_command_expect("<STR_LIT>")<EOL>
If replacement operation, perform 'configure replace' for the entire config.

If merge operation, perform copy <file> running-config.