Exemple #1
0
    def test_dict_merge(self):
        d1 = dict(a=1, b=dict(c=2, d=3), e=4)
        d2 = dict(b=dict(c=10, f=11), e=dict(g=12))
        dexp = dict(a=1, b=dict(c=10, d=3, f=11), e=dict(g=12))

        dres = util.dict_merge(d1, d2)
        self.assertEqual(dexp, dres)
Exemple #2
0
    def prepare_nodes(self, desc):
        """
        Sets up node descriptions.

        Upon instantiating the infrastructure, instantiated node descriptions
        inherit some of the information from the infrastructure description:

            - authentication information (``user_id``)
            - identifier of the instantiated infrastructure (``infra_id``)
            - variables (node description variables are kept intact)
            - attribute mappings

        The resulting node description should be completely self-contained.

        """

        for i in self.nodes:
            i['infra_id'] = self.infra_id  # Foreign key, if you like
            i['infra_name'] = desc['infra_name']

            # Variables inherited from the infrastructure
            # Variables specified in the node description are preferred
            i['variables'] = util.dict_merge(desc.get('variables', dict()),
                                             i.get('variables', dict()))

            # Copying the user_id into all nodes' descriptions is an
            # optimization, so IP::CreateNode does not need to resolve the
            # containing infrastructure's static description.
            i['user_id'] = desc['user_id']

            # Setup attribute mappings based on infrastructure description
            i['mappings'] = self.merge_mappings(i)
Exemple #3
0
    def prepare_nodes(self, desc):
        """
        Sets up node descriptions.

        Upon instantiating the infrastructure, instantiated node descriptions
        inherit some of the information from the infrastructure description:

            - authentication information (``user_id``)
            - identifier of the instantiated infrastructure (``infra_id``)
            - variables (node description variables are kept intact)
            - attribute mappings

        The resulting node description should be completely self-contained.

        """

        for i in self.nodes:
            i['infra_id'] = self.infra_id # Foreign key, if you like

            # Variables inherited from the infrastructure
            # Variables specified in the node description are preferred
            i['variables'] = util.dict_merge(desc.get('variables', dict()),
                                             i.get('variables', dict()))

            # Copying the user_id into all nodes' descriptions is an
            # optimization, so IP::CreateNode does not need to resolve the
            # containing infrastructure's static description.
            i['user_id'] = desc['user_id']

            # Setup attribute mappings based on infrastructure description
            i['mappings'] = self.merge_mappings(i)
Exemple #4
0
    def test_dict_merge(self):
        d1 = dict(a=1, b=dict(c=2, d=3), e=4)
        d2 = dict(b=dict(c=10, f=11), e=dict(g=12))
        dexp = dict(a=1, b=dict(c=10, d=3, f=11), e=dict(g=12))

        dres = util.dict_merge(d1, d2)
        self.assertEqual(dexp, dres)