[CORD-2639] Removing enodeb from profile

Change-Id: I826be4bb8fa8af58a24977ad7e100db99bc36d04
diff --git a/samples/README.md b/samples/README.md
index d75b705..0d3c2cf 100644
--- a/samples/README.md
+++ b/samples/README.md
@@ -26,4 +26,6 @@
 
 ```bash
 bash progran-curl.sh progran/progranserviceinstances profile.json
-```
\ No newline at end of file
+```
+
+curl -U xosadmin@opencord.org:bash -X PUT --data-binary @profile.json http://127.0.0.1:9101/xosapi/v1/progran/progranserviceinstances/4
\ No newline at end of file
diff --git a/samples/profile.json b/samples/profile.json
index d51a386..3ebb1c4 100644
--- a/samples/profile.json
+++ b/samples/profile.json
@@ -1,4 +1,3 @@
-
 {
   "name":"testcem",
   "DlSchedType":"RR",
@@ -12,5 +11,7 @@
   "SubsProfile":"",
   "DlWifiRate":13,
   "DlUeAllocRbRate":12,
-  "handover_id": 1
+  "handover_id": 1,
+  "id": 4,
+  "enodeb_id": 0
 }
\ No newline at end of file
diff --git a/xos/models/models.py b/xos/models/models.py
index 295c172..f8edcc7 100644
--- a/xos/models/models.py
+++ b/xos/models/models.py
@@ -63,6 +63,9 @@
 
         if instances_with_same_name:
             raise XOSValidationError("A ProgranServiceInstance with name '%s' already exists" % self.name)
+
+
+        # TODO when saving set status to "in progress"
         super(ProgranServiceInstance, self).save(*args, **kwargs)
 
 
diff --git a/xos/synchronizer/steps/sync_progranserviceinstance.py b/xos/synchronizer/steps/sync_progranserviceinstance.py
index 4daf104..bcfadfd 100644
--- a/xos/synchronizer/steps/sync_progranserviceinstance.py
+++ b/xos/synchronizer/steps/sync_progranserviceinstance.py
@@ -37,6 +37,10 @@
 
     observes = ProgranServiceInstance
 
+    # NOTE I need to keep track of the relations between profile and enodebs to remove them
+    # it contains: <profile-id>:<enodeb_id>
+    profile_enodebs = {}
+
     def skip_ansible_fields(self, o):
         # FIXME This model does not have an instance, this is a workaroung to make it work,
         # but it need to be cleaned up creating a general SyncUsingAnsible base class
@@ -103,7 +107,7 @@
 
         # progran enodeb specific fields
         if o.enodeb:
-            log.info("adding profile to enodeb", object=str(o), **o.tologdict())
+            log.info("adding profile %s to enodeb %s" % (o.id, o.enodeb.enbId), object=str(o), **o.tologdict())
             enodeb_fields = {
                 'body': json.dumps({
                     "ProfileArray": [
@@ -116,9 +120,26 @@
             enodeb_fields["ansible_tag"] =  o.__class__.__name__ + "_" + str(o.id) + "_enodeb_to_profile"
             enodeb_fields.update(base_field)
             self.run_playbook(o, enodeb_fields)
-        else:
-            log.warn("IMPLEMENT THE CALL TO REMOVE A PROFILE FROM ENODEB")
 
+            # update local state
+            self.profile_enodebs[o.id] = o.enodeb.enbId
+        else:
+            try:
+                enbid = self.profile_enodebs[o.id]
+            except KeyError:
+                enbid = None
+            if enbid:
+                print enbid
+                log.info("removing profile %s from enodeb %s" % (o.id, self.profile_enodebs[o.id]), object=str(o), **o.tologdict())
+                enodeb_fields = {
+                    'body': '',
+                    'method': 'DELETE',
+                    'endpoint': 'enodeb/%s/profile/%s' % (enbid, o.name)
+                }
+                enodeb_fields["ansible_tag"] = o.__class__.__name__ + "_" + str(o.id) + "_rm_enodeb_from_profile"
+                enodeb_fields.update(base_field)
+                self.run_playbook(o, enodeb_fields)
+                del self.profile_enodebs[o.id]
 
         o.save()