apiVersion: batch/v1
kind: Job
metadata:
  name: neutron-bootstrap
spec:
  template:
    metadata:
      name: neutron-bootstrap
    spec:
      containers:
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-database
          command: ["bash", "-c"]
          args:
            - ansible localhost -m mysql_db -a
              "login_host='{{ neutron_database_address }}'
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ neutron_database_name }}'"
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: database-password
                  key: password
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-user-permissions
          command: ["sh", "-c"]
          args:
            - ansible localhost -m mysql_user -a
              "login_host='{{ neutron_database_address }}'
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ neutron_database_name }}'
               password='$NEUTRON_DATABASE_PASSWORD'
               host='%'
               priv='{{ neutron_database_name }}.*:ALL'
               append_privs='yes'"
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: database-password
                  key: password
            - name: NEUTRON_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: neutron-database-password
                  key: password
        - image: "{{ neutron_server_image_full }}"
          name: neutron-server
          env:
            - name: KOLLA_BOOTSTRAP
              value: ""
            - name: KOLLA_CONFIG_STRATEGY
              value: "{{ config_strategy }}"
          volumeMounts:
            - mountPath: {{ container_config_directory }}
              name: neutron-server-config
              readOnly: true
            - mountPath: /var/log/kolla
              name: kolla-logs
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-neutron-service-and-endpoint-admin
          command: ["sh", "-c"]
          args:
            - ansible localhost -m kolla_keystone_service -a
              "service_name=neutron
               service_type=network
               description='Openstack Networking'
               endpoint_region={{ openstack_region_name }}
               url='{{ neutron_admin_endpoint }}'
               interface=admin
               region_name={{ openstack_region_name }}
               auth={{ '{{' }} openstack_neutron_auth {{ '}}' }}"
               "-e" "{'openstack_neutron_auth':{{ openstack_neutron_auth }}}"
          volumeMounts:
            - mountPath: /dev
              name: dev
            - mountPath: /run
              name: run
            - mountPath: /var/log/kolla
              name: kolla-logs
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: KEYSTONE_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keystone-admin-password
                  key: password
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-neutron-service-and-endpoint-internal
          command: ["sh", "-c"]
          args:
            - ansible localhost -m kolla_keystone_service -a
              "service_name=neutron
               service_type=network
               description='Openstack Networking'
               endpoint_region={{ openstack_region_name }}
               url='{{ neutron_internal_endpoint }}'
               interface=internal
               region_name={{ openstack_region_name }}
               auth={{ '{{' }} openstack_neutron_auth {{ '}}' }}"
               "-e" "{'openstack_neutron_auth':{{ openstack_neutron_auth }}}"
          volumeMounts:
            - mountPath: /dev
              name: dev
            - mountPath: /run
              name: run
            - mountPath: /var/log/kolla
              name: kolla-logs
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: KEYSTONE_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keystone-admin-password
                  key: password
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-neutron-service-and-endpoint-public
          command: ["sh", "-c"]
          args:
            - ansible localhost -m kolla_keystone_service -a
              "service_name=neutron
               service_type=network
               description='Openstack Networking'
               endpoint_region={{ openstack_region_name }}
               url='{{ neutron_public_endpoint }}'
               interface=public
               region_name={{ openstack_region_name }}
               auth={{ '{{' }} openstack_neutron_auth {{ '}}' }}"
               "-e" "{'openstack_neutron_auth':{{ openstack_neutron_auth }}}"
          volumeMounts:
            - mountPath: /dev
              name: dev
            - mountPath: /run
              name: run
            - mountPath: /var/log/kolla
              name: kolla-logs
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: KEYSTONE_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keystone-admin-password
                  key: password
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-neutron-user-project-role
          command: ["sh", "-c"]
          args:
            - ansible localhost -m kolla_keystone_user -a
              "project=service
               user=neutron
               password=$NEUTRON_KEYSTONE_PASSWORD
               role=admin
               region_name={{ openstack_region_name }}
               auth={{ '{{' }} openstack_neutron_auth {{ '}}' }}"
               "-e" "{'openstack_neutron_auth':{{ openstack_neutron_auth }}}"
          volumeMounts:
            - mountPath: /dev
              name: dev
            - mountPath: /run
              name: run
            - mountPath: /var/log/kolla
              name: kolla-logs
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: KEYSTONE_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keystone-admin-password
                  key: password
            - name: NEUTRON_KEYSTONE_PASSWORD
              valueFrom:
               secretKeyRef:
                  name: neutron-keystone-password
                  key: password
      volumes:
        - name: neutron-server-config
          configMap:
            name: neutron-server-configmap
            items:
            - key: neutron.conf
              path: neutron.conf
            - key: config.json
              path: config.json
            - key: ml2-conf.ini
              path: ml2_conf.ini
        - name: dev
          hostPath:
            path: /dev
        - name: run
          hostPath:
            path: /run
        - name: etc-localtime
          hostPath:
            path: /etc/localtime
        - name: kolla-logs
          emptyDir: {}
      restartPolicy: OnFailure
