complete the NetworkSlice->Port renaming
diff --git a/xos/core/models/__init__.py b/xos/core/models/__init__.py
index 0efe37b..ad271a4 100644
--- a/xos/core/models/__init__.py
+++ b/xos/core/models/__init__.py
@@ -26,7 +26,7 @@
from .instance import Instance
from .reservation import ReservedResource
from .reservation import Reservation
-from .network import Network, NetworkParameterType, NetworkParameter, NetworkInstance, Port, NetworkTemplate, Router, NetworkSlice, ControllerNetwork
+from .network import Network, NetworkParameterType, NetworkParameter, Port, NetworkTemplate, Router, NetworkSlice, ControllerNetwork
from .billing import Account, Invoice, Charge, UsableObject, Payment
from .program import Program
diff --git a/xos/core/models/instance.py b/xos/core/models/instance.py
index adb9395..6240c34 100644
--- a/xos/core/models/instance.py
+++ b/xos/core/models/instance.py
@@ -98,11 +98,6 @@
tags = generic.GenericRelation(Tag)
userData = models.TextField(blank=True, null=True, help_text="user_data passed to instance during creation")
- # TODO: Remove when NetworkInstance->Port rename is complete
- @property
- def ports(self):
- return self.networkinstances
-
def __unicode__(self):
if self.name and Slice.objects.filter(id=self.slice_id) and (self.name != self.slice.name):
# NOTE: The weird check on self.slice_id was due to a problem when
diff --git a/xos/core/models/network.py b/xos/core/models/network.py
index 63d617c..1258d76 100644
--- a/xos/core/models/network.py
+++ b/xos/core/models/network.py
@@ -108,7 +108,7 @@
permit_all_slices = models.BooleanField(default=False)
permitted_slices = models.ManyToManyField(Slice, blank=True, related_name="availableNetworks")
slices = models.ManyToManyField(Slice, blank=True, related_name="networks", through="NetworkSlice")
- instances = models.ManyToManyField(Instance, blank=True, related_name="networks", through="NetworkInstance")
+ instances = models.ManyToManyField(Instance, blank=True, related_name="networks", through="Port")
topology_parameters = models.TextField(null=True, blank=True)
controller_url = models.CharField(null=True, blank=True, max_length=1024)
@@ -123,11 +123,6 @@
def __unicode__(self): return u'%s' % (self.name)
- # TODO: Remove when NetworkInstance->Port rename is complete
- @property
- def links(self):
- return self.networkinstances
-
def save(self, *args, **kwds):
if (not self.subnet) and (NO_OBSERVER):
from util.network_subnet_allocator import find_unused_subnet
@@ -211,12 +206,12 @@
qs = NetworkSlice.objects.filter(id__in=slice_ids)
return qs
-class NetworkInstance(PlCoreBase):
+class Port(PlCoreBase):
# Please use "Port" instead of "NetworkInstance". NetworkInstance will soon be
# removed.
- network = models.ForeignKey(Network,related_name='networkinstances')
- instance = models.ForeignKey(Instance, null=True, blank=True, related_name='networkinstances')
+ network = models.ForeignKey(Network,related_name='links')
+ instance = models.ForeignKey(Instance, null=True, blank=True, related_name='ports')
ip = models.GenericIPAddressField(help_text="Instance ip address", blank=True, null=True)
port_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum port id")
mac = models.CharField(null=True, blank=True, max_length=256, help_text="MAC address associated with this port")
@@ -234,11 +229,7 @@
# 3) network's permitAllSlices is true
raise ValueError("Slice %s is not allowed to connect to network %s" % (str(slice), str(self.network)))
- if (not self.ip) and (NO_OBSERVER):
- from util.network_subnet_allocator import find_unused_address
- self.ip = find_unused_address(self.network.subnet,
- [x.ip for x in self.network.networkinstance_set.all()])
- super(NetworkInstance, self).save(*args, **kwds)
+ super(Port, self).save(*args, **kwds)
def __unicode__(self):
if self.instance:
@@ -256,17 +247,12 @@
@staticmethod
def select_by_user(user):
if user.is_admin:
- qs = NetworkInstance.objects.all()
+ qs = Port.objects.all()
else:
- instance_ids = [s.id for s in NetworkInstance.select_by_user(user)]
- qs = NetworkInstance.objects.filter(id__in=instance_ids)
+ instance_ids = [s.id for s in Port.select_by_user(user)]
+ qs = Port.objects.filter(id__in=instance_ids)
return qs
-class Port(NetworkInstance):
- # Rename in progress: NetworkInstance->Port
- class Meta:
- proxy = True
-
class Router(PlCoreBase):
name = models.CharField(max_length=32)
owner = models.ForeignKey(Slice, related_name="routers")
diff --git a/xos/xos/xosapi.py b/xos/xos/xosapi.py
index 62234f2..bec3ea2 100644
--- a/xos/xos/xosapi.py
+++ b/xos/xos/xosapi.py
@@ -212,9 +212,6 @@
url(r'xos/tenantrootprivileges/$', TenantRootPrivilegeList.as_view(), name='tenantrootprivilege-list'),
url(r'xos/tenantrootprivileges/(?P<pk>[a-zA-Z0-9\-]+)/$', TenantRootPrivilegeDetail.as_view(), name ='tenantrootprivilege-detail'),
- url(r'xos/networkinstances/$', NetworkInstanceList.as_view(), name='networkinstance-list'),
- url(r'xos/networkinstances/(?P<pk>[a-zA-Z0-9\-]+)/$', NetworkInstanceDetail.as_view(), name ='networkinstance-detail'),
-
url(r'xos/slicetags/$', SliceTagList.as_view(), name='slicetag-list'),
url(r'xos/slicetags/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceTagDetail.as_view(), name ='slicetag-detail'),
@@ -293,7 +290,6 @@
'deploymentroles': reverse('deploymentrole-list', request=request, format=format),
'usercredentials': reverse('usercredential-list', request=request, format=format),
'tenantrootprivileges': reverse('tenantrootprivilege-list', request=request, format=format),
- 'networkinstances': reverse('networkinstance-list', request=request, format=format),
'slicetags': reverse('slicetag-list', request=request, format=format),
'coarsetenants': reverse('coarsetenant-list', request=request, format=format),
'routers': reverse('router-list', request=request, format=format),
@@ -2532,41 +2528,6 @@
-class NetworkInstanceSerializer(serializers.HyperlinkedModelSerializer):
- id = IdField()
-
- humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
- validators = serializers.SerializerMethodField("getValidators")
- def getHumanReadableName(self, obj):
- return str(obj)
- def getValidators(self, obj):
- try:
- return obj.getValidators()
- except:
- return None
- class Meta:
- model = NetworkInstance
- fields = ('humanReadableName', 'validators', 'id','created','updated','enacted','policed','backend_register','backend_status','deleted','write_protect','lazy_blocked','no_sync','network','instance','ip','port_id','mac',)
-
-class NetworkInstanceIdSerializer(XOSModelSerializer):
- id = IdField()
-
- humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
- validators = serializers.SerializerMethodField("getValidators")
- def getHumanReadableName(self, obj):
- return str(obj)
- def getValidators(self, obj):
- try:
- return obj.getValidators()
- except:
- return None
- class Meta:
- model = NetworkInstance
- fields = ('humanReadableName', 'validators', 'id','created','updated','enacted','policed','backend_register','backend_status','deleted','write_protect','lazy_blocked','no_sync','network','instance','ip','port_id','mac',)
-
-
-
-
class SliceTagSerializer(serializers.HyperlinkedModelSerializer):
id = IdField()
@@ -2876,8 +2837,6 @@
TenantRootPrivilege: TenantRootPrivilegeSerializer,
- NetworkInstance: NetworkInstanceSerializer,
-
SliceTag: SliceTagSerializer,
CoarseTenant: CoarseTenantSerializer,
@@ -5620,53 +5579,6 @@
-class NetworkInstanceList(XOSListCreateAPIView):
- queryset = NetworkInstance.objects.select_related().all()
- serializer_class = NetworkInstanceSerializer
- id_serializer_class = NetworkInstanceIdSerializer
- filter_backends = (filters.DjangoFilterBackend,)
- filter_fields = ('id','created','updated','enacted','policed','backend_register','backend_status','deleted','write_protect','lazy_blocked','no_sync','network','instance','ip','port_id','mac',)
-
- def get_serializer_class(self):
- no_hyperlinks=False
- if hasattr(self.request,"QUERY_PARAMS"):
- no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
- if (no_hyperlinks):
- return self.id_serializer_class
- else:
- return self.serializer_class
-
- def get_queryset(self):
- if (not self.request.user.is_authenticated()):
- raise XOSNotAuthenticated()
- return NetworkInstance.select_by_user(self.request.user)
-
-
-class NetworkInstanceDetail(XOSRetrieveUpdateDestroyAPIView):
- queryset = NetworkInstance.objects.select_related().all()
- serializer_class = NetworkInstanceSerializer
- id_serializer_class = NetworkInstanceIdSerializer
-
- def get_serializer_class(self):
- no_hyperlinks=False
- if hasattr(self.request,"QUERY_PARAMS"):
- no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
- if (no_hyperlinks):
- return self.id_serializer_class
- else:
- return self.serializer_class
-
- def get_queryset(self):
- if (not self.request.user.is_authenticated()):
- raise XOSNotAuthenticated()
- return NetworkInstance.select_by_user(self.request.user)
-
- # update() is handled by XOSRetrieveUpdateDestroyAPIView
-
- # destroy() is handled by XOSRetrieveUpdateDestroyAPIView
-
-
-
class SliceTagList(XOSListCreateAPIView):
queryset = SliceTag.objects.select_related().all()
serializer_class = SliceTagSerializer