fix bugs
diff --git a/plstackapi/core/api/images.py b/plstackapi/core/api/images.py
index ef197a6..8fd6141 100644
--- a/plstackapi/core/api/images.py
+++ b/plstackapi/core/api/images.py
@@ -8,11 +8,11 @@
if isinstance(filter, StringTypes) and filter.isdigit():
filter = int(filter)
if isinstance(filter, int):
- images = image.objects.filter(id=filter)
+ images = Image.objects.filter(id=filter)
elif isinstance(filter, StringTypes):
- images = image.objects.filter(name=filter)
+ images = Image.objects.filter(name=filter)
elif isinstance(filter, dict):
- images = image.objects.filter(**filter)
+ images = Image.objects.filter(**filter)
else:
images = []
return images
diff --git a/plstackapi/core/api/sites.py b/plstackapi/core/api/sites.py
index daf8fa1..b8c463d 100644
--- a/plstackapi/core/api/sites.py
+++ b/plstackapi/core/api/sites.py
@@ -11,7 +11,7 @@
if isinstance(filter, int):
sites = Site.objects.filter(id=filter)
elif isinstance(filter, StringTypes):
- sites = Site.objects.filter(name=filter)
+ sites = Site.objects.filter(login_base=filter)
elif isinstance(filter, dict):
sites = Site.objects.filter(**filter)
else:
@@ -55,7 +55,7 @@
def get_sites(auth, filter={}):
client = auth_check(auth)
- sites = _get_sites(id)
+ sites = _get_sites(filter)
return sites
diff --git a/plstackapi/core/api/slices.py b/plstackapi/core/api/slices.py
index bfbc4d9..1072c07 100644
--- a/plstackapi/core/api/slices.py
+++ b/plstackapi/core/api/slices.py
@@ -1,3 +1,4 @@
+import re
from types import StringTypes
from plstackapi.openstack.client import OpenStackClient
from plstackapi.openstack.driver import OpenStackDriver
@@ -5,6 +6,19 @@
from plstackapi.core.models import Slice
from plstackapi.core.api.sites import _get_sites
+def validate_name(name):
+ # N.B.: Responsibility of the caller to ensure that login_base
+ # portion of the slice name corresponds to a valid site, if
+ # desired.
+
+ # 1. Lowercase.
+ # 2. Begins with login_base (letters or numbers).
+ # 3. Then single underscore after login_base.
+ # 4. Then letters, numbers, or underscores.
+ good_name = r'^[a-z0-9]+_[a-zA-Z0-9_]+$'
+ if not name or \
+ not re.match(good_name, name):
+ raise Exception, "Invalid slice name: %s" % name
def _get_slices(filter):
if isinstance(filter, StringTypes) and filter.isdigit():
@@ -22,9 +36,12 @@
def add_slice(auth, fields):
driver = OpenStackDriver(client = auth_check(auth))
- sites = _get_sites(fields.get('site'))
+ validate_name(fields.get('name'))
+ login_base = fields['name'][:fields['name'].find('_')]
+ sites = _get_sites(login_base)
if sites: fields['site'] = sites[0]
slice = Slice(**fields)
+
# create tenant
nova_fields = {'tenant_name': slice.name,
'description': slice.description,
diff --git a/plstackapi/core/api/slivers.py b/plstackapi/core/api/slivers.py
index f3807ab..0fcc191 100644
--- a/plstackapi/core/api/slivers.py
+++ b/plstackapi/core/api/slivers.py
@@ -27,7 +27,7 @@
def add_sliver(auth, fields):
driver = OpenStackDriver(client = auth_check(auth))
- flavors = _get_flavor(fields.get('flavor'))
+ flavors = _get_flavors(fields.get('flavor'))
if flavors: fields['flavor'] = flavors[0]
images = _get_images(fields.get('image'))
if images: fields['image'] = images[0]
@@ -35,8 +35,8 @@
if keys: fields['key'] = keys[0]
slices = _get_slices(fields.get('slice'))
if slices: fields['slice'] = slices[0]
- deployment_networks = _get_deployment_networks(field.get('deployment_network'))
- if deployment_networks: fields['deployment_network'] = deployment_networks[0]
+ deployment_networks = _get_deployment_networks(fields.get('deploymentNetwork'))
+ if deployment_networks: fields['deploymentNetwork'] = deployment_networks[0]
nodes = _get_nodes(fields.get('node'))
if nodes: fields['node'] = nodess[0]
diff --git a/plstackapi/core/api/subnets.py b/plstackapi/core/api/subnets.py
index 33a0269..6ef051e 100644
--- a/plstackapi/core/api/subnets.py
+++ b/plstackapi/core/api/subnets.py
@@ -11,7 +11,11 @@
if isinstance(filter, int):
subnets = Subnet.objects.filter(id=filter)
elif isinstance(filter, StringTypes):
- subnets = Subnet.objects.filter(name=filter)
+ # the name is the subnet's slice's name
+ slices = _get_slices(filter)
+ slice = None
+ if slices: slice=slices[0]
+ subnets = Subnet.objects.filter(slice=slice)
elif isinstance(filter, dict):
subnets = Subnet.objects.filter(**filter)
else:
@@ -20,11 +24,11 @@
def add_subnet(auth, fields):
driver = OpenStackDriver(client = auth_check(auth))
- slices = _get_slice(fields.get('slice'))
+ slices = _get_slices(fields.get('slice'))
if slices: fields['slice'] = slices[0]
subnet = Subnet(**fields)
# create quantum subnet
- subnet = driver.create_subnet(network_name=subnet.name,
+ subnet = driver.create_subnet(network_name=subnet.slice.name,
cidr_ip = subnet.cidr,
ip_version=subnet.ip_version,
start = subnet.start,
diff --git a/plstackapi/core/api/users.py b/plstackapi/core/api/users.py
index b2ba681..7483c37 100644
--- a/plstackapi/core/api/users.py
+++ b/plstackapi/core/api/users.py
@@ -11,7 +11,7 @@
if isinstance(filter, int):
users = User.objects.filter(id=filter)
elif isinstance(filter, StringTypes):
- users = User.objects.filter(role_type=filter)
+ users = User.objects.filter(email=filter)
elif isinstance(filter, dict):
users = User.objects.filter(**filter)
else:
diff --git a/plstackapi/core/models/sliver.py b/plstackapi/core/models/sliver.py
index 9d5857e..1c4065f 100644
--- a/plstackapi/core/models/sliver.py
+++ b/plstackapi/core/models/sliver.py
@@ -14,12 +14,12 @@
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')
+ flavor = models.ForeignKey(Flavor, related_name='slivers')
+ image = models.ForeignKey(Image, related_name='slivers')
+ key = models.ForeignKey(Key, related_name='slivers')
+ slice = models.ForeignKey(Slice, related_name='slivers')
+ node = models.ForeignKey(Node, related_name='slivers')
+ site = models.ForeignKey(Site, related_name='slivers')
deploymentNetwork = models.ForeignKey(DeploymentNetwork, related_name='sliver_deploymentNetwork')
def __unicode__(self): return u'%s::%s' % (self.slice, self.deploymentNetwork)
diff --git a/plstackapi/core/models/subnet.py b/plstackapi/core/models/subnet.py
index 70f8176..4ea2c40 100644
--- a/plstackapi/core/models/subnet.py
+++ b/plstackapi/core/models/subnet.py
@@ -12,7 +12,7 @@
ip_version = models.IntegerField()
start = models.IPAddressField()
end = models.IPAddressField()
- slice = models.ForeignKey(Slice, related_name='slice_subnet')
+ slice = models.ForeignKey(Slice, related_name='subnet')
def __unicode__(self): return u'%s' % (self.name)
diff --git a/plstackapi/core/serializers.py b/plstackapi/core/serializers.py
index f6fbe8c..206c1e0 100644
--- a/plstackapi/core/serializers.py
+++ b/plstackapi/core/serializers.py
@@ -52,7 +52,7 @@
id = serializers.Field()
site = serializers.HyperlinkedRelatedField(view_name='site-detail')
slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail')
- subnets = serializers.HyperlinkedRelatedField(view_name='subnet-detail')
+ subnet= serializers.HyperlinkedRelatedField(view_name='subnet-detail')
class Meta:
model = Slice
fields = ('id',
@@ -68,7 +68,7 @@
'router_id',
'site',
'slivers',
- 'subnets',
+ 'subnet',
'updated',
'created')
@@ -106,14 +106,12 @@
# HyperlinkedModelSerializer doesn't include the id by default
id = serializers.Field()
slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
- deployment_networks = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='deploymentnetwork-detail')
class Meta:
model = Site
fields = ('id',
'url',
'name',
- 'deployment_networks',
'slices',
'site_url',
'enabled',
diff --git a/plstackapi/core/views/deployment_networks.py b/plstackapi/core/views/deployment_networks.py
index 60e8b14..d57962a 100644
--- a/plstackapi/core/views/deployment_networks.py
+++ b/plstackapi/core/views/deployment_networks.py
@@ -17,8 +17,8 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'deployment_network' in data:
- deployment = add_deployment_network(data['auth'], data['deployment_network'].get('name'))
+ elif 'deploymentNetwork' in data:
+ deployment = add_deployment_network(data['auth'], data['deploymentNetwork'].get('name'))
serializer = DeploymentNetworkSerializer(deployment)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
diff --git a/plstackapi/core/views/roles.py b/plstackapi/core/views/roles.py
index 74fe789..b8c279c 100644
--- a/plstackapi/core/views/roles.py
+++ b/plstackapi/core/views/roles.py
@@ -18,7 +18,7 @@
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
elif 'role' in data:
- role = add_role(data['auth'], data['role']['name'])
+ role = add_role(data['auth'], data['role']['role_type'])
serializer = RoleSerializer(data=role)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else: