Preventing link and volumes duplication in XOSComponent model

Change-Id: I59778444bb052e9d1460a0c64de4f67ef74e44ad
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index 39ebf58..fd0a51a 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -216,6 +216,12 @@
     alias = StrippedCharField(max_length=200, help_text="alias for the link")
     kind = models.CharField(max_length=20, choices=LINK_KIND, default='internal')
 
+    def save(self, *args, **kwds):
+        existing = XOSComponentLink.objects.filter(container=self.container, alias=self.alias)
+        if len(existing) > 0:
+            raise XOSValidationError('XOSComponentLink for %s:%s already defined' % (self.container, self.alias))
+        super(XOSComponentLink, self).save(*args, **kwds)
+
 
 # NOTE can this be the same of XOSVolume??
 class XOSComponentVolume(PlCoreBase):
@@ -225,6 +231,12 @@
     host_path = StrippedCharField(max_length=1024, help_text="Path of Volume in Host")
     read_only = models.BooleanField(default=False, help_text="True if mount read-only")
 
+    def save(self, *args, **kwds):
+        existing = XOSComponentVolume.objects.filter(container_path=self.container_path, host_path=self.host_path)
+        if len(existing) > 0:
+            raise XOSValidationError('XOSComponentVolume for %s:%s already defined' % (self.container_path, self.host_path))
+        super(XOSComponentVolume, self).save(*args, **kwds)
+
 
 class ServiceController(LoadableModule):
     synchronizer_run = StrippedCharField(max_length=1024, help_text="synchronizer run command", null=True, blank=True)