def setup_metadata_controller(): """ Pulls in a local bundle or via charmstore api and sets up our controller. You can also further customize the bundle by providing a local bundle-custom.yaml that will be deep merged over whatever bundle is referenced. """ spell_dir = Path(app.config['spell-dir']) bundle_filename = spell_dir / 'bundle.yaml' bundle_custom_filename = spell_dir / 'bundle-custom.yaml' if bundle_filename.exists(): # Load bundle data early so we can merge any additional charm options bundle_data = yaml.load(bundle_filename.read_text()) else: bundle_name = app.config['metadata'].get('bundle-name', None) if bundle_name is None: raise Exception( "Could not determine a bundle to download, please make sure " "the spell contains a 'bundle-name' field.") bundle_channel = app.argv.channel app.log.debug("Pulling bundle for {} from channel: {}".format( bundle_name, bundle_channel)) bundle_data = charm.get_bundle(bundle_name, bundle_channel) if bundle_custom_filename.exists(): bundle_custom = yaml.load(slurp(bundle_custom_filename)) bundle_data = merge_dicts(bundle_data, bundle_custom) bundle = Bundle(bundle_data=bundle_data) app.metadata_controller = MetadataController(bundle, Config('bundle-cfg'))
def setup_metadata_controller(): bundle_filename = os.path.join(app.config['spell-dir'], 'bundle.yaml') if not os.path.isfile(bundle_filename): if 'bundle-location' not in app.config['metadata']: raise Exception( "Could not determine bundle location: no local bundle " "was found and bundle-location not set in spell metadata.") bundle_filename = charm.get_bundle( app.config['metadata']['bundle-location'], True) # Load bundle data early so we can merge any additional charm options with open(bundle_filename) as f: bundle_data = yaml.load(f) bundle_custom_filename = os.path.join(app.config['spell-dir'], 'bundle-custom.yaml') if os.path.isfile(bundle_custom_filename): with open(bundle_custom_filename) as f: bundle_custom = yaml.load(f) bundle_data = merge_dicts(bundle_data, bundle_custom) bundle = Bundle(bundle_data=bundle_data) bundleplacer_cfg = Config('bundle-placer', { 'bundle_filename': bundle_filename, 'bundle_key': None, }) app.metadata_controller = MetadataController(bundle, bundleplacer_cfg)
def setup_metadata_controller(): """ Pulls in a local bundle or via charmstore api and sets up our controller. You can also further customize the bundle by providing a local bundle-custom.yaml that will be deep merged over whatever bundle is referenced. """ spell_dir = Path(app.config['spell-dir']) bundle_filename = spell_dir / 'bundle.yaml' bundle_custom_filename = spell_dir / 'bundle-custom.yaml' if bundle_filename.exists(): # Load bundle data early so we can merge any additional charm options bundle_data = yaml.load(bundle_filename.read_text()) else: bundle_name = app.config['metadata'].get('bundle-name', None) if bundle_name is None: raise Exception( "Could not determine a bundle to download, please make sure " "the spell contains a 'bundle-name' field." ) bundle_channel = app.argv.channel app.log.debug("Pulling bundle for {} from channel: {}".format( bundle_name, bundle_channel)) bundle_data = charm.get_bundle(bundle_name, bundle_channel) if bundle_custom_filename.exists(): bundle_custom = yaml.load(slurp(bundle_custom_filename)) bundle_data = merge_dicts(bundle_data, bundle_custom) for name in app.selected_addons: addon = app.addons[name] bundle_data = merge_dicts(bundle_data, addon.bundle) steps = list(chain(app.steps, chain.from_iterable(app.addons[addon].steps for addon in app.selected_addons))) for step in steps: if not (step.bundle_add or step.bundle_remove): continue if step.bundle_remove: fragment = yaml.safe_load(step.bundle_remove.read_text()) _normalize_bundle(bundle_data, fragment) bundle_data = subtract_dicts(bundle_data, fragment) if step.bundle_add: fragment = yaml.safe_load(step.bundle_add.read_text()) _normalize_bundle(bundle_data, fragment) bundle_data = merge_dicts(bundle_data, fragment) if app.argv.bundle_remove: fragment = yaml.safe_load(app.argv.bundle_remove.read_text()) _normalize_bundle(bundle_data, fragment) bundle_data = subtract_dicts(bundle_data, fragment) if app.argv.bundle_add: fragment = yaml.safe_load(app.argv.bundle_add.read_text()) _normalize_bundle(bundle_data, fragment) bundle_data = merge_dicts(bundle_data, fragment) bundle = Bundle(bundle_data=bundle_data) app.metadata_controller = MetadataController(bundle, Config('bundle-cfg'))
def setup_metadata_controller(): bundle_filename = os.path.join(app.config['spell-dir'], 'bundle.yaml') if not os.path.isfile(bundle_filename): if 'bundle-location' not in app.config['metadata']: raise Exception( "Could not determine bundle location: no local bundle " "was found and bundle-location not set in spell metadata.") bundle_filename = charm.get_bundle( app.config['metadata']['bundle-location'], True) bundle = Bundle(filename=bundle_filename) bundleplacer_cfg = Config('bundle-placer', { 'bundle_filename': bundle_filename, 'bundle_key': None, }) app.metadata_controller = MetadataController(bundle, bundleplacer_cfg)
def setup_metadata_controller(): bundle_filename = os.path.join(app.config['spell-dir'], 'bundle.yaml') if not os.path.isfile(bundle_filename): if 'bundle-location' not in app.config['metadata']: raise Exception( "Could not determine bundle location: no local bundle " "was found and bundle-location not set in spell metadata.") bundle_filename = charm.get_bundle( app.config['metadata']['bundle-location'], True) bundle = Bundle(filename=bundle_filename) bundleplacer_cfg = Config( 'bundle-placer', { 'bundle_filename': bundle_filename, 'bundle_key': None, }) app.metadata_controller = MetadataController(bundle, bundleplacer_cfg)