当前位置: 首页>>代码示例>>Python>>正文


Python vnc_cassandra.VncCassandraClient类代码示例

本文整理汇总了Python中cfgm_common.vnc_cassandra.VncCassandraClient的典型用法代码示例。如果您正苦于以下问题:Python VncCassandraClient类的具体用法?Python VncCassandraClient怎么用?Python VncCassandraClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VncCassandraClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: issu_prepare

    def issu_prepare(self):
        self._logger(
            "Issu contrail cassandra prepare...",
            level=SandeshLevel.SYS_INFO,
        )
        for issu_func, ks, cflist in self._issu_info:

            if issu_func is None:
                issu_func = self._issu_basic_function
            ks_issu_func_info = {ks: issu_func}

            nks = {ks: cflist}
            oks = {ks: cflist}
            self._nkeyspaces.update(nks)
            self._okeyspaces.update(oks)
            self._ks_issu_func_info.update(ks_issu_func_info)


        self._oldversion_handle = VncCassandraClient(
            self._oldversion_server_list, self._odb_prefix,
            None, self._okeyspaces, self._logger,
            credential=self._old_creds,
            ssl_enabled=self._odb_use_ssl,
            ca_certs=self._odb_ca_certs)

        self._newversion_handle = VncCassandraClient(
            self._newversion_server_list, self._ndb_prefix,
            self._nkeyspaces, None, self._logger,
            credential=self._new_creds,
            ssl_enabled=self._ndb_use_ssl,
            ca_certs=self._ndb_ca_certs)
开发者ID:rombie,项目名称:contrail-controller,代码行数:31,代码来源:issu_contrail_common.py

示例2: init_cassandra

 def init_cassandra(self, ks_cf_info=None):
     self._cassandra = VncCassandraClient(
         self._api_args.cassandra_server_list, self._api_args.cluster_id,
         rw_keyspaces=ks_cf_info, ro_keyspaces=None, logger=self.log,
         reset_config=False,
         ssl_enabled=self._api_args.cassandra_use_ssl,
         ca_certs=self._api_args.cassandra_ca_certs)
开发者ID:rombie,项目名称:contrail-controller,代码行数:7,代码来源:db_json_exim.py

示例3: __init__

 def __init__(self, args_str):
     self._parse_args(args_str)
     self._cassandra = VncCassandraClient(
         self._api_args.cassandra_server_list, False,
         self._api_args.cluster_id, None, logger=self.log)
     self._zookeeper = kazoo.client.KazooClient(
         self._api_args.zk_server_ip)
     self._zookeeper.start()
开发者ID:ajayhn,项目名称:contrail-docker-deploy,代码行数:8,代码来源:db-import-json.py

示例4: __init__

    def __init__(self, force, resources_file, cassandra_servers,
                 cassandra_username, cassandra_password, db_prefix,
                 cassandra_batch_size, zookeeper_servers,
                 rules_per_security_group, keystone_client,
                 dont_populate_zookeeper):
        self._force = force
        self._resource_distribution = yaml.load(resources_file)
        self._cassandra_batch_size = cassandra_batch_size
        self._rules_per_security_group = rules_per_security_group
        self._keystone_client = keystone_client
        self._dont_populate_zookeeper = dont_populate_zookeeper

        # Connect to cassandra database
        logger.debug("Initilizing the cassandra connection on %s",
                     cassandra_servers)
        cassandra_credentials = {}
        if (cassandra_username is not None and
                cassandra_password is not None):
            cassandra_credentials = {
                'username': cassandra_username,
                'password': cassandra_password,
            }

        def vnc_cassandra_client_logger(msg, level=logging.INFO):
            logger.log(msg=msg, level=level)

        self._cassandra_db = VncCassandraClient(
            cassandra_servers,
            db_prefix,
            self._UUID_KEYSPACE,
            None,
            vnc_cassandra_client_logger,
            credential=cassandra_credentials)
        self._uuid_cf = self._cassandra_db.get_cf('obj_uuid_table')
        self._fqname_cf = self._cassandra_db.get_cf('obj_fq_name_table')

        # Initilize zookeeper client
        if self._dont_populate_zookeeper:
            self._zk_client = DummyZookeeperClient()
        else:
            self._zk_client = ZookeeperClient(zookeeper_servers)
开发者ID:tcpcloud,项目名称:contrail-controller,代码行数:41,代码来源:main.py

示例5: _connect_rabbit

    def _connect_rabbit(self):
        rabbit_server = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost

        self._db_resync_done = gevent.event.Event()

        q_name = 'svc_mon.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_server, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, q_name,
                                         self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        reset_config = self._args.reset_config
        self._cassandra = VncCassandraClient(cass_server_list, reset_config,
                                             self._args.cluster_id, None,
                                             self.config_log)
        DBBase.init(self, self.logger, self._cassandra)
开发者ID:haripk,项目名称:contrail-controller,代码行数:22,代码来源:svc_monitor.py

示例6: SvcMonitor

class SvcMonitor(object):

    """
    data + methods used/referred to by ssrc and arc greenlets
    """
    _REACTION_MAP = {
        "loadbalancer_pool": {
            'self': [],
            'virtual_ip': [],
            'loadbalancer_member': [],
            'loadbalancer_healthmonitor': [],
        },
        "loadbalancer_member": {
            'self': ['loadbalancer_pool'],
            'loadbalancer_pool': []
        },
        "virtual_ip": {
            'self': ['loadbalancer_pool'],
            'loadbalancer_pool': []
        },
        "loadbalancer_healthmonitor": {
            'self': ['loadbalancer_pool'],
            'loadbalancer_pool': []
        },
        "service_instance": {
            'self': [],
        },
        "service_template": {
            'self': [],
        }
    }

    def __init__(self, args=None):
        self._args = args

        # create database and logger
        self.db = ServiceMonitorDB(args)

        # initialize discovery client
        self._disc = None
        if self._args.disc_server_ip and self._args.disc_server_port:
            self._disc = client.DiscoveryClient(self._args.disc_server_ip,
                                                self._args.disc_server_port,
                                                ModuleNames[Module.SVC_MONITOR])

        # initialize logger
        self.logger = ServiceMonitorLogger(self.db, self._disc, args)
        self.db.add_logger(self.logger)
        self.db.init_database()

        # rotating log file for catchall errors
        self._err_file = self._args.trace_file
        self._svc_err_logger = logging.getLogger('SvcErrLogger')
        self._svc_err_logger.setLevel(logging.ERROR)
        try:
            with open(self._err_file, 'a'):
                handler = logging.handlers.RotatingFileHandler(
                    self._err_file, maxBytes=64*1024, backupCount=2)
                self._svc_err_logger.addHandler(handler)
        except IOError:
            self.logger.log("Failed to open trace file %s" % self._err_file)

        # Connect to Rabbit and Initialize cassandra connection
        # TODO activate this code
        # self._connect_rabbit()

    def _connect_rabbit(self):
        rabbit_server = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost

        self._db_resync_done = gevent.event.Event()

        q_name = 'svc_mon.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_server, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, q_name,
                                         self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        reset_config = self._args.reset_config
        self._cassandra = VncCassandraClient(cass_server_list, reset_config,
                                             self._args.cluster_id, None,
                                             self.config_log)
        DBBase.init(self, self.logger, self._cassandra)
    # end _connect_rabbit

    def config_log(self, msg, level):
        self.logger.log(msg)

    def _vnc_subscribe_callback(self, oper_info):
        import pdb;pdb.set_trace()
        self._db_resync_done.wait()
        try:
            msg = "Notification Message: %s" % (pformat(oper_info))
            self.config_log(msg, level=SandeshLevel.SYS_DEBUG)
            obj_type = oper_info['type'].replace('-', '_')
#.........这里部分代码省略.........
开发者ID:haripk,项目名称:contrail-controller,代码行数:101,代码来源:svc_monitor.py

示例7: SvcMonitor


#.........这里部分代码省略.........
        self._svc_err_logger = logging.getLogger('SvcErrLogger')
        self._svc_err_logger.setLevel(logging.ERROR)
        try:
            with open(self._err_file, 'a'):
                handler = logging.handlers.RotatingFileHandler(
                    self._err_file, maxBytes=64*1024, backupCount=2)
                self._svc_err_logger.addHandler(handler)
        except IOError:
            self.logger.log_warning("Failed to open trace file %s" %
                self._err_file)

        # Connect to Rabbit and Initialize cassandra connection
        self._connect_rabbit()

    def _connect_rabbit(self):
        rabbit_server = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost
        rabbit_ha_mode = self._args.rabbit_ha_mode

        self._db_resync_done = gevent.event.Event()

        q_name = 'svc_mon.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_server, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, rabbit_ha_mode,
                                         q_name, self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        reset_config = self._args.reset_config
        self._cassandra = VncCassandraClient(cass_server_list, reset_config,
                                             self._args.cluster_id, None,
                                             self.config_log)
        DBBase.init(self, self.logger, self._cassandra)
    # end _connect_rabbit

    def config_log(self, msg, level):
        self.logger.log(msg)

    def _vnc_subscribe_callback(self, oper_info):
        self._db_resync_done.wait()
        try:
            self._vnc_subscribe_actions(oper_info)
        except Exception:
            cgitb_error_log(self)

    def _vnc_subscribe_actions(self, oper_info):
        try:
            msg = "Notification Message: %s" % (pformat(oper_info))
            self.config_log(msg, level=SandeshLevel.SYS_DEBUG)
            obj_type = oper_info['type'].replace('-', '_')
            obj_class = DBBase._OBJ_TYPE_MAP.get(obj_type)
            if obj_class is None:
                return

            if oper_info['oper'] == 'CREATE' or oper_info['oper'] == 'UPDATE':
                dependency_tracker = DependencyTracker(DBBase._OBJ_TYPE_MAP,
                    self._REACTION_MAP)
                obj_id = oper_info['uuid']
                obj = obj_class.get(obj_id)
                if obj is not None:
                    dependency_tracker.evaluate(obj_type, obj)
                else:
开发者ID:overcastcloud,项目名称:contrail-controller,代码行数:67,代码来源:svc_monitor.py

示例8: __init__

    def __init__(self, args=None):
        self._args = args

        # Initialize discovery client
        self._disc = None
        if self._args.disc_server_ip and self._args.disc_server_port:
            self._disc = client.DiscoveryClient(
                self._args.disc_server_ip,
                self._args.disc_server_port,
                ModuleNames[Module.DEVICE_MANAGER])

        self._sandesh = Sandesh()
        module = Module.DEVICE_MANAGER
        module_name = ModuleNames[module]
        node_type = Module2NodeType[module]
        node_type_name = NodeTypeNames[node_type]
        instance_id = INSTANCE_ID_DEFAULT
        hostname = socket.gethostname()
        self._sandesh.init_generator(
            module_name, hostname, node_type_name, instance_id,
            self._args.collectors, 'to_bgp_context',
            int(args.http_server_port),
            ['cfgm_common', 'device_manager.sandesh'], self._disc)
        self._sandesh.set_logging_params(enable_local_log=args.log_local,
                                         category=args.log_category,
                                         level=args.log_level,
                                         file=args.log_file,
                                         enable_syslog=args.use_syslog,
                                         syslog_facility=args.syslog_facility)
        ConnectionState.init(
            self._sandesh, hostname, module_name, instance_id,
            staticmethod(ConnectionState.get_process_state_cb),
            NodeStatusUVE, NodeStatus)

        # Retry till API server is up
        connected = False
        self.connection_state_update(ConnectionStatus.INIT)
        while not connected:
            try:
                self._vnc_lib = VncApi(
                    args.admin_user, args.admin_password,
                    args.admin_tenant_name, args.api_server_ip,
                    args.api_server_port)
                connected = True
                self.connection_state_update(ConnectionStatus.UP)
            except requests.exceptions.ConnectionError as e:
                # Update connection info
                self.connection_state_update(ConnectionStatus.DOWN, str(e))
                time.sleep(3)
            except ResourceExhaustionError:  # haproxy throws 503
                time.sleep(3)

        rabbit_server = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost

        self._db_resync_done = gevent.event.Event()

        q_name = 'device_manager.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_server, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, q_name,
                                         self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        reset_config = self._args.reset_config
        self._cassandra = VncCassandraClient(cass_server_list, reset_config,
                                             self._args.cluster_id, None,
                                             self.config_log)

        DBBaseDM.init(self._sandesh.logger(), self._cassandra)
        ok, pr_list = self._cassandra._cassandra_physical_router_list()
        if not ok:
            self.config_log('physical router list returned error: %s' %
                            pr_list)
        else:
            vn_set = set()
            for fq_name, uuid in pr_list:
                pr = PhysicalRouterDM.locate(uuid)
                if pr.bgp_router:
                    BgpRouterDM.locate(pr.bgp_router)
                vn_set |= pr.virtual_networks
                li_set = pr.logical_interfaces
                for pi_id in pr.physical_interfaces:
                    pi = PhysicalInterfaceDM.locate(pi_id)
                    if pi:
                        li_set |= pi.logical_interfaces
                vmi_set = set()
                for li_id in li_set:
                    li = LogicalInterfaceDM.locate(li_id)
                    if li and li.virtual_machine_interface:
                        vmi_set |= set([li.virtual_machine_interface])
                for vmi_id in vmi_set:
                    vmi = VirtualMachineInterfaceDM.locate(vmi_id)
                    if vmi:
                        vn_set |= vmi.virtual_networks

#.........这里部分代码省略.........
开发者ID:rajreddy,项目名称:contrail-controller,代码行数:101,代码来源:device_manager.py

示例9: DeviceManager


#.........这里部分代码省略.........
        self.connection_state_update(ConnectionStatus.INIT)
        while not connected:
            try:
                self._vnc_lib = VncApi(
                    args.admin_user, args.admin_password,
                    args.admin_tenant_name, args.api_server_ip,
                    args.api_server_port)
                connected = True
                self.connection_state_update(ConnectionStatus.UP)
            except requests.exceptions.ConnectionError as e:
                # Update connection info
                self.connection_state_update(ConnectionStatus.DOWN, str(e))
                time.sleep(3)
            except ResourceExhaustionError:  # haproxy throws 503
                time.sleep(3)

        rabbit_server = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost

        self._db_resync_done = gevent.event.Event()

        q_name = 'device_manager.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_server, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, q_name,
                                         self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        reset_config = self._args.reset_config
        self._cassandra = VncCassandraClient(cass_server_list, reset_config,
                                             self._args.cluster_id, None,
                                             self.config_log)

        DBBaseDM.init(self._sandesh.logger(), self._cassandra)
        ok, pr_list = self._cassandra._cassandra_physical_router_list()
        if not ok:
            self.config_log('physical router list returned error: %s' %
                            pr_list)
        else:
            vn_set = set()
            for fq_name, uuid in pr_list:
                pr = PhysicalRouterDM.locate(uuid)
                if pr.bgp_router:
                    BgpRouterDM.locate(pr.bgp_router)
                vn_set |= pr.virtual_networks
                li_set = pr.logical_interfaces
                for pi_id in pr.physical_interfaces:
                    pi = PhysicalInterfaceDM.locate(pi_id)
                    if pi:
                        li_set |= pi.logical_interfaces
                vmi_set = set()
                for li_id in li_set:
                    li = LogicalInterfaceDM.locate(li_id)
                    if li and li.virtual_machine_interface:
                        vmi_set |= set([li.virtual_machine_interface])
                for vmi_id in vmi_set:
                    vmi = VirtualMachineInterfaceDM.locate(vmi_id)
                    if vmi:
                        vn_set |= vmi.virtual_networks

            for vn_id in vn_set:
                VirtualNetworkDM.locate(vn_id)
开发者ID:rajreddy,项目名称:contrail-controller,代码行数:67,代码来源:device_manager.py

示例10: __init__

    def __init__(self, args=None):
        self._args = args

        # Initialize discovery client
        self._disc = None
        if self._args.disc_server_ip and self._args.disc_server_port:
            self._disc = client.DiscoveryClient(
                self._args.disc_server_ip,
                self._args.disc_server_port,
                ModuleNames[Module.DEVICE_MANAGER])

        self._sandesh = Sandesh()
        module = Module.DEVICE_MANAGER
        module_name = ModuleNames[module]
        node_type = Module2NodeType[module]
        node_type_name = NodeTypeNames[node_type]
        instance_id = INSTANCE_ID_DEFAULT
        hostname = socket.gethostname()
        self._sandesh.init_generator(
            module_name, hostname, node_type_name, instance_id,
            self._args.collectors, 'to_bgp_context',
            int(args.http_server_port),
            ['cfgm_common', 'device_manager.sandesh'], self._disc)
        self._sandesh.set_logging_params(enable_local_log=args.log_local,
                                         category=args.log_category,
                                         level=args.log_level,
                                         file=args.log_file,
                                         enable_syslog=args.use_syslog,
                                         syslog_facility=args.syslog_facility)
        PhysicalRouterDM._sandesh = self._sandesh
        ConnectionState.init(
            self._sandesh, hostname, module_name, instance_id,
            staticmethod(ConnectionState.get_process_state_cb),
            NodeStatusUVE, NodeStatus)

        # Retry till API server is up
        connected = False
        self.connection_state_update(ConnectionStatus.INIT)
        while not connected:
            try:
                self._vnc_lib = VncApi(
                    args.admin_user, args.admin_password,
                    args.admin_tenant_name, args.api_server_ip,
                    args.api_server_port)
                connected = True
                self.connection_state_update(ConnectionStatus.UP)
            except requests.exceptions.ConnectionError as e:
                # Update connection info
                self.connection_state_update(ConnectionStatus.DOWN, str(e))
                time.sleep(3)
            except ResourceExhaustionError:  # haproxy throws 503
                time.sleep(3)

        rabbit_servers = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost
        rabbit_ha_mode = self._args.rabbit_ha_mode

        self._db_resync_done = gevent.event.Event()

        q_name = 'device_manager.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_servers, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, rabbit_ha_mode,
                                         q_name, self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        self._cassandra = VncCassandraClient(cass_server_list,
                                             self._args.cluster_id,
                                             None,
                                             self.config_log)

        DBBaseDM.init(self, self._sandesh.logger(), self._cassandra)
        ok, global_system_config_list = self._cassandra._cassandra_global_system_config_list()
        if not ok:
            self.config_log('global system config list returned error: %s' %
                            global_system_config_list)
        else:
            for fq_name, uuid in global_system_config_list:
                GlobalSystemConfigDM.locate(uuid)

        ok, global_vrouter_config_list = self._cassandra._cassandra_global_vrouter_config_list()
        if not ok:
            self.config_log('global vrouter config list returned error: %s' %
                            global_vrouter_config_list)
        else:
            for fq_name, uuid in global_vrouter_config_list:
                GlobalVRouterConfigDM.locate(uuid)

        ok, vn_list = self._cassandra._cassandra_virtual_network_list()
        if not ok:
            self.config_log('virtual network list returned error: %s' %
                            vn_list)
        else:
            for fq_name, uuid in vn_list:
                vn = VirtualNetworkDM.locate(uuid)
                if vn is not None and vn.routing_instances is not None:
#.........这里部分代码省略.........
开发者ID:kimcharli,项目名称:contrail-controller,代码行数:101,代码来源:device_manager.py

示例11: DeviceManager


#.........这里部分代码省略.........
                    args.admin_tenant_name, args.api_server_ip,
                    args.api_server_port)
                connected = True
                self.connection_state_update(ConnectionStatus.UP)
            except requests.exceptions.ConnectionError as e:
                # Update connection info
                self.connection_state_update(ConnectionStatus.DOWN, str(e))
                time.sleep(3)
            except ResourceExhaustionError:  # haproxy throws 503
                time.sleep(3)

        rabbit_servers = self._args.rabbit_server
        rabbit_port = self._args.rabbit_port
        rabbit_user = self._args.rabbit_user
        rabbit_password = self._args.rabbit_password
        rabbit_vhost = self._args.rabbit_vhost
        rabbit_ha_mode = self._args.rabbit_ha_mode

        self._db_resync_done = gevent.event.Event()

        q_name = 'device_manager.%s' % (socket.gethostname())
        self._vnc_kombu = VncKombuClient(rabbit_servers, rabbit_port,
                                         rabbit_user, rabbit_password,
                                         rabbit_vhost, rabbit_ha_mode,
                                         q_name, self._vnc_subscribe_callback,
                                         self.config_log)

        cass_server_list = self._args.cassandra_server_list
        cred = None
        if self._args.cassandra_user is not None and \
           self._args.cassandra_password is not None:
            cred={'username':self._args.cassandra_user,
                  'password':self._args.cassandra_password}
        self._cassandra = VncCassandraClient(cass_server_list,
                                             self._args.cluster_id,
                                             None,
                                             self.config_log,credential=cred)

        DBBaseDM.init(self, self._sandesh.logger(), self._cassandra)
        ok, global_system_config_list = self._cassandra._cassandra_global_system_config_list()
        if not ok:
            self.config_log('global system config list returned error: %s' %
                            global_system_config_list)
        else:
            for fq_name, uuid in global_system_config_list:
                GlobalSystemConfigDM.locate(uuid)

        ok, global_vrouter_config_list = self._cassandra._cassandra_global_vrouter_config_list()
        if not ok:
            self.config_log('global vrouter config list returned error: %s' %
                            global_vrouter_config_list)
        else:
            for fq_name, uuid in global_vrouter_config_list:
                GlobalVRouterConfigDM.locate(uuid)

        ok, vn_list = self._cassandra._cassandra_virtual_network_list()
        if not ok:
            self.config_log('virtual network list returned error: %s' %
                            vn_list)
        else:
            for fq_name, uuid in vn_list:
                vn = VirtualNetworkDM.locate(uuid)
                if vn is not None and vn.routing_instances is not None:
                    for ri_id in vn.routing_instances:
                        ri_obj = RoutingInstanceDM.locate(ri_id)
开发者ID:sheepcat,项目名称:contrail-controller,代码行数:66,代码来源:device_manager.py

示例12: LoadDataBase

class LoadDataBase(object):
    _UUID_KEYSPACE_NAME = 'config_db_uuid'
    _OBJ_UUID_CF_NAME = 'obj_uuid_table'
    _OBJ_FQ_NAME_CF_NAME = 'obj_fq_name_table'
    _OBJ_SHARED_CF_NAME = 'obj_shared_table'
    _UUID_KEYSPACE = {
        _UUID_KEYSPACE_NAME: {
            _OBJ_UUID_CF_NAME: {
                'cf_args': {
                    'autopack_names': False,
                    'autopack_values': False,
                    },
                },
            _OBJ_FQ_NAME_CF_NAME: {
                'cf_args': {
                    'autopack_values': False,
                    },
                },
            _OBJ_SHARED_CF_NAME: {}
            }
        }
    # Resources supported by that script
    # The order of that list is import, that defines the resources
    # order creation
    _SUPPORTED_RESOURCES = [
        'project',
        'security-group',
        'virtual-network',
        'virtual-machine-interface',
    ]
    _PERMS2 = {
        'owner': None,
        'owner_access': 7,
        'global_access': 0,
        'share': [],
    }

    BATCH_QUEUE_SIZE = 1000
    RULES_PER_SG = 4

    def __init__(self, force, resources_file, cassandra_servers,
                 cassandra_username, cassandra_password, db_prefix,
                 cassandra_batch_size, zookeeper_servers,
                 rules_per_security_group, keystone_client,
                 dont_populate_zookeeper):
        self._force = force
        self._resource_distribution = yaml.load(resources_file)
        self._cassandra_batch_size = cassandra_batch_size
        self._rules_per_security_group = rules_per_security_group
        self._keystone_client = keystone_client
        self._dont_populate_zookeeper = dont_populate_zookeeper

        # Connect to cassandra database
        logger.debug("Initilizing the cassandra connection on %s",
                     cassandra_servers)
        cassandra_credentials = {}
        if (cassandra_username is not None and
                cassandra_password is not None):
            cassandra_credentials = {
                'username': cassandra_username,
                'password': cassandra_password,
            }

        def vnc_cassandra_client_logger(msg, level=logging.INFO):
            logger.log(msg=msg, level=level)

        self._cassandra_db = VncCassandraClient(
            cassandra_servers,
            db_prefix,
            self._UUID_KEYSPACE,
            None,
            vnc_cassandra_client_logger,
            credential=cassandra_credentials)
        self._uuid_cf = self._cassandra_db.get_cf('obj_uuid_table')
        self._fqname_cf = self._cassandra_db.get_cf('obj_fq_name_table')

        # Initilize zookeeper client
        if self._dont_populate_zookeeper:
            self._zk_client = DummyZookeeperClient()
        else:
            self._zk_client = ZookeeperClient(zookeeper_servers)

    def sanitize_resources(self):
        logger.debug("Santizing resources distribution")
        self._resource_map = OrderedDict()
        for resource_type in self._SUPPORTED_RESOURCES:
            object_path = 'contrail_db_loader.resources.%s.%s' %\
                          (resource_type.replace('-', '_'),
                           camel_case(resource_type))
            kwargs = {
                'db_manager': self._cassandra_db,
                'batch_size': self._cassandra_batch_size,
                'zk_client': self._zk_client,
                'project_amount': self._resource_distribution.get('project',
                                                                  0),
                'amount_per_project': self._resource_distribution.get(
                    resource_type, 0),
            }
            self._resource_map[resource_type] = import_object(object_path,
                                                              **kwargs)
#.........这里部分代码省略.........
开发者ID:tcpcloud,项目名称:contrail-controller,代码行数:101,代码来源:main.py

示例13: _issu_basic_function

class ICCassandraClient:
    def _issu_basic_function(self, kspace, cfam, cols):
        return dict(cols)

    # end

    def __init__(self, oldversion_server_list, newversion_server_list, odb_prefix, ndb_prefix, issu_info, logger):
        self._oldversion_server_list = oldversion_server_list
        self._newversion_server_list = newversion_server_list
        self._odb_prefix = odb_prefix
        self._ndb_prefix = ndb_prefix
        self._issu_info = issu_info
        self._logger = logger
        self._ks_issu_func_info = {}
        self._nkeyspaces = {}
        self._okeyspaces = {}
        self._logger("Issu contrail cassandra initialized...", level=SandeshLevel.SYS_INFO)
        self.issu_prepare()

    # end

    def issu_prepare(self):
        self._logger("Issu contrail cassandra prepare...", level=SandeshLevel.SYS_INFO)
        for issu_func, ks, cflist in self._issu_info:

            if issu_func is None:
                issu_func = self._issu_basic_function
            ks_issu_func_info = {ks: issu_func}

            nks = {ks: cflist}
            oks = {ks: cflist}
            self._nkeyspaces.update(nks)
            self._okeyspaces.update(oks)
            self._ks_issu_func_info.update(ks_issu_func_info)

        self._oldversion_handle = VncCassandraClient(
            self._oldversion_server_list, self._odb_prefix, None, self._okeyspaces, self._logger
        )

        self._newversion_handle = VncCassandraClient(
            self._newversion_server_list, self._ndb_prefix, self._nkeyspaces, None, self._logger
        )

    # end

    def _fetch_issu_func(self, ks):
        return self._ks_issu_func_info[ks]

    # end

    # Overwrite what is seen in the newer with the old version.
    def _merge_overwrite(self, new, current):
        updated = current
        updated.update(new)
        return updated

    # end

    #  For now this function should be called for only config_db_uuid.
    #  If we separate out config_db_uuid keyspace from VncCassandraClient,
    #  then we don't need to pass keyspaces here.
    def issu_merge_copy(self, keyspaces):
        for ks, cflist in keyspaces.items():
            self._logger("Issu contrail cassandra merge copy, keyspace: " + str(ks), level=SandeshLevel.SYS_INFO)
            issu_funct = self._fetch_issu_func(ks)
            for cf in cflist:
                newList = []
                newversion_result = self._newversion_handle.get_range(cf)
                self._logger("Building New DB memory for columnfamily: " + str(cf), level=SandeshLevel.SYS_INFO)
                new_db = dict(newversion_result)

                oldversion_result = self._oldversion_handle.get_range(cf)
                self._logger("Doing ISSU copy for columnfamily: " + str(cf), level=SandeshLevel.SYS_INFO)
                for rows, columns in oldversion_result:
                    out = issu_funct(ks, cf, columns)
                    current = new_db.pop(rows, None)
                    if current is not None:
                        updated = self._merge_overwrite(out, dict(current))
                        x = self._newversion_handle.add(cf, rows, updated)
                    else:
                        updated = []
                        x = self._newversion_handle.add(cf, rows, out)
                    diff = set(updated) - set(out)
                    y = self._newversion_handle.get_cf(cf).remove(rows, diff)
                self._logger(
                    "Pruning New DB if entires don't exist in old DB column " "family: " + str(cf),
                    level=SandeshLevel.SYS_INFO,
                )
                for item in new_db:
                    # TBD should be catch exception and fail ISSU
                    self._newversion_handle.delete(cf, item)

    # end

    #  This is issu_copy function.
    def issu_copy(self, keyspaces):
        for ks, cflist in keyspaces.items():
            issu_funct = self._fetch_issu_func(ks)
            for cf in cflist:
                self._logger(
#.........这里部分代码省略.........
开发者ID:rasta-rocket,项目名称:contrail-controller,代码行数:101,代码来源:issu_contrail_common.py

示例14: DatabaseExim

class DatabaseExim(object):
    def __init__(self, args_str):
        self._parse_args(args_str)

        self._zookeeper = kazoo.client.KazooClient(
            self._api_args.zk_server_ip,
            timeout=400,
            handler=kazoo.handlers.gevent.SequentialGeventHandler())
        self._zookeeper.start()
    # end __init__

    def init_cassandra(self, ks_cf_info=None):
        self._cassandra = VncCassandraClient(
            self._api_args.cassandra_server_list, self._api_args.cluster_id,
            rw_keyspaces=ks_cf_info, ro_keyspaces=None, logger=self.log,
            reset_config=False,
            ssl_enabled=self._api_args.cassandra_use_ssl,
            ca_certs=self._api_args.cassandra_ca_certs)
    # end init_cassandra

    def log(self, msg, level):
        pass
    # end log

    def _parse_args(self, args_str):
        parser = argparse.ArgumentParser()

        help="Path to contrail-api conf file, default /etc/contrail-api.conf"
        parser.add_argument(
            "--api-conf", help=help, default="/etc/contrail/contrail-api.conf")
        parser.add_argument(
            "--verbose", help="Run in verbose/INFO mode, default False",
            action='store_true', default=False)
        parser.add_argument(
            "--debug", help="Run in debug mode, default False",
            action='store_true', default=False)
        parser.add_argument(
            "--import-from", help="Import from this json file to database",
            metavar='FILE')
        parser.add_argument(
            "--export-to", help="Export from database to this json file",
            metavar='FILE')
        parser.add_argument(
            "--omit-keyspaces",
            nargs='*',
            help="List of keyspaces to omit in export/import",
            metavar='FILE')

        args_obj, remaining_argv = parser.parse_known_args(args_str.split())
        if ((args_obj.import_from is not None) and
            (args_obj.export_to is not None)):
            raise InvalidArguments(
                'Both --import-from and --export-to cannot be specified %s' %(
                args_obj))
        self._args = args_obj

        self._api_args = utils.parse_args('-c %s %s'
            %(self._args.api_conf, ' '.join(remaining_argv)))[0]
        pass
    # end _parse_args

    def db_import(self):
        if self._args.import_from.endswith('.gz'):
            try:
                f = gzip.open(self._args.import_from, 'rb')
                self.import_data = json.loads(f.read())
            finally:
                f.close()
        else:
            with open(self._args.import_from, 'r') as f:
                self.import_data = json.loads(f.read())

        ks_cf_info = dict((ks, dict((c, {}) for c in cf.keys()))
            for ks,cf in self.import_data['cassandra'].items())
        self.init_cassandra(ks_cf_info)

        # refuse import if db already has data
        non_empty_errors = []
        for ks in self.import_data['cassandra'].keys():
            for cf in self.import_data['cassandra'][ks].keys():
                if len(list(self._cassandra.get_cf(cf).get_range(
                    column_count=0))) > 0:
                    non_empty_errors.append(
                        'Keyspace %s CF %s already has entries.' %(ks, cf))

        if non_empty_errors:
            raise CassandraNotEmptyError('\n'.join(non_empty_errors))

        non_empty_errors = []
        existing_zk_dirs = set(
            self._zookeeper.get_children(self._api_args.cluster_id+'/'))
        import_zk_dirs = set([p_v_ts[0].split('/')[1]
            for p_v_ts in json.loads(self.import_data['zookeeper'] or "[]")])

        for non_empty in ((existing_zk_dirs & import_zk_dirs) - 
                          set(['zookeeper'])):
            non_empty_errors.append(
                'Zookeeper has entries at /%s.' %(non_empty))

        if non_empty_errors:
#.........这里部分代码省略.........
开发者ID:rombie,项目名称:contrail-controller,代码行数:101,代码来源:db_json_exim.py

示例15: DatabaseExim

class DatabaseExim(object):
    def __init__(self, args_str):
        self._parse_args(args_str)
        self._cassandra = VncCassandraClient(
            self._api_args.cassandra_server_list, False,
            self._api_args.cluster_id, None, logger=self.log)
        self._zookeeper = kazoo.client.KazooClient(
            self._api_args.zk_server_ip)
        self._zookeeper.start()
    # end __init__

    def log(self, msg, level):
        pass
    # end log

    def _parse_args(self, args_str):
        parser = argparse.ArgumentParser()

        help="Path to contrail-api conf file, default /etc/contrail-api.conf"
        parser.add_argument(
            "--api-conf", help=help, default="/etc/contrail/contrail-api.conf")
        parser.add_argument(
            "--verbose", help="Run in verbose/INFO mode, default False",
            action='store_true', default=False)
        parser.add_argument(
            "--debug", help="Run in debug mode, default False",
            action='store_true', default=False)
        parser.add_argument(
            "--import-from", help="Import from this json file to database",
            metavar='FILE', default='db.json')
        parser.add_argument(
            "--export-to", help="Export from database to this json file",
            metavar='FILE')

        args_obj, remaining_argv = parser.parse_known_args(args_str.split())
        self._args = args_obj

        self._api_args = utils.parse_args('-c %s %s'
            %(self._args.api_conf, ' '.join(remaining_argv)))[0]
        pass
    # end _parse_args

    def db_import(self):
        if self._args.import_from.endswith('.gz'):
            try:
                f = gzip.open(self._args.import_from, 'rb')
                self.import_data = json.loads(f.read())
            finally:
                f.close()
        else:
            with open(self._args.import_from, 'r') as f:
                self.import_data = json.loads(f.read())

        # refuse import if db already has data
        if len(list(self._cassandra.get_cf('obj_uuid_table').get_range(column_count=0))) > 0:
            raise CassandraNotEmptyError('obj_uuid_table has entries')
        if len(list(self._cassandra.get_cf('obj_fq_name_table').get_range(column_count=0))) > 0:
            raise CassandraNotEmptyError('obj_fq_name_table has entries')
        zk_nodes = self._zookeeper.get_children('/')
        zk_nodes.remove('zookeeper')
        if len(zk_nodes) > 0:
            raise ZookeeperNotEmptyError('Zookeeper has entries')

        # seed cassandra
        for cf_name in ['obj_fq_name_table', 'obj_uuid_table']:
            for row, column in self.import_data['cassandra'][cf_name].items():
                self._cassandra.add(cf_name, row, column)

        # seed zookeeper
        for path_value_ts in json.loads(self.import_data['zookeeper']):
            path = path_value_ts[0]
            if path.endswith('/'): 
                path = path[:-1]
            if path.startswith('/zookeeper'):
                continue
            value = path_value_ts[1][0]
            self._zookeeper.create(path, str(value), makepath=True)

    # end db_import

    def db_export(self):
        pass
开发者ID:ajayhn,项目名称:contrail-docker-deploy,代码行数:82,代码来源:db-import-json.py


注:本文中的cfgm_common.vnc_cassandra.VncCassandraClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。