Example #1
0
    def __init__(self, manager, zkclient):
        self._manager = manager
        self._args = manager._args
        self._zkclient = zkclient

        if self._args.cluster_id:
            self._keyspace = '%s_%s' % (self._args.cluster_id, self._KEYSPACE)
            self._zk_path_pfx = self._args.cluster_id + '/'
        else:
            self._keyspace = self._KEYSPACE
            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

        if self._args.reset_config:
            cass_reset_config = [self._keyspace]
        else:
            cass_reset_config = []

        super(SchemaTransformerDB,
              self).__init__(cass_server_list,
                             self._args.cluster_id,
                             keyspaces,
                             manager.config_log,
                             reset_config=cass_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(
            zkclient, self._zk_path_pfx + self._VN_ID_ALLOC_PATH,
            self._VN_MAX_ID)
        self._sg_id_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._SECURITY_GROUP_ID_ALLOC_PATH,
            self._SECURITY_GROUP_MAX_ID)

        # 0 is not a valid sg id any more. So, if it was previously allocated,
        # delete it and reserve it
        if self._sg_id_allocator.read(0) != '__reserved__':
            self._sg_id_allocator.delete(0)
        self._sg_id_allocator.reserve(0, '__reserved__')

        self._rt_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._BGP_RTGT_ALLOC_PATH,
            self._BGP_RTGT_MAX_ID, common.BGP_RTGT_MIN_ID)

        self._sc_vlan_allocator_dict = {}
Example #2
0
        def _init_index_allocators():
            bgpaas_port_start = self._args.bgpaas_port_start
            bgpaas_port_end = self._args.bgpaas_port_end
            gsc_fq_name = ['default-global-system-config']

            gsc_uuid = self._object_db.fq_name_to_uuid(
                obj_type='global_system_config',
                fq_name=gsc_fq_name)

            _, cfg = self._object_db.object_read('global_system_config',
                                                 [gsc_uuid])
            cfg_bgpaas_ports = cfg[0].get('bgpaas_parameters')
            if cfg_bgpaas_ports:
                bgpaas_port_start = cfg_bgpaas_ports['port_start']
                bgpaas_port_end = cfg_bgpaas_ports['port_end']

            self._bgpaas_port_allocator = IndexAllocator(
                zkclient, self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH,
                bgpaas_port_end - bgpaas_port_start, bgpaas_port_start)

            self._rt_allocator = IndexAllocator(
                zkclient,
                self._zk_path_pfx + common.BGP_RTGT_ALLOC_PATH_TYPE0,
                common._BGP_RTGT_MAX_ID_TYPE0, common._BGP_RTGT_MIN_ID_TYPE0)
            self._rt_allocator_4 = IndexAllocator(
                zkclient,
                self._zk_path_pfx + common.BGP_RTGT_ALLOC_PATH_TYPE1_2,
                common._BGP_RTGT_MAX_ID_TYPE1_2,
                common._BGP_RTGT_MIN_ID_TYPE1_2)
Example #3
0
    def allocate_service_chain_vlan(self, service_vm, service_chain):
        alloc_new = False
        if service_vm not in self._sc_vlan_allocator_dict:
            self._sc_vlan_allocator_dict[service_vm] = IndexAllocator(
                self._zkclient,
                (self._zk_path_prefix + self._SERVICE_CHAIN_VLAN_ALLOC_PATH +
                 service_vm + '/'),
                self._SERVICE_CHAIN_MAX_VLAN)

        vlan_ia = self._sc_vlan_allocator_dict[service_vm]

        try:
            vlan = int(self.get_one_col(self._SERVICE_CHAIN_CF,
                                        service_vm, service_chain))
            db_sc = vlan_ia.read(vlan)
            if (db_sc is None) or (db_sc != service_chain):
                alloc_new = True
        except (KeyError, VncError, NoIdError):
            # TODO(ethuleau): VncError is raised if more than one row was
            #                 fetched from db with get_one_col method.
            #                 Probably need to be cleaned
            alloc_new = True

        if alloc_new:
            vlan = vlan_ia.alloc(service_chain)
            self._service_chain_cf.insert(service_vm,
                                          {service_chain: str(vlan)})

        # Since vlan tag 0 is not valid, increment before returning
        return vlan + 1
Example #4
0
    def allocate_service_chain_vlan(self, service_vm, service_chain):
        alloc_new = False
        if service_vm not in self._sc_vlan_allocator_dict:
            self._sc_vlan_allocator_dict[service_vm] = IndexAllocator(
                self._zkclient,
                (self._zk_path_prefix + self._SERVICE_CHAIN_VLAN_ALLOC_PATH +
                 service_vm), self._SERVICE_CHAIN_MAX_VLAN)

        vlan_ia = self._sc_vlan_allocator_dict[service_vm]

        try:
            vlan = int(self._service_chain_cf.get(service_vm)[service_chain])
            db_sc = vlan_ia.read(vlan)
            if (db_sc is None) or (db_sc != service_chain):
                alloc_new = True
        except (KeyError, NotFoundException):
            alloc_new = True

        if alloc_new:
            vlan = vlan_ia.alloc(service_chain)
            self._service_chain_cf.insert(service_vm,
                                          {service_chain: str(vlan)})

        # Since vlan tag 0 is not valid, increment before returning
        return vlan + 1
Example #5
0
 def get_pnf_unit_allocator(self, pi_id):
     return self.pnf_unit_allocator_map.setdefault(
         pi_id,
         IndexAllocator(
             self._zkclient,
             self._zk_path_pfx + self._PNF_UNIT_ALLOC_PATH + pi_id + '/',
             self._PNF_MAX_UNIT))
Example #6
0
 def get_pnf_vlan_allocator(self, pr_id):
     return self.pnf_vlan_allocator_map.setdefault(
         pr_id,
         IndexAllocator(
             self._zkclient,
             self._zk_path_pfx + self._PNF_VLAN_ALLOC_PATH + pr_id + '/',
             self._PNF_MAX_VLAN))
Example #7
0
    def __init__(self, manager, zkclient):
        self._zkclient = zkclient
        self._manager = manager
        self._args = manager._args

        keyspaces = {
            self._KEYSPACE: {self._PR_VN_IP_CF: {},
                             self._PNF_RESOURCE_CF: {}}}

        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(DMCassandraDB, self).__init__(
            cass_server_list, self._args.cluster_id, keyspaces, None,
            manager.logger.log, credential=cred)

        self.pr_vn_ip_map = {}
        self.init_pr_map()

        self.pnf_vlan_allocator_map = {}
        self.pnf_unit_allocator_map = {}
        self.pnf_network_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx+self._PNF_NETWORK_ALLOC_PATH,
            self._PNF_MAX_NETWORK_ID)

        self.pnf_cf = self.get_cf(self._PNF_RESOURCE_CF)
        self.pnf_resources_map = dict(
            self.pnf_cf.get_range(column_count=0, filter_empty=True))
Example #8
0
        def _init_bgpaas_ports_index_allocator():
            bgpaas_port_start = self._args.bgpaas_port_start
            bgpaas_port_end = self._args.bgpaas_port_end
            gsc_fq_name = ['default-global-system-config']

            gsc_uuid = self.fq_name_to_uuid(obj_type='global_system_config',
                                                       fq_name=gsc_fq_name)

            _, cfg = self.object_read('global_system_config', [gsc_uuid])
            cfg_bgpaas_ports = cfg[0].get('bgpaas_parameters')
            if cfg_bgpaas_ports:
                bgpaas_port_start = cfg_bgpaas_ports['port_start']
                bgpaas_port_end = cfg_bgpaas_ports['port_end']

            self._bgpaas_port_allocator = IndexAllocator(
                zkclient, self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH,
                bgpaas_port_end - bgpaas_port_start, bgpaas_port_start)
    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: {},
                self._SC_IP_CF: {},
                self._SERVICE_CHAIN_CF: {},
                self._SERVICE_CHAIN_UUID_CF: {}
            }
        }
        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.logger.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 + self._BGP_RTGT_ALLOC_PATH,
                                 True)
            zkclient.delete_node(
                self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH, True)
            zkclient.delete_node(
                self._zk_path_pfx + self._SERVICE_CHAIN_VLAN_ALLOC_PATH, True)

        # TODO(ethuleau): We keep the virtual network and security group ID
        #                 allocation in schema and in the vnc API for one
        #                 release overlap to prevent any upgrade issue. So the
        #                 following code need to be remove in release (3.2 + 1)
        self._vn_id_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._VN_ID_ALLOC_PATH,
            self._VN_MAX_ID)
        self._sg_id_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._SECURITY_GROUP_ID_ALLOC_PATH,
            self._SECURITY_GROUP_MAX_ID)

        # 0 is not a valid sg id any more. So, if it was previously allocated,
        # delete it and reserve it
        if self._sg_id_allocator.read(0) != '__reserved__':
            self._sg_id_allocator.delete(0)
        self._sg_id_allocator.reserve(0, '__reserved__')

        self._rt_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._BGP_RTGT_ALLOC_PATH,
            self._BGP_RTGT_MAX_ID, common.BGP_RTGT_MIN_ID)

        def _init_bgpaas_ports_index_allocator():
            bgpaas_port_start = self._args.bgpaas_port_start
            bgpaas_port_end = self._args.bgpaas_port_end
            gsc_fq_name = ['default-global-system-config']

            gsc_uuid = self._object_db.fq_name_to_uuid(
                obj_type='global_system_config', fq_name=gsc_fq_name)

            _, cfg = self._object_db.object_read('global_system_config',
                                                 [gsc_uuid])
            cfg_bgpaas_ports = cfg[0].get('bgpaas_parameters')
            if cfg_bgpaas_ports:
                bgpaas_port_start = cfg_bgpaas_ports['port_start']
                bgpaas_port_end = cfg_bgpaas_ports['port_end']

            self._bgpaas_port_allocator = IndexAllocator(
                zkclient, self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH,
                bgpaas_port_end - bgpaas_port_start, bgpaas_port_start)

        _init_bgpaas_ports_index_allocator()

        self._sc_vlan_allocator_dict = {}
        self._upgrade_vlan_alloc_path()
Example #10
0
    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: {},
                self._SC_IP_CF: {},
                self._SERVICE_CHAIN_CF: {},
                self._SERVICE_CHAIN_UUID_CF: {}
            }
        }
        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(
            zkclient, self._zk_path_pfx + self._VN_ID_ALLOC_PATH,
            self._VN_MAX_ID)
        self._sg_id_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._SECURITY_GROUP_ID_ALLOC_PATH,
            self._SECURITY_GROUP_MAX_ID)

        # 0 is not a valid sg id any more. So, if it was previously allocated,
        # delete it and reserve it
        if self._sg_id_allocator.read(0) != '__reserved__':
            self._sg_id_allocator.delete(0)
        self._sg_id_allocator.reserve(0, '__reserved__')

        self._rt_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._BGP_RTGT_ALLOC_PATH,
            self._BGP_RTGT_MAX_ID, common.BGP_RTGT_MIN_ID)

        self._bgpaas_port_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH,
            self._args.bgpaas_port_end - self._args.bgpaas_port_start,
            self._args.bgpaas_port_start)

        self._sc_vlan_allocator_dict = {}
        self._upgrade_vlan_alloc_path()
Example #11
0
    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: {},
                             self._SC_IP_CF: {},
                             self._SERVICE_CHAIN_CF: {},
                             self._SERVICE_CHAIN_UUID_CF: {}}}
        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.logger.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 + self._BGP_RTGT_ALLOC_PATH, True)
            zkclient.delete_node(
                 self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH, True)
            zkclient.delete_node(
                self._zk_path_pfx + self._SERVICE_CHAIN_VLAN_ALLOC_PATH, True)

        self._rt_allocator = IndexAllocator(
            zkclient, self._zk_path_pfx+self._BGP_RTGT_ALLOC_PATH,
            self._BGP_RTGT_MAX_ID, common.BGP_RTGT_MIN_ID)

        def _init_bgpaas_ports_index_allocator():
            bgpaas_port_start = self._args.bgpaas_port_start
            bgpaas_port_end = self._args.bgpaas_port_end
            gsc_fq_name = ['default-global-system-config']

            gsc_uuid = self._object_db.fq_name_to_uuid(obj_type='global_system_config',
                                                       fq_name=gsc_fq_name)

            _, cfg = self._object_db.object_read('global_system_config', [gsc_uuid])
            cfg_bgpaas_ports = cfg[0].get('bgpaas_parameters')
            if cfg_bgpaas_ports:
                bgpaas_port_start = cfg_bgpaas_ports['port_start']
                bgpaas_port_end = cfg_bgpaas_ports['port_end']

            self._bgpaas_port_allocator = IndexAllocator(
                zkclient, self._zk_path_pfx + self._BGPAAS_PORT_ALLOC_PATH,
                bgpaas_port_end - bgpaas_port_start, bgpaas_port_start)

        _init_bgpaas_ports_index_allocator()

        self._sc_vlan_allocator_dict = {}
        self._upgrade_vlan_alloc_path()