factor out the imageselect stuff, make way for parameters
diff --git a/xos/tosca/execute.py b/xos/tosca/execute.py
index 7160ec4..4f74d28 100644
--- a/xos/tosca/execute.py
+++ b/xos/tosca/execute.py
@@ -7,6 +7,7 @@
from core.models import Slice,Sliver,User,Flavor,Node,Image
from nodeselect import XOSNodeSelector
+from imageselect import XOSImageSelector
class XOSTosca(object):
def __init__(self, tosca_yaml, parent_dir=None):
@@ -39,7 +40,7 @@
# TODO: pick flavor based on parameters
flavor = Flavor.objects.get(name="m1.small")
- compute_node = XOSNodeSelector(user).get_nodes(1)[0]
+ compute_node = XOSNodeSelector(user, mem_size=mem_size, num_cpus=num_cpus, disk_size=disk_size).get_nodes(1)[0]
return (compute_node, flavor)
@@ -49,12 +50,7 @@
type = v.get_property_value("type")
architecture = v.get_property_value("architecture")
- # TODO: pick image based on parameters
-
- imgs=Image.objects.filter(name="Ubuntu 14.04 LTS") # portal
- if imgs:
- return imgs[0]
- return Image.objects.get(name="Ubuntu-14.04-LTS") # demo
+ return XOSImageSelector(user, distribution=distribution, version=version, type=type, architecture=architecture).get_image()
def execute_nodetemplate(self, user, nodetemplate):
if (nodetemplate.type == "tosca.nodes.Slice"):
@@ -79,14 +75,6 @@
if not sliceName:
raise Exception("No slice requirement for node %s" % nodetemplate.name)
- #sliceName = None
- #artifacts = nodetemplate.entity_tpl.get("artifacts",[])
- #for artifact in artifacts:
- # if artifact.get("xos_slice", None):
- # sliceName = artifact["xos_slice"]
- #if not sliceName:
- # raise Exception("No xos_slice artifact for node %s" % nodetemplate.name)
-
slice = Slice.objects.filter(name=sliceName)
if not slice:
raise Exception("Could not find slice %s" % sliceName)
diff --git a/xos/tosca/imageselect.py b/xos/tosca/imageselect.py
new file mode 100644
index 0000000..2c0064f
--- /dev/null
+++ b/xos/tosca/imageselect.py
@@ -0,0 +1,29 @@
+import os
+import sys
+
+from core.models import User,Image
+
+class XOSImageSelector(object):
+ def __init__(self, user, distribution=None, type=None, architecture=None, version=None):
+ self.user = user
+
+ def get_allowed_images(self):
+ # TODO: logic to get images that the user can use
+ nodes = Image.objects.all()
+ return nodes
+
+ def get_image(self):
+ images = self.get_allowed_images()
+
+ # TODO: pick image based on parameters
+
+ found_imgs=images.filter(name="Ubuntu 14.04 LTS") # portal
+ if found_imgs:
+ return found_imgs[0]
+
+ found_imgs=images.filter(name="Ubuntu-14.04-LTS") # demo
+ if found_imgs:
+ return found_imgs[0]
+
+ raise Exception("Failed to find an acceptable image")
+
diff --git a/xos/tosca/nodeselect.py b/xos/tosca/nodeselect.py
index f139de7..8badb14 100644
--- a/xos/tosca/nodeselect.py
+++ b/xos/tosca/nodeselect.py
@@ -1,14 +1,10 @@
import os
import sys
-sys.path.append("/opt/xos")
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
-import django
-django.setup()
from core.models import Slice,Sliver,User,Flavor,Node,Image
class XOSNodeSelector(object):
- def __init__(self, user):
+ def __init__(self, user, mem_size=None, num_cpus=None, disk_size=None):
self.user = user
def get_allowed_nodes(self):