allocate bbs account in vcpe object
diff --git a/xos/cord/models.py b/xos/cord/models.py
index 3fc970c..7eb8581 100644
--- a/xos/cord/models.py
+++ b/xos/cord/models.py
@@ -187,6 +187,20 @@
verbose_name = "vCPE Service"
proxy = True
+ def allocate_bbs_account(self):
+ vcpes = VCPETenant.get_tenant_objects().all()
+ bbs_accounts = [vcpe.bbs_account for vcpe in vcpes]
+
+ # There's a bit of a race here; some other user could be trying to
+ # allocate a bbs_account at the same time we are.
+
+ for i in range(1,21):
+ account_name = "bbs%02d@onlab.us" % i
+ if (account_name not in bbs_accounts):
+ return account_name
+
+ raise XOSConfigurationError("We've run out of available broadbandshield accounts. Delete some vcpe and try again.")
+
class VCPETenant(Tenant):
class Meta:
proxy = True
@@ -210,7 +224,8 @@
"url_filter_level": "PG",
"cdn_enable": False,
"sliver_id": None,
- "users": []}
+ "users": [],
+ "bbs_account": None}
def __init__(self, *args, **kwargs):
super(VCPETenant, self).__init__(*args, **kwargs)
@@ -353,6 +368,14 @@
def users(self, value):
self.set_attribute("users", value)
+ @property
+ def bbs_account(self):
+ return self.get_attribute("bbs_account", self.default_attributes["bbs_account"])
+
+ @bbs_account.setter
+ def bbs_account(self, value):
+ return self.set_attribute("bbs_account", value)
+
def find_user(self, uid):
uid = int(uid)
for user in self.users:
@@ -516,6 +539,14 @@
self.vbng.delete()
self.vbng = None
+ def manage_bbs_account(self):
+ if self.deleted:
+ return
+
+ if not self.bbs_account:
+ self.bbs_account = self.provider_service.allocate_bbs_account()
+ super(VCPETenant, self).save()
+
def save(self, *args, **kwargs):
if not self.creator:
if not getattr(self, "caller", None):
@@ -528,6 +559,7 @@
super(VCPETenant, self).save(*args, **kwargs)
self.manage_sliver()
self.manage_vbng()
+ self.manage_bbs_account()
def delete(self, *args, **kwargs):
self.cleanup_vbng()
diff --git a/xos/core/xoslib/methods/cordsubscriber.py b/xos/core/xoslib/methods/cordsubscriber.py
index 55af19a..650f0b3 100644
--- a/xos/core/xoslib/methods/cordsubscriber.py
+++ b/xos/core/xoslib/methods/cordsubscriber.py
@@ -40,6 +40,7 @@
sliver_name = ReadOnlyField()
image_name = ReadOnlyField()
routeable_subnet = serializers.CharField(required=False)
+ bbs_account = ReadOnlyField()
lan_ip = ReadOnlyField()
wan_ip = ReadOnlyField()
diff --git a/xos/core/xoslib/objects/cordsubscriber.py b/xos/core/xoslib/objects/cordsubscriber.py
index e6f0e10..1301f90 100644
--- a/xos/core/xoslib/objects/cordsubscriber.py
+++ b/xos/core/xoslib/objects/cordsubscriber.py
@@ -25,11 +25,15 @@
def __init__(self, *args, **kwargs):
super(VOLTTenant, self).__init__(*args, **kwargs)
+ def __unicode__(self):
+ return u"cordSubscriber-%s" % str(self.id)
+
passthroughs = ( ("firewall_enable", "vcpe.firewall_enable"),
("firewall_rules", "vcpe.firewall_rules"),
("url_filter_enable", "vcpe.url_filter_enable"),
("url_filter_rules", "vcpe.url_filter_rules"),
("url_filter_level", "vcpe.url_filter_level"),
+ ("bbs_account", "vcpe.bbs_account"),
("users", "vcpe.users"),
("services", "vcpe.services"),
("cdn_enable", "vcpe.cdn_enable"),
diff --git a/xos/core/xoslib/templates/xosCordSubscriber.html b/xos/core/xoslib/templates/xosCordSubscriber.html
index 402f9b0..7a8abe0 100644
--- a/xos/core/xoslib/templates/xosCordSubscriber.html
+++ b/xos/core/xoslib/templates/xosCordSubscriber.html
@@ -19,15 +19,16 @@
<tr><td class="xos-label-cell xos-cord-label">Id:</td><td><%= model.attributes.vcpe_id %></td></tr>
<tr><td class="xos-label-cell xos-cord-label">Image:</td><td><%= model.attributes.image_name %></td></tr>
<tr><td class="xos-label-cell xos-cord-label">Sliver Id:</td><td><%= model.attributes.sliver %></td></tr>
+ <tr><td class="xos-label-cell xos-cord-label">BBS Account:</td><td><%= model.attributes.bbs_account %></td></tr>
<tr><td class="xos-label-cell xos-cord-label">Firewall:</td><td><input type="checkbox" name="firewall_enable" <% if (model.attributes.firewall_enable) print("checked"); %>>Enable<br>
<textarea name="firewall_rules" style="width:320px; height:80px"><%= model.attributes.firewall_rules %></textarea></td></tr>
<tr><td class="xos-label-cell xos-cord-label">URL Filter:</td><td><input type="checkbox" name="url_filter_enable" <% if (model.attributes.url_filter_enable) print("checked"); %>>Enable<br>
<textarea name="url_filter_rules" style="width:320px; height:80px"><%= model.attributes.url_filter_rules %></textarea></td></tr>
<tr><td class="xos-label-cell xos-cord-label">CDN:</td><td><input type="checkbox" name="cdn_enable" <% if (model.attributes.cdn_enable) print("checked"); %>>Enable</td></tr>
- <tr><td class="xos-label-cell xos-cord-label">Addresses:</td><td><%= wan_ip %> (wan)<br>
- <%= lan_ip %> (lan)<br>
- <%= nat_ip %> (nat)<br>
- <%= private_ip %> (private) </td></tr>
+ <tr><td class="xos-label-cell xos-cord-label">Addresses:</td><td><%= model.attributes.wan_ip %> (wan)<br>
+ <%= model.attributes.lan_ip %> (lan)<br>
+ <%= model.attributes.nat_ip %> (nat)<br>
+ <%= model.attributes.private_ip %> (private) </td></tr>
</table>
</div>