-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathswapsetup.py
More file actions
62 lines (51 loc) · 2.17 KB
/
Copy pathswapsetup.py
File metadata and controls
62 lines (51 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2009-2014 Justin Riley
#
# This file is part of StarCluster.
#
# StarCluster is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# StarCluster is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with StarCluster. If not, see <http://www.gnu.org/licenses/>.
"""
"""
from starcluster.clustersetup import DefaultClusterSetup
from starcluster.logger import log
from starcluster.utils import print_timing
class SwapSetup(DefaultClusterSetup):
"""Setup swap space"""
def __init__(self, swap_file="/swapfile", amount=None):
super(SwapSetup, self).__init__()
self.swap_file = swap_file
self.amount = amount and amount.strip()
@print_timing("SwapSetup")
def setup_swap(self, nodes):
if not self.amount:
log.info("No amount specified!")
return
log.info("Setting up swap")
commands = []
commands.append('fallocate -l %s %s' % (self.amount, self.swap_file))
commands.append('chmod 600 %s' % self.swap_file)
commands.append('mkswap %s' % self.swap_file)
commands.append('swapon %s' % self.swap_file)
commands.append('swapon -s')
for command in commands:
log.info("$ " + command)
cmd = "\n".join(commands)
for node in nodes:
self.pool.simple_job(node.ssh.execute, (cmd,), jobid=node.alias)
self.pool.wait(len(nodes))
def run(self, nodes, master, user, user_shell, volumes):
self.setup_swap(nodes)
def on_add_node(self, node, nodes, master, user, user_shell, volumes):
self.setup_swap([node])
def on_remove_node(self, node, nodes, master, user, user_shell, volumes):
raise NotImplementedError("on_remove_node method not implemented")