Merge "Write JSON to a file"
diff --git a/xos/synchronizer/steps/sync_host.yaml b/xos/synchronizer/steps/sync_host.yaml
index 55dc70b..4bfd789 100644
--- a/xos/synchronizer/steps/sync_host.yaml
+++ b/xos/synchronizer/steps/sync_host.yaml
@@ -4,5 +4,10 @@
tasks:
- name: Add host entry for fabric
- command: curl -sS --user onos:rocks -X POST -HContent-Type:application/json -d '{{ rest_json }}' http://{{ rest_hostname }}:{{ rest_port }}/{{ rest_endpoint }}
-
+ uri:
+ url: http://{{ rest_hostname }}:{{ rest_port }}/{{ rest_endpoint }}
+ method: POST
+ user: onos
+ password: rocks
+ body: "{{ '{{' }} lookup('file', '{{ files_dir }}/{{ rest_config.fn }}') {{ '}}' }}"
+ body_format: json
\ No newline at end of file
diff --git a/xos/synchronizer/steps/sync_vroutertenant.py b/xos/synchronizer/steps/sync_vroutertenant.py
index 2f3701a..150a596 100644
--- a/xos/synchronizer/steps/sync_vroutertenant.py
+++ b/xos/synchronizer/steps/sync_vroutertenant.py
@@ -20,6 +20,16 @@
requested_interval=30
playbook='sync_host.yaml'
+ def get_files_dir(self):
+ if not hasattr(Config(), "observer_steps_dir"):
+ # make steps_dir mandatory; there's no valid reason for it to not
+ # be defined.
+ raise Exception("observer_steps_dir is not defined in config file")
+
+ step_dir = Config().observer_steps_dir
+
+ return os.path.join(step_dir, "..", "files")
+
def get_fabric_onos_service(self):
fos = None
fs = FabricService.get_service_objects().all()[0]
@@ -63,6 +73,22 @@
return objs
+ def write_config(self, files_dir, name, public_mac, public_ip, location):
+ if not os.path.exists(files_dir):
+ os.makedirs(files_dir)
+
+ # Create JSON
+ data = {
+ "%s/-1"%public_mac : {
+ "basic" : {
+ "ips" : [ public_ip ],
+ "location" : location
+ }
+ }
+ }
+
+ file(os.path.join(files_dir, name),"w").write(json_dumps(data,indent=4))
+
def map_sync_inputs(self, vroutertenant):
fos = self.get_fabric_onos_service()
@@ -87,25 +113,17 @@
node = instance.node
location = self.get_node_tag(node, "location")
+ files_dir = self.get_files_dir()
+ self.write_config(files_dir, name, vroutertenant.public_mac, vroutertenant.public_ip, location)
+
# Is it a POST or DELETE?
- # Create JSON
- data = {
- "%s/-1"%vroutertenant.public_mac : {
- "basic" : {
- "ips" : [ vroutertenant.public_ip ],
- "location" : location
- }
- }
- }
-
- rest_json = json.dumps(data)
-
fields = {
'rest_hostname': fos.rest_hostname,
'rest_port': fos.rest_port,
- 'rest_json': rest_json,
'rest_endpoint': "onos/v1/network/configuration/hosts",
+ 'files_dir': files_dir,
+ 'rest_config.fn': name,
'ansible_tag': '%s'%name, # name of ansible playbook
}
return fields