Custom Search

Tuesday, June 9, 2015

How to contrail sync keystone domain and project while starting api_server

How to opencontrail sync keystone domain and project while starting api_server
1)
Script to Start/Stop Contrail API Server
#python /usr/local/lib/python2.7/dist-packages/vnc_cfg_api_server/vnc_cfg_api_server.py --conf_file /etc/contrail/contrail-api.conf --reset_config --rabbit_user guest --rabbit_password contrail123

2)
https://github.com/Juniper/contrail-controller/blob/master/src/config/api-server/vnc_cfg_api_server.py#L1038

/usr/local/lib/python2.7/dist-packages/vnc_cfg_api_server/vnc_cfg_api_server.py

contrail-controller/src/config/api-server/vnc_cfg_api_server.py

class VncApiServer(VncApiServerGen):

    def _db_init_entries(self):
        try:
            self._extension_mgrs['resync'].map(self._resync_domains_projects) <==1
        except Exception as e:
            pass

    def _resync_domains_projects(self, ext): <==2
        ext.obj.resync_domains_projects() <==3

3)
https://github.com/Juniper/contrail-controller/blob/master/src/config/vnc_openstack/vnc_openstack/__init__.py#L591
contrail-controller/src/config/vnc_openstack/vnc_openstack/__init__.py


class OpenstackDriver(vnc_plugin_base.Resync):

    def resync_domains_projects(self): <==4
        # add asynchronously
        self._main_glet = gevent.spawn(self._resync_domains_projects_forever)<==5
        self._worker_glets = []
        for x in range(self._resync_number_workers):
            self._worker_glets.append(gevent.spawn(self._resync_worker)) <==11

    def _resync_domains_projects_forever(self):<==6
         while True:
            retry = self._resync_all_domains() <==7
            retry = self._resync_all_projects()  <==8

    def _resync_all_projects(self):<==9
            ks_project_ids = set(
                [str(uuid.UUID(proj['id']))
                    for proj in self._ks_projects_list()])

            for ks_project_id in ks_project_ids - vnc_project_ids:
                self.q.put((Q_CREATE, 'project', ks_project_id))<==10

    def _resync_worker(self): <==12
        while True:
            oper, obj_type, obj_id = self.q.get()<==13
            try:
                if oper == Q_DELETE:
                    if obj_type == 'domain':
                        self._del_domain_from_vnc(obj_id)
                    elif obj_type == 'project':
                        self._del_project_from_vnc(obj_id)
                    else:
                        raise KeyError("An invalid obj_type was specified: %s",
                                        obj_type)
                elif oper == Q_CREATE:<==14
                    if obj_type == 'domain':
                        self._add_domain_to_vnc(obj_id)
                    elif obj_type == 'project':<==15
                        self._add_project_to_vnc(obj_id)<==16
                    else:
                        raise KeyError("An invalid obj_type was specified: %s",
                                        obj_type)
                else:
                    raise KeyError("An invalid operation was specified: %s", oper)
            except (ValueError, KeyError):
                # For an unpack error or and invalid kind.
                self.log_exception()
            finally:
                self.q.task_done()

4)
Notes
>>> import Queue
>>> q = Queue.Queue(maxsize=1000)
>>> q.put((1,2,3))
>>> q.put((2,2,3))
>>> q.put((3,2,3))
>>> q.put((4,2,3))
>>>
>>> q.get()
(1, 2, 3)
>>> q.get()
(2, 2, 3)
>>> q.get()
(3, 2, 3)
>>> q.get()
(4, 2, 3)
>>>
>>> q.queue



No comments:

Post a Comment