Beispiel #1
0
    def add_tenant(self,
                   owner,
                   desc,
                   tenant_name,
                   bssid_type,
                   tenant_id=None,
                   plmn_id=None):
        """Create new Tenant."""

        if tenant_id in self.tenants:
            raise ValueError("Tenant %s exists" % tenant_id)

        plmn_ids = [tenant.plmn_id for tenant in self.tenants.values()]

        if plmn_id and plmn_id in plmn_ids:
            raise ValueError("PLMN ID %s exists" % plmn_id)

        if bssid_type not in T_TYPES:
            raise ValueError("Invalid bssid_type %s" % bssid_type)

        session = Session()

        if tenant_id:
            request = TblTenant(tenant_id=tenant_id,
                                tenant_name=tenant_name,
                                owner=owner,
                                desc=desc,
                                bssid_type=bssid_type,
                                plmn_id=plmn_id)
        else:
            request = TblTenant(owner=owner,
                                tenant_name=tenant_name,
                                desc=desc,
                                bssid_type=bssid_type,
                                plmn_id=plmn_id)

        session.add(request)
        session.commit()

        self.tenants[request.tenant_id] = \
            Tenant(request.tenant_id,
                   request.tenant_name,
                   self.accounts[owner].username,
                   desc,
                   request.bssid_type,
                   request.plmn_id)

        # create default queue
        dscp = DSCP()
        descriptor = {}

        self.tenants[request.tenant_id].add_slice(dscp, descriptor)

        return request.tenant_id
Beispiel #2
0
    def __load_tenants(self):
        """Load Tenants."""

        for tenant in Session().query(TblTenant).all():

            if tenant.tenant_id in self.tenants:
                raise KeyError(tenant.tenant_id)

            self.tenants[tenant.tenant_id] = \
                Tenant(tenant.tenant_id,
                       tenant.tenant_name,
                       tenant.owner,
                       tenant.desc,
                       tenant.bssid_type)
Beispiel #3
0
    def add_tenant(self,
                   owner,
                   desc,
                   tenant_name,
                   bssid_type,
                   tenant_id=None,
                   plmn_id=None):
        """Create new Tenant."""

        if tenant_id in self.tenants:
            raise ValueError("Tenant %s exists", tenant_id)

        try:

            session = Session()

            if tenant_id:
                request = TblTenant(tenant_id=tenant_id,
                                    tenant_name=tenant_name,
                                    owner=owner,
                                    desc=desc,
                                    bssid_type=bssid_type,
                                    plmn_id=plmn_id)
            else:
                request = TblTenant(owner=owner,
                                    tenant_name=tenant_name,
                                    desc=desc,
                                    bssid_type=bssid_type,
                                    plmn_id=plmn_id)

            session.add(request)
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("Tenant name %s exists", tenant_name)

        self.tenants[request.tenant_id] = \
            Tenant(request.tenant_id,
                   request.tenant_name,
                   self.accounts[owner].username,
                   desc,
                   request.bssid_type,
                   request.plmn_id)

        return request.tenant_id