added 'image_name' property to vPGWC Tenant model
you can now choose which VM you want for a given instance
in tosca using the 'image_name' property
Change-Id: I2f889caf6640d96c18f2cb006d3270cd8cb4555a
diff --git a/xos/admin.py b/xos/admin.py
index 9055b3b..d9fafe5 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -111,6 +111,8 @@
self.fields['creator'].initial = self.instance.creator
self.fields[
'display_message'].initial = self.instance.display_message
+ self.fields[
+ 'image_name'].initial = self.instance.image_name
# If there is not an instance then we need to set initial values.
if (not self.instance) or (not self.instance.pk):
@@ -134,8 +136,8 @@
verbose_name_plural = "vPGWC Service Tenants"
form = VPGWCTenantForm
- list_display = ('id', 'backend_status_icon', 'instance', 'display_message')
- list_display_links = ('backend_status_icon', 'instance', 'display_message', 'id')
+ list_display = ('id', 'backend_status_icon', 'instance', 'display_message', 'image_name')
+ list_display_links = ('backend_status_icon', 'instance', 'display_message', 'id', 'image_name')
fieldsets = [(None, {'fields': ['backend_status_text', 'kind',
'provider_service', 'instance', 'creator',
'display_message'],
diff --git a/xos/models.py b/xos/models.py
index 987260b..f52a8ac 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -60,7 +60,7 @@
# default_attributes is used cleanly indicate what the default values for
# the fields are.
- default_attributes = {"display_message": "New vPGWC Component", "s5s8_pgw_tag": "300"}
+ default_attributes = {"display_message": "New vPGWC Component", "s5s8_pgw_tag": "300", "image_name": "default"}
def __init__(self, *args, **kwargs):
pgwc_services = VPGWCService.get_service_objects().all()
# When the tenant is created the default service in the form is set
@@ -183,6 +183,15 @@
(a, b, c, d) = ip.split('.')
return "02:42:%02x:%02x:%02x:%02x" % (int(a), int(b), int(c), int(d))
+
+ @property
+ def image(self):
+ img = self.image_name.strip()
+ if img.lower() != "default":
+ return Image.objects.get(name=img)
+ else:
+ return super(VMMETenant, self).image
+
# Getter for the message that will appear on the webpage
# By default it is "Hello World!"
@property
@@ -196,6 +205,16 @@
self.set_attribute("display_message", value)
@property
+ def image_name(self):
+ return self.get_attribute(
+ "image_name",
+ self.default_attributes['image_name'])
+
+ @image_name.setter
+ def image_name(self, value):
+ self.set_attribute("image_name", value)
+
+ @property
def s5s8_pgw_tag(self):
return self.get_attribute(
"s5s8_pgw_tag",
diff --git a/xos/synchronizer/steps/sync_vpgwc.py b/xos/synchronizer/steps/sync_vpgwc.py
index bbfc0a8..d9ec4f0 100644
--- a/xos/synchronizer/steps/sync_vpgwc.py
+++ b/xos/synchronizer/steps/sync_vpgwc.py
@@ -36,4 +36,7 @@
# Gets the attributes that are used by the Ansible template but are not
# part of the set of default attributes.
def get_extra_attributes(self, o):
- return {"display_message": o.display_message, "s5s8_pgw_tag": o.s5s8_pgw_tag}
+ return {"display_message": o.display_message,
+ "s5s8_pgw_tag": o.s5s8_pgw_tag,
+ "image_name": o.image_name,
+ }
diff --git a/xos/tosca/resources/VPGWCTenant.py b/xos/tosca/resources/VPGWCTenant.py
index afd6966..434972a 100644
--- a/xos/tosca/resources/VPGWCTenant.py
+++ b/xos/tosca/resources/VPGWCTenant.py
@@ -4,7 +4,7 @@
class XOSVPGWCTenant(XOSResource):
provides = "tosca.nodes.VPGWCTenant"
xos_model = VPGWCTenant
- copyin_props = ["s5s8_pgw_tag", "display_message"]
+ copyin_props = ["s5s8_pgw_tag", "display_message", "image_name"]
name_field = None
def get_xos_args(self, throw_exception=True):