Decomposed models.py into models/ with individual files per topic. Added new admin views, consolidated/reverted views back to Generics, adjusted modeling of Site<->DeploymentNetwork to remove SiteDeploymentNetwork object
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index c3b655f..36c1bf9 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -1,18 +1,113 @@
+from plstackapi.core.models import Site
from plstackapi.core.models import *
from django.contrib import admin
+from django import forms
from django.contrib.auth.admin import UserAdmin
-from django.contrib.auth.models import User
+from django.contrib.admin.widgets import FilteredSelectMultiple
-admin.site.register(Role)
-admin.site.register(Site)
-#admin.site.register(User)
-admin.site.register(Key)
-admin.site.register(Slice)
-admin.site.register(Node)
-admin.site.register(DeploymentNetwork)
-admin.site.register(SiteDeploymentNetwork)
+
+class ReadonlyTabularInline(admin.TabularInline):
+ can_delete = False
+ extra = 0
+ editable_fields = []
+
+ def get_readonly_fields(self, request, obj=None):
+ fields = []
+ for field in self.model._meta.get_all_field_names():
+ if (not field == 'id'):
+ if (field not in self.editable_fields):
+ fields.append(field)
+ return fields
+
+ def has_add_permission(self, request):
+ return False
+
+class SliverInline(admin.TabularInline):
+ model = Sliver
+ extra = 0
+
+class SiteInline(admin.TabularInline):
+ model = Site
+ extra = 0
+
+class NodeInline(admin.TabularInline):
+ model = Node
+ extra = 0
+
+class PlanetStackBaseAdmin(admin.ModelAdmin):
+ save_on_top = False
+
+class DeploymentNetworkAdminForm(forms.ModelForm):
+ sites = forms.ModelMultipleChoiceField(
+ queryset=Site.objects.all(),
+ required=False,
+ widget=FilteredSelectMultiple(
+ verbose_name=('Sites'), is_stacked=False
+ )
+ )
+ class Meta:
+ model = DeploymentNetwork
+
+ def __init__(self, *args, **kwargs):
+ super(DeploymentNetworkAdminForm, self).__init__(*args, **kwargs)
+
+ if self.instance and self.instance.pk:
+ self.fields['sites'].initial = self.instance.sites.all()
+
+ def save(self, commit=True):
+ deploymentNetwork = super(DeploymentNetworkAdminForm, self).save(commit=False)
+
+ if commit:
+ deploymentNetwork.save()
+
+ if deploymentNetwork.pk:
+ deploymentNetwork.sites = self.cleaned_data['sites']
+ self.save_m2m()
+
+ return deploymentNetwork
+
+class DeploymentNetworkAdmin(PlanetStackBaseAdmin):
+ form = DeploymentNetworkAdminForm
+ inlines = [NodeInline,]
+
+class SiteAdmin(admin.ModelAdmin):
+ fieldsets = [
+ (None, {'fields': ['name', 'site_url', 'enabled', 'is_public', 'login_base']}),
+ ('Location', {'fields': ['latitude', 'longitude']}),
+ ('Deployment Networks', {'fields': ['deployments']})
+ ]
+ list_display = ('name', 'login_base','site_url', 'enabled')
+ filter_horizontal = ('deployments',)
+ inlines = [NodeInline,]
+ search_fields = ['name']
+
+class SliceAdmin(PlanetStackBaseAdmin):
+ fields = ['name', 'site', 'instantiation', 'description', 'slice_url']
+ list_display = ('name', 'site','slice_url', 'instantiation')
+ inlines = [SliverInline]
+
+class SubnetAdmin(admin.ModelAdmin):
+ fields = ['cidr', 'ip_version', 'start', 'end', 'slice']
+
+class ImageAdmin(admin.ModelAdmin):
+ fields = ['image_id', 'name', 'disk_format', 'container_format']
+
+class NodeAdmin(admin.ModelAdmin):
+ list_display = ('name', 'site', 'deploymentNetwork')
+ list_filter = ('deploymentNetwork',)
+
+admin.site.register(Site, SiteAdmin)
+admin.site.register(SitePrivilege)
+admin.site.register(Slice, SliceAdmin)
+admin.site.register(SliceMembership)
+admin.site.register(Subnet, SubnetAdmin)
+admin.site.register(Image, ImageAdmin)
+admin.site.register(Node, NodeAdmin)
admin.site.register(Sliver)
-admin.site.register(Image)
admin.site.register(Flavor)
+admin.site.register(Key)
+admin.site.register(Role)
+admin.site.register(User)
+admin.site.register(DeploymentNetwork, DeploymentNetworkAdmin)
diff --git a/plstackapi/core/models/__init__.py b/plstackapi/core/models/__init__.py
new file mode 100644
index 0000000..1ecda7e
--- /dev/null
+++ b/plstackapi/core/models/__init__.py
@@ -0,0 +1,15 @@
+from .plcorebase import PlCoreBase
+from .deploymentnetwork import DeploymentNetwork
+from .site import Site
+from .site import SitePrivilege
+from .flavor import Flavor
+from .image import Image
+from .user import User
+from .role import Role
+from .key import Key
+from .node import Node
+from .slice import Slice
+from .slice import SliceMembership
+from .sliver import Sliver
+from .subnet import Subnet
+
diff --git a/plstackapi/core/models/deploymentnetwork.py b/plstackapi/core/models/deploymentnetwork.py
new file mode 100644
index 0000000..740be33
--- /dev/null
+++ b/plstackapi/core/models/deploymentnetwork.py
@@ -0,0 +1,11 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+
+# Create your models here.
+
+class DeploymentNetwork(PlCoreBase):
+ name = models.CharField(max_length=200, unique=True, help_text="Name of the Deployment Network")
+
+ def __unicode__(self): return u'%s' % (self.name)
+
diff --git a/plstackapi/core/models/flavor.py b/plstackapi/core/models/flavor.py
new file mode 100644
index 0000000..3081f82
--- /dev/null
+++ b/plstackapi/core/models/flavor.py
@@ -0,0 +1,14 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+
+# Create your models here.
+
+class Flavor(PlCoreBase):
+ flavor_id = models.IntegerField(unique=True)
+ name = models.CharField(max_length=256, unique=True)
+ memory_mb = models.IntegerField()
+ disk_gb = models.IntegerField()
+ vcpus = models.IntegerField()
+
+ def __unicode__(self): return u'%s' % (self.name)
diff --git a/plstackapi/core/models/image.py b/plstackapi/core/models/image.py
new file mode 100644
index 0000000..930b7df
--- /dev/null
+++ b/plstackapi/core/models/image.py
@@ -0,0 +1,13 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+
+# Create your models here.
+
+class Image(PlCoreBase):
+ image_id = models.CharField(max_length=256, unique=True)
+ name = models.CharField(max_length=256, unique=True)
+ disk_format = models.CharField(max_length=256)
+ container_format = models.CharField(max_length=256)
+
+ def __unicode__(self): return u'%s' % (self.name)
diff --git a/plstackapi/core/models/key.py b/plstackapi/core/models/key.py
new file mode 100644
index 0000000..d0a0a07
--- /dev/null
+++ b/plstackapi/core/models/key.py
@@ -0,0 +1,15 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import User
+
+# Create your models here.
+
+class Key(PlCoreBase):
+ name = models.CharField(max_length=256, unique=True)
+ key = models.CharField(max_length=512)
+ type = models.CharField(max_length=256)
+ blacklisted = models.BooleanField(default=False)
+ user = models.ForeignKey(User, related_name='keys')
+
+ def __unicode__(self): return u'%s' % (self.name)
diff --git a/plstackapi/core/models/node.py b/plstackapi/core/models/node.py
new file mode 100644
index 0000000..a4252b1
--- /dev/null
+++ b/plstackapi/core/models/node.py
@@ -0,0 +1,14 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import Site
+from plstackapi.core.models import DeploymentNetwork
+
+# Create your models here.
+
+class Node(PlCoreBase):
+ name = models.CharField(max_length=200, unique=True, help_text="Name of the Node")
+ site = models.ForeignKey(Site, related_name='nodes')
+ deploymentNetwork = models.ForeignKey(DeploymentNetwork, related_name='nodes')
+
+ def __unicode__(self): return u'%s' % (self.name)
diff --git a/plstackapi/core/models/plcorebase.py b/plstackapi/core/models/plcorebase.py
new file mode 100644
index 0000000..52aa0f7
--- /dev/null
+++ b/plstackapi/core/models/plcorebase.py
@@ -0,0 +1,14 @@
+import os
+from django.db import models
+
+class PlCoreBase(models.Model):
+
+ created = models.DateTimeField(auto_now_add=True)
+ updated = models.DateTimeField(auto_now=True)
+
+ class Meta:
+ abstract = True
+ app_label = "core"
+
+
+
diff --git a/plstackapi/core/models/role.py b/plstackapi/core/models/role.py
new file mode 100644
index 0000000..7b3268c
--- /dev/null
+++ b/plstackapi/core/models/role.py
@@ -0,0 +1,20 @@
+import os
+import datetime
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+
+# Create your models here.
+
+class Role(PlCoreBase):
+
+ ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
+ role_id = models.CharField(max_length=256, unique=True)
+ role_type = models.CharField(max_length=80, unique=True, choices=ROLE_CHOICES)
+
+ def __unicode__(self): return u'%s' % (self.role_type)
+
+ def save(self):
+ if not self.id:
+ self.created = datetime.date.today()
+ self.updated = datetime.datetime.today()
+ super(Role, self).save()
diff --git a/plstackapi/core/models/site.py b/plstackapi/core/models/site.py
new file mode 100644
index 0000000..5ec04c4
--- /dev/null
+++ b/plstackapi/core/models/site.py
@@ -0,0 +1,49 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import DeploymentNetwork
+
+from plstackapi.openstack.driver import OpenStackDriver
+
+# Create your models here.
+
+
+class Site(PlCoreBase):
+
+ tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
+ name = models.CharField(max_length=200, help_text="Name for this Site")
+ site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page")
+ enabled = models.BooleanField(default=True, help_text="Status for this Site")
+ longitude = models.FloatField(null=True, blank=True)
+ latitude = models.FloatField(null=True, blank=True)
+ login_base = models.CharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site")
+ is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members")
+ abbreviated_name = models.CharField(max_length=80)
+
+ deployments = models.ManyToManyField(DeploymentNetwork, blank=True, related_name='sites')
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+class SitePrivilege(PlCoreBase):
+
+ user = models.ForeignKey('User', related_name='site_privileges')
+ site = models.ForeignKey('Site', related_name='site_privileges')
+ role = models.ForeignKey('Role')
+
+ def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
+
+ def save(self, *args, **kwds):
+ driver = OpenStackDriver()
+ driver.add_user_role(user_id=user.user_id,
+ tenant_id=site.tenant_id,
+ role_name=role.name)
+ super(SitePrivilege, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ driver = OpenStackDriver()
+ driver.delete_user_role(user_id=user.user_id,
+ tenant_id=site.tenant_id,
+ role_name=role.name)
+ super(SitePrivilege, self).delete(*args, **kwds)
+
+
diff --git a/plstackapi/core/models/slice.py b/plstackapi/core/models/slice.py
new file mode 100644
index 0000000..24c44a6
--- /dev/null
+++ b/plstackapi/core/models/slice.py
@@ -0,0 +1,76 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import Site
+from plstackapi.core.models import User
+from plstackapi.core.models import Role
+from plstackapi.core.models import DeploymentNetwork
+
+from plstackapi.openstack.driver import OpenStackDriver
+
+# Create your models here.
+
+class Slice(PlCoreBase):
+ tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
+ name = models.CharField(help_text="The Name of the Slice", max_length=80)
+ enabled = models.BooleanField(default=True, help_text="Status for this Slice")
+ SLICE_CHOICES = (('plc', 'PLC'), ('delegated', 'Delegated'), ('controller','Controller'), ('none','None'))
+ instantiation = models.CharField(help_text="The instantiation type of the slice", max_length=80, choices=SLICE_CHOICES)
+ omf_friendly = models.BooleanField()
+ description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024)
+ slice_url = models.URLField(blank=True, max_length=512)
+ site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Node belongs too")
+ network_id = models.CharField(max_length=256, help_text="Quantum network")
+ router_id = models.CharField(max_length=256, help_text="Quantum router id")
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+ def save(self, *args, **kwds):
+ # sync keystone tenant
+ driver = OpenStackDriver()
+
+ if not self.id:
+ tenant = driver.create_tenant(tenant_name=self.name,
+ description=self.description,
+ enabled=self.enabled)
+ self.tenant_id = tenant.id
+
+ # create a network
+ network = driver.create_network(name=self.name)
+ self.network_id = network['id']
+ # create router
+ router = driver.create_router(name=self.name)
+ self.router_id = router['id']
+
+/bin/sh: 1: command not found
+ # update record
+ self.driver.update_tenant(self.tenant_id, name=self.name,
+ description=self.description, enabled=self.enabled)
+ super(Slice, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ # delete keystone tenant
+ driver = OpenStackDriver()
+ driver.delete_tenant(self.tenant_id)
+ super(Slice, self).delete(*args, **kwds)
+
+class SliceMembership(PlCoreBase):
+ user = models.ForeignKey('User', related_name='slice_memberships')
+ slice = models.ForeignKey('Slice', related_name='slice_memberships')
+ role = models.ForeignKey('Role')
+
+ def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role)
+
+ def save(self, *args, **kwds):
+ driver = OpenStackDriver()
+ driver.add_user_role(user_id=user.user_id,
+ tenant_id=slice.tenant_id,
+ role_name=role.name)
+ super(SliceMembership, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ driver = OpenStackDriver()
+ driver.delete_user_role(user_id=user.user_id,
+ tenant_id=slice.tenant_id,
+ role_name=role.name)
+ super(SliceMembership, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/sliver.py b/plstackapi/core/models/sliver.py
new file mode 100644
index 0000000..6f7aabe
--- /dev/null
+++ b/plstackapi/core/models/sliver.py
@@ -0,0 +1,41 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import Flavor
+from plstackapi.core.models import Image
+from plstackapi.core.models import Key
+from plstackapi.core.models import Slice
+from plstackapi.core.models import Node
+from plstackapi.core.models import Site
+from plstackapi.core.models import DeploymentNetwork
+from plstackapi.openstack.driver import OpenStackDriver
+
+# Create your models here.
+class Sliver(PlCoreBase):
+ instance_id = models.CharField(max_length=200, help_text="Nova instance id")
+ name = models.CharField(max_length=200, help_text="Sliver name")
+ flavor = models.ForeignKey(Flavor, related_name='sliver_flavor')
+ image = models.ForeignKey(Image, related_name='sliver_image')
+ key = models.ForeignKey(Key, related_name='sliver_key')
+ slice = models.ForeignKey(Slice, related_name='sliver_slice')
+ node = models.ForeignKey(Node, related_name='sliver_node')
+ site = models.ForeignKey(Site, related_name='sliver_site')
+ deploymentNetwork = models.ForeignKey(DeploymentNetwork, related_name='sliver_deploymentNetwork')
+
+ def __unicode__(self): return u'%s::%s' % (self.slice, self.siteDeploymentNetwork)
+
+ def save(self, *args, **kwds):
+ driver = OpenStackDriver()
+ instance = driver.spawn_instances(name=self.name,
+ keyname=self.name,
+ hostnames=self.node.name,
+ flavor=self.flavor.name,
+ image=self.image.name)
+ self.instance_id = instance.id
+ super(Sliver, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ driver = OpenStackDriver()
+ driver.destroy_instance(name=self.name, id=self.instance_id)
+ super(Sliver, self).delete(*args, **kwds)
+
diff --git a/plstackapi/core/models/subnet.py b/plstackapi/core/models/subnet.py
new file mode 100644
index 0000000..291ffe8
--- /dev/null
+++ b/plstackapi/core/models/subnet.py
@@ -0,0 +1,41 @@
+import os
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import Slice
+from plstackapi.openstack.driver import OpenStackDriver
+
+# Create your models here.
+
+class Subnet(PlCoreBase):
+ subnet_id = models.CharField(max_length=256, unique=True)
+ cidr = models.CharField(max_length=20)
+ ip_version = models.IntegerField()
+ start = models.IPAddressField()
+ end = models.IPAddressField()
+ slice = models.ForeignKey(Slice, related_name='slice_subnet')
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+ def save(self, *args, **kwargs):
+ driver = OpenStackDriver()
+ if not self.id:
+ subnet = driver.create_subnet(network_name=self.slice.name,
+ cidr_ip = self.cidr,
+ ip_version=self.ip_version,
+ start = self.start,
+ end = self.end)
+
+ self.subnet_id = subnet.id
+
+ # add subnet as interface to slice router
+ driver.add_router_interface(self.slice.router_id, subnet.id)
+
+ super(Subnet, self).save(*args, **kwargs)
+
+
+ def delete(self, *args, **kwargs):
+ # delete quantum network
+ driver = OpenStackDriver()
+ driver.delete_subnet(self.subnet_id)
+ driver.delete_router_interface(self.slice.router_id, self.subnet.id)
+ super(Subnet, self).delete(*args, **kwargs)
diff --git a/plstackapi/core/models/user.py b/plstackapi/core/models/user.py
new file mode 100644
index 0000000..765fb62
--- /dev/null
+++ b/plstackapi/core/models/user.py
@@ -0,0 +1,20 @@
+import os
+import datetime
+from django.db import models
+from plstackapi.core.models import PlCoreBase
+from plstackapi.core.models import Site
+
+# Create your models here.
+
+class User(PlCoreBase):
+ user_id = models.CharField(max_length=256, unique=True)
+ firstname = models.CharField(help_text="person's given name", max_length=200)
+ lastname = models.CharField(help_text="person's surname", max_length=200)
+ email = models.EmailField(help_text="e-mail address")
+ phone = models.CharField(null=True, blank=True, help_text="phone number contact", max_length=100)
+ user_url = models.URLField(null=True, blank=True)
+ is_admin = models.BooleanField(default=False)
+ enabled = models.BooleanField(default=True, help_text="Status for this User")
+ site = models.ForeignKey(Site, related_name='users', verbose_name="Site this user will be homed too")
+
+ def __unicode__(self): return u'%s' % (self.email)
diff --git a/plstackapi/core/urls.py b/plstackapi/core/urls.py
index 5a97354..e4bf5c3 100644
--- a/plstackapi/core/urls.py
+++ b/plstackapi/core/urls.py
@@ -2,16 +2,9 @@
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
-from plstackapi.core.views.roles import RoleListCreate, RoleRetrieveUpdateDestroy
-from plstackapi.core.views.sites import SiteListCreate, SiteRetrieveUpdateDestroy
-from plstackapi.core.views.users import UserListCreate, UserRetrieveUpdateDestroy
-from plstackapi.core.views.slices import SliceListCreate, SliceRetrieveUpdateDestroy
-from plstackapi.core.views.keys import KeyListCreate, KeyRetrieveUpdateDestroy
-from plstackapi.core.views.deployment_networks import DeploymentNetworkListCreate, DeploymentNetworkRetrieveUpdateDestroy
-from plstackapi.core.views.images import ImageListCreate, ImageRetrieveUpdateDestroy
-from plstackapi.core.views.flavors import FlavorListCreate, FlavorRetrieveUpdateDestroy
+from plstackapi.core import views
+from plstackapi.core.views import api_root
from plstackapi.core.models import Site
-from plstackapi.core.api_root import api_root
from rest_framework import generics
admin.autodiscover()
@@ -28,41 +21,22 @@
url(r'^admin/', include(admin.site.urls)),
url(r'^plstackapi/$', api_root),
-
- url(r'^plstackapi/roles/$', RoleListCreate.as_view(), name='role-list'),
- url(r'^plstackapi/roles/(?P<pk>[a-zA-Z0-9]+)/$', RoleRetrieveUpdateDestroy.as_view(), name='role-detail'),
+ url(r'^plstackapi/sites/$', views.SiteList.as_view(), name='site-list'),
+ url(r'^plstackapi/sites/(?P<pk>[0-9]+)/$', views.SiteDetail.as_view(), name='site-detail'),
- url(r'^plstackapi/users/$', UserListCreate.as_view(), name='user-list'),
- url(r'^plstackapi/users/(?P<pk>[a-zA-Z0-9]+)/$', UserRetrieveUpdateDestroy.as_view(), name='user-detail'),
+ url(r'^plstackapi/slices/$', views.SliceList.as_view(), name='slice-list'),
+ url(r'^plstackapi/slices/(?P<pk>[0-9]+)/$', views.SliceDetail.as_view(), name='slice-detail'),
- url(r'^plstackapi/keys/$', KeyListCreate.as_view(), name='key-list'),
- url(r'^plstackapi/keys/(?P<pk>[a-zA-Z0-9]+)/$', KeyRetrieveUpdateDestroy.as_view(), name='key-detail'),
+ url(r'^plstackapi/slivers/$', views.SliverList.as_view()),
+ url(r'^plstackapi/slivers/(?P<pk>[0-9]+)/$', views.SliverDetail.as_view()),
- url(r'^plstackapi/sites/$', SiteListCreate.as_view(), name='site-list'),
- url(r'^plstackapi/sites/(?P<pk>[a-zA-Z0-9_]+)/$', SiteRetrieveUpdateDestroy.as_view(), name='site-detail'),
+ url(r'^plstackapi/nodes/$', views.NodeList.as_view(), name='node-list'),
+ url(r'^plstackapi/nodes/(?P<pk>[0-9]+)/$', views.NodeDetail.as_view(), name='node-detail'),
+
+ url(r'^plstackapi/deploymentnetworks/$', views.DeploymentNetworkList.as_view(), name='deploymentnetwork-list'),
+ url(r'^plstackapi/deploymentnetworks/(?P<pk>[0-9]+)/$', views.DeploymentNetworkDetail.as_view(), name='deploymentnetwork-detail'),
- url(r'^plstackapi/slices/$', SliceListCreate.as_view(), name='slice-list'),
- url(r'^plstackapi/slices/(?P<pk>[0-9]+)/$', SliceRetrieveUpdateDestroy.as_view(), name='slice-detail'),
-
- #url(r'^plstackapi/slivers/$', views.SliverList.as_view()),
- #url(r'^plstackapi/slivers/(?P<pk>[0-9]+)/$', views.SliverDetail.as_view()),
-
- #url(r'^plstackapi/nodes/$', views.NodeList.as_view(), name='node-list'),
- #url(r'^plstackapi/nodes/(?P<pk>[0-9]+)/$', views.NodeDetail.as_view(), name='node-detail'),
-
-
- url(r'^plstackapi/deploymentnetworks/$', DeploymentNetworkListCreate.as_view(), name='deploymentnetwork-list'),
- url(r'^plstackapi/deploymentnetworks/(?P<pk>[a-zA-Z0-9]+)/$', DeploymentNetworkRetrieveUpdateDestroy.as_view(), name='deploymentnetwork-detail'),
-
- #url(r'^plstackapi/sitedeploymentnetworks/$', views.SiteDeploymentNetworkList.as_view(), name='sitedeploymentnetwork-list'),
- #url(r'^plstackapi/sitedeploymentnetworks/(?P<pk>[0-9]+)/$', views.SiteDeploymentNetworkDetail.as_view(), name='sitedeploymentnetwork-detail'),
-
- url(r'^plstackapi/images/$', ImageListCreate.as_view(), name='image-list'),
- url(r'^plstackapi/images/(?P<pk>[a-zA-Z0-9_]+)/$', ImageRetrieveUpdateDestroy.as_view(), name='image-detail'),
-
- url(r'^plstackapi/flavors/$', FlavorListCreate.as_view(), name='flavor-list'),
- url(r'^plstackapi/flavors/(?P<pk>[a-zA-Z0-9_]+)/$', FlavorRetrieveUpdateDestroy.as_view(), name='flavor-detail'),
#Adding in rest_framework urls
url(r'^plstackapi/', include('rest_framework.urls', namespace='rest_framework')),
diff --git a/plstackapi/core/views.py b/plstackapi/core/views.py
new file mode 100644
index 0000000..c2730bb
--- /dev/null
+++ b/plstackapi/core/views.py
@@ -0,0 +1,58 @@
+# Create your views here.
+
+from plstackapi.core.models import Site
+from serializers import *
+from rest_framework import generics
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import renderers
+
+@api_view(['GET'])
+def api_root(request, format=None):
+ return Response({
+ 'nodes': reverse('node-list', request=request, format=format),
+ 'sites': reverse('site-list', request=request, format=format),
+ 'deploymentNetworks': reverse('deploymentnetwork-list', request=request, format=format),
+ 'slices': reverse('slice-list', request=request, format=format)
+ })
+
+class SiteList(generics.ListCreateAPIView):
+ model=Site
+ serializer_class = SiteSerializer
+
+class SiteDetail(generics.RetrieveUpdateDestroyAPIView):
+ model = Site
+ serializer_class = SiteSerializer
+
+class SliceList(generics.ListCreateAPIView):
+ model=Slice
+ serializer_class = SliceSerializer
+
+class SliceDetail(generics.RetrieveUpdateDestroyAPIView):
+ model = Slice
+ serializer_class = SliceSerializer
+
+class NodeList(generics.ListCreateAPIView):
+ model=Node
+ serializer_class = NodeSerializer
+
+class NodeDetail(generics.RetrieveUpdateDestroyAPIView):
+ model = Node
+ serializer_class = NodeSerializer
+
+class SliverList(generics.ListCreateAPIView):
+ model=Sliver
+ serializer_class = SliverSerializer
+
+class SliverDetail(generics.RetrieveUpdateDestroyAPIView):
+ model = Sliver
+ serializer_class = SliverSerializer
+
+class DeploymentNetworkList(generics.ListCreateAPIView):
+ model=DeploymentNetwork
+ serializer_class = DeploymentNetworkSerializer
+
+class DeploymentNetworkDetail(generics.RetrieveUpdateDestroyAPIView):
+ model = DeploymentNetwork
+ serializer_class = DeploymentNetworkSerializer