CORD-2330 Add networks to slices before creating instances

Change-Id: Ic00a77eded9bd61b9e982cd6a30e587c8c152027
(cherry picked from commit ea2eb5e97cad3dbd9fba2c3458984b8bacae6e19)
diff --git a/xos/synchronizer/model_policies/model_policy_vepcserviceinstance.py b/xos/synchronizer/model_policies/model_policy_vepcserviceinstance.py
index 3bb658c..867d5d2 100644
--- a/xos/synchronizer/model_policies/model_policy_vepcserviceinstance.py
+++ b/xos/synchronizer/model_policies/model_policy_vepcserviceinstance.py
@@ -97,6 +97,17 @@
         self.in_memory_instances.append(s)
         return s
 
+    def add_networks_to_service(self, service, networks):
+        for n in networks:
+            net = Network.objects.filter(name=n)[0]
+            one_and_only_slice_hopefully = service.slices.all()[0]
+            ns_object = NetworkSlice.objects.filter(
+                network=net.id, slice=one_and_only_slice_hopefully.id)
+            if not ns_object:
+                ns_object = NetworkSlice(
+                    network=net, slice=one_and_only_slice_hopefully)
+                ns_object.save()
+
     def add_networks_to_service_instance(self, instance, networks):
         for n in networks:
             net = Network.objects.filter(name=n)[0]
@@ -109,12 +120,13 @@
                 ns_object.save()
 
     def create_service_instance_with_networks(self, si_name, networks):
+        service = self.get_service_for_service_instance(si_name)
+        self.add_networks_to_service(service, networks)
+
         instance = self.child_service_instance_from_name(si_name)
         if not instance:
             instance = self.create_service_instance(si_name)
 
-        self.add_networks_to_service_instance(instance, networks)
-
         return instance
 
     def create_link(self, src_instance, dst_instance):
diff --git a/xos/synchronizer/vepc_config.yaml b/xos/synchronizer/vepc_config.yaml
index 3e2d56d..f11ffb2 100644
--- a/xos/synchronizer/vepc_config.yaml
+++ b/xos/synchronizer/vepc_config.yaml
@@ -33,9 +33,14 @@
       - name: VENBServiceInstance
         networks: 
           - management
+          - s1u_network
+          - sgi_network
+          - s11_network
       - name: VSPGWCTenant
         networks: 
           - management
+          - s11_network
+          - spgw_network
         links:
           - name: VENBServiceInstance
             networks:
@@ -46,6 +51,9 @@
       - name: VSPGWUTenant
         networks: 
           - management
+          - s1u_network
+          - sgi_network
+          - spgw_network
         links:
           - name: VENBServiceInstance
             networks: