9
9
from shlex import split
10
11
from subprocess import (
16
19
sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
21
from charmhelpers import fetch
18
22
from charmhelpers.core import (
27
GPFS_PATH = '/Linux/x86_64'
23
30
def add_to_path(p, new):
24
31
return p if new in p.split(':') else p + ':' + new
26
33
os.environ['PATH'] = add_to_path(os.environ['PATH'], '/usr/lpp/mmfs/bin')
36
## installation methods ##
37
def _get_source(url, source_dir=""):
38
return "deb %s%s ./" % (url, source_dir)
41
def check_empty_source(gpfs_url):
42
# Check if there is a repository to install from
43
# TODO: check if packages are already installed
45
log("No GPFS source available. Use juju set gpfs gpfs_url=<url> "
46
"to install packages. See README for more info.", log.ERROR)
50
def gpfs_install(url, version):
51
# install main gpfs packages
52
gpfs_source = _get_source(url, source_dir=GPFS_PATH)
53
log('Gpfs source' + gpfs_source)
55
# Add gpfs source and update apt
56
fetch.add_source(gpfs_source)
58
fetch.apt_update(fatal=True)
59
# Install gpfs packages
60
fetch.apt_install("gpfs*", options=["--allow-unauthenticated"],
62
except CalledProcessError:
63
#TODO: verify source was configured correctly
67
def gpfs_install_updates(url, version, update=True):
68
# install update packages (patches), if given
70
log('Applying patches')
71
source_dir = '/gpfs' + version + '_patches' + GPFS_PATH
72
patch_source = _get_source(url, source_dir=source_dir)
73
fetch.add_source(patch_source)
74
fetch.apt_update(fatal=True)
75
fetch.apt_install("gpfs*", options=["--allow-unauthenticated"],
28
79
## ssh key methods ##
29
80
def create_ssh_keys():
30
81
# Generate ssh keys if needed
91
145
idfile.write("StrictHostKeyChecking no\n")
149
## Other utility methods##
150
def validate_quorum(quorum):
151
valid_values = ['', 'quorum', 'non-quorum']
152
return quorum if quorum in valid_values else ''
94
155
## cluster management methods ##
157
# build binary gpfs modules after installation
159
check_call(["mmbuildgpl"])
160
except CalledProcessError:
161
log('mmbuildgpl was not executed', level=hookenv.WARNING)
163
log('mmbuildgpl not found/installed')
97
167
# Only manager can start/stop cluster
99
169
log(check_output(split('mmstartup -a')))
102
173
# stop the server
104
175
check_output(split('mmshutdown -a'))
106
178
def node_exists(nodename):
107
179
# Check if node has already been added to cluster
108
180
lscluster = check_output('mmlscluster')
109
181
node = re.search('^.*\d+.*%s.*\n' % nodename, lscluster, re.M)
110
182
return False if node is None else True
112
185
def add_node(nodename, m_designation='client', q_designation='nonquorum'):
113
186
# add new node to the cluster
114
187
if cluster_exists() and not node_exists(nodename):
115
log(check_output(split('mmaddnode -N %s:%s-%s' % \
116
(nodename, m_designation, q_designation))))
188
log(check_output(split('mmaddnode -N %s:%s-%s' %
189
(nodename, m_designation, q_designation))))
118
191
log('Node %s could not be added. Manager not defined' % nodename)
120
194
def apply_license(nodename):
121
195
check_output(split('mmchlicense server --accept -N %s' % nodename))
123
198
def set_manager_file():
124
199
# define a file that indicates the node is a manager
125
open("/var/mmfs/.manager","a").close()
200
open("/var/mmfs/.manager", "a").close()
127
203
def is_manager():
128
204
# check if the node is a manager
129
205
if os.path.exists("/var/mmfs/.manager"):
132
209
def cluster_exists():
133
210
# Check if cluster is already defined
134
211
return True if call('mmlscluster') == 0 else False
136
214
def create_cluster(hostname):
137
215
# create the cluster for the hostname, manager only
138
216
if is_manager() and not cluster_exists():
139
log(check_output(split('mmcrcluster -N %s:quorum-manager' % \
140
hostname + ' -r /usr/bin/ssh -R /usr/bin/scp')))
217
log(check_output(split('mmcrcluster -N %s:quorum-manager' %
218
hostname + ' -r /usr/bin/ssh -R /usr/bin/scp')))
142
221
def chk_dns(hostname, ip):