def stop_nodes(self, names): """ Stops nodes of the given blueprint at this facility :param names: the name(s) of the target blueprint(s) :type names: ``str`` or ``list`` of ``str`` You can use the following setting to prevent plumbery from stopping a node:: - sql: domain: *vdc1 ethernet: *data nodes: - slaveSQL: running: always """ nodes = PlumberyNodes(self) if isinstance(names, str): names = names.split(' ') for name in names: blueprint = self.get_blueprint(name) if blueprint is None: continue if 'nodes' not in blueprint: continue nodes.stop_blueprint(blueprint)
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` """ self.power_on() infrastructure = PlumberyInfrastructure(self) nodes = PlumberyNodes(self) if isinstance(names, str): names = names.split(' ') for name in names: blueprint = self.get_blueprint(name) if blueprint is None: continue container = infrastructure.get_container(blueprint) for polisher in polishers: polisher.shine_container(container) nodes.polish_blueprint(blueprint, polishers, container)
def destroy_all_blueprints(self): """ Destroys all blueprints at this facility """ self.power_on() nodes = PlumberyNodes(self) infrastructure = PlumberyInfrastructure(self) basement = self.list_basement() for name in self.expand_blueprint('*'): if name in basement: continue blueprint = self.get_blueprint(name) logging.debug("Destroying blueprint '{}'".format(name)) nodes.destroy_blueprint(blueprint) infrastructure.destroy_blueprint(blueprint) for name in basement: blueprint = self.get_blueprint(name) logging.debug("Destroying blueprint '{}'".format(name)) nodes.destroy_blueprint(blueprint) infrastructure.destroy_blueprint(blueprint)
def build_blueprint(self, names): """ Builds a named blueprint for this facility :param names: the name(s) of the blueprint(s) to build :type names: ``str`` or ``list`` of ``str`` This function builds the named blueprint in two steps: the infrastructure comes first, and then the nodes themselves. >>>facility.build_blueprint('sql') If the keyword ``basement`` mentions one or several blueprints, then network domains of these special blueprints are built before the actual target blueprint. Example ``fittings.yaml``:: --- basement: admin blueprints: - admin: ethernet: control - sql: ethernet: data nodes: - server1: glue: control In this example, the node ``server1``has two network interfaces. The main network interface is connected to the network ``data``, and the secondary network interface is connected to the network ``control``. """ self.power_on() infrastructure = PlumberyInfrastructure(self) nodes = PlumberyNodes(self) basement = self.list_basement() for name in basement: blueprint = self.get_blueprint(name) infrastructure.build(blueprint) for name in self.expand_blueprint(names): blueprint = self.get_blueprint(name) if name not in basement: infrastructure.build(blueprint) nodes.build_blueprint( blueprint, infrastructure.get_container(blueprint))
def lookup(self, token): """ Retrieves the value attached to a token :param token: the token, e.g., 'node.ipv6' :type token: ``str`` :return: the value attached to this token, or `None` """ if token in self.cache: return str(self.cache[token]) value = None if self.context is not None: value = self.context.lookup(token) if value is not None: return value if self.container is None: return None tokens = token.split('.') if len(tokens) < 2: tokens.append('private') nodes = PlumberyNodes(self.container.facility) node = nodes.get_node(tokens[0]) if node is None: return None if self.context is not None: self.context.remember(tokens[0], node.private_ips[0]) self.context.remember(tokens[0] + '.private', node.private_ips[0]) self.context.remember(tokens[0] + '.ipv6', node.extra['ipv6']) if len(node.public_ips) > 0: self.context.remember(tokens[0] + '.public', node.public_ips[0]) if tokens[1] == 'private': return node.private_ips[0] if tokens[1] == 'ipv6': return node.extra['ipv6'] if tokens[1] == 'public': if len(node.public_ips) > 0: return node.public_ips[0] else: return '' return None
def destroy_all_nodes(self): """ Destroys all nodes at this facility """ self.power_on() nodes = PlumberyNodes(self) for name in self.list_blueprints(): blueprint = self.get_blueprint(name) if blueprint is not None: logging.info("Destroying nodes of blueprint '{}'".format(name)) nodes.destroy_blueprint(blueprint)
def wipe_blueprint(self, names): """ Destroys nodes of a given blueprint at this facility :param names: the names of the blueprint to destroy :type names: ``str`` or ``list`` of ``str`` """ self.power_on() nodes = PlumberyNodes(self) for name in self.expand_blueprint(names): blueprint = self.get_blueprint(name) nodes.destroy_blueprint(blueprint)
def destroy_blueprint(self, names): """ Destroys a given blueprint at this facility :param names: the name(s) of the blueprint(s) to destroy :type names: ``str`` or ``list`` of ``str`` """ self.power_on() nodes = PlumberyNodes(self) infrastructure = PlumberyInfrastructure(self) for name in self.expand_blueprint(names): blueprint = self.get_blueprint(name) nodes.destroy_blueprint(blueprint) infrastructure.destroy_blueprint(blueprint)
def start_blueprint(self, names): """ Starts nodes from a given blueprint at this facility :param names: the name(s) of the target blueprint(s) :type names: ``str`` or ``list`` of ``str`` """ nodes = PlumberyNodes(self) for name in self.expand_blueprint(names): blueprint = self.get_blueprint(name) if 'nodes' not in blueprint: continue nodes.start_blueprint(blueprint)
def build_all_blueprints(self): """ Builds all blueprints defined for this facility This function builds all network domains across all blueprints, then it builds all nodes across all blueprints. If the keyword ``basement`` mentions one or several blueprints, then these are built before the other blueprints. """ self.power_on() infrastructure = PlumberyInfrastructure(self) nodes = PlumberyNodes(self) for name in self.list_basement(): blueprint = self.get_blueprint(name) if blueprint is not None: infrastructure.build(blueprint) for name in self.list_blueprints(): if name not in self.list_basement(): blueprint = self.get_blueprint(name) if blueprint is not None: infrastructure.build(blueprint) for name in self.list_basement(): blueprint = self.get_blueprint(name) if blueprint is not None: container = infrastructure.get_container(blueprint) nodes.build_blueprint(blueprint, container) for name in self.list_blueprints(): if name not in self.list_basement(): blueprint = self.get_blueprint(name) if blueprint is not None: container = infrastructure.get_container(blueprint) nodes.build_blueprint(blueprint, container)
def destroy_nodes(self, names): """ Destroys nodes of a given blueprint at this facility :param names: the names of the blueprint to destroy :type names: ``str`` or ``list`` of ``str`` """ self.power_on() nodes = PlumberyNodes(self) if isinstance(names, str): names = names.split(' ') for name in names: blueprint = self.get_blueprint(name) if blueprint is None: continue nodes.destroy_blueprint(blueprint)
def start_nodes(self, names): """ Starts nodes from a given blueprint at this facility :param names: the name(s) of the target blueprint(s) :type names: ``str`` or ``list`` of ``str`` """ nodes = PlumberyNodes(self) if isinstance(names, str): names = names.split(' ') for name in names: blueprint = self.get_blueprint(name) if blueprint is None: continue if 'nodes' not in blueprint: continue nodes.start_blueprint(blueprint)