def set(self, settings): """ Changes the settings of the engine :param settings: the new settings :type settings: ``dict`` """ if not isinstance(settings, dict): raise TypeError('settings should be a dictionary') if 'safeMode' not in settings: raise LookupError('safeMode is not defined') self.safeMode = settings['safeMode'] if self.safeMode not in [True, False]: raise ValueError('safeMode should be either True or False') if 'polishers' in settings: for item in settings['polishers']: key = item.keys()[0] value = item[key] self.polishers.append(PlumberyPolisher.from_shelf(key, value)) if 'buildPolisher' in settings: self._buildPolisher = settings['buildPolisher'] else: self._buildPolisher = 'spit'
def polish_blueprint(self, names, polishers): """ Walks a named blueprint for this facility and polish related resources :param names: the name(s) of the blueprint(s) to polish :type names: ``str`` or ``list`` of ``str`` :param polishers: polishers to be applied :type polishers: list of :class:`plumbery.PlumberyPolisher` """ if isinstance(polishers, str): polishers = PlumberyPolisher.filter(self.plumbery.polishers, polishers) self.power_on() infrastructure = PlumberyInfrastructure(self) nodes = PlumberyNodes(self) for name in self.expand_blueprint(names): blueprint = self.get_blueprint(name) container = infrastructure.get_container(blueprint) for polisher in polishers: polisher.shine_container(container) nodes.polish_blueprint(blueprint, polishers, container)
def configure(self, settings): """ Changes running settings of the engine :param settings: the new settings :type settings: ``dict`` """ if not isinstance(settings, dict): raise TypeError('settings should be a dictionary') if 'safeMode' not in settings: raise LookupError('safeMode is not defined') self.safeMode = settings['safeMode'] if self.safeMode not in [True, False]: raise ValueError('safeMode should be either True or False') if 'polishers' in settings: for item in settings['polishers']: key = item.keys()[0] value = item[key] self.polishers.append( PlumberyPolisher.from_shelf(key, value))
def polish_all_blueprints(self, filter=None): """ Walk all resources and polish them :param filter: the name of a single polisher to apply. If this parameter is missing, all polishers declared in the fittings plan will be applied :type filter: ``str`` This function checks all facilities, one at a time and in the order defined in fittings plan, to apply custom polishers there. Example:: from plumbery.engine import PlumberyEngine PlumberyEngine('fittings.yaml').polish_all_blueprints() """ logging.info("Polishing all blueprints") polishers = PlumberyPolisher.filter(self.polishers, filter) for polisher in polishers: polisher.go(self) for facility in self.facilities: facility.focus() for polisher in polishers: polisher.move_to(facility) facility.polish_all_blueprints(polishers) for polisher in polishers: polisher.reap()
def polish_blueprint(self, names, polishers): """ Walks a named blueprint for this facility and polish related resources :param names: the name(s) of the blueprint(s) to polish :type names: ``str`` or ``list`` of ``str`` :param polishers: polishers to be applied :type polishers: list of :class:`plumbery.PlumberyPolisher` """ if isinstance(polishers, str): polishers = PlumberyPolisher.filter(self.plumbery.polishers, polishers) self.power_on() infrastructure = PlumberyInfrastructure(self) nodes = PlumberyNodes(self) for polisher in polishers: polisher.move_to(self) for name in self.expand_blueprint(names): blueprint = self.get_blueprint(name) container = infrastructure.get_container(blueprint) for polisher in polishers: polisher.shine_container(container) nodes.polish_blueprint(blueprint, polishers, container)
def polish_blueprint(self, names, filter=None, facilities=None): """ Walks resources from the target blueprint and polishes them :param names: the name(s) of the blueprint(s) to polish :type names: ``str`` or ``list`` of ``str`` :param filter: the name of a single polisher to apply. If this parameter is missing, all polishers declared in the fittings plan will be applied :type filter: ``str`` :param facilities: explicit list of target facilities :type facilities: ``str`` or ``list`` of ``str`` This function checks facilities to apply one polisher to one blueprint. The default behaviour is to consider all facilities mentioned in the fittings plan. If a list of facilities is provided, than the action is limited to this subset only. Example:: from plumbery.engine import PlumberyEngine PlumberyEngine('fittings.yaml').polish_blueprint('sql') """ polishers = PlumberyPolisher.filter(self.polishers, filter) if len(polishers) < 1: logging.debug('No polisher has been found') return if isinstance(names, list): label = ' '.join(names) else: label = names logging.info("Polishing blueprint '{}'".format(label)) for polisher in polishers: polisher.go(self) if facilities is not None: facilities = self.list_facility(facilities) else: facilities = self.facilities for facility in facilities: facility.focus() for polisher in polishers: polisher.move_to(facility) facility.polish_blueprint(names, polishers) for polisher in polishers: polisher.reap()
def polish_all_blueprints(self, filter=None, facilities=None): """ Walks all resources and polishes them :param filter: the name of a single polisher to apply. If this parameter is missing, all polishers declared in the fittings plan will be applied :type filter: ``str`` :param facilities: explicit list of target facilities :type facilities: ``str`` or ``list`` of ``str`` This function checks facilities to apply polishers there. The default behaviour is to consider all facilities mentioned in the fittings plan. If a list of facilities is provided, than the action is limited to this subset only. Example:: from plumbery.engine import PlumberyEngine PlumberyEngine('fittings.yaml').polish_all_blueprints() """ polishers = PlumberyPolisher.filter(self.polishers, filter) if len(polishers) < 1: return False logging.info("Polishing all blueprints") for polisher in polishers: polisher.go(self) if facilities is not None: facilities = self.list_facility(facilities) else: facilities = self.facilities for facility in facilities: facility.focus() for polisher in polishers: polisher.move_to(facility) facility.polish_all_blueprints(polishers) for polisher in polishers: polisher.reap()
def set(self, settings): """ Changes the settings of the engine :param settings: the new settings :type settings: ``dict`` """ if not isinstance(settings, dict): raise TypeError('settings should be a dictionary') if 'safeMode' not in settings: raise LookupError('safeMode is not defined') self.safeMode = settings['safeMode'] if self.safeMode not in [True, False]: raise ValueError('safeMode should be either True or False') if 'polishers' in settings: for item in settings['polishers']: key = item.keys()[0] value = item[key] self.polishers.append( PlumberyPolisher.from_shelf(key, value)) if 'buildPolisher' in settings: self._buildPolisher = settings['buildPolisher'] else: self._buildPolisher = 'spit' if 'cloud-config' in settings: self.cloudConfig = settings['cloud-config'] if 'defaults' in settings: self.defaults = settings['defaults'] if len(self.defaults) > 1: logging.debug("Default parameters:") for key in self.defaults.keys(): logging.debug("- {}: {}".format(key, self.defaults[key]))
def set(self, settings): """ Changes the settings of the engine :param settings: the new settings :type settings: ``dict`` """ if not isinstance(settings, dict): raise TypeError('settings should be a dictionary') if 'buildPolisher' in settings: self._buildPolisher = settings['buildPolisher'] if 'defaults' in settings: self.defaults = settings['defaults'] if not isinstance(self.defaults, dict): raise TypeError('defaults should be a dictionary') if len(self.defaults) > 1: logging.debug("Default values:") for key in self.defaults.keys(): logging.debug("- {}: {}".format(key, self.defaults[key])) if 'information' in settings: self.information = settings['information'] if not isinstance(self.information, list): raise TypeError('information should be a list') if 'links' in settings: self.links = settings['links'] if not isinstance(self.links, dict): raise TypeError('links should be a dictionary') if 'parameters' in settings: self.parameters = settings['parameters'] if not isinstance(self.parameters, dict): raise TypeError('parameters should be a dictionary') for label in self.parameters.keys(): if 'information' not in self.parameters[label]: raise ValueError("Parameter '{}' has no information" .format(label)) if 'type' not in self.parameters[label]: raise ValueError("Parameter '{}' has no type" .format(label)) if 'default' not in self.parameters[label]: raise ValueError("Parameter '{}' has no default value" .format(label)) if 'polishers' in settings: for item in settings['polishers']: key = item.keys()[0] value = item[key] self.polishers.append( PlumberyPolisher.from_shelf(key, value)) if 'safeMode' in settings: self.safeMode = settings['safeMode'] if self.safeMode not in [True, False]: raise ValueError('safeMode should be either True or False')
def set_settings(self, settings): """ Changes the settings of the engine :param settings: the new settings :type settings: ``dict`` """ if not isinstance(settings, dict): raise TypeError('settings should be a dictionary') if 'buildPolisher' in settings: if not isinstance(settings['buildPolisher'], str): raise TypeError('buildPolisher should be a string') self.buildPolisher = settings['buildPolisher'] logging.debug("Build polisher: {}".format(self.buildPolisher)) if 'defaults' in settings: if not isinstance(settings['defaults'], dict): raise TypeError('defaults should be a dictionary') logging.debug("Default values:") for key in settings['defaults'].keys(): self.defaults[key] = settings['defaults'][key] logging.debug("- {}: {}".format(key, self.defaults[key])) if 'information' in settings: if not isinstance(settings['information'], list): raise TypeError('information should be a list') self.information = settings['information'] if 'links' in settings: if not isinstance(settings['links'], dict): raise TypeError('links should be a dictionary') self.links = settings['links'] if 'parameters' in settings: if not isinstance(settings['parameters'], dict): raise TypeError('parameters should be a dictionary') logging.debug("Parameters:") for key in settings['parameters']: if key not in self.parameters: self.parameters[key] = {} if 'information' not in settings['parameters'][key]: raise ValueError("Parameter '{}' has no information" .format(key)) self.parameters[key]['information'] = \ settings['parameters'][key]['information'] if 'type' not in settings['parameters'][key]: raise ValueError("Parameter '{}' has no type" .format(key)) self.parameters[key]['type'] = \ settings['parameters'][key]['type'] if 'default' not in settings['parameters'][key]: raise ValueError("Parameter '{}' has no default value" .format(key)) self.parameters[key]['default'] = \ settings['parameters'][key]['default'] logging.debug("- {}: {}".format( key, self.parameters[key]['default'])) if 'polishers' in settings: if not isinstance(settings['polishers'], list): raise TypeError('polishers should be a list') logging.debug("Polishers:") for item in settings['polishers']: key = item.keys()[0] value = item[key] self.polishers.append( PlumberyPolisher.from_shelf(key, value)) logging.debug("- {}".format(key)) if 'safeMode' in settings: if settings['safeMode'] not in [True, False]: raise ValueError('safeMode should be either True or False') self.safeMode = settings['safeMode']
def set_settings(self, settings): """ Changes the settings of the engine :param settings: the new settings :type settings: ``dict`` """ if not isinstance(settings, dict): raise TypeError('settings should be a dictionary') if 'buildPolisher' in settings: if not isinstance(settings['buildPolisher'], str): raise TypeError('buildPolisher should be a string') self.buildPolisher = settings['buildPolisher'] logging.debug("Build polisher: {}".format(self.buildPolisher)) if 'defaults' in settings: if not isinstance(settings['defaults'], dict): raise TypeError('defaults should be a dictionary') logging.debug("Default values:") for key in settings['defaults'].keys(): self.defaults[key] = settings['defaults'][key] logging.debug("- {}: {}".format(key, self.defaults[key])) if 'information' in settings: if not isinstance(settings['information'], list): raise TypeError('information should be a list') self.information = settings['information'] if 'links' in settings: if not isinstance(settings['links'], dict): raise TypeError('links should be a dictionary') self.links = settings['links'] if 'parameters' in settings: if not isinstance(settings['parameters'], dict): raise TypeError('parameters should be a dictionary') logging.debug("Parameters:") for key in settings['parameters']: if key not in self.parameters: self.parameters[key] = {} if 'information' not in settings['parameters'][key]: raise ValueError( "Parameter '{}' has no information".format(key)) self.parameters[key]['information'] = \ settings['parameters'][key]['information'] if 'type' not in settings['parameters'][key]: raise ValueError("Parameter '{}' has no type".format(key)) self.parameters[key]['type'] = \ settings['parameters'][key]['type'] if 'default' not in settings['parameters'][key]: raise ValueError( "Parameter '{}' has no default value".format(key)) self.parameters[key]['default'] = \ settings['parameters'][key]['default'] logging.debug("- {}: {}".format( key, self.parameters[key]['default'])) if 'polishers' in settings: if not isinstance(settings['polishers'], list): raise TypeError('polishers should be a list') logging.debug("Polishers:") for item in settings['polishers']: key = item.keys()[0] value = item[key] self.polishers.append(PlumberyPolisher.from_shelf(key, value)) logging.debug("- {}".format(key)) if 'safeMode' in settings: if settings['safeMode'] not in [True, False]: raise ValueError('safeMode should be either True or False') self.safeMode = settings['safeMode']