From 3230bf9baa0e635779cb986f98ad09f5a9a2ef5c Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 3 Feb 2016 10:09:35 +0100 Subject: [PATCH] amsterdam: let full update be full Now config files are overwritten too. --- amsterdam | 2 +- src/amsterdam.py | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/amsterdam b/amsterdam index 0c7a4cc..8d3aafe 100755 --- a/amsterdam +++ b/amsterdam @@ -25,7 +25,7 @@ parser.add_argument('-i', '--iface', default=None, help='Host iface to sniff') parser.add_argument('-v', '--verbose', default=False, action="count", help="Show verbose output, use multiple times increase verbosity") parser.add_argument('-d', '--data', default=None, help='Directory to store generated data into (default to ./data)') parser.add_argument('-n', '--name', default=None, help='Set project name') -parser.add_argument('-f', '--full', default=False, const=True, action='store_const', help="Do a full update of instance. This will erase any modified version of Dockerfile") +parser.add_argument('-f', '--full', default=False, const=True, action='store_const', help="Do a full update of instance. This will erase any modified version of config and Dockerfile") parser.add_argument('command', metavar='command', nargs=1, help='Amsterdam command [setup|start|stop|restart|update|rm])', default=None) parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + AMSTERDAM_VERSION) diff --git a/src/amsterdam.py b/src/amsterdam.py index dd7ed88..48fdf5f 100755 --- a/src/amsterdam.py +++ b/src/amsterdam.py @@ -53,6 +53,13 @@ def create_data_dirs(self): if not os.path.exists(dir_path): os.makedirs(dir_path) + def update_files(self, source='docker'): + sourcetree = os.path.join(self.basepath, source) + if os.path.exists(sourcetree): + shutil.rmtree(sourcetree) + if os.path.exists(self.basepath): + shutil.copytree(self.get_sys_data_dirs(source), sourcetree) + def update_config(self): try: shutil.copytree(self.get_sys_data_dirs('config'), os.path.join(self.basepath, 'config')) @@ -63,11 +70,10 @@ def update_config(self): pass def update_docker(self): - dockertree = os.path.join(self.basepath, 'docker') - if os.path.exists(dockertree): - shutil.rmtree(dockertree) - if os.path.exists(self.basepath): - shutil.copytree(self.get_sys_data_dirs('docker'), dockertree) + return self.update_files('docker') + + def update_config_files(self): + return self.update_files('config') def generate_template(self, options): template_path = os.path.join(self.get_sys_data_dirs('templates'), 'docker-compose.yml.j2') @@ -144,16 +150,19 @@ def run_docker_compose(self, cmd, options = None): docker_cmd.extend(options) return subprocess.call(docker_cmd, env = localenv) + def setup_options(self, args): + self.options = {} + self.options['capture_option'] = "--af-packet=%s" % args.iface + self.options['basepath'] = self.basepath + self.options['iface'] = args.iface + def setup(self, args): - options = {} - options['capture_option'] = "--af-packet=%s" % args.iface - options['basepath'] = self.basepath - options['iface'] = args.iface + self.setup_options(args) if args.verbose: sys.stdout.write("Generating docker compose file\n") self.create_data_dirs() self.update_config() - self.generate_template(options) + self.generate_template(self.options) return 0 def start(self, args): @@ -176,7 +185,10 @@ def restart(self, args): def update(self, args): if args.full: + self.setup_options(args) + self.generate_template(self.options) self.update_docker() + self.update_config_files() self.run_docker_compose('pull') self.run_docker_compose('build', options = ['--no-cache']) return True