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

Commit

Permalink
better assets fix for non-running VM
Browse files Browse the repository at this point in the history
  • Loading branch information
jsingle committed Sep 9, 2015
1 parent b8a308e commit 6cbc250
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion dusty/commands/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from prettytable import PrettyTable

from ..compiler.spec_assembler import get_specs, get_assembled_specs
from ..systems.virtualbox import asset_is_set, asset_value, asset_vm_path, remove_asset, initialize_docker_vm
from ..systems.virtualbox import (asset_is_set, asset_value, asset_vm_path, remove_asset,
initialize_docker_vm, docker_vm_is_running)
from ..systems.rsync import sync_local_path_to_vm
from ..log import log_to_client
from .. import constants

def list_by_app_or_lib(app_or_lib):
initialize_docker_vm()
spec = get_specs().get_app_or_lib(app_or_lib)
table = PrettyTable(["Asset", "Is Set", "Required", "In-Container Path"])
for asset in spec['assets']:
Expand All @@ -18,6 +21,8 @@ def _get_string_of_set(items):
return ', '.join(sorted(items))

def list_all():
initialize_docker_vm()
log_to_client('Listing assets used by active apps and libs')
table = PrettyTable(["Asset", "Is Set", "Used By", "Required By"])
assembled_specs = get_assembled_specs()
for asset_name, asset_info in assembled_specs['assets'].iteritems():
Expand All @@ -27,6 +32,7 @@ def list_all():
log_to_client(table.get_string())

def read_asset(asset_key):
initialize_docker_vm()
if not asset_is_set(asset_key):
log_to_client('Asset {} isn\'t set'.format(asset_key))
return
Expand All @@ -37,6 +43,7 @@ def set_asset(asset_key, local_path):
sync_local_path_to_vm(local_path, asset_vm_path(asset_key))

def unset_asset(asset_key):
initialize_docker_vm()
if not asset_is_set(asset_key):
log_to_client('Asset {} isn\'t set'.format(asset_key))
return
Expand Down
4 changes: 3 additions & 1 deletion dusty/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def start_local_env(recreate_containers=True, pull_repos=True):
assembled_spec = spec_assembler.get_assembled_specs()
if not assembled_spec[constants.CONFIG_BUNDLES_KEY]:
raise RuntimeError('No bundles are activated. Use `dusty bundles` to activate bundles before running `dusty up`.')

virtualbox.initialize_docker_vm()

required_absent_assets = virtualbox.required_absent_assets(assembled_spec)
if required_absent_assets:
raise RuntimeError('Assets {} are specified as required but are not set. Set them with `dusty assets set`'.format(required_absent_assets))

virtualbox.initialize_docker_vm()
docker_ip = virtualbox.get_docker_vm_ip()

# Stop will fail if we've never written a Composefile before
Expand Down
7 changes: 6 additions & 1 deletion dusty/systems/virtualbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ def _init_docker_vm():
check_call_demoted(['docker-machine', 'create'] + machine_options + [constants.VM_MACHINE_NAME],
redirect_stderr=True)

def _docker_vm_is_running():
return check_output_demoted(['docker-machine', 'status', constants.VM_MACHINE_NAME]).rstrip() == 'Running'

def _start_docker_vm():
"""Start the Dusty VM if it is not already running."""
check_and_log_output_and_error_demoted(['docker-machine', 'start', constants.VM_MACHINE_NAME], quiet_on_success=True)
if not _docker_vm_is_running():
logging.info('Starting docker-machine VM {}'.format(constants.VM_MACHINE_NAME))
check_and_log_output_and_error_demoted(['docker-machine', 'start', constants.VM_MACHINE_NAME], quiet_on_success=True)

def _stop_docker_vm():
"""Stop the Dusty VM if it is not already stopped."""
Expand Down

0 comments on commit 6cbc250

Please sign in to comment.