示例#1
0
def create_location_relationship(manager, location_handle_id, other_handle_id,
                                 rel_type):
    """
    Makes relationship between the two nodes and returns the relationship.
    If a relationship is not possible NoRelationshipPossible exception is
    raised.
    """
    other_meta_type = get_node_meta_type(manager, other_handle_id)
    if other_meta_type == 'Location' and rel_type == 'Has':
        return _create_relationship(manager, location_handle_id,
                                    other_handle_id, rel_type)
    raise exceptions.NoRelationshipPossible(location_handle_id, 'Location',
                                            other_handle_id, other_meta_type,
                                            rel_type)
示例#2
0
def create_physical_relationship(manager, physical_handle_id, other_handle_id,
                                 rel_type):
    """
    Makes relationship between the two nodes and returns the relationship.
    If a relationship is not possible NoRelationshipPossible exception is
    raised.
    """
    other_meta_type = get_node_meta_type(manager, other_handle_id)
    if other_meta_type == 'Physical':
        if rel_type == 'Has' or rel_type == 'Connected_to':
            return _create_relationship(manager, physical_handle_id,
                                        other_handle_id, rel_type)
    elif other_meta_type == 'Location' and rel_type == 'Located_in':
        return _create_relationship(manager, physical_handle_id,
                                    other_handle_id, rel_type)
    raise exceptions.NoRelationshipPossible(physical_handle_id, 'Physical',
                                            other_handle_id, other_meta_type,
                                            rel_type)
示例#3
0
def create_logical_relationship(manager, logical_handle_id, other_handle_id,
                                rel_type):
    """
    Makes relationship between the two nodes and returns the relationship.
    If a relationship is not possible NoRelationshipPossible exception is
    raised.
    """
    other_meta_type = get_node_meta_type(manager, other_handle_id)
    if rel_type == 'Depends_on':
        if other_meta_type == 'Logical' or other_meta_type == 'Physical':
            return _create_relationship(manager, logical_handle_id,
                                        other_handle_id, rel_type)
    elif rel_type == 'Part_of':
        if other_meta_type == 'Physical':
            return _create_relationship(manager, logical_handle_id,
                                        other_handle_id, rel_type)
    raise exceptions.NoRelationshipPossible(logical_handle_id, 'Logical',
                                            other_handle_id, other_meta_type,
                                            rel_type)
示例#4
0
def create_relation_relationship(manager, relation_handle_id, other_handle_id,
                                 rel_type):
    """
    Makes relationship between the two nodes and returns the relationship.
    If a relationship is not possible NoRelationshipPossible exception is
    raised.
    """
    other_meta_type = get_node_meta_type(manager, other_handle_id)
    if other_meta_type == 'Logical':
        if rel_type in ['Uses', 'Provides']:
            return _create_relationship(manager, relation_handle_id,
                                        other_handle_id, rel_type)
    elif other_meta_type == 'Location' and rel_type == 'Responsible_for':
        return _create_relationship(manager, relation_handle_id,
                                    other_handle_id, rel_type)
    elif other_meta_type == 'Physical':
        if rel_type in ['Owns', 'Provides']:
            return _create_relationship(manager, relation_handle_id,
                                        other_handle_id, rel_type)
    raise exceptions.NoRelationshipPossible(relation_handle_id, 'Relation',
                                            other_handle_id, other_meta_type,
                                            rel_type)
示例#5
0
def create_relationship(manager, handle_id, other_handle_id, rel_type):
    """
    Makes a relationship from node to other_node depending on which
    meta_type the nodes are. Returns the relationship or raises
    NoRelationshipPossible exception.
    """
    meta_type = get_node_meta_type(manager, handle_id)
    if meta_type == 'Location':
        return create_location_relationship(manager, handle_id,
                                            other_handle_id, rel_type)
    elif meta_type == 'Logical':
        return create_logical_relationship(manager, handle_id, other_handle_id,
                                           rel_type)
    elif meta_type == 'Relation':
        return create_relation_relationship(manager, handle_id,
                                            other_handle_id, rel_type)
    elif meta_type == 'Physical':
        return create_physical_relationship(manager, handle_id,
                                            other_handle_id, rel_type)
    other_meta_type = get_node_meta_type(manager, other_handle_id)
    raise exceptions.NoRelationshipPossible(handle_id, meta_type,
                                            other_handle_id, other_meta_type,
                                            rel_type)