[docker] Switch to containerized Salt Master
[fuel.git] / mcp / patches / salt-formula-maas / 0003-Add-machines.delete-co-pxe_nat-sls.patch
1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Sun, 19 Aug 2018 05:38:27 +0200
3 Subject: [PATCH] Add machines.delete & co, pxe_nat sls
4
5 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
6 ---
7  maas/machines/delete.sls                  | 20 ++++++++++++
8  maas/machines/mark_broken_fixed.sls       | 20 ++++++++++++
9  maas/machines/override_failed_testing.sls | 20 ++++++++++++
10  maas/pxe_nat.sls                          | 37 +++++++++++++++++++++++
11  4 files changed, 97 insertions(+)
12  create mode 100644 maas/machines/delete.sls
13  create mode 100644 maas/machines/mark_broken_fixed.sls
14  create mode 100644 maas/machines/override_failed_testing.sls
15  create mode 100644 maas/pxe_nat.sls
16
17 diff --git a/maas/machines/delete.sls b/maas/machines/delete.sls
18 new file mode 100644
19 index 0000000..2903f92
20 --- /dev/null
21 +++ b/maas/machines/delete.sls
22 @@ -0,0 +1,20 @@
23 +##############################################################################
24 +# Copyright (c) 2017 Mirantis Inc., Enea AB and others.
25 +# All rights reserved. This program and the accompanying materials
26 +# are made available under the terms of the Apache License, Version 2.0
27 +# which accompanies this distribution, and is available at
28 +# http://www.apache.org/licenses/LICENSE-2.0
29 +##############################################################################
30 +{%- from "maas/map.jinja" import region with context %}
31 +
32 +maas_login_admin:
33 +  cmd.run:
34 +  - name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
35 +  - unless: 'test -e /var/lib/maas/.maas_credentials'
36 +
37 +# TODO: implement delete_machine via _modules/maas.py
38 +delete_machine:
39 +  cmd.run:
40 +  - name: "maas login {{ region.admin.username }} http://{{ region.bind.host }}:5240/MAAS/api/2.0 - < /var/lib/maas/.maas_credentials && maas opnfv machine delete {{ pillar['system_id'] }}"
41 +  - require:
42 +    - cmd: maas_login_admin
43 diff --git a/maas/machines/mark_broken_fixed.sls b/maas/machines/mark_broken_fixed.sls
44 new file mode 100644
45 index 0000000..46691bb
46 --- /dev/null
47 +++ b/maas/machines/mark_broken_fixed.sls
48 @@ -0,0 +1,20 @@
49 +##############################################################################
50 +# Copyright (c) 2017 Mirantis Inc., Enea AB and others.
51 +# All rights reserved. This program and the accompanying materials
52 +# are made available under the terms of the Apache License, Version 2.0
53 +# which accompanies this distribution, and is available at
54 +# http://www.apache.org/licenses/LICENSE-2.0
55 +##############################################################################
56 +{%- from "maas/map.jinja" import region with context %}
57 +
58 +maas_login_admin:
59 +  cmd.run:
60 +  - name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
61 +  - unless: 'test -e /var/lib/maas/.maas_credentials'
62 +
63 +# TODO: implement mark_broken_fixed_machine via _modules/maas.py
64 +mark_broken_fixed_machine:
65 +  cmd.run:
66 +  - name: "maas login {{ region.admin.username }} http://{{ region.bind.host }}:5240/MAAS/api/2.0 - < /var/lib/maas/.maas_credentials && maas opnfv machine mark-broken {{ pillar['system_id'] }} && sleep 10 && maas opnfv machine mark-fixed {{ pillar['system_id'] }} && maas opnfv machine test {{ pillar['system_id'] }} testing_scripts=fio"
67 +  - require:
68 +    - cmd: maas_login_admin
69 diff --git a/maas/machines/override_failed_testing.sls b/maas/machines/override_failed_testing.sls
70 new file mode 100644
71 index 0000000..e7fe1d2
72 --- /dev/null
73 +++ b/maas/machines/override_failed_testing.sls
74 @@ -0,0 +1,20 @@
75 +##############################################################################
76 +# Copyright (c) 2018 Mirantis Inc., Enea AB and others.
77 +# All rights reserved. This program and the accompanying materials
78 +# are made available under the terms of the Apache License, Version 2.0
79 +# which accompanies this distribution, and is available at
80 +# http://www.apache.org/licenses/LICENSE-2.0
81 +##############################################################################
82 +{%- from "maas/map.jinja" import region with context %}
83 +
84 +maas_login_admin:
85 +  cmd.run:
86 +  - name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
87 +  - unless: 'test -e /var/lib/maas/.maas_credentials'
88 +
89 +# TODO: implement override_failed_testing via _modules/maas.py
90 +mark_broken_fixed_machine:
91 +  cmd.run:
92 +  - name: "maas login {{ region.admin.username }} http://{{ region.bind.host }}:5240/MAAS/api/2.0 - < /var/lib/maas/.maas_credentials && maas opnfv machine override-failed-testing {{ pillar['system_id'] }}"
93 +  - require:
94 +    - cmd: maas_login_admin
95 diff --git a/maas/pxe_nat.sls b/maas/pxe_nat.sls
96 new file mode 100644
97 index 0000000..8a03c4f
98 --- /dev/null
99 +++ b/maas/pxe_nat.sls
100 @@ -0,0 +1,37 @@
101 +##############################################################################
102 +# Copyright (c) 2017 Mirantis Inc., Enea AB and others.
103 +# All rights reserved. This program and the accompanying materials
104 +# are made available under the terms of the Apache License, Version 2.0
105 +# which accompanies this distribution, and is available at
106 +# http://www.apache.org/licenses/LICENSE-2.0
107 +##############################################################################
108 +net.ipv4.ip_forward:
109 +  sysctl.present:
110 +    - value: 1
111 +
112 +iptables_pxe_nat:
113 +  iptables.append:
114 +    - table: nat
115 +    - chain: POSTROUTING
116 +    - jump: MASQUERADE
117 +    - destination: 0/0
118 +    - source: {{ salt['pillar.get']('_param:single_address') }}/{{ salt['pillar.get']('_param:opnfv_net_admin_mask') }}
119 +    - save: True
120 +
121 +iptables_pxe_source:
122 +  iptables.append:
123 +    - table: filter
124 +    - chain: INPUT
125 +    - jump: ACCEPT
126 +    - destination: 0/0
127 +    - source: {{ salt['pillar.get']('_param:single_address') }}/{{ salt['pillar.get']('_param:opnfv_net_admin_mask') }}
128 +    - save: True
129 +
130 +iptables_pxe_destination:
131 +  iptables.append:
132 +    - table: filter
133 +    - chain: INPUT
134 +    - jump: ACCEPT
135 +    - destination: {{ salt['pillar.get']('_param:single_address') }}/{{ salt['pillar.get']('_param:opnfv_net_admin_mask') }}
136 +    - source: 0/0
137 +    - save: True