Merge branch 'master' of github.com:open-cloud/xos
diff --git a/xos/services/cord/admin.py b/xos/services/cord/admin.py
index 56e46ae..4195aaa 100644
--- a/xos/services/cord/admin.py
+++ b/xos/services/cord/admin.py
@@ -351,6 +351,7 @@
downlink_speed = forms.CharField(required = False)
status = forms.ChoiceField(choices=CordSubscriberRoot.status_choices, required=True)
enable_uverse = forms.BooleanField(required=False)
+ cdn_enable = forms.BooleanField(required=False)
def __init__(self,*args,**kwargs):
super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
@@ -361,6 +362,7 @@
self.fields['downlink_speed'].initial = self.instance.downlink_speed
self.fields['status'].initial = self.instance.status
self.fields['enable_uverse'].initial = self.instance.enable_uverse
+ self.fields['cdn_enable'].initial = self.instance.cdn_enable
if (not self.instance) or (not self.instance.pk):
# default fields for an 'add' form
self.fields['kind'].initial = CORD_SUBSCRIBER_KIND
@@ -368,6 +370,7 @@
self.fields['downlink_speed'].initial = CordSubscriberRoot.get_default_attribute("downlink_speed")
self.fields['status'].initial = CordSubscriberRoot.get_default_attribute("status")
self.fields['enable_uverse'].initial = CordSubscriberRoot.get_default_attribute("enable_uverse")
+ self.fields['cdn_enable'].initial = CordSubscriberRoot.get_default_attribute("cdn_enable")
def save(self, commit=True):
self.instance.url_filter_level = self.cleaned_data.get("url_filter_level")
@@ -375,6 +378,7 @@
self.instance.downlink_speed = self.cleaned_data.get("downlink_speed")
self.instance.status = self.cleaned_data.get("status")
self.instance.enable_uverse = self.cleaned_data.get("enable_uverse")
+ self.instance.cdn_enable = self.cleaned_data.get("cdn_enable")
return super(CordSubscriberRootForm, self).save(commit=commit)
class Meta:
@@ -384,7 +388,7 @@
list_display = ('backend_status_icon', 'id', 'name', )
list_display_links = ('backend_status_icon', 'id', 'name', )
fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute',
- 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse"],
+ 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse", "cdn_enable"],
'classes':['suit-tab suit-tab-general']})]
readonly_fields = ('backend_status_text', 'service_specific_attribute',)
form = CordSubscriberRootForm
diff --git a/xos/synchronizers/vcpe/steps/sync_vcpetenant.py b/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
index 2e8e0c6..a8c6b4f 100644
--- a/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
+++ b/xos/synchronizers/vcpe/steps/sync_vcpetenant.py
@@ -66,38 +66,52 @@
vcpe_service = self.get_vcpe_service(o)
dnsdemux_ip = None
- if vcpe_service.backend_network_label:
- # Connect to dnsdemux using the network specified by
- # vcpe_service.backend_network_label
- for service in HpcService.objects.all():
- for slice in service.slices.all():
- if "dnsdemux" in slice.name:
- for instance in slice.instances.all():
- for ns in instance.ports.all():
- if ns.ip and ns.network.labels and (vcpe_service.backend_network_label in ns.network.labels):
- dnsdemux_ip = ns.ip
- if not dnsdemux_ip:
- logger.info("failed to find a dnsdemux on network %s" % vcpe_service.backend_network_label)
+ cdn_prefixes = []
+
+ cdn_config_fn = "/opt/xos/synchronizers/vcpe/cdn_config"
+ if os.path.exists(cdn_config_fn):
+ # manual CDN configuration
+ # the first line is the address of dnsredir
+ # the remaining lines are domain names, one per line
+ lines = file(cdn_config_fn).readlines()
+ if len(lines)>=2:
+ dnsdemux_ip = lines[0].strip()
+ cdn_prefixes = [x.strip() for x in lines[1:] if x.strip()]
else:
- # Connect to dnsdemux using the instance's public address
- for service in HpcService.objects.all():
- for slice in service.slices.all():
- if "dnsdemux" in slice.name:
- for instance in slice.instances.all():
- if dnsdemux_ip=="none":
- try:
- dnsdemux_ip = socket.gethostbyname(instance.node.name)
- except:
- pass
- if not dnsdemux_ip:
- logger.info("failed to find a dnsdemux with a public address")
+ # automatic CDN configuiration
+ # it learns everything from CDN objects in XOS
+ # not tested on pod.
+ if vcpe_service.backend_network_label:
+ # Connect to dnsdemux using the network specified by
+ # vcpe_service.backend_network_label
+ for service in HpcService.objects.all():
+ for slice in service.slices.all():
+ if "dnsdemux" in slice.name:
+ for instance in slice.instances.all():
+ for ns in instance.ports.all():
+ if ns.ip and ns.network.labels and (vcpe_service.backend_network_label in ns.network.labels):
+ dnsdemux_ip = ns.ip
+ if not dnsdemux_ip:
+ logger.info("failed to find a dnsdemux on network %s" % vcpe_service.backend_network_label)
+ else:
+ # Connect to dnsdemux using the instance's public address
+ for service in HpcService.objects.all():
+ for slice in service.slices.all():
+ if "dnsdemux" in slice.name:
+ for instance in slice.instances.all():
+ if dnsdemux_ip=="none":
+ try:
+ dnsdemux_ip = socket.gethostbyname(instance.node.name)
+ except:
+ pass
+ if not dnsdemux_ip:
+ logger.info("failed to find a dnsdemux with a public address")
+
+ for prefix in CDNPrefix.objects.all():
+ cdn_prefixes.append(prefix.prefix)
dnsdemux_ip = dnsdemux_ip or "none"
- cdn_prefixes = []
- for prefix in CDNPrefix.objects.all():
- cdn_prefixes.append(prefix.prefix)
-
# Broadbandshield can either be set up internally, using vcpe_service.bbs_slice,
# or it can be setup externally using vcpe_service.bbs_server.
diff --git a/xos/synchronizers/vcpe/templates/dnsmasq_safe_servers.j2 b/xos/synchronizers/vcpe/templates/dnsmasq_safe_servers.j2
index 2f93777..0b3c807 100644
--- a/xos/synchronizers/vcpe/templates/dnsmasq_safe_servers.j2
+++ b/xos/synchronizers/vcpe/templates/dnsmasq_safe_servers.j2
@@ -3,11 +3,13 @@
no-resolv
{% if cdn_enable %}
+{% if cdn_prefixes %}
# CDN
{% for prefix in cdn_prefixes %}
server=/{{ prefix }}/{{ dnsdemux_ip }}
{% endfor %}
{% endif %}
+{% endif %}
# use OpenDNS service
server=208.67.222.123
diff --git a/xos/synchronizers/vcpe/templates/dnsmasq_servers.j2 b/xos/synchronizers/vcpe/templates/dnsmasq_servers.j2
index 3682cdf..004576f 100644
--- a/xos/synchronizers/vcpe/templates/dnsmasq_servers.j2
+++ b/xos/synchronizers/vcpe/templates/dnsmasq_servers.j2
@@ -3,11 +3,13 @@
no-resolv
{% if cdn_enable %}
+{% if cdn_prefixes %}
# CDN
{% for prefix in cdn_prefixes %}
server=/{{ prefix }}/{{ dnsdemux_ip }}
{% endfor %}
{% endif %}
+{% endif %}
# use google's DNS service
{% for dns_server in dns_servers %}