Updating vEG to new docker containers, new_base and dependecies
Change-Id: I6414cae27801ff0d26b0a7b3eb2f53312d874bf0
diff --git a/xos/models.py b/xos/models.py
index 6cb81b1..3d828e6 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,5 @@
from django.db import models
-from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber, NetworkParameter, NetworkParameterType, Port, AddressPool, User
+from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool, User
from core.models.plcorebase import StrippedCharField
import os
from django.db import models, transaction
@@ -19,8 +19,6 @@
VEG_KIND = "vEG"
CORD_SUBSCRIBER_KIND = "CordSubscriberRoot"
-CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
-
# -------------------------------------------
# VEG
# -------------------------------------------
@@ -30,87 +28,34 @@
URL_FILTER_KIND_CHOICES = ( (None, "None"), ("safebrowsing", "Safe Browsing"), ("answerx", "AnswerX") )
- simple_attributes = ( ("bbs_api_hostname", None),
- ("bbs_api_port", None),
- ("bbs_server", None),
- ("backend_network_label", "hpc_client"),
- ("dns_servers", "8.8.8.8"),
- ("url_filter_kind", None),
- ("node_label", None),
- ("docker_image_name", "docker.io/xosproject/veg"),
- ("docker_insecure_registry", False) )
-
- def __init__(self, *args, **kwargs):
- super(VEGService, self).__init__(*args, **kwargs)
+ url_filter_kind = StrippedCharField(max_length=30, choices=URL_FILTER_KIND_CHOICES, null=True, blank=True)
+ dns_servers = StrippedCharField(max_length=255, default="8.8.8.8")
+ node_label = StrippedCharField(max_length=30, null=True, blank=True)
+ docker_image_name = StrippedCharField(max_length=255, default="docker.io/xosproject/veg")
+ docker_insecure_registry = models.BooleanField(default=False)
class Meta:
app_label = "veg"
verbose_name = "vEG Service"
- proxy = True
- def allocate_bbs_account(self):
- vegs = VEGTenant.get_tenant_objects().all()
- bbs_accounts = [veg.bbs_account for veg in vegs]
- # 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(2,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 veg and try again.")
-
- @property
- def bbs_slice(self):
- bbs_slice_id=self.get_attribute("bbs_slice_id")
- if not bbs_slice_id:
- return None
- bbs_slices=Slice.objects.filter(id=bbs_slice_id)
- if not bbs_slices:
- return None
- return bbs_slices[0]
-
- @bbs_slice.setter
- def bbs_slice(self, value):
- if value:
- value = value.id
- self.set_attribute("bbs_slice_id", value)
-
-VEGService.setup_simple_attributes()
class VEGTenant(TenantWithContainer):
- class Meta:
- proxy = True
-
KIND = VEG_KIND
+ class Meta:
+ app_label = "veg"
+
sync_attributes = ("wan_container_ip", "wan_container_mac", "wan_container_netbits",
"wan_container_gateway_ip", "wan_container_gateway_mac",
"wan_vm_ip", "wan_vm_mac")
- default_attributes = {"instance_id": None,
- "container_id": None,
- "users": [],
- "bbs_account": None,
- "last_ansible_hash": None,
- "wan_container_ip": None}
def __init__(self, *args, **kwargs):
super(VEGTenant, self).__init__(*args, **kwargs)
self.cached_vrouter=None
@property
- def vbng(self):
- # not supported
- return None
-
- @vbng.setter
- def vbng(self, value):
- raise XOSConfigurationError("vEG.vBNG cannot be set this way -- create a new vBNG object and set it's subscriber_tenant instead")
-
- @property
def vrouter(self):
vrouter = self.get_newest_subscribed_tenant(VRouterTenant)
if not vrouter:
@@ -126,7 +71,7 @@
@vrouter.setter
def vrouter(self, value):
- raise XOSConfigurationError("vEG.vRouter cannot be set this way -- create a new vRuter object and set its subscriber_tenant instead")
+ raise XOSConfigurationError("vEGTenant.vrouter setter is not implemented")
@property
def volt(self):
@@ -138,21 +83,9 @@
return None
return volts[0]
- @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)
-
- @property
- def last_ansible_hash(self):
- return self.get_attribute("last_ansible_hash", self.default_attributes["last_ansible_hash"])
-
- @last_ansible_hash.setter
- def last_ansible_hash(self, value):
- return self.set_attribute("last_ansible_hash", value)
+ @volt.setter
+ def volt(self, value):
+ raise XOSConfigurationError("VEGTenant.volt setter is not implemented")
@property
def ssh_command(self):
@@ -161,10 +94,6 @@
else:
return "no-instance"
- @ssh_command.setter
- def ssh_command(self, value):
- pass
-
def get_vrouter_field(self, name, default=None):
if self.vrouter:
return getattr(self.vrouter, name, default)
@@ -334,21 +263,6 @@
# To-do: cleanup unused instances
pass
- def manage_bbs_account(self):
- if self.deleted:
- return
-
- if self.volt and self.volt.subscriber and self.volt.subscriber.url_filter_enable:
- if not self.bbs_account:
- # make sure we use the proxied VEGService object, not the generic Service object
- veg_service = VEGService.objects.get(id=self.provider_service.id)
- self.bbs_account = veg_service.allocate_bbs_account()
- super(VEGTenant, self).save()
- else:
- if self.bbs_account:
- self.bbs_account = None
- super(VEGTenant, self).save()
-
def find_or_make_port(self, instance, network, **kwargs):
port = Port.objects.filter(instance=instance, network=network)
if port:
@@ -360,13 +274,10 @@
def get_lan_network(self, instance):
slice = self.provider_service.slices.all()[0]
- if CORD_USE_VTN:
- # there should only be one network private network, and its template should not be the management template
- lan_networks = [x for x in slice.networks.all() if x.template.visibility=="private" and (not "management" in x.template.name)]
- if len(lan_networks)>1:
- raise XOSProgrammingError("The vEG slice should only have one non-management private network")
- else:
- lan_networks = [x for x in slice.networks.all() if "lan" in x.name]
+ # there should only be one network private network, and its template should not be the management template
+ lan_networks = [x for x in slice.networks.all() if x.template.visibility == "private" and (not "management" in x.template.name)]
+ if len(lan_networks) > 1:
+ raise XOSProgrammingError("The vEG slice should only have one non-management private network")
if not lan_networks:
raise XOSProgrammingError("No lan_network")
return lan_networks[0]
@@ -409,14 +320,14 @@
# VTN-CORD needs a WAN address for the VM, so that the VM can
# be configured.
- if CORD_USE_VTN:
- tags = Tag.select_by_content_object(instance).filter(name="vm_vrouter_tenant")
- if not tags:
- vrouter = self.get_vrouter_service().get_tenant(address_pool_name="addresses_veg", subscriber_service = self.provider_service)
- vrouter.set_attribute("tenant_for_instance_id", instance.id)
- vrouter.save()
- tag = Tag(service=self.provider_service, content_object=instance, name="vm_vrouter_tenant", value="%d" % vrouter.id)
- tag.save()
+ tags = Tag.select_by_content_object(instance).filter(name="vm_vrouter_tenant")
+
+ if not tags:
+ vrouter = self.get_vrouter_service().get_tenant(address_pool_name="addresses_veg", subscriber_service=self.provider_service)
+ vrouter.set_attribute("tenant_for_instance_id", instance.id)
+ vrouter.save()
+ tag = Tag(service=self.provider_service, content_object=instance, name="vm_vrouter_tenant",value="%d" % vrouter.id)
+ tag.save()
def save(self, *args, **kwargs):
if not self.creator:
@@ -444,7 +355,6 @@
veg = veg[0]
veg.manage_container()
veg.manage_vrouter()
- veg.manage_bbs_account()
veg.cleanup_orphans()