Merge lp:~mcs-chasal/ibmcharms/dnsfix into lp:ibmcharms

Proposed by Michael Chase-Salerno
Status: Merged
Approved by: Michael Chase-Salerno
Approved revision: 27
Merged at revision: 25
Proposed branch: lp:~mcs-chasal/ibmcharms/dnsfix
Merge into: lp:ibmcharms
Diff against target: 120 lines (+38/-29)
3 files modified
charms/trusty/gpfs/hooks/common-relation-changed (+21/-26)
charms/trusty/gpfs/hooks/common-relation-joined (+5/-2)
charms/trusty/gpfs/hooks/gpfshooklib.py (+12/-1)
To merge this branch: bzr merge lp:~mcs-chasal/ibmcharms/dnsfix
Reviewer Review Type Date Requested Status
Adalberto Medeiros Needs Fixing
Review via email: mp+251024@code.launchpad.net

Description of the change

Added creation of /etc/hosts entries if hostnames are not resolving on the systems.

To post a comment you must log in.
Revision history for this message
Adalberto Medeiros (adalbas) wrote :

There are a few comments regarding how the hostname and ip is being handled by the local unit and a few improvements.

Other than that, will you add that to peers relation as well? Is it necessary?

Revision history for this message
Adalberto Medeiros (adalbas) :
review: Needs Fixing
lp:~mcs-chasal/ibmcharms/dnsfix updated
27. By Michael Chase-Salerno

Incorporating review comments and fixing startup

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charms/trusty/gpfs/hooks/common-relation-changed'
2--- charms/trusty/gpfs/hooks/common-relation-changed 2015-02-10 12:24:34 +0000
3+++ charms/trusty/gpfs/hooks/common-relation-changed 2015-03-03 17:58:00 +0000
4@@ -15,38 +15,33 @@
5
6 def main():
7 hookname = hookenv.hook_name()
8+ relid = hookenv.relation_id()
9+ runit = hookenv.remote_unit()
10+ unit = hookenv.local_unit()
11+
12+ # Get hosts in relationship and configure /etc/hosts if needed
13+ rip = hookenv.relation_get(attribute='pip', unit=runit, rid=relid)
14+ rlhn = hookenv.relation_get(attribute='lhostname', unit=runit, rid=relid)
15+ llhn = socket.getfqdn()
16+ if not rlhn is None:
17+ gpfshooklib.chk_dns(rlhn,rip)
18+
19 if hookname == "client-relation-changed":
20 # Save the keypair from the manager
21 log("Copying keys to client")
22- relid = hookenv.relation_id()
23- unit = hookenv.remote_unit()
24- pubkey = hookenv.relation_get(attribute='pubkey', unit=unit, rid=relid)
25- privkey = hookenv.relation_get(attribute='privkey', unit=unit, rid=relid)
26- log("Public key config: %s" % pubkey)
27+ pubkey = hookenv.relation_get(attribute='pubkey', unit=runit, rid=relid)
28+ privkey = hookenv.relation_get(attribute='privkey', unit=runit, rid=relid)
29 gpfshooklib.set_ssh_key(pubkey, private=False)
30 gpfshooklib.set_ssh_key(privkey, private=True)
31- # start gpfs
32- # set the node to the manager
33- #call(split('mmstartup -a'))
34- if hookname == "manager-relation-changed":
35+ if hookname == "manager-relation-changed" and not rlhn is None:
36 log("Creating GPFS cluster")
37- relid = hookenv.relation_id()
38- runit = hookenv.remote_unit()
39- hostname = socket.gethostname()
40- gpfshooklib.create_cluster(hostname)
41- gpfshooklib.apply_license(hostname)
42- chostname = hookenv.relation_get(attribute='hostname',
43- unit=runit, rid=relid)
44+ gpfshooklib.create_cluster(llhn)
45+ gpfshooklib.apply_license(llhn)
46 log("Adding remote client")
47- gpfshooklib.add_node(chostname)
48- gpfshooklib.apply_license(chostname)
49- # Create disk stanza
50- # Create nsd
51- # mmcrnsd -F stanza.txt
52- # create and mount fs
53- # mmcrfs gpfs1 -F stanza.txt -A yes -T /gpfs
54- # mmmount gpfs1 -a
55- # start gpfs
56- #call(split('mmstartup -a'))
57+ gpfshooklib.add_node(rlhn)
58+ gpfshooklib.apply_license(rlhn)
59+ log("Starting cluster")
60+ gpfshooklib.start()
61+
62 if __name__ == '__main__':
63 main()
64
65=== modified file 'charms/trusty/gpfs/hooks/common-relation-joined'
66--- charms/trusty/gpfs/hooks/common-relation-joined 2015-02-09 11:42:31 +0000
67+++ charms/trusty/gpfs/hooks/common-relation-joined 2015-03-03 17:58:00 +0000
68@@ -17,9 +17,13 @@
69 def main():
70 hookname = hookenv.hook_name()
71 hookenv.relation_set(hookenv.relation_id(), {
72- 'hostname': socket.gethostname()
73+ 'lhostname': socket.getfqdn(),
74+ 'pip': hookenv.unit_private_ip()
75 })
76+
77 if hookname == "manager-relation-joined":
78+ # Denote this as a manager
79+ gpfshooklib.set_manager_file()
80 # Generate ssh keys if needed
81 gpfshooklib.create_ssh_keys()
82 privkey, pubkey = gpfshooklib.get_ssh_keys()
83@@ -31,7 +35,6 @@
84 if hookname == "client-relation-joined":
85 # Set the node designation values and hostname
86 hookenv.relation_set(hookenv.relation_id(), {
87- 'hostname': socket.gethostname(),
88 'quorum': 'quorum',
89 'client': 'client'
90 })
91
92=== modified file 'charms/trusty/gpfs/hooks/gpfshooklib.py'
93--- charms/trusty/gpfs/hooks/gpfshooklib.py 2015-02-19 12:46:34 +0000
94+++ charms/trusty/gpfs/hooks/gpfshooklib.py 2015-03-03 17:58:00 +0000
95@@ -5,6 +5,7 @@
96 import sys
97 import shutil
98 import tempfile
99+import socket
100 from shlex import split
101 from subprocess import (
102 call,
103@@ -134,6 +135,16 @@
104
105 def create_cluster(hostname):
106 # create the cluster for the hostname, manager only
107- if not is_manager() and not cluster_exists():
108+ if is_manager() and not cluster_exists():
109 log(check_output(split('mmcrcluster -N %s:quorum-manager' % \
110 hostname + ' -r /usr/bin/ssh -R /usr/bin/scp')))
111+
112+def chk_dns(hostname, ip):
113+ try:
114+ socket.gethostbyname(hostname)
115+ except:
116+ log("Hostname not resolving, adding to /etc/hosts")
117+ with open("/etc/hosts", "a") as hostfile:
118+ hostfile.write("%s %s\n" % (ip, hostname) )
119+ hostfile.close()
120+

Subscribers

People subscribed via source and target branches