Statistics
| Branch: | Tag: | Revision:

root / snf-deploy / snfdeploy / components.py @ 38cfb0c3

History | View | Annotate | Download (31.7 kB)

1 3c3bccab Dimitris Aragiorgis
# Copyright (C) 2010, 2011, 2012, 2013 GRNET S.A. All rights reserved.
2 3c3bccab Dimitris Aragiorgis
#
3 3c3bccab Dimitris Aragiorgis
# Redistribution and use in source and binary forms, with or
4 3c3bccab Dimitris Aragiorgis
# without modification, are permitted provided that the following
5 3c3bccab Dimitris Aragiorgis
# conditions are met:
6 3c3bccab Dimitris Aragiorgis
#
7 3c3bccab Dimitris Aragiorgis
#   1. Redistributions of source code must retain the above
8 3c3bccab Dimitris Aragiorgis
#      copyright notice, this list of conditions and the following
9 3c3bccab Dimitris Aragiorgis
#      disclaimer.
10 3c3bccab Dimitris Aragiorgis
#
11 3c3bccab Dimitris Aragiorgis
#   2. Redistributions in binary form must reproduce the above
12 3c3bccab Dimitris Aragiorgis
#      copyright notice, this list of conditions and the following
13 3c3bccab Dimitris Aragiorgis
#      disclaimer in the documentation and/or other materials
14 3c3bccab Dimitris Aragiorgis
#      provided with the distribution.
15 3c3bccab Dimitris Aragiorgis
#
16 3c3bccab Dimitris Aragiorgis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 3c3bccab Dimitris Aragiorgis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 3c3bccab Dimitris Aragiorgis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 3c3bccab Dimitris Aragiorgis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A. OR
20 3c3bccab Dimitris Aragiorgis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 3c3bccab Dimitris Aragiorgis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 3c3bccab Dimitris Aragiorgis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 3c3bccab Dimitris Aragiorgis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 3c3bccab Dimitris Aragiorgis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 3c3bccab Dimitris Aragiorgis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 3c3bccab Dimitris Aragiorgis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 3c3bccab Dimitris Aragiorgis
# POSSIBILITY OF SUCH DAMAGE.
28 3c3bccab Dimitris Aragiorgis
#
29 3c3bccab Dimitris Aragiorgis
# The views and conclusions contained in the software and
30 3c3bccab Dimitris Aragiorgis
# documentation are those of the authors and should not be
31 3c3bccab Dimitris Aragiorgis
# interpreted as representing official policies, either expressed
32 3c3bccab Dimitris Aragiorgis
# or implied, of GRNET S.A.
33 3c3bccab Dimitris Aragiorgis
34 3c3bccab Dimitris Aragiorgis
import datetime
35 3c3bccab Dimitris Aragiorgis
from snfdeploy.utils import debug
36 3c3bccab Dimitris Aragiorgis
37 d4f28d8f Dimitris Aragiorgis
38 3c3bccab Dimitris Aragiorgis
class SynnefoComponent(object):
39 3c3bccab Dimitris Aragiorgis
40 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = []
41 3c3bccab Dimitris Aragiorgis
42 3c3bccab Dimitris Aragiorgis
    def debug(self, msg, info=""):
43 3c3bccab Dimitris Aragiorgis
        debug(self.__class__.__name__, msg, info)
44 3c3bccab Dimitris Aragiorgis
45 3c3bccab Dimitris Aragiorgis
    def __init__(self, node_info, env, *args, **kwargs):
46 3c3bccab Dimitris Aragiorgis
        """ Take a node_info and env as argument and initialize local vars """
47 3c3bccab Dimitris Aragiorgis
        self.node_info = node_info
48 3c3bccab Dimitris Aragiorgis
        self.env = env
49 3c3bccab Dimitris Aragiorgis
50 3c3bccab Dimitris Aragiorgis
    def check(self):
51 3c3bccab Dimitris Aragiorgis
        """ Returns a list of bash commands that check prerequisites """
52 3c3bccab Dimitris Aragiorgis
        return []
53 3c3bccab Dimitris Aragiorgis
54 3c3bccab Dimitris Aragiorgis
    def install(self):
55 3c3bccab Dimitris Aragiorgis
        """ Returns a list of debian packages to install """
56 3c3bccab Dimitris Aragiorgis
        return self.REQUIRED_PACKAGES
57 3c3bccab Dimitris Aragiorgis
58 3c3bccab Dimitris Aragiorgis
    def prepare(self):
59 3c3bccab Dimitris Aragiorgis
        """ Returs a list of bash commands that prepares the component """
60 3c3bccab Dimitris Aragiorgis
        return []
61 3c3bccab Dimitris Aragiorgis
62 3c3bccab Dimitris Aragiorgis
    def configure(self):
63 3c3bccab Dimitris Aragiorgis
        """ Must return a list of tuples (tmpl_path, replace_dict, mode) """
64 3c3bccab Dimitris Aragiorgis
        return []
65 3c3bccab Dimitris Aragiorgis
66 3c3bccab Dimitris Aragiorgis
    def initialize(self):
67 3c3bccab Dimitris Aragiorgis
        """ Returs a list of bash commands that initialize the component """
68 3c3bccab Dimitris Aragiorgis
        return []
69 3c3bccab Dimitris Aragiorgis
70 3c3bccab Dimitris Aragiorgis
    def test(self):
71 3c3bccab Dimitris Aragiorgis
        """ Returs a list of bash commands that test existing installation """
72 3c3bccab Dimitris Aragiorgis
        return []
73 3c3bccab Dimitris Aragiorgis
74 3c3bccab Dimitris Aragiorgis
    def restart(self):
75 3c3bccab Dimitris Aragiorgis
        return []
76 3c3bccab Dimitris Aragiorgis
77 3c3bccab Dimitris Aragiorgis
    #TODO: add cleanup method for each component
78 3c3bccab Dimitris Aragiorgis
    def clean(self):
79 3c3bccab Dimitris Aragiorgis
        return []
80 3c3bccab Dimitris Aragiorgis
81 3c3bccab Dimitris Aragiorgis
82 3c3bccab Dimitris Aragiorgis
class HW(SynnefoComponent):
83 3c3bccab Dimitris Aragiorgis
    def test(self):
84 3c3bccab Dimitris Aragiorgis
        return [
85 3c3bccab Dimitris Aragiorgis
            "ping -c 1 %s" % self.node_info.ip,
86 3c3bccab Dimitris Aragiorgis
            "ping -c 1 www.google.com",
87 3c3bccab Dimitris Aragiorgis
            "apt-get update",
88 3c3bccab Dimitris Aragiorgis
            ]
89 3c3bccab Dimitris Aragiorgis
90 d4f28d8f Dimitris Aragiorgis
91 3c3bccab Dimitris Aragiorgis
class SSH(SynnefoComponent):
92 3c3bccab Dimitris Aragiorgis
    def prepare(self):
93 3c3bccab Dimitris Aragiorgis
        return [
94 3c3bccab Dimitris Aragiorgis
            "mkdir -p /root/.ssh",
95 3c3bccab Dimitris Aragiorgis
            "for f in $(ls /root/.ssh/*); do cp $f $f.bak ; done",
96 3c3bccab Dimitris Aragiorgis
            "echo StrictHostKeyChecking no >> /etc/ssh/ssh_config",
97 3c3bccab Dimitris Aragiorgis
            ]
98 3c3bccab Dimitris Aragiorgis
99 3c3bccab Dimitris Aragiorgis
    def configure(self):
100 3c3bccab Dimitris Aragiorgis
        files = [
101 3c3bccab Dimitris Aragiorgis
            "authorized_keys", "id_dsa", "id_dsa.pub", "id_rsa", "id_rsa.pub"
102 3c3bccab Dimitris Aragiorgis
            ]
103 632ea467 Dimitris Aragiorgis
        ssh = [("/root/.ssh/%s" % f, {}, {"mode": 0600}) for f in files]
104 3c3bccab Dimitris Aragiorgis
        return ssh
105 3c3bccab Dimitris Aragiorgis
106 3c3bccab Dimitris Aragiorgis
    def initialize(self):
107 3c3bccab Dimitris Aragiorgis
        f = "/root/.ssh/authorized_keys"
108 3c3bccab Dimitris Aragiorgis
        return [
109 3c3bccab Dimitris Aragiorgis
            "test -e {0}.bak && cat {0}.bak >> {0}".format(f)
110 3c3bccab Dimitris Aragiorgis
            ]
111 3c3bccab Dimitris Aragiorgis
112 3c3bccab Dimitris Aragiorgis
    def test(self):
113 3c3bccab Dimitris Aragiorgis
        return ["ssh %s date" % self.node_info.ip]
114 3c3bccab Dimitris Aragiorgis
115 3c3bccab Dimitris Aragiorgis
116 3c3bccab Dimitris Aragiorgis
class DNS(SynnefoComponent):
117 3c3bccab Dimitris Aragiorgis
    def prepare(self):
118 3c3bccab Dimitris Aragiorgis
        return [
119 3c3bccab Dimitris Aragiorgis
            "chattr -i /etc/resolv.conf",
120 3c3bccab Dimitris Aragiorgis
            "sed -i 's/^127.*$/127.0.0.1 localhost/g' /etc/hosts",
121 3c3bccab Dimitris Aragiorgis
            ]
122 3c3bccab Dimitris Aragiorgis
123 3c3bccab Dimitris Aragiorgis
    def configure(self):
124 3c3bccab Dimitris Aragiorgis
        r1 = {
125 3c3bccab Dimitris Aragiorgis
            "date": str(datetime.datetime.today()),
126 3c3bccab Dimitris Aragiorgis
            "domain": self.env.env.domain,
127 3c3bccab Dimitris Aragiorgis
            "ns_node_ip": self.env.env.ns.ip,
128 3c3bccab Dimitris Aragiorgis
            }
129 3c3bccab Dimitris Aragiorgis
        resolv = [
130 3c3bccab Dimitris Aragiorgis
            ("/etc/resolv.conf", r1, {})
131 3c3bccab Dimitris Aragiorgis
            ]
132 3c3bccab Dimitris Aragiorgis
        return resolv
133 3c3bccab Dimitris Aragiorgis
134 3c3bccab Dimitris Aragiorgis
    def initialize(self):
135 3c3bccab Dimitris Aragiorgis
        return ["chattr +i /etc/resolv.conf"]
136 3c3bccab Dimitris Aragiorgis
137 3c3bccab Dimitris Aragiorgis
138 3c3bccab Dimitris Aragiorgis
class DDNS(SynnefoComponent):
139 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
140 3c3bccab Dimitris Aragiorgis
        "dnsutils",
141 3c3bccab Dimitris Aragiorgis
        ]
142 3c3bccab Dimitris Aragiorgis
143 3c3bccab Dimitris Aragiorgis
    def prepare(self):
144 3c3bccab Dimitris Aragiorgis
        return [
145 3c3bccab Dimitris Aragiorgis
            "mkdir -p /root/ddns/"
146 3c3bccab Dimitris Aragiorgis
            ]
147 3c3bccab Dimitris Aragiorgis
148 3c3bccab Dimitris Aragiorgis
    def configure(self):
149 3c3bccab Dimitris Aragiorgis
        return [
150 3c3bccab Dimitris Aragiorgis
            ("/root/ddns/" + k, {}, {}) for k in self.env.env.ddns_keys
151 3c3bccab Dimitris Aragiorgis
            ]
152 3c3bccab Dimitris Aragiorgis
153 3c3bccab Dimitris Aragiorgis
154 3c3bccab Dimitris Aragiorgis
class NS(SynnefoComponent):
155 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
156 3c3bccab Dimitris Aragiorgis
        "bind9",
157 3c3bccab Dimitris Aragiorgis
        ]
158 3c3bccab Dimitris Aragiorgis
159 3c3bccab Dimitris Aragiorgis
    def nsupdate(self, cmd):
160 3c3bccab Dimitris Aragiorgis
        ret = """
161 3c3bccab Dimitris Aragiorgis
nsupdate -k {0} > /dev/null <<EOF || true
162 3c3bccab Dimitris Aragiorgis
server {1}
163 3c3bccab Dimitris Aragiorgis
{2}
164 3c3bccab Dimitris Aragiorgis
send
165 3c3bccab Dimitris Aragiorgis
EOF
166 3c3bccab Dimitris Aragiorgis
""".format(self.env.env.ddns_private_key, self.node_info.ip, cmd)
167 3c3bccab Dimitris Aragiorgis
        return ret
168 3c3bccab Dimitris Aragiorgis
169 3c3bccab Dimitris Aragiorgis
    def prepare(self):
170 3c3bccab Dimitris Aragiorgis
        return [
171 3c3bccab Dimitris Aragiorgis
            "mkdir -p /etc/bind/zones",
172 3c3bccab Dimitris Aragiorgis
            "chmod g+w /etc/bind/zones",
173 3c3bccab Dimitris Aragiorgis
            "mkdir -p /etc/bind/rev",
174 3c3bccab Dimitris Aragiorgis
            "chmod g+w /etc/bind/rev",
175 3c3bccab Dimitris Aragiorgis
            ]
176 3c3bccab Dimitris Aragiorgis
177 3c3bccab Dimitris Aragiorgis
    def configure(self):
178 3c3bccab Dimitris Aragiorgis
        d = self.env.env.domain
179 3c3bccab Dimitris Aragiorgis
        ip = self.node_info.ip
180 3c3bccab Dimitris Aragiorgis
        return [
181 3c3bccab Dimitris Aragiorgis
            ("/etc/bind/named.conf.local", {"domain": d}, {}),
182 3c3bccab Dimitris Aragiorgis
            ("/etc/bind/zones/example.com",
183 3c3bccab Dimitris Aragiorgis
             {"domain": d, "ns_node_ip": ip},
184 3c3bccab Dimitris Aragiorgis
             {"remote": "/etc/bind/zones/%s" % d}),
185 3c3bccab Dimitris Aragiorgis
            ("/etc/bind/zones/vm.example.com",
186 3c3bccab Dimitris Aragiorgis
             {"domain": d, "ns_node_ip": ip},
187 3c3bccab Dimitris Aragiorgis
             {"remote": "/etc/bind/zones/vm.%s" % d}),
188 3c3bccab Dimitris Aragiorgis
            ("/etc/bind/rev/synnefo.in-addr.arpa.zone", {"domain": d}, {}),
189 3c3bccab Dimitris Aragiorgis
            ("/etc/bind/rev/synnefo.ip6.arpa.zone", {"domain": d}, {}),
190 3c3bccab Dimitris Aragiorgis
            ("/etc/bind/named.conf.options",
191 3c3bccab Dimitris Aragiorgis
             {"node_ips": ";".join(self.env.env.ips)}, {}),
192 3c3bccab Dimitris Aragiorgis
            ("/root/ddns/ddns.key", {}, {"remote": "/etc/bind/ddns.key"}),
193 3c3bccab Dimitris Aragiorgis
            ]
194 3c3bccab Dimitris Aragiorgis
195 3c3bccab Dimitris Aragiorgis
    def update_cnamerecord(self, node_info):
196 3c3bccab Dimitris Aragiorgis
        return self.nsupdate("update add %s" % node_info.cnamerecord)
197 3c3bccab Dimitris Aragiorgis
198 3c3bccab Dimitris Aragiorgis
    def update_arecord(self, node_info):
199 3c3bccab Dimitris Aragiorgis
        return self.nsupdate("update add %s" % node_info.arecord)
200 3c3bccab Dimitris Aragiorgis
201 3c3bccab Dimitris Aragiorgis
    def update_ptrrecord(self, node_info):
202 3c3bccab Dimitris Aragiorgis
        return self.nsupdate("update add %s" % node_info.ptrrecord)
203 3c3bccab Dimitris Aragiorgis
204 3c3bccab Dimitris Aragiorgis
    def update_ns_for_node(self, node_info):
205 3c3bccab Dimitris Aragiorgis
        return [
206 3c3bccab Dimitris Aragiorgis
            self.update_arecord(node_info),
207 3c3bccab Dimitris Aragiorgis
            self.update_cnamerecord(node_info),
208 3c3bccab Dimitris Aragiorgis
            self.update_ptrrecord(node_info)
209 3c3bccab Dimitris Aragiorgis
            ]
210 3c3bccab Dimitris Aragiorgis
211 3c3bccab Dimitris Aragiorgis
    def initialize(self):
212 3c3bccab Dimitris Aragiorgis
        a = [self.update_arecord(n)
213 3c3bccab Dimitris Aragiorgis
             for n in self.env.env.nodes_info.values()]
214 3c3bccab Dimitris Aragiorgis
        ptr = [self.update_ptrrecord(n)
215 3c3bccab Dimitris Aragiorgis
               for n in self.env.env.nodes_info.values()]
216 3c3bccab Dimitris Aragiorgis
        cnames = [self.update_cnamerecord(n)
217 3c3bccab Dimitris Aragiorgis
                  for n in self.env.env.roles_info.values()]
218 3c3bccab Dimitris Aragiorgis
219 3c3bccab Dimitris Aragiorgis
        return a + ptr + cnames
220 3c3bccab Dimitris Aragiorgis
221 3c3bccab Dimitris Aragiorgis
    def restart(self):
222 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/bind9 restart"]
223 3c3bccab Dimitris Aragiorgis
224 3c3bccab Dimitris Aragiorgis
    def test(self):
225 3c3bccab Dimitris Aragiorgis
        n = ["host %s localhost" % i.fqdn
226 3c3bccab Dimitris Aragiorgis
             for i in self.env.env.nodes_info.values()]
227 3c3bccab Dimitris Aragiorgis
        a = ["host %s localhost" % i.fqdn
228 3c3bccab Dimitris Aragiorgis
             for i in self.env.env.roles_info.values()]
229 3c3bccab Dimitris Aragiorgis
        return n + a
230 3c3bccab Dimitris Aragiorgis
231 3c3bccab Dimitris Aragiorgis
232 3c3bccab Dimitris Aragiorgis
class APT(SynnefoComponent):
233 3c3bccab Dimitris Aragiorgis
    """ Setup apt repos and check fqdns """
234 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = ["curl"]
235 3c3bccab Dimitris Aragiorgis
236 3c3bccab Dimitris Aragiorgis
    def prepare(self):
237 3c3bccab Dimitris Aragiorgis
        return [
238 3c3bccab Dimitris Aragiorgis
            "echo 'APT::Install-Suggests \"false\";' >> /etc/apt/apt.conf",
239 d4f28d8f Dimitris Aragiorgis
            "curl -k https://dev.grnet.gr/files/apt-grnetdev.pub | \
240 d4f28d8f Dimitris Aragiorgis
                apt-key add -",
241 3c3bccab Dimitris Aragiorgis
            ]
242 3c3bccab Dimitris Aragiorgis
243 3c3bccab Dimitris Aragiorgis
    def configure(self):
244 3c3bccab Dimitris Aragiorgis
        return [
245 3c3bccab Dimitris Aragiorgis
            ("/etc/apt/sources.list.d/synnefo.wheezy.list", {}, {})
246 3c3bccab Dimitris Aragiorgis
            ]
247 3c3bccab Dimitris Aragiorgis
248 3c3bccab Dimitris Aragiorgis
    def initialize(self):
249 3c3bccab Dimitris Aragiorgis
        return [
250 3c3bccab Dimitris Aragiorgis
            "apt-get update",
251 3c3bccab Dimitris Aragiorgis
            ]
252 3c3bccab Dimitris Aragiorgis
253 3c3bccab Dimitris Aragiorgis
254 3c3bccab Dimitris Aragiorgis
class MQ(SynnefoComponent):
255 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = ["rabbitmq-server"]
256 3c3bccab Dimitris Aragiorgis
257 3c3bccab Dimitris Aragiorgis
    def check(self):
258 3c3bccab Dimitris Aragiorgis
        return ["ping -c 1 mq.%s" % self.env.env.domain]
259 3c3bccab Dimitris Aragiorgis
260 3c3bccab Dimitris Aragiorgis
    def initialize(self):
261 3c3bccab Dimitris Aragiorgis
        u = self.env.env.synnefo_user
262 3c3bccab Dimitris Aragiorgis
        p = self.env.env.synnefo_rabbitmq_passwd
263 3c3bccab Dimitris Aragiorgis
        return [
264 3c3bccab Dimitris Aragiorgis
            "rabbitmqctl add_user %s %s" % (u, p),
265 3c3bccab Dimitris Aragiorgis
            "rabbitmqctl set_permissions %s \".*\" \".*\" \".*\"" % u,
266 3c3bccab Dimitris Aragiorgis
            "rabbitmqctl delete_user guest",
267 3c3bccab Dimitris Aragiorgis
            "rabbitmqctl set_user_tags %s administrator" % u,
268 3c3bccab Dimitris Aragiorgis
            ]
269 3c3bccab Dimitris Aragiorgis
270 3c3bccab Dimitris Aragiorgis
271 3c3bccab Dimitris Aragiorgis
class DB(SynnefoComponent):
272 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = ["postgresql"]
273 3c3bccab Dimitris Aragiorgis
274 3c3bccab Dimitris Aragiorgis
    def check(self):
275 3c3bccab Dimitris Aragiorgis
        return ["ping -c 1 db.%s" % self.env.env.domain]
276 3c3bccab Dimitris Aragiorgis
277 3c3bccab Dimitris Aragiorgis
    def get_user_info_from_db(self):
278 3c3bccab Dimitris Aragiorgis
        cmd = """
279 3c3bccab Dimitris Aragiorgis
cat > /tmp/psqlcmd <<EOF
280 3c3bccab Dimitris Aragiorgis
select id, auth_token, uuid, email from auth_user, im_astakosuser \
281 3c3bccab Dimitris Aragiorgis
where auth_user.id = im_astakosuser.user_ptr_id and auth_user.email = '{0}';
282 3c3bccab Dimitris Aragiorgis
EOF
283 3c3bccab Dimitris Aragiorgis

284 3c3bccab Dimitris Aragiorgis
su - postgres -c  "psql -w -d snf_apps -f /tmp/psqlcmd"
285 3c3bccab Dimitris Aragiorgis
""".format(self.env.env.user_email)
286 3c3bccab Dimitris Aragiorgis
287 3c3bccab Dimitris Aragiorgis
        return [cmd]
288 3c3bccab Dimitris Aragiorgis
289 3c3bccab Dimitris Aragiorgis
    def allow_access_in_db(self, node_info, user="all", method="md5"):
290 3c3bccab Dimitris Aragiorgis
        f = "/etc/postgresql/*/main/pg_hba.conf"
291 3c3bccab Dimitris Aragiorgis
        cmd1 = "echo host all %s %s/32 %s >> %s" % \
292 632ea467 Dimitris Aragiorgis
            (user, node_info.ip, method, f)
293 3c3bccab Dimitris Aragiorgis
        cmd2 = "sed -i 's/\(host.*127.0.0.1.*\)md5/\\1trust/' %s" % f
294 3c3bccab Dimitris Aragiorgis
        return [cmd1, cmd2] + self.restart()
295 3c3bccab Dimitris Aragiorgis
296 3c3bccab Dimitris Aragiorgis
    def configure(self):
297 3c3bccab Dimitris Aragiorgis
        u = self.env.env.synnefo_user
298 3c3bccab Dimitris Aragiorgis
        p = self.env.env.synnefo_db_passwd
299 3c3bccab Dimitris Aragiorgis
        replace = {"synnefo_user": u, "synnefo_db_passwd": p}
300 3c3bccab Dimitris Aragiorgis
        return [
301 3c3bccab Dimitris Aragiorgis
            ("/tmp/db-init.psql", replace, {}),
302 3c3bccab Dimitris Aragiorgis
            ]
303 3c3bccab Dimitris Aragiorgis
304 3c3bccab Dimitris Aragiorgis
    def make_db_fast(self):
305 3c3bccab Dimitris Aragiorgis
        f = "/etc/postgresql/*/main/postgresql.conf"
306 3c3bccab Dimitris Aragiorgis
        opts = "fsync=off\nsynchronous_commit=off\nfull_page_writes=off\n"
307 3c3bccab Dimitris Aragiorgis
        return ["""echo -e "%s" >> %s""" % (opts, f)]
308 3c3bccab Dimitris Aragiorgis
309 3c3bccab Dimitris Aragiorgis
    def prepare(self):
310 3c3bccab Dimitris Aragiorgis
        f = "/etc/postgresql/*/main/postgresql.conf"
311 3c3bccab Dimitris Aragiorgis
        return [
312 3c3bccab Dimitris Aragiorgis
            """echo "listen_addresses = '*'" >> %s""" % f,
313 3c3bccab Dimitris Aragiorgis
            ]
314 3c3bccab Dimitris Aragiorgis
315 3c3bccab Dimitris Aragiorgis
    def initialize(self):
316 3c3bccab Dimitris Aragiorgis
        script = "/tmp/db-init.psql"
317 3c3bccab Dimitris Aragiorgis
        cmd = "su - postgres -c \"psql -w -f %s\" " % script
318 3c3bccab Dimitris Aragiorgis
        return [cmd]
319 3c3bccab Dimitris Aragiorgis
320 3c3bccab Dimitris Aragiorgis
    def restart(self):
321 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/postgresql restart"]
322 3c3bccab Dimitris Aragiorgis
323 3c3bccab Dimitris Aragiorgis
    def destroy_db(self):
324 3c3bccab Dimitris Aragiorgis
        return [
325 3c3bccab Dimitris Aragiorgis
            """su - postgres -c ' psql -w -c "drop database snf_apps" '""",
326 3c3bccab Dimitris Aragiorgis
            """su - postgres -c ' psql -w -c "drop database snf_pithos" '"""
327 3c3bccab Dimitris Aragiorgis
            ]
328 3c3bccab Dimitris Aragiorgis
329 3c3bccab Dimitris Aragiorgis
330 3c3bccab Dimitris Aragiorgis
class Ganeti(SynnefoComponent):
331 3c3bccab Dimitris Aragiorgis
332 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
333 3c3bccab Dimitris Aragiorgis
        "qemu-kvm",
334 3c3bccab Dimitris Aragiorgis
        "python-bitarray",
335 3c3bccab Dimitris Aragiorgis
        "ganeti-htools",
336 3c3bccab Dimitris Aragiorgis
        "ganeti-haskell",
337 3c3bccab Dimitris Aragiorgis
        "snf-ganeti",
338 3c3bccab Dimitris Aragiorgis
        "ganeti2",
339 3c3bccab Dimitris Aragiorgis
        "bridge-utils",
340 3c3bccab Dimitris Aragiorgis
        "lvm2",
341 3c3bccab Dimitris Aragiorgis
        "drbd8-utils",
342 3c3bccab Dimitris Aragiorgis
        ]
343 3c3bccab Dimitris Aragiorgis
344 3c3bccab Dimitris Aragiorgis
    def check(self):
345 3c3bccab Dimitris Aragiorgis
        commands = [
346 3c3bccab Dimitris Aragiorgis
            "getent hosts %s | grep -v ^127" % self.node_info.hostname,
347 3c3bccab Dimitris Aragiorgis
            "hostname -f | grep %s" % self.node_info.fqdn,
348 3c3bccab Dimitris Aragiorgis
            ]
349 3c3bccab Dimitris Aragiorgis
        return commands
350 3c3bccab Dimitris Aragiorgis
351 3c3bccab Dimitris Aragiorgis
    def configure(self):
352 3c3bccab Dimitris Aragiorgis
        return [
353 3c3bccab Dimitris Aragiorgis
            ("/etc/ganeti/file-storage-paths", {}, {}),
354 3c3bccab Dimitris Aragiorgis
            ]
355 3c3bccab Dimitris Aragiorgis
356 3c3bccab Dimitris Aragiorgis
    def prepare_lvm(self):
357 3c3bccab Dimitris Aragiorgis
        return [
358 3c3bccab Dimitris Aragiorgis
            "pvcreate %s" % self.env.env.extra_disk,
359 3c3bccab Dimitris Aragiorgis
            "vgcreate %s %s" % (self.env.env.extra_disk, self.env.env.vg)
360 3c3bccab Dimitris Aragiorgis
            ]
361 3c3bccab Dimitris Aragiorgis
362 3c3bccab Dimitris Aragiorgis
    def prepare_net_infra(self):
363 3c3bccab Dimitris Aragiorgis
        br = self.env.env.common_bridge
364 3c3bccab Dimitris Aragiorgis
        return [
365 3c3bccab Dimitris Aragiorgis
            "brctl addbr {0}; ip link set {0} up".format(br)
366 3c3bccab Dimitris Aragiorgis
            ]
367 3c3bccab Dimitris Aragiorgis
368 3c3bccab Dimitris Aragiorgis
    def prepare(self):
369 3c3bccab Dimitris Aragiorgis
        return [
370 3c3bccab Dimitris Aragiorgis
            "mkdir -p /srv/ganeti/file-storage/",
371 3c3bccab Dimitris Aragiorgis
            "sed -i 's/^127.*$/127.0.0.1 localhost/g' /etc/hosts"
372 3c3bccab Dimitris Aragiorgis
            ] + self.prepare_net_infra()
373 3c3bccab Dimitris Aragiorgis
374 3c3bccab Dimitris Aragiorgis
    def restart(self):
375 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/ganeti restart"]
376 3c3bccab Dimitris Aragiorgis
377 3c3bccab Dimitris Aragiorgis
378 3c3bccab Dimitris Aragiorgis
class Master(SynnefoComponent):
379 3c3bccab Dimitris Aragiorgis
    def add_rapi_user(self):
380 31d179f3 Dimitris Aragiorgis
        user = self.env.env.synnefo_user
381 31d179f3 Dimitris Aragiorgis
        passwd = self.env.env.synnefo_rapi_passwd
382 31d179f3 Dimitris Aragiorgis
        x = "%s:Ganeti Remote API:%s" % (user, passwd)
383 3c3bccab Dimitris Aragiorgis
384 31d179f3 Dimitris Aragiorgis
        cmd = """
385 31d179f3 Dimitris Aragiorgis
cat >> /var/lib/ganeti/rapi/users <<EOF
386 31d179f3 Dimitris Aragiorgis
%s {HA1}$(echo -n %s | openssl md5 | sed 's/^.* //') write
387 31d179f3 Dimitris Aragiorgis
EOF
388 31d179f3 Dimitris Aragiorgis
""" % (self.env.env.synnefo_user, x)
389 3c3bccab Dimitris Aragiorgis
390 31d179f3 Dimitris Aragiorgis
        return [cmd] + self.restart()
391 3c3bccab Dimitris Aragiorgis
392 3c3bccab Dimitris Aragiorgis
    def add_node(self, node_info):
393 3c3bccab Dimitris Aragiorgis
        commands = [
394 d4f28d8f Dimitris Aragiorgis
            "gnt-node add --no-ssh-key-check --master-capable=yes " +
395 632ea467 Dimitris Aragiorgis
            "--vm-capable=yes " + node_info.fqdn,
396 3c3bccab Dimitris Aragiorgis
            ]
397 3c3bccab Dimitris Aragiorgis
        return commands
398 3c3bccab Dimitris Aragiorgis
399 3c3bccab Dimitris Aragiorgis
    def try_use_vg(self):
400 3c3bccab Dimitris Aragiorgis
        vg = self.env.env.vg
401 3c3bccab Dimitris Aragiorgis
        return [
402 3c3bccab Dimitris Aragiorgis
            "gnt-cluster modify --vg-name=%s || true" % vg,
403 3c3bccab Dimitris Aragiorgis
            "gnt-cluster modify --disk-parameters=drbd:metavg=%s" % vg,
404 3c3bccab Dimitris Aragiorgis
            "gnt-group modify --disk-parameters=drbd:metavg=%s default" % vg,
405 3c3bccab Dimitris Aragiorgis
            ]
406 3c3bccab Dimitris Aragiorgis
407 3c3bccab Dimitris Aragiorgis
    def initialize(self):
408 3c3bccab Dimitris Aragiorgis
        cmd = """
409 3c3bccab Dimitris Aragiorgis
        gnt-cluster init --enabled-hypervisors=kvm \
410 3c3bccab Dimitris Aragiorgis
            --no-lvm-storage --no-drbd-storage \
411 3c3bccab Dimitris Aragiorgis
            --nic-parameters link={0},mode=bridged \
412 3c3bccab Dimitris Aragiorgis
            --master-netdev {1} \
413 3c3bccab Dimitris Aragiorgis
            --specs-nic-count min=0,max=8 \
414 3c3bccab Dimitris Aragiorgis
            --default-iallocator hail \
415 3c3bccab Dimitris Aragiorgis
            --hypervisor-parameters kvm:kernel_path=,vnc_bind_address=0.0.0.0 \
416 3c3bccab Dimitris Aragiorgis
            --no-ssh-init --no-etc-hosts \
417 3c3bccab Dimitris Aragiorgis
            --enabled-disk-templates file,plain,ext,drbd \
418 3c3bccab Dimitris Aragiorgis
            {2}
419 3c3bccab Dimitris Aragiorgis
        """.format(self.env.env.common_bridge,
420 3c3bccab Dimitris Aragiorgis
                   self.env.env.cluster_netdev, self.env.env.cluster.fqdn)
421 3c3bccab Dimitris Aragiorgis
422 3c3bccab Dimitris Aragiorgis
        return [cmd] + self.try_use_vg() + self.add_rapi_user()
423 3c3bccab Dimitris Aragiorgis
424 3c3bccab Dimitris Aragiorgis
    def restart(self):
425 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/ganeti restart"]
426 3c3bccab Dimitris Aragiorgis
427 3c3bccab Dimitris Aragiorgis
428 3c3bccab Dimitris Aragiorgis
class Image(SynnefoComponent):
429 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
430 3c3bccab Dimitris Aragiorgis
        "snf-pithos-backend",
431 3c3bccab Dimitris Aragiorgis
        "snf-image",
432 3c3bccab Dimitris Aragiorgis
        ]
433 3c3bccab Dimitris Aragiorgis
434 3c3bccab Dimitris Aragiorgis
    def check(self):
435 3c3bccab Dimitris Aragiorgis
        return ["mkdir -p %s" % self.env.env.image_dir]
436 3c3bccab Dimitris Aragiorgis
437 3c3bccab Dimitris Aragiorgis
    def configure(self):
438 3c3bccab Dimitris Aragiorgis
        tmpl = "/etc/default/snf-image"
439 3c3bccab Dimitris Aragiorgis
        replace = {
440 3c3bccab Dimitris Aragiorgis
            "synnefo_user": self.env.env.synnefo_user,
441 3c3bccab Dimitris Aragiorgis
            "synnefo_db_passwd": self.env.env.synnefo_db_passwd,
442 3c3bccab Dimitris Aragiorgis
            "pithos_dir": self.env.env.pithos_dir,
443 3c3bccab Dimitris Aragiorgis
            "db_node": self.env.env.db.ip,
444 3c3bccab Dimitris Aragiorgis
            "image_dir": self.env.env.image_dir,
445 3c3bccab Dimitris Aragiorgis
            }
446 3c3bccab Dimitris Aragiorgis
        return [(tmpl, replace, {})]
447 3c3bccab Dimitris Aragiorgis
448 3c3bccab Dimitris Aragiorgis
    def initialize(self):
449 3c3bccab Dimitris Aragiorgis
        return ["snf-image-update-helper -y"]
450 3c3bccab Dimitris Aragiorgis
451 3c3bccab Dimitris Aragiorgis
452 3c3bccab Dimitris Aragiorgis
class GTools(SynnefoComponent):
453 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
454 3c3bccab Dimitris Aragiorgis
        "snf-cyclades-gtools",
455 3c3bccab Dimitris Aragiorgis
        ]
456 3c3bccab Dimitris Aragiorgis
457 3c3bccab Dimitris Aragiorgis
    def check(self):
458 3c3bccab Dimitris Aragiorgis
        return ["ping -c1 %s" % self.env.env.mq.ip]
459 3c3bccab Dimitris Aragiorgis
460 3c3bccab Dimitris Aragiorgis
    def configure(self):
461 3c3bccab Dimitris Aragiorgis
        tmpl = "/etc/synnefo/gtools.conf"
462 3c3bccab Dimitris Aragiorgis
        replace = {
463 3c3bccab Dimitris Aragiorgis
            "synnefo_user": self.env.env.synnefo_user,
464 3c3bccab Dimitris Aragiorgis
            "synnefo_rabbitmq_passwd": self.env.env.synnefo_rabbitmq_passwd,
465 3c3bccab Dimitris Aragiorgis
            "mq_node": self.env.env.mq.ip,
466 3c3bccab Dimitris Aragiorgis
            }
467 3c3bccab Dimitris Aragiorgis
        return [(tmpl, replace, {})]
468 3c3bccab Dimitris Aragiorgis
469 3c3bccab Dimitris Aragiorgis
    def initialize(self):
470 3c3bccab Dimitris Aragiorgis
        return [
471 3c3bccab Dimitris Aragiorgis
            "sed -i 's/false/true/' /etc/default/snf-ganeti-eventd",
472 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/snf-ganeti-eventd start",
473 3c3bccab Dimitris Aragiorgis
            ]
474 3c3bccab Dimitris Aragiorgis
475 3c3bccab Dimitris Aragiorgis
    def restart(self):
476 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/snf-ganeti-eventd restart"]
477 3c3bccab Dimitris Aragiorgis
478 3c3bccab Dimitris Aragiorgis
479 3c3bccab Dimitris Aragiorgis
class Network(SynnefoComponent):
480 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
481 3c3bccab Dimitris Aragiorgis
        "python-nfqueue",
482 3c3bccab Dimitris Aragiorgis
        "snf-network",
483 3c3bccab Dimitris Aragiorgis
        "nfdhcpd",
484 3c3bccab Dimitris Aragiorgis
        ]
485 3c3bccab Dimitris Aragiorgis
486 3c3bccab Dimitris Aragiorgis
    def configure(self):
487 3c3bccab Dimitris Aragiorgis
        r1 = {
488 3c3bccab Dimitris Aragiorgis
            "ns_node_ip": self.env.env.ns.ip
489 3c3bccab Dimitris Aragiorgis
            }
490 3c3bccab Dimitris Aragiorgis
        r2 = {
491 3c3bccab Dimitris Aragiorgis
            "common_bridge": self.env.env.common_bridge,
492 3c3bccab Dimitris Aragiorgis
            "public_iface": self.env.env.public_iface,
493 3c3bccab Dimitris Aragiorgis
            "subnet": self.env.env.synnefo_public_network_subnet,
494 3c3bccab Dimitris Aragiorgis
            "gateway": self.env.env.synnefo_public_network_gateway,
495 3c3bccab Dimitris Aragiorgis
            "router_ip": self.env.env.router.ip,
496 3c3bccab Dimitris Aragiorgis
            "node_ip": self.node_info.ip,
497 3c3bccab Dimitris Aragiorgis
            }
498 3c3bccab Dimitris Aragiorgis
        r3 = {
499 3c3bccab Dimitris Aragiorgis
            "domain": self.env.env.domain,
500 3c3bccab Dimitris Aragiorgis
            "server": self.env.env.ns.ip,
501 3c3bccab Dimitris Aragiorgis
            "keyfile": self.env.env.ddns_private_key,
502 3c3bccab Dimitris Aragiorgis
            }
503 3c3bccab Dimitris Aragiorgis
504 3c3bccab Dimitris Aragiorgis
        return [
505 3c3bccab Dimitris Aragiorgis
            ("/etc/nfdhcpd/nfdhcpd.conf", r1, {}),
506 3c3bccab Dimitris Aragiorgis
            ("/etc/rc.local", r2, {"mode": 0755}),
507 3c3bccab Dimitris Aragiorgis
            ("/etc/default/snf-network", r3, {}),
508 3c3bccab Dimitris Aragiorgis
            ]
509 3c3bccab Dimitris Aragiorgis
510 3c3bccab Dimitris Aragiorgis
    def initialize(self):
511 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/rc.local start"]
512 3c3bccab Dimitris Aragiorgis
513 3c3bccab Dimitris Aragiorgis
    def restart(self):
514 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/nfdhcpd restart"]
515 3c3bccab Dimitris Aragiorgis
516 3c3bccab Dimitris Aragiorgis
517 3c3bccab Dimitris Aragiorgis
class Apache(SynnefoComponent):
518 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
519 3c3bccab Dimitris Aragiorgis
        "apache2",
520 3c3bccab Dimitris Aragiorgis
        ]
521 3c3bccab Dimitris Aragiorgis
522 3c3bccab Dimitris Aragiorgis
    def prepare(self):
523 3c3bccab Dimitris Aragiorgis
        return [
524 3c3bccab Dimitris Aragiorgis
            "a2enmod ssl", "a2enmod rewrite", "a2dissite default",
525 3c3bccab Dimitris Aragiorgis
            "a2enmod headers",
526 3c3bccab Dimitris Aragiorgis
            "a2enmod proxy_http", "a2dismod autoindex",
527 3c3bccab Dimitris Aragiorgis
            ]
528 3c3bccab Dimitris Aragiorgis
529 3c3bccab Dimitris Aragiorgis
    def configure(self):
530 3c3bccab Dimitris Aragiorgis
        r1 = {"HOST": self.node_info.fqdn}
531 3c3bccab Dimitris Aragiorgis
        return [
532 3c3bccab Dimitris Aragiorgis
            ("/etc/apache2/sites-available/synnefo", r1, {}),
533 3c3bccab Dimitris Aragiorgis
            ("/etc/apache2/sites-available/synnefo-ssl", r1, {}),
534 3c3bccab Dimitris Aragiorgis
            ]
535 3c3bccab Dimitris Aragiorgis
536 3c3bccab Dimitris Aragiorgis
    def initialize(self):
537 3c3bccab Dimitris Aragiorgis
        return [
538 3c3bccab Dimitris Aragiorgis
            "a2ensite synnefo", "a2ensite synnefo-ssl",
539 3c3bccab Dimitris Aragiorgis
            ]
540 3c3bccab Dimitris Aragiorgis
541 3c3bccab Dimitris Aragiorgis
    def restart(self):
542 3c3bccab Dimitris Aragiorgis
        return [
543 632ea467 Dimitris Aragiorgis
            "/etc/init.d/apache2 restart",
544 632ea467 Dimitris Aragiorgis
            ]
545 3c3bccab Dimitris Aragiorgis
546 3c3bccab Dimitris Aragiorgis
547 3c3bccab Dimitris Aragiorgis
class Gunicorn(SynnefoComponent):
548 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
549 3c3bccab Dimitris Aragiorgis
        "gunicorn",
550 3c3bccab Dimitris Aragiorgis
        ]
551 3c3bccab Dimitris Aragiorgis
552 3c3bccab Dimitris Aragiorgis
    def prepare(self):
553 3c3bccab Dimitris Aragiorgis
        return [
554 3c3bccab Dimitris Aragiorgis
            "chown root.www-data /var/log/gunicorn",
555 3c3bccab Dimitris Aragiorgis
            ]
556 3c3bccab Dimitris Aragiorgis
557 3c3bccab Dimitris Aragiorgis
    def configure(self):
558 3c3bccab Dimitris Aragiorgis
        r1 = {"HOST": self.node_info.fqdn}
559 3c3bccab Dimitris Aragiorgis
        return [
560 3c3bccab Dimitris Aragiorgis
            ("/etc/gunicorn.d/synnefo", r1, {}),
561 3c3bccab Dimitris Aragiorgis
            ]
562 3c3bccab Dimitris Aragiorgis
563 3c3bccab Dimitris Aragiorgis
    def restart(self):
564 3c3bccab Dimitris Aragiorgis
        return [
565 632ea467 Dimitris Aragiorgis
            "/etc/init.d/gunicorn restart",
566 632ea467 Dimitris Aragiorgis
            ]
567 3c3bccab Dimitris Aragiorgis
568 3c3bccab Dimitris Aragiorgis
569 3c3bccab Dimitris Aragiorgis
class Common(SynnefoComponent):
570 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
571 3c3bccab Dimitris Aragiorgis
        # snf-common
572 3c3bccab Dimitris Aragiorgis
        "python-objpool",
573 3c3bccab Dimitris Aragiorgis
        "snf-common",
574 3c3bccab Dimitris Aragiorgis
        "python-astakosclient",
575 3c3bccab Dimitris Aragiorgis
        "snf-django-lib",
576 3c3bccab Dimitris Aragiorgis
        "snf-branding",
577 3c3bccab Dimitris Aragiorgis
        ]
578 3c3bccab Dimitris Aragiorgis
579 3c3bccab Dimitris Aragiorgis
    def configure(self):
580 3c3bccab Dimitris Aragiorgis
        r1 = {
581 3c3bccab Dimitris Aragiorgis
            "EMAIL_SUBJECT_PREFIX": self.node_info.hostname,
582 3c3bccab Dimitris Aragiorgis
            "domain": self.env.env.domain,
583 3c3bccab Dimitris Aragiorgis
            "HOST": self.node_info.fqdn,
584 3c3bccab Dimitris Aragiorgis
            "MAIL_DIR": self.env.env.mail_dir,
585 3c3bccab Dimitris Aragiorgis
            }
586 3c3bccab Dimitris Aragiorgis
        return [
587 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/common.conf", r1, {}),
588 3c3bccab Dimitris Aragiorgis
            ]
589 3c3bccab Dimitris Aragiorgis
590 3c3bccab Dimitris Aragiorgis
    def initialize(self):
591 3c3bccab Dimitris Aragiorgis
        return ["mkdir -p {0}; chmod 777 {0}".format(self.env.env.mail_dir)]
592 3c3bccab Dimitris Aragiorgis
593 3c3bccab Dimitris Aragiorgis
    def restart(self):
594 3c3bccab Dimitris Aragiorgis
        return [
595 632ea467 Dimitris Aragiorgis
            "/etc/init.d/gunicorn restart",
596 632ea467 Dimitris Aragiorgis
            ]
597 3c3bccab Dimitris Aragiorgis
598 3c3bccab Dimitris Aragiorgis
599 3c3bccab Dimitris Aragiorgis
class WEB(SynnefoComponent):
600 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
601 3c3bccab Dimitris Aragiorgis
        "snf-webproject",
602 3c3bccab Dimitris Aragiorgis
        "python-psycopg2",
603 3c3bccab Dimitris Aragiorgis
        "python-gevent",
604 3c3bccab Dimitris Aragiorgis
        "python-django",
605 3c3bccab Dimitris Aragiorgis
        ]
606 3c3bccab Dimitris Aragiorgis
607 3c3bccab Dimitris Aragiorgis
    def check(self):
608 3c3bccab Dimitris Aragiorgis
        return ["ping -c1 %s" % self.env.env.db.fqdn]
609 3c3bccab Dimitris Aragiorgis
610 3c3bccab Dimitris Aragiorgis
    def configure(self):
611 3c3bccab Dimitris Aragiorgis
        r1 = {
612 3c3bccab Dimitris Aragiorgis
            "synnefo_user": self.env.env.synnefo_user,
613 3c3bccab Dimitris Aragiorgis
            "synnefo_db_passwd": self.env.env.synnefo_db_passwd,
614 3c3bccab Dimitris Aragiorgis
            "db_node": self.env.env.db.fqdn,
615 3c3bccab Dimitris Aragiorgis
            "domain": self.env.env.domain,
616 3c3bccab Dimitris Aragiorgis
            }
617 3c3bccab Dimitris Aragiorgis
        return [
618 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/webproject.conf", r1, {}),
619 3c3bccab Dimitris Aragiorgis
            ]
620 3c3bccab Dimitris Aragiorgis
621 3c3bccab Dimitris Aragiorgis
    def restart(self):
622 3c3bccab Dimitris Aragiorgis
        return [
623 632ea467 Dimitris Aragiorgis
            "/etc/init.d/gunicorn restart",
624 632ea467 Dimitris Aragiorgis
            ]
625 3c3bccab Dimitris Aragiorgis
626 3c3bccab Dimitris Aragiorgis
627 3c3bccab Dimitris Aragiorgis
class Astakos(SynnefoComponent):
628 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
629 3c3bccab Dimitris Aragiorgis
        "python-django-south",
630 3c3bccab Dimitris Aragiorgis
        "snf-astakos-app",
631 3c3bccab Dimitris Aragiorgis
        "kamaki",
632 3c3bccab Dimitris Aragiorgis
        ]
633 3c3bccab Dimitris Aragiorgis
634 3c3bccab Dimitris Aragiorgis
    def export_service(self):
635 3c3bccab Dimitris Aragiorgis
        f = self.env.jsonfile
636 3c3bccab Dimitris Aragiorgis
        return [
637 3c3bccab Dimitris Aragiorgis
            "snf-manage service-export-astakos > %s" % f
638 3c3bccab Dimitris Aragiorgis
            ]
639 3c3bccab Dimitris Aragiorgis
640 3c3bccab Dimitris Aragiorgis
    def import_service(self):
641 3c3bccab Dimitris Aragiorgis
        f = self.env.jsonfile
642 3c3bccab Dimitris Aragiorgis
        return [
643 3c3bccab Dimitris Aragiorgis
            "snf-manage service-import --json=%s" % f
644 3c3bccab Dimitris Aragiorgis
            ]
645 3c3bccab Dimitris Aragiorgis
646 3c3bccab Dimitris Aragiorgis
    def set_default_quota(self):
647 d4f28d8f Dimitris Aragiorgis
        cmd = "snf-manage resource-modify --default-quota"
648 d4f28d8f Dimitris Aragiorgis
        return [
649 d4f28d8f Dimitris Aragiorgis
            "%s 40G pithos.diskspace" % cmd,
650 d4f28d8f Dimitris Aragiorgis
            "%s 2 astakos.pending_app" % cmd,
651 d4f28d8f Dimitris Aragiorgis
            "%s 4 cyclades.vm" % cmd,
652 d4f28d8f Dimitris Aragiorgis
            "%s 40G cyclades.disk" % cmd,
653 d4f28d8f Dimitris Aragiorgis
            "%s 16G cyclades.total_ram" % cmd,
654 d4f28d8f Dimitris Aragiorgis
            "%s 8G cyclades.ram" % cmd,
655 d4f28d8f Dimitris Aragiorgis
            "%s 32 cyclades.total_cpu" % cmd,
656 d4f28d8f Dimitris Aragiorgis
            "%s 16 cyclades.cpu" % cmd,
657 d4f28d8f Dimitris Aragiorgis
            "%s 4 cyclades.network.private" % cmd,
658 d4f28d8f Dimitris Aragiorgis
            "%s 4 cyclades.floating_ip" % cmd,
659 3c3bccab Dimitris Aragiorgis
            ]
660 3c3bccab Dimitris Aragiorgis
661 3c3bccab Dimitris Aragiorgis
    def modify_all_quota(self):
662 d4f28d8f Dimitris Aragiorgis
        cmd = "snf-manage user-modify -f --all --base-quota"
663 d4f28d8f Dimitris Aragiorgis
        return [
664 d4f28d8f Dimitris Aragiorgis
            "%s pithos.diskspace 40G" % cmd,
665 d4f28d8f Dimitris Aragiorgis
            "%s astakos.pending_app 2" % cmd,
666 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.vm 4" % cmd,
667 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.disk 40G" % cmd,
668 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.total_ram 16G" % cmd,
669 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.ram 8G" % cmd,
670 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.total_cpu 32" % cmd,
671 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.cpu 16" % cmd,
672 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.network.private 4" % cmd,
673 d4f28d8f Dimitris Aragiorgis
            "%s cyclades.floating_ip 4" % cmd,
674 3c3bccab Dimitris Aragiorgis
            ]
675 3c3bccab Dimitris Aragiorgis
676 3c3bccab Dimitris Aragiorgis
    def get_services(self):
677 3c3bccab Dimitris Aragiorgis
        return [
678 3c3bccab Dimitris Aragiorgis
            "snf-manage component-list -o id,name,token"
679 3c3bccab Dimitris Aragiorgis
            ]
680 3c3bccab Dimitris Aragiorgis
681 3c3bccab Dimitris Aragiorgis
    def configure(self):
682 3c3bccab Dimitris Aragiorgis
        r1 = {
683 3c3bccab Dimitris Aragiorgis
            "ACCOUNTS": self.env.env.accounts.fqdn,
684 3c3bccab Dimitris Aragiorgis
            "domain": self.env.env.domain,
685 3c3bccab Dimitris Aragiorgis
            "CYCLADES": self.env.env.cyclades.fqdn,
686 3c3bccab Dimitris Aragiorgis
            "PITHOS": self.env.env.pithos.fqdn,
687 3c3bccab Dimitris Aragiorgis
            }
688 3c3bccab Dimitris Aragiorgis
        return [
689 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/astakos.conf", r1, {})
690 3c3bccab Dimitris Aragiorgis
            ]
691 3c3bccab Dimitris Aragiorgis
692 3c3bccab Dimitris Aragiorgis
    def initialize(self):
693 3c3bccab Dimitris Aragiorgis
        secret = self.env.env.oa2_secret
694 3c3bccab Dimitris Aragiorgis
        view = "https://%s/pithos/ui/view" % self.env.env.pithos.fqdn
695 3c3bccab Dimitris Aragiorgis
        oa2 = "snf-manage oauth2-client-add pithos-view \
696 3c3bccab Dimitris Aragiorgis
                  --secret=%s --is-trusted --url %s" % (secret, view)
697 3c3bccab Dimitris Aragiorgis
698 3c3bccab Dimitris Aragiorgis
        return [
699 3c3bccab Dimitris Aragiorgis
            "snf-manage syncdb --noinput",
700 3c3bccab Dimitris Aragiorgis
            "snf-manage migrate im --delete-ghost-migrations",
701 3c3bccab Dimitris Aragiorgis
            "snf-manage migrate quotaholder_app",
702 3c3bccab Dimitris Aragiorgis
            "snf-manage migrate oa2",
703 3c3bccab Dimitris Aragiorgis
            "snf-manage loaddata groups",
704 3c3bccab Dimitris Aragiorgis
            oa2
705 3c3bccab Dimitris Aragiorgis
            ] + self.astakos_register_components()
706 3c3bccab Dimitris Aragiorgis
707 3c3bccab Dimitris Aragiorgis
    def astakos_register_components(self):
708 3c3bccab Dimitris Aragiorgis
        # base urls
709 3c3bccab Dimitris Aragiorgis
        cbu = "https://%s/cyclades" % self.env.env.cyclades.fqdn
710 3c3bccab Dimitris Aragiorgis
        pbu = "https://%s/pithos" % self.env.env.pithos.fqdn
711 3c3bccab Dimitris Aragiorgis
        abu = "https://%s/astakos" % self.env.env.accounts.fqdn
712 3c3bccab Dimitris Aragiorgis
        cmsurl = "https://%s/home" % self.env.env.cms.fqdn
713 3c3bccab Dimitris Aragiorgis
714 3c3bccab Dimitris Aragiorgis
        cmd = "snf-manage component-add"
715 3c3bccab Dimitris Aragiorgis
        h = "%s home --base-url %s --ui-url %s" % (cmd, cmsurl, cmsurl)
716 3c3bccab Dimitris Aragiorgis
        c = "%s cyclades --base-url %s --ui-url %s/ui" % (cmd, cbu, cbu)
717 3c3bccab Dimitris Aragiorgis
        p = "%s pithos --base-url %s --ui-url %s/ui" % (cmd, pbu, pbu)
718 3c3bccab Dimitris Aragiorgis
        a = "%s astakos --base-url %s --ui-url %s/ui" % (cmd, abu, abu)
719 3c3bccab Dimitris Aragiorgis
720 3c3bccab Dimitris Aragiorgis
        return [h, c, p, a]
721 3c3bccab Dimitris Aragiorgis
722 3c3bccab Dimitris Aragiorgis
    def add_user(self):
723 3c3bccab Dimitris Aragiorgis
        info = (
724 3c3bccab Dimitris Aragiorgis
            self.env.env.user_passwd,
725 3c3bccab Dimitris Aragiorgis
            self.env.env.user_email,
726 3c3bccab Dimitris Aragiorgis
            self.env.env.user_name,
727 3c3bccab Dimitris Aragiorgis
            self.env.env.user_lastname,
728 3c3bccab Dimitris Aragiorgis
            )
729 3c3bccab Dimitris Aragiorgis
        cmd = "snf-manage user-add --password %s %s %s %s" % info
730 3c3bccab Dimitris Aragiorgis
        return [cmd]
731 3c3bccab Dimitris Aragiorgis
732 3c3bccab Dimitris Aragiorgis
    def activate_user(self):
733 3c3bccab Dimitris Aragiorgis
        user_id = self.env.user_id
734 3c3bccab Dimitris Aragiorgis
        return [
735 3c3bccab Dimitris Aragiorgis
            "snf-manage user-modify --verify %s" % user_id,
736 3c3bccab Dimitris Aragiorgis
            "snf-manage user-modify --accept %s" % user_id,
737 3c3bccab Dimitris Aragiorgis
            ]
738 3c3bccab Dimitris Aragiorgis
739 3c3bccab Dimitris Aragiorgis
740 3c3bccab Dimitris Aragiorgis
class CMS(SynnefoComponent):
741 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
742 3c3bccab Dimitris Aragiorgis
        "snf-cloudcms"
743 3c3bccab Dimitris Aragiorgis
        ]
744 3c3bccab Dimitris Aragiorgis
745 3c3bccab Dimitris Aragiorgis
    def configure(self):
746 3c3bccab Dimitris Aragiorgis
        r1 = {
747 3c3bccab Dimitris Aragiorgis
            "ACCOUNTS": self.env.env.accounts.fqdn
748 3c3bccab Dimitris Aragiorgis
            }
749 3c3bccab Dimitris Aragiorgis
        r2 = {
750 3c3bccab Dimitris Aragiorgis
            "DOMAIN": self.env.env.domain
751 3c3bccab Dimitris Aragiorgis
            }
752 3c3bccab Dimitris Aragiorgis
        return [
753 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/cms.conf", r1, {}),
754 3c3bccab Dimitris Aragiorgis
            ("/tmp/sites.json", r2, {}),
755 3c3bccab Dimitris Aragiorgis
            ("/tmp/page.json", {}, {}),
756 3c3bccab Dimitris Aragiorgis
            ]
757 3c3bccab Dimitris Aragiorgis
758 3c3bccab Dimitris Aragiorgis
    def initialize(self):
759 3c3bccab Dimitris Aragiorgis
        return [
760 3c3bccab Dimitris Aragiorgis
            "snf-manage syncdb",
761 3c3bccab Dimitris Aragiorgis
            "snf-manage migrate --delete-ghost-migrations",
762 3c3bccab Dimitris Aragiorgis
            "snf-manage loaddata /tmp/sites.json",
763 3c3bccab Dimitris Aragiorgis
            "snf-manage loaddata /tmp/page.json",
764 3c3bccab Dimitris Aragiorgis
            "snf-manage createsuperuser --username=admin \
765 3c3bccab Dimitris Aragiorgis
                  --email=admin@%s --noinput" % self.env.env.domain,
766 3c3bccab Dimitris Aragiorgis
            ]
767 3c3bccab Dimitris Aragiorgis
768 3c3bccab Dimitris Aragiorgis
    def restart(self):
769 3c3bccab Dimitris Aragiorgis
        return ["/etc/init.d/gunicorn restart"]
770 3c3bccab Dimitris Aragiorgis
771 3c3bccab Dimitris Aragiorgis
772 3c3bccab Dimitris Aragiorgis
class Mount(SynnefoComponent):
773 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
774 3c3bccab Dimitris Aragiorgis
        "nfs-common"
775 3c3bccab Dimitris Aragiorgis
        ]
776 3c3bccab Dimitris Aragiorgis
777 3c3bccab Dimitris Aragiorgis
    def prepare(self):
778 3c3bccab Dimitris Aragiorgis
        ret = []
779 3c3bccab Dimitris Aragiorgis
        for d in [self.env.env.pithos_dir, self.env.env.image_dir]:
780 3c3bccab Dimitris Aragiorgis
            ret.append("mkdir -p %s" % d)
781 3c3bccab Dimitris Aragiorgis
            cmd = """
782 3c3bccab Dimitris Aragiorgis
cat >> /etc/fstab <<EOF
783 3c3bccab Dimitris Aragiorgis
{0}:{1} {1}  nfs defaults,rw,noatime,rsize=131072,wsize=131072 0 0
784 3c3bccab Dimitris Aragiorgis
EOF
785 3c3bccab Dimitris Aragiorgis
""".format(self.env.env.pithos.ip, d)
786 3c3bccab Dimitris Aragiorgis
            ret.append(cmd)
787 3c3bccab Dimitris Aragiorgis
788 3c3bccab Dimitris Aragiorgis
        return ret
789 3c3bccab Dimitris Aragiorgis
790 3c3bccab Dimitris Aragiorgis
    def initialize(self):
791 3c3bccab Dimitris Aragiorgis
        ret = []
792 3c3bccab Dimitris Aragiorgis
        for d in [self.env.env.pithos_dir, self.env.env.image_dir]:
793 3c3bccab Dimitris Aragiorgis
            ret.append("mount %s" % d)
794 3c3bccab Dimitris Aragiorgis
        return ret
795 3c3bccab Dimitris Aragiorgis
796 3c3bccab Dimitris Aragiorgis
797 3c3bccab Dimitris Aragiorgis
class NFS(SynnefoComponent):
798 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
799 3c3bccab Dimitris Aragiorgis
        "nfs-kernel-server"
800 3c3bccab Dimitris Aragiorgis
        ]
801 3c3bccab Dimitris Aragiorgis
802 3c3bccab Dimitris Aragiorgis
    def prepare_image(self):
803 3c3bccab Dimitris Aragiorgis
        url = self.env.env.debian_base_url
804 3c3bccab Dimitris Aragiorgis
        d = self.env.env.image_dir
805 3c3bccab Dimitris Aragiorgis
        image = "debian_base.diskdump"
806 3c3bccab Dimitris Aragiorgis
        return ["wget %s -O %s/%s" % (url, d, image)]
807 3c3bccab Dimitris Aragiorgis
808 3c3bccab Dimitris Aragiorgis
    def prepare(self):
809 3c3bccab Dimitris Aragiorgis
        p = self.env.env.pithos_dir
810 3c3bccab Dimitris Aragiorgis
        return [
811 3c3bccab Dimitris Aragiorgis
            "mkdir -p %s" % self.env.env.image_dir,
812 3c3bccab Dimitris Aragiorgis
            "mkdir -p %s/data" % p,
813 3c3bccab Dimitris Aragiorgis
            "chown www-data.www-data %s/data" % p,
814 3c3bccab Dimitris Aragiorgis
            "chmod g+ws %s/data" % p,
815 3c3bccab Dimitris Aragiorgis
            ] + self.prepare_image()
816 3c3bccab Dimitris Aragiorgis
817 3c3bccab Dimitris Aragiorgis
    def update_exports(self, node_info):
818 3c3bccab Dimitris Aragiorgis
        cmd = """
819 3c3bccab Dimitris Aragiorgis
cat >> /etc/exports <<EOF
820 3c3bccab Dimitris Aragiorgis
{0} {2}(rw,async,no_subtree_check,no_root_squash)
821 3c3bccab Dimitris Aragiorgis
{1} {2}(rw,async,no_subtree_check,no_root_squash)
822 3c3bccab Dimitris Aragiorgis
EOF
823 3c3bccab Dimitris Aragiorgis
""".format(self.env.env.pithos_dir, self.env.env.image_dir, node_info.ip)
824 3c3bccab Dimitris Aragiorgis
        return [cmd] + self.restart()
825 3c3bccab Dimitris Aragiorgis
826 3c3bccab Dimitris Aragiorgis
    def restart(self):
827 3c3bccab Dimitris Aragiorgis
        return ["exportfs -a"]
828 3c3bccab Dimitris Aragiorgis
829 3c3bccab Dimitris Aragiorgis
830 3c3bccab Dimitris Aragiorgis
class Pithos(SynnefoComponent):
831 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
832 3c3bccab Dimitris Aragiorgis
        "kamaki",
833 3c3bccab Dimitris Aragiorgis
        "snf-pithos-backend",
834 3c3bccab Dimitris Aragiorgis
        "snf-pithos-app",
835 3c3bccab Dimitris Aragiorgis
        "snf-pithos-webclient",
836 3c3bccab Dimitris Aragiorgis
        ]
837 3c3bccab Dimitris Aragiorgis
838 3c3bccab Dimitris Aragiorgis
    def export_service(self):
839 3c3bccab Dimitris Aragiorgis
        f = self.env.jsonfile
840 3c3bccab Dimitris Aragiorgis
        return [
841 3c3bccab Dimitris Aragiorgis
            "snf-manage service-export-pithos > %s" % f
842 3c3bccab Dimitris Aragiorgis
            ]
843 3c3bccab Dimitris Aragiorgis
844 3c3bccab Dimitris Aragiorgis
    def configure(self):
845 3c3bccab Dimitris Aragiorgis
        r1 = {
846 3c3bccab Dimitris Aragiorgis
            "ACCOUNTS": self.env.env.accounts.fqdn,
847 3c3bccab Dimitris Aragiorgis
            "PITHOS": self.env.env.pithos.fqdn,
848 3c3bccab Dimitris Aragiorgis
            "db_node": self.env.env.db.ip,
849 3c3bccab Dimitris Aragiorgis
            "synnefo_user": self.env.env.synnefo_user,
850 3c3bccab Dimitris Aragiorgis
            "synnefo_db_passwd": self.env.env.synnefo_db_passwd,
851 3c3bccab Dimitris Aragiorgis
            "pithos_dir": self.env.env.pithos_dir,
852 3c3bccab Dimitris Aragiorgis
            "PITHOS_SERVICE_TOKEN": self.env.service_token,
853 3c3bccab Dimitris Aragiorgis
            "oa2_secret": self.env.env.oa2_secret,
854 3c3bccab Dimitris Aragiorgis
            }
855 3c3bccab Dimitris Aragiorgis
        r2 = {
856 3c3bccab Dimitris Aragiorgis
            "ACCOUNTS": self.env.env.accounts.fqdn,
857 3c3bccab Dimitris Aragiorgis
            "PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE": self.env.service_id,
858 3c3bccab Dimitris Aragiorgis
            }
859 3c3bccab Dimitris Aragiorgis
860 3c3bccab Dimitris Aragiorgis
        return [
861 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/pithos.conf", r1, {}),
862 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/webclient.conf", r2, {}),
863 3c3bccab Dimitris Aragiorgis
            ]
864 3c3bccab Dimitris Aragiorgis
865 38cfb0c3 Sofia Papagiannaki
    def initialize(self):
866 38cfb0c3 Sofia Papagiannaki
        return ["pithos-migrate stamp head"]
867 38cfb0c3 Sofia Papagiannaki
868 d4f28d8f Dimitris Aragiorgis
869 3c3bccab Dimitris Aragiorgis
class Cyclades(SynnefoComponent):
870 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
871 3c3bccab Dimitris Aragiorgis
        "memcached",
872 3c3bccab Dimitris Aragiorgis
        "python-memcache",
873 3c3bccab Dimitris Aragiorgis
        "snf-pithos-backend",
874 3c3bccab Dimitris Aragiorgis
        "kamaki",
875 3c3bccab Dimitris Aragiorgis
        "snf-cyclades-app",
876 3c3bccab Dimitris Aragiorgis
        "python-django-south",
877 3c3bccab Dimitris Aragiorgis
        ]
878 3c3bccab Dimitris Aragiorgis
879 d4f28d8f Dimitris Aragiorgis
    def add_network(self):
880 d4f28d8f Dimitris Aragiorgis
        subnet = self.env.env.synnefo_public_network_subnet
881 d4f28d8f Dimitris Aragiorgis
        gw = self.env.env.synnefo_public_network_gateway
882 d4f28d8f Dimitris Aragiorgis
        ntype = self.env.env.synnefo_public_network_type
883 d4f28d8f Dimitris Aragiorgis
        link = self.env.env.common_bridge
884 3c3bccab Dimitris Aragiorgis
885 3c3bccab Dimitris Aragiorgis
        cmd = """
886 3c3bccab Dimitris Aragiorgis
snf-manage network-create --subnet={0} --gateway={1} --public \
887 3c3bccab Dimitris Aragiorgis
  --dhcp=True --flavor={2} --mode=bridged --link={3} --name=Internet \
888 3c3bccab Dimitris Aragiorgis
  --floating-ip-pool=True
889 3c3bccab Dimitris Aragiorgis
""".format(subnet, gw, ntype, link)
890 3c3bccab Dimitris Aragiorgis
891 3c3bccab Dimitris Aragiorgis
        return [cmd]
892 3c3bccab Dimitris Aragiorgis
893 d4f28d8f Dimitris Aragiorgis
    def add_network6(self):
894 d4f28d8f Dimitris Aragiorgis
        subnet = "babe::/64"
895 d4f28d8f Dimitris Aragiorgis
        gw = "babe::1"
896 d4f28d8f Dimitris Aragiorgis
        ntype = self.env.env.synnefo_public_network_type
897 d4f28d8f Dimitris Aragiorgis
        link = self.env.env.common_bridge
898 3c3bccab Dimitris Aragiorgis
899 d4f28d8f Dimitris Aragiorgis
        cmd = """
900 d4f28d8f Dimitris Aragiorgis
snf-manage network-create --subnet6={0} \
901 d4f28d8f Dimitris Aragiorgis
      --gateway6={1} --public --dhcp=True --flavor={2} --mode=bridged \
902 d4f28d8f Dimitris Aragiorgis
       --link={3} --name=IPv6PublicNetwork
903 d4f28d8f Dimitris Aragiorgis
""".format(subnet, gw, ntype, link)
904 3c3bccab Dimitris Aragiorgis
905 3c3bccab Dimitris Aragiorgis
        return [cmd]
906 3c3bccab Dimitris Aragiorgis
907 3c3bccab Dimitris Aragiorgis
    def export_service(self):
908 3c3bccab Dimitris Aragiorgis
        f = self.env.jsonfile
909 3c3bccab Dimitris Aragiorgis
        return [
910 3c3bccab Dimitris Aragiorgis
            "snf-manage service-export-cyclades > %s" % f
911 3c3bccab Dimitris Aragiorgis
            ]
912 3c3bccab Dimitris Aragiorgis
913 3c3bccab Dimitris Aragiorgis
    def list_backends(self):
914 3c3bccab Dimitris Aragiorgis
        return [
915 3c3bccab Dimitris Aragiorgis
            "snf-manage backend-list"
916 3c3bccab Dimitris Aragiorgis
            ]
917 3c3bccab Dimitris Aragiorgis
918 3c3bccab Dimitris Aragiorgis
    def add_backend(self):
919 3c3bccab Dimitris Aragiorgis
        cluster = self.env.env.cluster
920 3c3bccab Dimitris Aragiorgis
        user = self.env.env.synnefo_user
921 3c3bccab Dimitris Aragiorgis
        passwd = self.env.env.synnefo_rapi_passwd
922 3c3bccab Dimitris Aragiorgis
        return [
923 d4f28d8f Dimitris Aragiorgis
            "snf-manage backend-add --clustername=%s --user=%s --pass=%s" %
924 632ea467 Dimitris Aragiorgis
            (cluster.fqdn, user, passwd)
925 3c3bccab Dimitris Aragiorgis
            ]
926 3c3bccab Dimitris Aragiorgis
927 3c3bccab Dimitris Aragiorgis
    def undrain_backend(self):
928 3c3bccab Dimitris Aragiorgis
        backend_id = self.env.backend_id
929 3c3bccab Dimitris Aragiorgis
        return [
930 3c3bccab Dimitris Aragiorgis
            "snf-manage backend-modify --drained=False %s" % str(backend_id)
931 3c3bccab Dimitris Aragiorgis
            ]
932 3c3bccab Dimitris Aragiorgis
933 3c3bccab Dimitris Aragiorgis
    def prepare(self):
934 3c3bccab Dimitris Aragiorgis
        return ["sed -i 's/false/true/' /etc/default/snf-dispatcher"]
935 3c3bccab Dimitris Aragiorgis
936 3c3bccab Dimitris Aragiorgis
    def configure(self):
937 3c3bccab Dimitris Aragiorgis
        r1 = {
938 3c3bccab Dimitris Aragiorgis
            "ACCOUNTS": self.env.env.accounts.fqdn,
939 3c3bccab Dimitris Aragiorgis
            "CYCLADES": self.env.env.cyclades.fqdn,
940 3c3bccab Dimitris Aragiorgis
            "mq_node": self.env.env.mq.ip,
941 3c3bccab Dimitris Aragiorgis
            "db_node": self.env.env.db.ip,
942 3c3bccab Dimitris Aragiorgis
            "synnefo_user": self.env.env.synnefo_user,
943 3c3bccab Dimitris Aragiorgis
            "synnefo_db_passwd": self.env.env.synnefo_db_passwd,
944 3c3bccab Dimitris Aragiorgis
            "synnefo_rabbitmq_passwd": self.env.env.synnefo_rabbitmq_passwd,
945 3c3bccab Dimitris Aragiorgis
            "pithos_dir": self.env.env.pithos_dir,
946 3c3bccab Dimitris Aragiorgis
            "common_bridge": self.env.env.common_bridge,
947 3c3bccab Dimitris Aragiorgis
            "HOST": self.env.env.cyclades.ip,
948 3c3bccab Dimitris Aragiorgis
            "domain": self.env.env.domain,
949 3c3bccab Dimitris Aragiorgis
            "CYCLADES_SERVICE_TOKEN": self.env.service_token,
950 e23023e8 Dimitris Aragiorgis
            "STATS": self.env.env.stats.fqdn,
951 e23023e8 Dimitris Aragiorgis
            "SYNNEFO_VNC_PASSWD": self.env.env.synnefo_vnc_passwd,
952 3c3bccab Dimitris Aragiorgis
            }
953 3c3bccab Dimitris Aragiorgis
        return [
954 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/cyclades.conf", r1, {})
955 3c3bccab Dimitris Aragiorgis
            ]
956 3c3bccab Dimitris Aragiorgis
957 3c3bccab Dimitris Aragiorgis
    def initialize(self):
958 3c3bccab Dimitris Aragiorgis
        cpu = self.env.env.flavor_cpu
959 3c3bccab Dimitris Aragiorgis
        ram = self.env.env.flavor_ram
960 3c3bccab Dimitris Aragiorgis
        disk = self.env.env.flavor_disk
961 3c3bccab Dimitris Aragiorgis
        storage = self.env.env.flavor_storage
962 3c3bccab Dimitris Aragiorgis
        return [
963 3c3bccab Dimitris Aragiorgis
            "snf-manage syncdb",
964 3c3bccab Dimitris Aragiorgis
            "snf-manage migrate --delete-ghost-migrations",
965 d4f28d8f Dimitris Aragiorgis
            "snf-manage pool-create --type=mac-prefix \
966 d4f28d8f Dimitris Aragiorgis
              --base=aa:00:0 --size=65536",
967 3c3bccab Dimitris Aragiorgis
            "snf-manage pool-create --type=bridge --base=prv --size=20",
968 3c3bccab Dimitris Aragiorgis
            "snf-manage flavor-create %s %s %s %s" % (cpu, ram, disk, storage),
969 3c3bccab Dimitris Aragiorgis
            ]
970 3c3bccab Dimitris Aragiorgis
971 3c3bccab Dimitris Aragiorgis
    def restart(self):
972 3c3bccab Dimitris Aragiorgis
        return [
973 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/gunicorn restart",
974 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/snf-dispatcher restart",
975 3c3bccab Dimitris Aragiorgis
            ]
976 3c3bccab Dimitris Aragiorgis
977 d4f28d8f Dimitris Aragiorgis
978 3c3bccab Dimitris Aragiorgis
class VNC(SynnefoComponent):
979 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
980 3c3bccab Dimitris Aragiorgis
        "snf-vncauthproxy"
981 3c3bccab Dimitris Aragiorgis
        ]
982 3c3bccab Dimitris Aragiorgis
983 e23023e8 Dimitris Aragiorgis
    def prepare(self):
984 368bac96 Dimitris Aragiorgis
        return ["mkdir -p /var/lib/vncauthproxy"]
985 e23023e8 Dimitris Aragiorgis
986 e23023e8 Dimitris Aragiorgis
    def configure(self):
987 e23023e8 Dimitris Aragiorgis
        return [
988 e23023e8 Dimitris Aragiorgis
            ("/var/lib/vncauthproxy/users", {}, {})
989 e23023e8 Dimitris Aragiorgis
            ]
990 e23023e8 Dimitris Aragiorgis
991 e23023e8 Dimitris Aragiorgis
    def initialize(self):
992 e23023e8 Dimitris Aragiorgis
        user = self.env.env.synnefo_user
993 e23023e8 Dimitris Aragiorgis
        passwd = self.env.env.synnefo_vnc_passwd
994 e23023e8 Dimitris Aragiorgis
        #TODO: run vncauthproxy-passwd
995 e23023e8 Dimitris Aragiorgis
        return []
996 e23023e8 Dimitris Aragiorgis
997 3c3bccab Dimitris Aragiorgis
    def restart(self):
998 3c3bccab Dimitris Aragiorgis
        return [
999 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/vncauthproxy restart"
1000 3c3bccab Dimitris Aragiorgis
            ]
1001 3c3bccab Dimitris Aragiorgis
1002 3c3bccab Dimitris Aragiorgis
1003 3c3bccab Dimitris Aragiorgis
class Kamaki(SynnefoComponent):
1004 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
1005 3c3bccab Dimitris Aragiorgis
        "python-progress",
1006 3c3bccab Dimitris Aragiorgis
        "kamaki",
1007 3c3bccab Dimitris Aragiorgis
        ]
1008 3c3bccab Dimitris Aragiorgis
1009 3c3bccab Dimitris Aragiorgis
    def initialize(self):
1010 3c3bccab Dimitris Aragiorgis
        url = "https://%s/astakos/identity/v2.0" % self.env.env.accounts.fqdn
1011 632ea467 Dimitris Aragiorgis
        token = self.env.user_auth_token
1012 3c3bccab Dimitris Aragiorgis
        return [
1013 d4f28d8f Dimitris Aragiorgis
            "kamaki config set cloud.default.url %s" % url,
1014 632ea467 Dimitris Aragiorgis
            "kamaki config set cloud.default.token %s" % token,
1015 3c3bccab Dimitris Aragiorgis
            "kamaki container create images",
1016 3c3bccab Dimitris Aragiorgis
            ]
1017 3c3bccab Dimitris Aragiorgis
1018 3c3bccab Dimitris Aragiorgis
    def fetch_image(self):
1019 3c3bccab Dimitris Aragiorgis
        url = self.env.env.debian_base_url
1020 3c3bccab Dimitris Aragiorgis
        image = "debian_base.diskdump"
1021 3c3bccab Dimitris Aragiorgis
        return [
1022 3c3bccab Dimitris Aragiorgis
            "wget %s -O /tmp/%s" % (url, image)
1023 3c3bccab Dimitris Aragiorgis
            ]
1024 3c3bccab Dimitris Aragiorgis
1025 3c3bccab Dimitris Aragiorgis
    def upload_image(self):
1026 3c3bccab Dimitris Aragiorgis
        image = "debian_base.diskdump"
1027 3c3bccab Dimitris Aragiorgis
        return [
1028 3c3bccab Dimitris Aragiorgis
            "kamaki file upload --container images /tmp/%s %s" % (image, image)
1029 3c3bccab Dimitris Aragiorgis
            ]
1030 3c3bccab Dimitris Aragiorgis
1031 3c3bccab Dimitris Aragiorgis
    def register_image(self):
1032 3c3bccab Dimitris Aragiorgis
        image = "debian_base.diskdump"
1033 3c3bccab Dimitris Aragiorgis
        image_location = "/images/%s" % image
1034 3c3bccab Dimitris Aragiorgis
        cmd = """
1035 3c3bccab Dimitris Aragiorgis
        kamaki image register --name "Debian Base" --location {0} \
1036 3c3bccab Dimitris Aragiorgis
              --public --disk-format=diskdump \
1037 3c3bccab Dimitris Aragiorgis
              --property OSFAMILY=linux --property ROOT_PARTITION=1 \
1038 3c3bccab Dimitris Aragiorgis
              --property description="Debian Squeeze Base System" \
1039 3c3bccab Dimitris Aragiorgis
              --property size=450M --property kernel=2.6.32 \
1040 3c3bccab Dimitris Aragiorgis
              --property GUI="No GUI" --property sortorder=1 \
1041 3c3bccab Dimitris Aragiorgis
              --property USERS=root --property OS=debian
1042 3c3bccab Dimitris Aragiorgis
        """.format(image_location)
1043 3c3bccab Dimitris Aragiorgis
        return [
1044 3c3bccab Dimitris Aragiorgis
            "sleep 5",
1045 3c3bccab Dimitris Aragiorgis
            cmd
1046 3c3bccab Dimitris Aragiorgis
            ]
1047 3c3bccab Dimitris Aragiorgis
1048 d4f28d8f Dimitris Aragiorgis
1049 3c3bccab Dimitris Aragiorgis
class Burnin(SynnefoComponent):
1050 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
1051 3c3bccab Dimitris Aragiorgis
        "kamaki",
1052 3c3bccab Dimitris Aragiorgis
        "snf-tools",
1053 3c3bccab Dimitris Aragiorgis
        ]
1054 3c3bccab Dimitris Aragiorgis
1055 d4f28d8f Dimitris Aragiorgis
1056 3c3bccab Dimitris Aragiorgis
class Collectd(SynnefoComponent):
1057 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
1058 3c3bccab Dimitris Aragiorgis
        "collectd",
1059 3c3bccab Dimitris Aragiorgis
        ]
1060 3c3bccab Dimitris Aragiorgis
1061 3c3bccab Dimitris Aragiorgis
    def configure(self):
1062 3c3bccab Dimitris Aragiorgis
        return [
1063 3c3bccab Dimitris Aragiorgis
            ("/etc/collectd/collectd.conf", {}, {}),
1064 3c3bccab Dimitris Aragiorgis
            ]
1065 3c3bccab Dimitris Aragiorgis
1066 3c3bccab Dimitris Aragiorgis
    def restart(self):
1067 3c3bccab Dimitris Aragiorgis
        return [
1068 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/collectd restart",
1069 3c3bccab Dimitris Aragiorgis
            ]
1070 3c3bccab Dimitris Aragiorgis
1071 3c3bccab Dimitris Aragiorgis
1072 3c3bccab Dimitris Aragiorgis
class Stats(SynnefoComponent):
1073 3c3bccab Dimitris Aragiorgis
    REQUIRED_PACKAGES = [
1074 3c3bccab Dimitris Aragiorgis
        "snf-stats-app",
1075 3c3bccab Dimitris Aragiorgis
        ]
1076 3c3bccab Dimitris Aragiorgis
1077 3c3bccab Dimitris Aragiorgis
    def prepare(self):
1078 3c3bccab Dimitris Aragiorgis
        return [
1079 3c3bccab Dimitris Aragiorgis
            "mkdir -p /var/cache/snf-stats-app/",
1080 3c3bccab Dimitris Aragiorgis
            "chown www-data:www-data /var/cache/snf-stats-app/",
1081 3c3bccab Dimitris Aragiorgis
            ]
1082 3c3bccab Dimitris Aragiorgis
1083 3c3bccab Dimitris Aragiorgis
    def configure(self):
1084 3c3bccab Dimitris Aragiorgis
        r1 = {
1085 3c3bccab Dimitris Aragiorgis
            "STATS": self.env.env.stats.fqdn,
1086 3c3bccab Dimitris Aragiorgis
            }
1087 3c3bccab Dimitris Aragiorgis
        return [
1088 3c3bccab Dimitris Aragiorgis
            ("/etc/synnefo/stats.conf", r1, {}),
1089 3c3bccab Dimitris Aragiorgis
            ("/etc/collectd/synnefo-stats.conf", r1, {}),
1090 3c3bccab Dimitris Aragiorgis
            ]
1091 3c3bccab Dimitris Aragiorgis
1092 3c3bccab Dimitris Aragiorgis
    def restart(self):
1093 3c3bccab Dimitris Aragiorgis
        return [
1094 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/gunicorn restart",
1095 3c3bccab Dimitris Aragiorgis
            "/etc/init.d/apache2 restart",
1096 3c3bccab Dimitris Aragiorgis
            ]
1097 3c3bccab Dimitris Aragiorgis
1098 d4f28d8f Dimitris Aragiorgis
1099 3c3bccab Dimitris Aragiorgis
class GanetiCollectd(SynnefoComponent):
1100 3c3bccab Dimitris Aragiorgis
    def configure(self):
1101 3c3bccab Dimitris Aragiorgis
        r1 = {
1102 3c3bccab Dimitris Aragiorgis
            "STATS": self.env.env.stats.fqdn,
1103 3c3bccab Dimitris Aragiorgis
            }
1104 3c3bccab Dimitris Aragiorgis
        return [
1105 3c3bccab Dimitris Aragiorgis
            ("/etc/collectd/passwd", {}, {}),
1106 3c3bccab Dimitris Aragiorgis
            ("/etc/collectd/synnefo-ganeti.conf", r1, {}),
1107 3c3bccab Dimitris Aragiorgis
            ]