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


Python VncCassandraClient.get_cf方法代码示例

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


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

示例1: LoadDataBase

# 需要导入模块: from cfgm_common.vnc_cassandra import VncCassandraClient [as 别名]
# 或者: from cfgm_common.vnc_cassandra.VncCassandraClient import get_cf [as 别名]
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,代码行数:103,代码来源:main.py

示例2: DatabaseExim

# 需要导入模块: from cfgm_common.vnc_cassandra import VncCassandraClient [as 别名]
# 或者: from cfgm_common.vnc_cassandra.VncCassandraClient import get_cf [as 别名]
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,代码行数:103,代码来源:db_json_exim.py

示例3: _issu_basic_function

# 需要导入模块: from cfgm_common.vnc_cassandra import VncCassandraClient [as 别名]
# 或者: from cfgm_common.vnc_cassandra.VncCassandraClient import get_cf [as 别名]
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,代码行数:103,代码来源:issu_contrail_common.py

示例4: DatabaseExim

# 需要导入模块: from cfgm_common.vnc_cassandra import VncCassandraClient [as 别名]
# 或者: from cfgm_common.vnc_cassandra.VncCassandraClient import get_cf [as 别名]
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,代码行数:84,代码来源:db-import-json.py


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