def clean(migration, ansible_context, skip_check): nodes = generate_shard_prune_playbook(migration) if nodes: run_ansible_playbook(migration.target_environment, migration.prune_playbook_path, ansible_context, skip_check=skip_check)
def _run_rolling_restart_yml(self, tags, limit): from commcare_cloud.commands.ansible.ansible_playbook import run_ansible_playbook extra_args = ['--tags={}'.format(tags)] if limit: extra_args.extend(['--limit={}'.format(limit)]) run_ansible_playbook(environment=self.environment, playbook='es_rolling_restart.yml', ansible_context=AnsibleContext(args=None), unknown_args=extra_args, skip_check=True, quiet=True)
def _run_rolling_restart_yml(self, tags, limit): from commcare_cloud.commands.ansible.ansible_playbook import run_ansible_playbook extra_args = ['--tags={}'.format(tags)] if limit: extra_args.extend(['--limit={}'.format(limit)]) run_ansible_playbook(environment=self.environment, playbook='es_rolling_restart.yml', ansible_context=AnsibleContext(args=None), unknown_args=extra_args, skip_check=True, quiet=True)
def clean(migration, ansible_context, skip_check, limit): diff_with_db = diff_plan(migration) if diff_with_db: puts(color_warning("Current plan differs with database:\n")) puts("{}\n\n".format(diff_with_db)) puts( color_notice( "This could mean that the plan hasn't been committed yet\n" "or that the plan was re-generated.\n" "Performing the 'clean' operation is still safe but may\n" "not have the outcome you are expecting.\n")) if not ask("Do you wish to continue?"): puts(color_error('Abort.')) return 0 alloc_docs_by_db = get_db_allocations(migration.target_couch_config) puts(color_summary("Checking shards on disk vs DB. Please wait.")) if not assert_files(migration, alloc_docs_by_db, ansible_context): puts(color_error("Not all couch files are accounted for. Aborting.")) return 1 nodes = generate_shard_prune_playbook(migration) if nodes: return run_ansible_playbook(migration.target_environment, migration.prune_playbook_path, ansible_context, skip_check=skip_check, limit=limit)
def clean(migration, ansible_context, skip_check, limit): diff_with_db = diff_plan(migration) if diff_with_db: puts(colored.red("Current plan differs with database:\n")) puts("{}\n\n".format(diff_with_db)) puts( "This could mean that the plan hasn't been committed yet\n" "or that the plan was re-generated.\n" "Performing the 'clean' operation is still safe but may\n" "not have the outcome you are expecting.\n" ) if not ask("Do you wish to continue?"): puts(colored.red('Abort.')) return 0 alloc_docs_by_db = get_db_allocations(migration.target_couch_config) puts(colored.yellow("Checking shards on disk vs DB. Please wait.")) if not assert_files(migration, alloc_docs_by_db, ansible_context): puts(colored.red("Not all couch files are accounted for. Aborting.")) return 1 nodes = generate_shard_prune_playbook(migration) if nodes: return run_ansible_playbook( migration.target_environment, migration.prune_playbook_path, ansible_context, skip_check=skip_check, limit=limit )
def run_ansible_playbook_command(environment, args): skip_check = True environment.create_generated_yml() ansible_context = AnsibleContext(args) return ansible_playbook.run_ansible_playbook( environment, 'deploy_stack.yml', ansible_context, skip_check=skip_check, quiet=skip_check, always_skip_check=skip_check, limit='formplayer', use_factory_auth=False, unknown_args=('--tags=formplayer_deploy',), respect_ansible_skip=True, )
def assert_files(migration, alloc_docs_by_db, ansible_context): files_by_node = get_files_for_assertion(alloc_docs_by_db) expected_files_vars = os.path.abspath(os.path.join(migration.working_dir, 'assert_vars.yml')) with open_for_write(expected_files_vars) as f: yaml.safe_dump({ 'files_by_node': files_by_node, 'couch_data_dir': migration.couchdb2_data_dir, }, f, indent=2) play_path = os.path.join(PLAY_DIR, 'assert_couch_files.yml') return_code = run_ansible_playbook( migration.target_environment, play_path, ansible_context, always_skip_check=True, quiet=True, unknown_args=['-e', '@{}'.format(expected_files_vars)] ) return return_code == 0
def assert_files(migration, alloc_docs_by_db, ansible_context): files_by_node = get_files_for_assertion(alloc_docs_by_db) expected_files_vars = os.path.abspath(os.path.join(migration.working_dir, 'assert_vars.yml')) with open(expected_files_vars, 'w') as f: yaml.safe_dump({ 'files_by_node': files_by_node, 'couch_data_dir': migration.couchdb2_data_dir, }, f, indent=2) play_path = os.path.join(PLAY_DIR, 'assert_couch_files.yml') return_code = run_ansible_playbook( migration.target_environment, play_path, ansible_context, always_skip_check=True, quiet=True, unknown_args=['-e', '@{}'.format(expected_files_vars)] ) return return_code == 0