maas: Avoid race condition in node fixups
[fuel.git] / mcp / patches / salt-formula-maas / 0005-Implement-tags-support.patch
1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2019 Mirantis Inc., Enea AB and others.
3 :
4 : All rights reserved. This program and the accompanying materials
5 : are made available under the terms of the Apache License, Version 2.0
6 : which accompanies this distribution, and is available at
7 : http://www.apache.org/licenses/LICENSE-2.0
8 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
10 Date: Sat, 29 Dec 2018 23:09:01 +0100
11 Subject: [PATCH] Implement 'tags' support
12
13 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
14 ---
15  README.rst       |  5 +++++
16  _modules/maas.py | 26 ++++++++++++++++++++++++++
17  maas/region.sls  |  8 ++++++++
18  3 files changed, 39 insertions(+)
19
20 diff --git a/README.rst b/README.rst
21 index 78d8aef..8c35458 100644
22 --- a/README.rst
23 +++ b/README.rst
24 @@ -181,6 +181,11 @@ Single MAAS region service [single UI/API]:
25            mac: '66:55:44:33:22:11'
26        commissioning_scripts:
27          00-maas-05-simplify-network-interfaces: /etc/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces
28 +      tags:
29 +        aarch64_hugepages_1g:
30 +          comment: 'Enable 1G pagesizes on aarch64'
31 +          definition: '//capability[@id="asimd"]'
32 +          kernel_opts: 'default_hugepagesz=1G hugepagesz=1G'
33        maas_config:
34          # domain: mydomain.local # This function broken
35          http_proxy: http://192.168.0.10:3142
36 diff --git a/_modules/maas.py b/_modules/maas.py
37 index bb70576..0cda8dd 100644
38 --- a/_modules/maas.py
39 +++ b/_modules/maas.py
40 @@ -876,6 +876,28 @@ class Domain(MaasObject):
41          return ret
42
43
44 +class Tags(MaasObject):
45 +    def __init__(self):
46 +        super(Tags, self).__init__()
47 +        self._all_elements_url = u'api/2.0/tags/'
48 +        self._create_url = u'api/2.0/tags/'
49 +        self._config_path = 'region.tags'
50 +        self._update_url = u'api/2.0/tags/{0}/'
51 +        self._update_key = 'name'
52 +
53 +    def fill_data(self, name, tag_data):
54 +        data = {
55 +            'name': name,
56 +        }
57 +        for key in ['comment', 'definition', 'kernel_opts']:
58 +            if key in tag_data:
59 +                data[key] = tag_data[key]
60 +        return data
61 +
62 +    def update(self, new, old):
63 +        return new
64 +
65 +
66  class MachinesStatus(MaasObject):
67      @classmethod
68      def execute(cls, objects_name=None):
69 @@ -1065,5 +1087,9 @@ def process_sshprefs():
70      return SSHPrefs().process()
71
72
73 +def process_tags():
74 +    return Tags().process()
75 +
76 +
77  def wait_for_machine_status(**kwargs):
78      return MachinesStatus.wait_for_machine_status(**kwargs)
79 diff --git a/maas/region.sls b/maas/region.sls
80 index 4a7f6cc..52fb952 100644
81 --- a/maas/region.sls
82 +++ b/maas/region.sls
83 @@ -444,4 +444,12 @@ maas_sshkey_{{ idx }}:
84  {% endfor %}
85  {%- endif %}
86
87 +{%- if region.get('tags', False)  %}
88 +maas_tags:
89 +  module.run:
90 +  - name: maas.process_tags
91 +  - require:
92 +    - cmd: maas_login_admin
93 +{%- endif %}
94 +
95  {%- endif %}