[CORD-2608]
Install helm/kubespray and create chart for XOS

Change-Id: I1bb90fd2575fb399d367985659719378f17680fe
diff --git a/roles/cord-helm-charts/defaults/main.yml b/roles/cord-helm-charts/defaults/main.yml
new file mode 100644
index 0000000..69147f5
--- /dev/null
+++ b/roles/cord-helm-charts/defaults/main.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.
+
+# cord-helm-charts/defaults/main.yml
+
+config_cord_profile_dir: "/opt/cord_profile"
+config_cord_helm_dir: "{{ config_cord_profile_dir }}/helm"
+
+head_cord_profile_dir: "/opt/cord_profile"
+head_cord_helm_dir: "{{ head_cord_profile_dir }}/helm"
+
+# site name
+site_name: placeholder-sitename
+site_suffix: "{{ site_name }}.test"
+
+# Docker related settings
+docker_registry_ext_port: "5000"
+docker_registry: "registry.{{ site_suffix }}:{{ docker_registry_ext_port }}"
+
+docker_tag: "candidate"
+
diff --git a/roles/cord-helm-charts/files/core_templates/_helpers.tpl b/roles/cord-helm-charts/files/core_templates/_helpers.tpl
new file mode 100644
index 0000000..399c79a
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/_helpers.tpl
@@ -0,0 +1,8 @@
+{{- define "xos-core.release_labels" }}
+app: {{ printf "%s-%s" .Release.Name .Chart.Name | trunc 63 }}
+version: {{ .Chart.Version }}
+release: {{ .Release.Name }}
+{{- end }}
+{{- define "xos-core.full_name" -}}
+{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 -}}
+{{- end -}}
diff --git a/roles/cord-helm-charts/files/core_templates/core-configmap.yaml b/roles/cord-helm-charts/files/core_templates/core-configmap.yaml
new file mode 100644
index 0000000..1e79d79
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/core-configmap.yaml
@@ -0,0 +1,31 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: xos-core
+  labels:
+    {{- include "xos-core.release_labels" . | indent 4 }}
+data:
+  config: |-
+    ---
+    name: xos-core
+    database:
+      name: xos
+      username: postgres
+      password: password
+    logging:
+      version: 1
+      handlers:
+        console:
+          class: logging.StreamHandler
+        file:
+          class: logging.handlers.RotatingFileHandler
+          filename: /var/log/xos.log
+          maxBytes: 10485760
+          backupCount: 5
+      loggers:
+        '':
+          handlers:
+              - console
+              - file
+          level: DEBUG
+    xos_dir: /opt/xos
diff --git a/roles/cord-helm-charts/files/core_templates/core-deployment.yaml b/roles/cord-helm-charts/files/core_templates/core-deployment.yaml
new file mode 100644
index 0000000..8090347
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/core-deployment.yaml
@@ -0,0 +1,34 @@
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+  name: xos-core
+  labels:
+    app: xos-core
+spec:
+  replicas: 1
+  template:
+    metadata:
+      labels:
+        app: xos-core
+    spec:
+      containers:
+        - name: xos-core
+          image: {{ .Values.images.xos_core.repository }}:{{ .Values.images.xos_core.tag }}
+          # command: ["/bin/bash", "-c", "cd coreapi; ./start_coreapi.sh"]
+          command: ["/bin/bash", "-c", "sleep 86400"]
+          ports:
+            - containerPort: 50051
+              protocol: TCP
+            - containerPort: 50055
+              protocol: TCP
+          volumeMounts:
+            - name: xos-core-config
+              mountPath: /opt/xos/xos_config.yaml
+              subPath: config/xos_config.yaml
+      volumes:
+        - name: xos-core-config
+          configMap:
+            name: xos-core
+            items:
+             - key: config
+               path: config/xos_config.yaml
diff --git a/roles/cord-helm-charts/files/core_templates/core-service.yaml b/roles/cord-helm-charts/files/core_templates/core-service.yaml
new file mode 100644
index 0000000..ab63b07
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/core-service.yaml
@@ -0,0 +1,19 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: "xos-core"
+  labels:
+    {{- include "xos-core.release_labels" . | indent 4 }}
+spec:
+  type: NodePort
+  ports:
+  - port: 50051
+    name: secure
+    targetPort: 50051
+    protocol: TCP
+  - port: 50055
+    name: insecure
+    targetPort: 50055
+    protocol: TCP
+  selector:
+    app: "xos-core"
diff --git a/roles/cord-helm-charts/files/core_templates/db-configmap.yaml b/roles/cord-helm-charts/files/core_templates/db-configmap.yaml
new file mode 100644
index 0000000..45183b2
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/db-configmap.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: xos-db
+  labels:
+    {{- include "xos-core.release_labels" . | indent 4 }}
+data:
+  service_5432_name: 'xos-db'
diff --git a/roles/cord-helm-charts/files/core_templates/db-deployment.yaml b/roles/cord-helm-charts/files/core_templates/db-deployment.yaml
new file mode 100644
index 0000000..326c475
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/db-deployment.yaml
@@ -0,0 +1,27 @@
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+  name: xos-db
+  labels:
+    app: xos-db
+spec:
+  replicas: 1
+  template:
+    metadata:
+      labels:
+        app: xos-db
+      annotations:
+        checksum/config-map: {{ include (print $.Chart.Name "/templates/db-configmap.yaml") . | sha256sum }}
+    spec:
+      containers:
+        - name: xos-db
+          image: {{ .Values.images.xos_db.repository }}:{{ .Values.images.xos_db.tag }}
+          ports:
+            - containerPort: 5432
+              protocol: TCP
+          env:
+            - name: SERVICE_5432_NAME
+              valueFrom:
+                configMapKeyRef:
+                  name: xos-db
+                  key: service_5432_name
diff --git a/roles/cord-helm-charts/files/core_templates/db-service.yaml b/roles/cord-helm-charts/files/core_templates/db-service.yaml
new file mode 100644
index 0000000..96433b2
--- /dev/null
+++ b/roles/cord-helm-charts/files/core_templates/db-service.yaml
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: "xos-db"
+  labels:
+    {{- include "xos-core.release_labels" . | indent 4 }}
+spec:
+  type: NodePort
+  ports:
+  - port: 5432
+    targetPort: 5432
+    protocol: TCP
+  selector:
+    app: "xos-db"
diff --git a/roles/cord-helm-charts/tasks/main.yml b/roles/cord-helm-charts/tasks/main.yml
new file mode 100644
index 0000000..f626a30
--- /dev/null
+++ b/roles/cord-helm-charts/tasks/main.yml
@@ -0,0 +1,58 @@
+---
+# 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.
+
+# cord-helm-charts/tasks/main.yml
+# Creates Helm charts for CORD services
+
+- name: Create cord_profile/helm directory and chart subdirectories
+  file:
+    dest: "{{ config_cord_helm_dir }}"
+    state: directory
+    mode: 0755
+    owner: "{{ ansible_user_id }}"
+    group: "{{ ansible_user_gid }}"
+
+- name: Create chart subdirectories
+  file:
+    dest: "{{ config_cord_helm_dir }}/{{ item }}"
+    state: directory
+    mode: 0755
+    owner: "{{ ansible_user_id }}"
+    group: "{{ ansible_user_gid }}"
+  with_items:
+    - "xos-core"
+    - "xos-core/templates"
+    - "xos-services"
+    - "xos-services/templates"
+
+- name: Copy XOS Core templates
+  copy:
+    src: "core_templates/"
+    dest: "{{ config_cord_helm_dir }}/xos-core/templates/"
+    mode: 0755
+    owner: "{{ ansible_user_id }}"
+    group: "{{ ansible_user_gid }}"
+
+- name: Create chart configuration from templates
+  template:
+    src: "{{ item }}.j2"
+    dest: "{{ config_cord_helm_dir }}/xos-core/{{ item }}"
+    mode: 0755
+    owner: "{{ ansible_user_id }}"
+    group: "{{ ansible_user_gid }}"
+  with_items:
+    - Chart.yaml
+    - values.yaml
+
diff --git a/roles/cord-helm-charts/templates/Chart.yaml.j2 b/roles/cord-helm-charts/templates/Chart.yaml.j2
new file mode 100644
index 0000000..40a1708
--- /dev/null
+++ b/roles/cord-helm-charts/templates/Chart.yaml.j2
@@ -0,0 +1,2 @@
+name: xos-core
+version: 1.0.0
diff --git a/roles/cord-helm-charts/templates/values.yaml.j2 b/roles/cord-helm-charts/templates/values.yaml.j2
new file mode 100644
index 0000000..36127e2
--- /dev/null
+++ b/roles/cord-helm-charts/templates/values.yaml.j2
@@ -0,0 +1,12 @@
+images:
+  xos_core:
+    repository: "{{ docker_registry }}/xosproject/xos-ui"
+    tag: "{{ docker_tag }}"
+  xos_db:
+    repository: "{{ docker_registry }}/xosproject/xos-postgres"
+    tag: "{{ docker_tag }}"
+
+services:
+  - name: vsg
+    repository: "{{ docker_registry }}/xosproject/vsg-synchronizer"
+    tag: "{{ docker_tag }}"