From e56a695332b33815b4a02977cc8a198b1f810e75 Mon Sep 17 00:00:00 2001
From: Szeberényi Imre <szebi@iit.bme.hu>
Date: Sat, 15 Jan 2022 00:56:36 +0100
Subject: [PATCH] First try

---
 pillar/agentdriver.sls          |  4 ++--
 pillar/common.sls               |  1 +
 pillar/firewall.sls             |  2 +-
 pillar/installer.sls            |  1 +
 pillar/manager.sls              |  2 +-
 pillar/monitor-client.sls       |  4 ++--
 pillar/storagedriver.sls        |  4 ++--
 pillar/vmdriver.sls             |  4 ++--
 pillar/vncproxy.sls             |  4 ++--
 requirements.txt                | 10 ++++++----
 salt/common.sls                 |  4 ++++
 salt/manager/configuration.sls  | 12 +++++++-----
 salt/manager/files/init.sh      |  4 ++--
 salt/manager/init.sls           | 27 +++++++--------------------
 salt/manager/pipeline.sls       |  4 ++--
 salt/manager/rabbitmq.sls       | 20 +++++++++++---------
 salt/manager/virtualenv.sls     |  6 ++++++
 salt/node.sls                   |  1 -
 salt/profile.sls                | 12 +++---------
 salt/vncproxy/configuration.sls |  6 +++---
 salt/vncproxy/init.sls          | 12 ++++++------
 salt/vncproxy/virtualenv.sls    |  4 +++-
 22 files changed, 74 insertions(+), 74 deletions(-)

diff --git a/pillar/agentdriver.sls b/pillar/agentdriver.sls
index f425fa9..ddb1398 100644
--- a/pillar/agentdriver.sls
+++ b/pillar/agentdriver.sls
@@ -1,3 +1,3 @@
 agentdriver:
-  repo_name: https://git.ik.bme.hu/circle/agentdriver.git
-  repo_revision: master
+  repo_name: https://git.ik.bme.hu/circle3/agentdriver.git
+  repo_revision: python3.6
diff --git a/pillar/common.sls b/pillar/common.sls
index 0e7a732..c09b2ff 100644
--- a/pillar/common.sls
+++ b/pillar/common.sls
@@ -5,6 +5,7 @@ secret_key: Ga4aex3Eesohngo
 timezone: Europe/Budapest
 
 deployment_type: local
+init_type: systemd
 
 admin_user: admin
 admin_pass: 4j23oihreehfd
diff --git a/pillar/firewall.sls b/pillar/firewall.sls
index ff1d9ac..3233be7 100644
--- a/pillar/firewall.sls
+++ b/pillar/firewall.sls
@@ -1,5 +1,5 @@
 fwdriver:
-  repo_name: https://git.ik.bme.hu/circle/fwdriver.git
+  repo_name: https://git.ik.bme.hu/circle3/fwdriver.git
   repo_revision: master
 
   user: fw
diff --git a/pillar/installer.sls b/pillar/installer.sls
index 239afab..aba44da 100644
--- a/pillar/installer.sls
+++ b/pillar/installer.sls
@@ -5,6 +5,7 @@
 #timezone: Europe/Budapest
 
 #deployment_type: local
+#init_type: systemd
 
 #admin_user: admin
 #admin_pass: 4j23oihreehfd
diff --git a/pillar/manager.sls b/pillar/manager.sls
index 00f841f..b536682 100644
--- a/pillar/manager.sls
+++ b/pillar/manager.sls
@@ -1,4 +1,4 @@
 manager:
-  repo_name: https://git.ik.bme.hu/circle/cloud.git
+  repo_name: https://git.ik.bme.hu/circle3/cloud.git
   repo_revision: master
   
diff --git a/pillar/monitor-client.sls b/pillar/monitor-client.sls
index 56bef4b..a5b2d85 100644
--- a/pillar/monitor-client.sls
+++ b/pillar/monitor-client.sls
@@ -1,3 +1,3 @@
 monitor-client:
-  repo_name: https://git.ik.bme.hu/circle/monitor-client.git
-  repo_revision: master
+  repo_name: https://git.ik.bme.hu/circle3/monitor-client.git
+  repo_revision: ptyhon3.6
diff --git a/pillar/storagedriver.sls b/pillar/storagedriver.sls
index 7cafb0f..644689e 100644
--- a/pillar/storagedriver.sls
+++ b/pillar/storagedriver.sls
@@ -1,4 +1,4 @@
 storagedriver:
-  repo_name: https://git.ik.bme.hu/circle/storagedriver.git
-  repo_revision: master
+  repo_name: https://git.ik.bme.hu/circle3/storagedriver.git
+  repo_revision: python3.6
   queue_name: storageserver
diff --git a/pillar/vmdriver.sls b/pillar/vmdriver.sls
index 5107834..feb8858 100644
--- a/pillar/vmdriver.sls
+++ b/pillar/vmdriver.sls
@@ -1,4 +1,4 @@
 vmdriver:
-  repo_name: https://git.ik.bme.hu/circle/vmdriver.git
-  repo_revision: master
+  repo_name: https://git.ik.bme.hu/circle3/vmdriver.git
+  repo_revision: python3.6
   hypervisor_type: kvm
diff --git a/pillar/vncproxy.sls b/pillar/vncproxy.sls
index e88be6c..0e3f1e1 100644
--- a/pillar/vncproxy.sls
+++ b/pillar/vncproxy.sls
@@ -1,3 +1,3 @@
 vncproxy:
-  repo_name: https://git.ik.bme.hu/circle/vncproxy.git
-  repo_revision: master
+  repo_name: https://git.ik.bme.hu/circle3/vncproxy.git
+  repo_revision: python3.6
diff --git a/requirements.txt b/requirements.txt
index 9694b20..2556b10 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,6 @@
-salt==2014.7.1
-netaddr==0.7.14
-netifaces==0.10.6
-halo==0.0.7
+salt==3003
+netaddr
+netifaces
+halo
+virtualenvwrapper
+stevedore
diff --git a/salt/common.sls b/salt/common.sls
index a128098..a4016a8 100644
--- a/salt/common.sls
+++ b/salt/common.sls
@@ -1,3 +1,7 @@
+include:
+  - profile
+
 git:
   pkg.installed
 
+
diff --git a/salt/manager/configuration.sls b/salt/manager/configuration.sls
index 1d00b76..1350ca1 100644
--- a/salt/manager/configuration.sls
+++ b/salt/manager/configuration.sls
@@ -5,10 +5,13 @@ manager_postactivate:
       - template: jinja
       - user: {{ pillar['user'] }}
       - mode: 700
+      - require:
+        - virtualenv: virtualenv_manager
+
 
 portal.conf:
   file.managed:
-    {% if grains['os_family'] == 'RedHat' or grains['os'] == 'Debian' %}
+    {% if pillar['init_type'] == 'systemd' %}
     - name: /etc/systemd/system/portal.service
     {% else %}
     - name: /etc/init/portal.conf
@@ -16,14 +19,13 @@ portal.conf:
     - user: root
     - group: root
     - template: jinja
-    {% if grains['os_family'] == 'RedHat' or grains['os'] == 'Debian' %}
-
+    {% if pillar['init_type'] == 'systemd' %}
     {% if pillar['deployment_type'] == 'production' %}
     - source: file:///home/{{ pillar['user'] }}/circle/miscellaneous/portal-uwsgi.service
     {% else %}
     - source: file:///home/{{ pillar['user'] }}/circle/miscellaneous/portal.service
     {% endif %}
-    
+
     {% else %}
     
     {% if pillar['deployment_type'] == 'production' %}
@@ -34,7 +36,7 @@ portal.conf:
 
     {% endif %}
 
-{% if grains['os_family'] == 'RedHat' or grains['os'] == 'Debian' %}
+{% if pillar['init_type'] == 'systemd' %}
 /etc/systemd/system/manager.service:
   file.managed:
     - user: root
diff --git a/salt/manager/files/init.sh b/salt/manager/files/init.sh
index aaa92a3..510d8ca 100644
--- a/salt/manager/files/init.sh
+++ b/salt/manager/files/init.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-source /home/{{ pillar['user'] }}/.virtualenvs/circle/bin/activate
-source /home/{{ pillar['user'] }}/.virtualenvs/circle/bin/postactivate
+source /etc/profile.d/virtualenvwrapper.sh
+workon circle
 {% set fw = pillar['fwdriver'] %}
 
 HOSTNAME=$(hostname -s)
diff --git a/salt/manager/init.sls b/salt/manager/init.sls
index e5fa39d..8087be2 100644
--- a/salt/manager/init.sls
+++ b/salt/manager/init.sls
@@ -1,7 +1,7 @@
 include:
-  - manager.pipeline
+#  - manager.pipeline
   - manager.gitrepo
-  - manager.agentgit
+#  - manager.agentgit
   - manager.postgres
   - manager.rabbitmq
   - manager.virtualenv
@@ -13,14 +13,13 @@ manager:
     - pkgs:
       - postgresql
       - git
-      - ntp
+      - chrony
       - rabbitmq-server
       - memcached
       - gettext
       - wget
       - swig
       {% if grains['os_family'] == 'RedHat' %}
-      - python2-pip
       - libffi-devel
       - openssl-devel
       - libmemcached-devel
@@ -29,25 +28,22 @@ manager:
       - postgresql-server
       - libxml2-devel
       - libxslt-devel
-      - python-devel
-      - python-virtualenvwrapper
+      - python3-devel
       {% else %}
-      - python-pip
       - libffi-dev
       - libssl-dev
       - libmemcached-dev
       - libpq-dev
       - libxml2-dev
       - libxslt1-dev
-      - python-dev
-      - virtualenvwrapper
+      - python3-dev
       {% endif %}
     - require_in:
       - service: postgres_service
   user:
     - present
     - name: {{ pillar['user'] }}
-    - gid_from_name: True
+    - usergroup: True
     - shell: /bin/bash
     - groups:
       {% if grains['os_family'] == 'RedHat' %}
@@ -56,21 +52,12 @@ manager:
       - sudo
       {% endif %}
      
-
   service:
     - running
     - enable: True
     - watch:
       - file: manager_postactivate
-      {% if grains['os_family'] == 'RedHat' or grains['os'] == 'Debian' %}
-      - file: /etc/systemd/system/manager.service
-      - file: /etc/systemd/system/managercelery@.service
-      {% else %}
-      - file: /etc/init/manager.conf
-      - file: /etc/init/mancelery.conf
-      - file: /etc/init/moncelery.conf
-      - file: /etc/init/slowcelery.conf
-      {% endif %}
+      - sls: manager.configuration
       - sls: manager.gitrepo
 
 portal:
diff --git a/salt/manager/pipeline.sls b/salt/manager/pipeline.sls
index dbb8120..2bfc493 100644
--- a/salt/manager/pipeline.sls
+++ b/salt/manager/pipeline.sls
@@ -1,10 +1,10 @@
-{% if grains['os'] == 'Ubuntu' or grains['os'] == 'Debian' %}
+{% if grains['os'] == 'Ubuntu' or grains['os_family'] == 'Debian' %}
 nodejs-legacy:
   pkg.installed
 {% endif %}
 
 npm:
-  {% if grains['os'] == 'Ubuntu' or grains['os'] == 'Debian' %}
+  {% if grains['os'] == 'Ubuntu' or grains['os_family'] == 'Debian' %}
   pkg.installed:
     - require:
       - pkg: nodejs-legacy
diff --git a/salt/manager/rabbitmq.sls b/salt/manager/rabbitmq.sls
index ff8142c..b3f7c6b 100644
--- a/salt/manager/rabbitmq.sls
+++ b/salt/manager/rabbitmq.sls
@@ -14,19 +14,21 @@ rabbitmq-server:
       - file: rabbitmq-server
       {% endif %}
 
+virtual_host:
+  rabbitmq_vhost.present:
+    - name: {{ pillar['amqp']['vhost']}}
+    - require:
+      - service: rabbitmq-server
+
 rabbitmq_user:
   rabbitmq_user.present:
     - name: {{ pillar['amqp']['user'] }}
     - password: {{ pillar['amqp']['password'] }}
+    - perms: [{ {{ pillar['amqp']['vhost']}}: [.*, .*, .*]}]
+#      - '{{ pillar['amqp']['vhost']}}':
+#        - conf: ".*"
+#        - write: " .*"
+#        - read: ".*"
     - require:
       - service: rabbitmq-server
 
-virtual_host:
-  rabbitmq_vhost.present:
-    - name: {{ pillar['amqp']['vhost']}}
-    - user: {{ pillar['amqp']['user'] }}
-    - conf: .*
-    - write: .*
-    - read: .*
-    - require:
-      - service: rabbitmq-server
diff --git a/salt/manager/virtualenv.sls b/salt/manager/virtualenv.sls
index 5256f47..9171144 100644
--- a/salt/manager/virtualenv.sls
+++ b/salt/manager/virtualenv.sls
@@ -15,6 +15,7 @@ m2crypto_swig_env:
 
 virtualenv_manager:
   virtualenv.managed:
+    - python: /usr/bin/python3
     - name: /home/{{ pillar['user'] }}/.virtualenvs/circle
     - requirements: /home/{{ pillar['user'] }}/circle/requirements/{{ pillar['deployment_type'] }}.txt
     - user: {{ pillar['user'] }}
@@ -26,6 +27,11 @@ virtualenv_manager:
       - environ: m2crypto_swig_env
       {% endif %}
 
+/home/{{ pillar['user'] }}/.virtualenvs/circle/lib/python3.6/site-packages/simplesshkey/models.py:
+  file.patch:
+    - source: file:///home/{{ pillar['user'] }}/circle/requirements/simplesshkey.patch
+    - strip: 5
+
 salt://manager/files/syncdb.sh:
   cmd.script:
     - template: jinja
diff --git a/salt/node.sls b/salt/node.sls
index d1e8a54..2566a8a 100644
--- a/salt/node.sls
+++ b/salt/node.sls
@@ -1,5 +1,4 @@
 include:
-    - profile
     - agentdriver
     - monitor-client
     - vmdriver
diff --git a/salt/profile.sls b/salt/profile.sls
index b83f800..3a6d4f8 100644
--- a/salt/profile.sls
+++ b/salt/profile.sls
@@ -1,10 +1,4 @@
-{% if grains['os']=='Debian' %}
-{# For non-interactive shells, virtualenvwrapper commands 
-   ('workon' etc.) are not sourced automatically #}
-/etc/profile:
-  file.append:
-    - text:
-      - "#Line below added for Debian by CIRCLE Salt installer"
-      - . /etc/bash_completion
-{% endif %}
+/etc/profile.d/virtualenvwrapper.sh:
+  file.symlink:
+    - target: /usr/local/bin/virtualenvwrapper.sh
 
diff --git a/salt/vncproxy/configuration.sls b/salt/vncproxy/configuration.sls
index dc4112c..fac2068 100644
--- a/salt/vncproxy/configuration.sls
+++ b/salt/vncproxy/configuration.sls
@@ -6,16 +6,14 @@
     - group: {{ pillar['user'] }}
     - mode: 700
 
-{% if grains['os_family'] == 'RedHat' or grains['os'] == 'Debian' %}
+{% if pillar['init_type'] == 'systemd' %}
 /etc/systemd/system/vncproxy.service:
   file.managed:
     - user: root
     - group: root
     - template: jinja
     - source: file:///home/{{ pillar['user'] }}/vncproxy/miscellaneous/vncproxy.service
-
 {% else %}
-
 /etc/init/vncproxy.conf:
   file.managed:
     - user: root
@@ -23,3 +21,5 @@
     - template: jinja
     - source: file:///home/{{ pillar['user'] }}/vncproxy/miscellaneous/vncproxy.conf
 {% endif %}
+
+
diff --git a/salt/vncproxy/init.sls b/salt/vncproxy/init.sls
index e28de25..888c414 100644
--- a/salt/vncproxy/init.sls
+++ b/salt/vncproxy/init.sls
@@ -7,19 +7,19 @@ vncproxy:
   pkg.installed:
     - pkgs:
       - git
-      - ntp
+      - chrony
       - wget
       {% if grains['os_family'] == 'RedHat' %}
-      - python2-pip
+      - python3-pip
       - libffi-devel
       - openssl-devel
-      - python-devel
-      - python-virtualenvwrapper
+      - python3-devel
+      - python3-virtualenvwrapper
       {% else %}
-      - python-pip
+      - python3-pip
       - libffi-dev
       - libssl-dev
-      - python-dev
+      - python3-dev
       - virtualenvwrapper
       {% endif %}
     - require_in:
diff --git a/salt/vncproxy/virtualenv.sls b/salt/vncproxy/virtualenv.sls
index 2f1f2d1..480aa24 100644
--- a/salt/vncproxy/virtualenv.sls
+++ b/salt/vncproxy/virtualenv.sls
@@ -1,6 +1,8 @@
 virtualenv_vncproxy:
   virtualenv.managed:
+    - python: /usr/bin/python3
     - name: /home/{{ pillar['user'] }}/.virtualenvs/vncproxy
-    - requirements: /home/{{ pillar['user'] }}/vncproxy/requirements.txt
+    - requirements: /home/{{ pillar['user'] }}/vncproxy/requirements/{{ pillar['deployment_type'] }}.txt
+    - cwd: /home/{{ pillar['user'] }}/vncproxy
     - user: {{ pillar['user'] }}
     - no_chown: true
--
libgit2 0.26.0