def nodes_match(old_node, new_node): """ Determines if old node is a sufficient match for the new node. """ if old_node.get('instance_type') != new_node.instance_type: return False # Because this function deals with the locations json file we use this # method from LocalState. local_state_roles = LocalState.get_node_roles(old_node) if local_state_roles == ['open']: return True old_roles = {self.DEPRECATED_ROLES.get(role, role) for role in local_state_roles} return old_roles == set(new_node.roles)
def nodes_match(old_node, new_node): """ Determines if old node is a sufficient match for the new node. """ if old_node.get('instance_type') != new_node.instance_type: return False # Because this function deals with the locations json file we use this # method from LocalState. local_state_roles = LocalState.get_node_roles(old_node) if local_state_roles == ['open']: return True old_roles = { self.DEPRECATED_ROLES.get(role, role) for role in local_state_roles } return old_roles == set(new_node.roles)
def from_locations_json_list(self, locations_nodes_list): """Returns a list of nodes if the previous locations JSON matches with the current NodeLayout from the AppScalefile. Args: locations_nodes_list: A list of nodes in dictionary form loaded from the locations json. Raises: BadConfigurationException if the locations json nodes cannot be matched with the AppScalefile nodes. """ # If the length does not match up the user has added or removed a node in # the AppScalefile. if len(locations_nodes_list) != len(self.nodes): raise BadConfigurationException("AppScale does not currently support " "changes to AppScalefile or locations " "JSON between a down and an up. If " "you would like to " "change the node layout use " "down --terminate before an up.") # Place defined nodes first so they will be matched before open nodes. old_nodes = [node for node in locations_nodes_list if LocalState.get_node_roles(node) != ['open']] old_nodes.extend( [node for node in locations_nodes_list if LocalState.get_node_roles(node) == ['open']]) def nodes_match(old_node, new_node): """ Determines if old node is a sufficient match for the new node. """ if old_node.get('instance_type') != new_node.instance_type: return False # Because this function deals with the locations json file we use this # method from LocalState. local_state_roles = LocalState.get_node_roles(old_node) if local_state_roles == ['open']: return True old_roles = {self.DEPRECATED_ROLES.get(role, role) for role in local_state_roles} return old_roles == set(new_node.roles) # Ensure each node has a matching locations.json entry. for new_node in self.nodes: index = next((index for index, old_node in enumerate(old_nodes) if nodes_match(old_node, new_node)), -1) if index == -1: raise BadConfigurationException('Unable to find a match for {}' 'in locations.json'.format(new_node)) roles = new_node.roles old_node = old_nodes.pop(index) new_node.from_json(old_node) new_node.roles = roles if not new_node.is_valid(): raise BadConfigurationException('Node is invalid: {}'.format(new_node)) return self.nodes
def from_locations_json_list(self, locations_nodes_list): """Returns a list of nodes if the previous locations JSON matches with the current NodeLayout from the AppScalefile. Args: locations_nodes_list: A list of nodes in dictionary form loaded from the locations json. Raises: BadConfigurationException if the locations json nodes cannot be matched with the AppScalefile nodes. """ # If the length does not match up the user has added or removed a node in # the AppScalefile. if len(locations_nodes_list) != len(self.nodes): raise BadConfigurationException( "AppScale does not currently support " "changes to AppScalefile or locations " "JSON between a down and an up. If " "you would like to " "change the node layout use " "down --terminate before an up.") # Place defined nodes first so they will be matched before open nodes. old_nodes = [ node for node in locations_nodes_list if LocalState.get_node_roles(node) != ['open'] ] old_nodes.extend([ node for node in locations_nodes_list if LocalState.get_node_roles(node) == ['open'] ]) def nodes_match(old_node, new_node): """ Determines if old node is a sufficient match for the new node. """ if old_node.get('instance_type') != new_node.instance_type: return False # Because this function deals with the locations json file we use this # method from LocalState. local_state_roles = LocalState.get_node_roles(old_node) if local_state_roles == ['open']: return True old_roles = { self.DEPRECATED_ROLES.get(role, role) for role in local_state_roles } return old_roles == set(new_node.roles) # Ensure each node has a matching locations.json entry. for new_node in self.nodes: index = next((index for index, old_node in enumerate(old_nodes) if nodes_match(old_node, new_node)), -1) if index == -1: raise BadConfigurationException( 'Unable to find a match for {}' 'in locations.json'.format(new_node)) roles = new_node.roles old_node = old_nodes.pop(index) new_node.from_json(old_node) new_node.roles = roles if not new_node.is_valid(): raise BadConfigurationException( 'Node is invalid: {}'.format(new_node)) return self.nodes