def add(self, aspect, ifpresent="error"):
        """
        Add a network, ansible_host, system, deploy, configure or contextualize.

        Args:
        - aspect(network, system, deploy, configure or contextualize): thing to add.
        - ifpresent(str): if it has been defined, do:

           - ``"ignore"``: not add the aspect.
           - ``"replace"``: replace by the old defined.
           - ``"error"``: raise an error.

        Return(bool): True if aspect was added.
        """

        # If aspect is a contextualization, it is trated separately
        if isinstance(aspect, contextualize):
            self.contextualize.update(aspect)
            return True

        classification = [(network, self.networks), (system, self.systems), (ansible, self.ansible_hosts),
                          (deploy, self.deploys), (configure, self.configures)]
        aspect_list = [l for t, l in classification if isinstance(aspect, t)]
        assert len(aspect_list) == 1, "Unexpected aspect for RADL."
        aspect_list = aspect_list[0]

        old_aspect = [a for a in aspect_list if a.getId() == aspect.getId()]
        if old_aspect:
            # If some aspect with the same id is found
            if ifpresent == "error":
                raise Exception("Aspect with the same id was found.")
            elif ifpresent == "replace":
                for i, elem in enumerate(aspect_list):
                    if elem.getId() == old_aspect[0].getId():
                        del aspect_list[i]
                        break
                aspect_list.append(aspect)
                return True
            elif ifpresent == "ignore":
                return False
            else:
                raise ValueError
        else:
            # Otherwise add aspect
            aspect_list.append(aspect)
            return True
def add ( self , aspect , ifpresent = "error" ) : if isinstance ( aspect , contextualize ) : self . contextualize . update ( aspect ) return True classification = [ ( network , self . networks ) , ( system , self . systems ) , ( ansible , self . ansible_hosts ) , ( deploy , self . deploys ) , ( configure , self . configures ) ] aspect_list = [ l for t , l in classification if isinstance ( aspect , t ) ] assert len ( aspect_list ) == 1 , "Unexpected aspect for RADL." aspect_list = aspect_list [ 0 ] old_aspect = [ a for a in aspect_list if a . getId ( ) == aspect . getId ( ) ] if old_aspect : if ifpresent == "error" : raise Exception ( "Aspect with the same id was found." ) elif ifpresent == "replace" : for i , elem in enumerate ( aspect_list ) : if elem . getId ( ) == old_aspect [ 0 ] . getId ( ) : del aspect_list [ i ] break aspect_list . append ( aspect ) return True elif ifpresent == "ignore" : return False else : raise ValueError else : aspect_list . append ( aspect ) return True
Add a network, ansible_host, system, deploy, configure or contextualize.

        Args:
        - aspect(network, system, deploy, configure or contextualize): thing to add.
        - ifpresent(str): if it has been defined, do:

           - ``"ignore"``: not add the aspect.
           - ``"replace"``: replace by the old defined.
           - ``"error"``: raise an error.

        Return(bool): True if aspect was added.