Initial prototype of synchronizer
Change-Id: I45de04debd89e7007d7985728d51aa5d03178675
diff --git a/xos/synchronizer/steps/sync_controller_slices.yaml b/xos/synchronizer/steps/sync_controller_slices.yaml
new file mode 100644
index 0000000..7c85872
--- /dev/null
+++ b/xos/synchronizer/steps/sync_controller_slices.yaml
@@ -0,0 +1,79 @@
+---
+- hosts: 127.0.0.1
+ connection: local
+ # These variables are expanded by the Synchronizer framework
+ # and used to create the TOSCA recipe from a template
+ vars:
+ slice_name: "{{ slice_name }}"
+ slice_description: "{{ slice_description }}"
+ image: "{{ image }}"
+ addresses: "{{ addresses }}"
+ gateway_ip: "{{ gateway_ip }}"
+ gateway_mac: "{{ gateway_mac }}"
+ max_instances: "{{ max_instances }}"
+ tasks:
+ {% if delete -%}
+ {% else -%}
+ - name: Lookup local name of remote site
+ uri:
+ url: "{{ endpoint }}/api/core/sites/"
+ method: GET
+ user: "{{ admin_user }}"
+ password: "{{ admin_password }}"
+ return_content: yes
+ force_basic_auth: yes
+ register: sites
+
+ - name: Save site name in local_site variable
+ set_fact:
+ local_site: "{{ '{{' }} sites.json[0]['name'] {{ '}}' }}"
+
+ - name: Get list of images
+ uri:
+ url: "{{ endpoint }}/api/core/images/"
+ method: GET
+ user: "{{ admin_user }}"
+ password: "{{ admin_password }}"
+ return_content: yes
+ force_basic_auth: yes
+ register: images
+
+ - fail: msg="Image {{ image }} is not present at {{ endpoint }}"
+ when: not ((images.json | selectattr('name', 'equalto', image)) | list)
+
+ - name: Get list of networks
+ uri:
+ url: "{{ endpoint }}/api/core/networks/"
+ method: GET
+ user: "{{ admin_user }}"
+ password: "{{ admin_password }}"
+ return_content: yes
+ force_basic_auth: yes
+ register: networks
+
+ - fail: msg="Network {{ '{{' }} item {{ '}}' }} is not present at {{ endpoint }}"
+ when: not ((networks.json | selectattr('name', 'equalto', item)) | list)
+ with_items:
+ - "management"
+ - "public"
+
+ - name: Ensure TOSCA directory exists
+ file:
+ path=/opt/xos/synchronizers/globalxos/tosca/slices/
+ state=directory
+
+ - name: Create TOSCA recipe from the template
+ template:
+ src=/opt/xos/synchronizers/globalxos/templates/slice.yaml.j2
+ dest=/opt/xos/synchronizers/globalxos/tosca/slices/{{ ansible_tag }}.yml
+
+ - name: Create slice "{{ slice }}"
+ uri:
+ url: "{{ endpoint }}/api/utility/tosca/run/"
+ method: POST
+ user: "{{ admin_user }}"
+ password: "{{ admin_password }}"
+ body: { "recipe": "{{ '{{' }} lookup('file', '/opt/xos/synchronizers/globalxos/tosca/slices/{{ ansible_tag }}.yml') {{ '}}' }}" }
+ force_basic_auth: yes
+ body_format: json
+ {% endif %}