コード例 #1
0
    def _remove_network_view(self):
        session = self.ib_cxt.context.session
        network_view = self.ib_cxt.mapping.network_view

        if (self.grid_config.default_network_view_scope
                == const.NETWORK_VIEW_SCOPE_SINGLE
                and network_view == self.grid_config.default_network_view):
            return

        # remove ib network view
        self.ib_cxt.ibom.delete_network_view(network_view)

        # release authority member
        dbi.remove_mapping_member(
            session, self.ib_cxt.mapping.network_view,
            self.ib_cxt.mapping.authority_member.member_id)

        # remove network view
        dbi.remove_network_views(session,
                                 [self.ib_cxt.mapping.network_view_id])
コード例 #2
0
ファイル: ipam.py プロジェクト: yuewko/networking-infoblox
    def _remove_network_view(self):
        session = self.ib_cxt.context.session
        network_view = self.ib_cxt.mapping.network_view

        if (self.grid_config.default_network_view_scope ==
                const.NETWORK_VIEW_SCOPE_SINGLE and
                network_view == self.grid_config.default_network_view):
            return

        # remove ib network view
        self.ib_cxt.ibom.delete_network_view(network_view)

        # release authority member
        dbi.remove_mapping_member(
            session,
            self.ib_cxt.mapping.network_view,
            self.ib_cxt.mapping.authority_member.member_id)

        # remove network view
        dbi.remove_network_views(session,
                                 [self.ib_cxt.mapping.network_view_id])
コード例 #3
0
    def _sync_network_mapping(self, discovered_networks,
                              discovered_delegations):
        """Discover networks and sync with db.

        The discovered network json contains the following data:
        - network view
        - network
        - cloud_info for delegated member if cloud platform is supported
        - dhcp members

        :param discovered_networks: discovered network json
        :param discovered_delegations: discovered delegation members
        :return: None
        """
        session = self._context.session
        self._load_persisted_mappings()

        discovered_mapping = self._get_member_mapping(discovered_networks,
                                                      discovered_delegations)

        # add or remove authority mapping members
        persisted_authority_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            self.db_authority_members, DELIMITER)
        persisted_set = set(persisted_authority_members)
        discovered_set = set(discovered_mapping['authority_members'])
        addable_set = discovered_set.difference(persisted_set)
        removable_set = persisted_set.difference(discovered_set)

        for authority_member_info in addable_set:
            authority_member = authority_member_info.split(DELIMITER)
            network_view_id = authority_member[0]
            member_id = authority_member[1]
            mapping_relation = authority_member[2]
            dbi.add_mapping_member(session, network_view_id, member_id,
                                   mapping_relation)

        for authority_member_info in removable_set:
            authority_member = authority_member_info.split(DELIMITER)
            network_view_id = authority_member[0]
            member_id = authority_member[1]
            dbi.remove_mapping_member(session, network_view_id, member_id)

        # add or remove service members
        persisted_service_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'service'],
            self.db_service_members, DELIMITER)
        persisted_set = set(persisted_service_members)
        discovered_set = set(discovered_mapping['service_members'])
        addable_set = discovered_set.difference(persisted_set)
        removable_set = persisted_set.difference(discovered_set)

        for service_member_info in addable_set:
            service_member = service_member_info.split(DELIMITER)
            network_view_id = service_member[0]
            member_id = service_member[1]
            service = service_member[2]
            dbi.add_service_member(session, network_view_id, member_id,
                                   service)

        for service_member_info in removable_set:
            service_member = service_member_info.split(DELIMITER)
            network_view_id = service_member[0]
            member_id = service_member[1]
            service = service_member[2]
            dbi.remove_service_member(session,
                                      network_view_id,
                                      member_id=member_id,
                                      service=service)
コード例 #4
0
    def test_mapping_management_mapping_members(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        self._create_simple_members()
        db_members = infoblox_db.get_members(self.ctx.session)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)

        # prepare network views
        netview_dict = {'default': gm_member.member_id}
        self._create_network_views(netview_dict)

        # get network view id
        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        netview_default_row = utils.find_one_in_list('network_view',
                                                     'default',
                                                     db_network_views)
        netview_id = netview_default_row.id

        # should be no mapping members
        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        self.assertEqual(0, len(db_mapping_members))

        # test mapping member additions
        expected_rows = []
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        member_id = db_members[1]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member update
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_GM_OWNED
        infoblox_db.update_mapping_member(self.ctx.session, netview_id,
                                          member_id, relation)
        expected_rows[0] = netview_id + ':' + member_id + ':' + relation

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member removals
        member_id = db_members[0]['member_id']
        infoblox_db.remove_mapping_member(self.ctx.session, netview_id,
                                          member_id)
        db_mapping_members = infoblox_db.get_mapping_members(
            self.ctx.session, member_id=member_id)
        self.assertEqual([], db_mapping_members)
コード例 #5
0
    def test_mapping_management_mapping_members(self):
        # prepare grid
        self._create_default_grid()

        # prepare grid members
        self._create_simple_members()
        db_members = infoblox_db.get_members(self.ctx.session)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)

        # prepare network views
        netview_dict = {'default': gm_member.member_id}
        self._create_network_views(netview_dict)

        # get network view id
        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        netview_default_row = utils.find_one_in_list('network_view', 'default',
                                                     db_network_views)
        netview_id = netview_default_row.id

        # should be no mapping members
        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        self.assertEqual(0, len(db_mapping_members))

        # test mapping member additions
        expected_rows = []
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        member_id = db_members[1]['member_id']
        relation = const.MAPPING_RELATION_DELEGATED
        infoblox_db.add_mapping_member(self.ctx.session, netview_id, member_id,
                                       relation)
        expected_rows.append(netview_id + ':' + member_id + ':' + relation)

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member update
        member_id = db_members[0]['member_id']
        relation = const.MAPPING_RELATION_GM_OWNED
        infoblox_db.update_mapping_member(self.ctx.session, netview_id,
                                          member_id, relation)
        expected_rows[0] = netview_id + ':' + member_id + ':' + relation

        db_mapping_members = infoblox_db.get_mapping_members(self.ctx.session)
        actual_rows = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            db_mapping_members, ':')
        self.assertEqual(expected_rows, actual_rows)

        # test mapping member removals
        member_id = db_members[0]['member_id']
        infoblox_db.remove_mapping_member(self.ctx.session, netview_id,
                                          member_id)
        db_mapping_members = infoblox_db.get_mapping_members(
            self.ctx.session, member_id=member_id)
        self.assertEqual([], db_mapping_members)
コード例 #6
0
    def _sync_network_mapping(self, discovered_networks,
                              discovered_delegations):
        """Discover networks and sync with db.

        The discovered network json contains the following data:
        - network view
        - network
        - cloud_info for delegated member if cloud platform is supported
        - dhcp members

        :param discovered_networks: discovered network json
        :param discovered_delegations: discovered delegation members
        :return: None
        """
        session = self._context.session
        self._load_persisted_mappings()

        discovered_mapping = self._get_member_mapping(discovered_networks,
                                                      discovered_delegations)

        # add or remove authority mapping members
        persisted_authority_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'mapping_relation'],
            self.db_authority_members,
            DELIMITER)
        persisted_set = set(persisted_authority_members)
        discovered_set = set(discovered_mapping['authority_members'])
        addable_set = discovered_set.difference(persisted_set)
        removable_set = persisted_set.difference(discovered_set)

        for authority_member_info in addable_set:
            authority_member = authority_member_info.split(DELIMITER)
            network_view_id = authority_member[0]
            member_id = authority_member[1]
            mapping_relation = authority_member[2]
            dbi.add_mapping_member(session, network_view_id, member_id,
                                   mapping_relation)

        for authority_member_info in removable_set:
            authority_member = authority_member_info.split(DELIMITER)
            network_view_id = authority_member[0]
            member_id = authority_member[1]
            dbi.remove_mapping_member(session, network_view_id, member_id)

        # add or remove service members
        persisted_service_members = utils.get_composite_values_from_records(
            ['network_view_id', 'member_id', 'service'],
            self.db_service_members,
            DELIMITER)
        persisted_set = set(persisted_service_members)
        discovered_set = set(discovered_mapping['service_members'])
        addable_set = discovered_set.difference(persisted_set)
        removable_set = persisted_set.difference(discovered_set)

        for service_member_info in addable_set:
            service_member = service_member_info.split(DELIMITER)
            network_view_id = service_member[0]
            member_id = service_member[1]
            service = service_member[2]
            dbi.add_service_member(session, network_view_id, member_id,
                                   service)

        for service_member_info in removable_set:
            service_member = service_member_info.split(DELIMITER)
            network_view_id = service_member[0]
            member_id = service_member[1]
            service = service_member[2]
            dbi.remove_service_member(session, network_view_id,
                                      member_id=member_id, service=service)