<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

"""
Schema transformer DB to store ids allocated by it
"""
from pycassa import NotFoundException

import cfgm_common as common
from cfgm_common.zkclient import IndexAllocator
from cfgm_common.vnc_cassandra import VncCassandraClient
from sandesh_common.vns.constants import SCHEMA_KEYSPACE_NAME
import uuid

class SchemaTransformerDB(VncCassandraClient):

    _KEYSPACE = SCHEMA_KEYSPACE_NAME
    _RT_CF = 'route_target_table'
    _SC_IP_CF = 'service_chain_ip_address_table'
    _SERVICE_CHAIN_CF = 'service_chain_table'
    _SERVICE_CHAIN_UUID_CF = 'service_chain_uuid_table'
    _zk_path_prefix = ''

    _BGP_RTGT_MAX_ID = 1 << 24
    _BGP_RTGT_ALLOC_PATH = "/id/bgp/route-targets/"

    _VN_MAX_ID = 1 << 24
    _VN_ID_ALLOC_PATH = "/id/virtual-networks/"

    _SECURITY_GROUP_MAX_ID = 1 << 32
    _SECURITY_GROUP_ID_ALLOC_PATH = "/id/security-groups/id/"

    _SERVICE_CHAIN_MAX_VLAN = 4093
    _SERVICE_CHAIN_VLAN_ALLOC_PATH = "/id/service-chain/vlan/"

    _BGPAAS_PORT_ALLOC_PATH = "/id/bgpaas/port/"

    @classmethod
    def get_db_info(cls):
        db_info = [(cls._KEYSPACE, [cls._RT_CF, cls._SC_IP_CF,
                                    cls._SERVICE_CHAIN_CF,
                                    cls._SERVICE_CHAIN_UUID_CF])]
        return db_info
    # end get_db_info

    def __init__(self, manager, zkclient):
        self._manager = manager
        self._args = manager._args
        self._zkclient = zkclient

        if self._args.cluster_id:
            self._zk_path_pfx = self._args.cluster_id + '/'
        else:
            self._zk_path_pfx = ''

        keyspaces = {
            self._KEYSPACE: [(self._RT_CF, None),
                             (self._SC_IP_CF, None),
                             (self._SERVICE_CHAIN_CF, None),
                             (self._SERVICE_CHAIN_UUID_CF, None)]}
        cass_server_list = self._args.cassandra_server_list

        super(SchemaTransformerDB, self).__init__(
            cass_server_list, self._args.cluster_id, keyspaces, None,
            manager.config_log, reset_config=self._args.reset_config)

        SchemaTransformerDB._rt_cf = self._cf_dict[self._RT_CF]
        SchemaTransformerDB._sc_ip_cf = self._cf_dict[self._SC_IP_CF]
        SchemaTransformerDB._service_chain_cf = self._cf_dict[
            self._SERVICE_CHAIN_CF]
        SchemaTransformerDB._service_chain_uuid_cf = self._cf_dict[
            self._SERVICE_CHAIN_UUID_CF]

        # reset zookeeper config
        if self._args.reset_config:
            zkclient.delete_node(self._zk_path_pfx + "/id", True)

        self._vn_id_allocator = IndexAllocator(<commit_msg>Adding cassandra authentication whenever available<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

"""
Schema transformer DB to store ids allocated by it
"""
from pycassa import NotFoundException

import cfgm_common as common
from cfgm_common.zkclient import IndexAllocator
from cfgm_common.vnc_cassandra import VncCassandraClient
from sandesh_common.vns.constants import SCHEMA_KEYSPACE_NAME
import uuid

class SchemaTransformerDB(VncCassandraClient):

    _KEYSPACE = SCHEMA_KEYSPACE_NAME
    _RT_CF = 'route_target_table'
    _SC_IP_CF = 'service_chain_ip_address_table'
    _SERVICE_CHAIN_CF = 'service_chain_table'
    _SERVICE_CHAIN_UUID_CF = 'service_chain_uuid_table'
    _zk_path_prefix = ''

    _BGP_RTGT_MAX_ID = 1 << 24
    _BGP_RTGT_ALLOC_PATH = "/id/bgp/route-targets/"

    _VN_MAX_ID = 1 << 24
    _VN_ID_ALLOC_PATH = "/id/virtual-networks/"

    _SECURITY_GROUP_MAX_ID = 1 << 32
    _SECURITY_GROUP_ID_ALLOC_PATH = "/id/security-groups/id/"

    _SERVICE_CHAIN_MAX_VLAN = 4093
    _SERVICE_CHAIN_VLAN_ALLOC_PATH = "/id/service-chain/vlan/"

    _BGPAAS_PORT_ALLOC_PATH = "/id/bgpaas/port/"

    @classmethod
    def get_db_info(cls):
        db_info = [(cls._KEYSPACE, [cls._RT_CF, cls._SC_IP_CF,
                                    cls._SERVICE_CHAIN_CF,
                                    cls._SERVICE_CHAIN_UUID_CF])]
        return db_info
    # end get_db_info

    def __init__(self, manager, zkclient):
        self._manager = manager
        self._args = manager._args
        self._zkclient = zkclient

        if self._args.cluster_id:
            self._zk_path_pfx = self._args.cluster_id + '/'
        else:
            self._zk_path_pfx = ''

        keyspaces = {
            self._KEYSPACE: [(self._RT_CF, None),
                             (self._SC_IP_CF, None),
                             (self._SERVICE_CHAIN_CF, None),
                             (self._SERVICE_CHAIN_UUID_CF, None)]}
        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}

        super(SchemaTransformerDB, self).__init__(
            cass_server_list, self._args.cluster_id, keyspaces, None,
            manager.config_log, reset_config=self._args.reset_config,
            credential=cred)

        SchemaTransformerDB._rt_cf = self._cf_dict[self._RT_CF]
        SchemaTransformerDB._sc_ip_cf = self._cf_dict[self._SC_IP_CF]
        SchemaTransformerDB._service_chain_cf = self._cf_dict[
            self._SERVICE_CHAIN_CF]
        SchemaTransformerDB._service_chain_uuid_cf = self._cf_dict[
            self._SERVICE_CHAIN_UUID_CF]

        # reset zookeeper config
        if self._args.reset_config:
            zkclient.delete_node(self._zk_path_pfx + "/id", True)

        self._vn_id_allocator = IndexAllocator(
{'fraction_non_alphanumeric': 0.08260196179659267, 'fraction_numerical': 0.006883496816382722, 'mean_word_length': 2.6279650436953808, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4134255', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1938, 'n_words': 314}