[CORD-2378] Generating docker-compose.yml for services and executing them
Change-Id: Ic83d1701ee8537c32f761125cc51c532d18487e5
diff --git a/onboard-profile-playbook.yml b/onboard-profile-playbook.yml
index ecb45d6..3fabf22 100644
--- a/onboard-profile-playbook.yml
+++ b/onboard-profile-playbook.yml
@@ -21,6 +21,18 @@
roles:
- xos-ready
+- name: Generate config for dynamic services
+ hosts: head
+ roles:
+ - xos-services-config
+
+# NOTE the images are built by imagebuilder for services defined in xos_dynamic_services
+# we'll need to manually build the one for real dynamic services
+- name: Run dynamic services
+ hosts: head
+ roles:
+ - xos-services-up
+
- name: Apply profile config
hosts: head
roles:
diff --git a/roles/cord-profile/defaults/main.yml b/roles/cord-profile/defaults/main.yml
index cd9449b..24bb259 100644
--- a/roles/cord-profile/defaults/main.yml
+++ b/roles/cord-profile/defaults/main.yml
@@ -59,6 +59,7 @@
pod_sshkey_name: "headnode"
xos_services: []
+xos_dynamic_services: []
xos_gui_service_graph_constraints: []
diff --git a/roles/cord-profile/tasks/main.yml b/roles/cord-profile/tasks/main.yml
index c5e0fc1..da5dd44 100644
--- a/roles/cord-profile/tasks/main.yml
+++ b/roles/cord-profile/tasks/main.yml
@@ -65,6 +65,14 @@
remote_src: True
with_items: "{{ xos_services | selectattr('keypair', 'defined') | list }}"
+- name: Copy ssh private key to key_import directory for dynamic services that require it
+ copy:
+ src: "{{ ssh_pki_dir }}/client_certs/{{ pod_sshkey_name }}_sshkey"
+ dest: "{{ config_cord_profile_dir }}/key_import/{{ item.keypair }}"
+ mode: 0600
+ remote_src: True
+ with_items: "{{ xos_dynamic_services | selectattr('keypair', 'defined') | list }}"
+
- name: Copy ssh public key to key_import directory for services that require it
copy:
src: "{{ ssh_pki_dir }}/client_certs/{{ pod_sshkey_name }}_sshkey.pub"
@@ -73,6 +81,14 @@
remote_src: True
with_items: "{{ xos_services | selectattr('keypair', 'defined') | list }}"
+- name: Copy ssh public key to key_import directory for dynamic services that require it
+ copy:
+ src: "{{ ssh_pki_dir }}/client_certs/{{ pod_sshkey_name }}_sshkey.pub"
+ dest: "{{ config_cord_profile_dir }}/key_import/{{ item.keypair }}.pub"
+ mode: 0644
+ remote_src: True
+ with_items: "{{ xos_dynamic_services | selectattr('keypair', 'defined') | list }}"
+
- name: Copy cert chain and core api key and cert
copy:
src: "{{ pki_dir }}/{{ item.src }}"
diff --git a/roles/exampleservice-config/templates/test-exampleservice.yaml.j2 b/roles/exampleservice-config/templates/test-exampleservice.yaml.j2
index cb34206..e2d3d48 100644
--- a/roles/exampleservice-config/templates/test-exampleservice.yaml.j2
+++ b/roles/exampleservice-config/templates/test-exampleservice.yaml.j2
@@ -144,7 +144,7 @@
type: tosca.nodes.ExampleService
properties:
name: exampleservice
- public_key: {{ lookup('file', config_cord_profile_dir + '/key_import/exampleservice_rsa.pub') }}
+ public_key: {{ lookup('file', head_cord_profile_dir + '/key_import/exampleservice_rsa.pub') }}
private_key_fn: /opt/xos/services/exampleservice/keys/exampleservice_rsa
service_message: hello
diff --git a/roles/xos-services-config/defaults/main.yml b/roles/xos-services-config/defaults/main.yml
new file mode 100644
index 0000000..8b6eff7
--- /dev/null
+++ b/roles/xos-services-config/defaults/main.yml
@@ -0,0 +1,22 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+build_cord_dir: '{{ playbook_dir ~ ''/../..'' }}'
+head_cord_profile_dir: '/opt/cord_profile'
+head_credentials_dir: '/opt/credentials'
+pull_docker_registry: ''
+pull_docker_tag: candidate
+xos_dynamic_services: []
+xos_docker_networks:
+- xos
diff --git a/roles/xos-services-config/tasks/main.yml b/roles/xos-services-config/tasks/main.yml
new file mode 100644
index 0000000..c856ff1
--- /dev/null
+++ b/roles/xos-services-config/tasks/main.yml
@@ -0,0 +1,25 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: Create to host services docker-compose.yml
+ file:
+ path: "{{ config_cord_profile_dir }}/dynamic_load/"
+ state: directory
+
+- name: Copy docker-compose.yaml from the service repo
+ template:
+ src: "{{ config_cord_dir }}/{{ item.path }}/docker-compose.yml.j2"
+ dest: "{{ config_cord_profile_dir }}/dynamic_load/{{ item.name }}-docker-compose.yml"
+ mode: 0644
+ with_items: "{{ xos_dynamic_services }}"
\ No newline at end of file
diff --git a/roles/xos-services-up/defaults/main.yml b/roles/xos-services-up/defaults/main.yml
new file mode 100644
index 0000000..2c80b95
--- /dev/null
+++ b/roles/xos-services-up/defaults/main.yml
@@ -0,0 +1,15 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+head_cord_profile_dir: /opt/cord_profile
diff --git a/roles/xos-services-up/tasks/main.yml b/roles/xos-services-up/tasks/main.yml
new file mode 100644
index 0000000..78fe744
--- /dev/null
+++ b/roles/xos-services-up/tasks/main.yml
@@ -0,0 +1,34 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: Inizialize docker-compose.yml list
+ set_fact:
+ onboarding_recipes: ['docker-compose.yml']
+- name: Read docker-compose.yml files for services
+ find:
+ paths: "{{ head_cord_profile_dir }}/dynamic_load/"
+ patterns: '*docker-compose.yml'
+ register: onboarding_recipes_files
+- name: Add docker-compose.yml files for services to the list
+ set_fact:
+ onboarding_recipes: "{{ onboarding_recipes }} + ['{{ item.path }}']"
+ with_items: "{{ onboarding_recipes_files.files }}"
+- debug:
+ var: onboarding_recipes
+- name: Start services
+ docker_service:
+ files: "{{ onboarding_recipes }}"
+ project_name: "{{ cord_profile | regex_replace('\\W','') }}"
+ project_src: "{{ head_cord_profile_dir }}"
+ pull: "{{ always_pull_xos_images | default('false') }}"
\ No newline at end of file
diff --git a/xos-service-config.yml b/xos-service-config.yml
new file mode 100644
index 0000000..c965baa
--- /dev/null
+++ b/xos-service-config.yml
@@ -0,0 +1,39 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+---
+# start-xos-playbook.yml
+# Start and configure XOS docker containers
+
+- name: Include vars
+ hosts: all
+ tasks:
+ - name: Include variables
+ include_vars: "{{ item }}"
+ with_items:
+ - "profile_manifests/{{ cord_profile }}.yml"
+ - profile_manifests/local_vars.yml
+ - name: Store service name
+ set_fact:
+ service_name: "{{ service_name }}"
+ service_dir: "{{ service_dir }}"
+ - debug:
+ msg: "The service name is: {{ service_name }} and the service directory is {{ service_dir }}"
+
+- name: Generate docker-compose.yml for service
+ hosts: head
+ roles:
+ - xos-services-config
+
diff --git a/xos-services-up.yml b/xos-services-up.yml
new file mode 100644
index 0000000..b398781
--- /dev/null
+++ b/xos-services-up.yml
@@ -0,0 +1,33 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+---
+# start-xos-playbook.yml
+# Start and configure XOS docker containers
+
+- name: Include vars
+ hosts: all
+ tasks:
+ - name: Include variables
+ include_vars: "{{ item }}"
+ with_items:
+ - "profile_manifests/{{ cord_profile }}.yml"
+ - profile_manifests/local_vars.yml
+
+- name: Start XOS synchronizers containers with docker-compose
+ hosts: head
+ roles:
+ - xos-services-up