Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
amsterdam: let full update be full
Browse files Browse the repository at this point in the history
Now config files are overwritten too.
  • Loading branch information
regit committed Feb 3, 2016
1 parent c0314ea commit 3230bf9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion amsterdam
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 22 additions & 10 deletions src/amsterdam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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

0 comments on commit 3230bf9

Please sign in to comment.