1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """C{installosh -c CLUSTER [-d INSTALL_DIRECTORY] [OSH_CONFIG_FILE]}
19
20 Installs osh on C{CLUSTER}. If C{-d} is not specified, then
21 installation is to the standard site-packages directory
22 (e.g. /usr/lib/python2.4/site-packages). Otherwise, installation goes
23 to C{INSTALL_DIRECTORY}. (C{INSTALL_DIRECTORY} replaces the entire path, not just
24 the C{/usr} or C{/usr/lib} part of the path.) On each node of the
25 cluster, a C{.oshrc} files is created in the home directory of the
26 user specified for C{CLUSTER}. This file is copied from
27 C{OSH_CONFIG_FILE}, if specified. Otherwise, C{~/.oshrc} is copied.
28
29 Not available through the API.
30 """
31
32 import os
33 import sys
34 import threading
35
36 import osh.core
37 import osh.config
38 import osh.spawn
39 import progtrack
40
41
42 _DISTRIBUTION_FILENAME = 'osh-' + osh.config.OSH_VERSION + '.tar.gz'
43 _CONFIG_FILE = '.oshrc'
44 _PACKAGE_HOME = '/usr/share/osh'
45
46 Spawn = osh.spawn.Spawn
47 SpawnSSH = osh.spawn.SpawnSSH
48 collect_lines = osh.spawn.collect_lines
49
50 -def _scp(user, host, source, target):
51 err_lines = []
52 scp_command = 'scp %s %s@%s:%s' % (source, user, host, target)
53 Spawn(scp_command,
54 None,
55 None,
56 collect_lines(err_lines)).run()
57 if len(err_lines) > 0:
58 raise Exception(' '.join(err_lines))
59
60 -def _ssh(user, host, command):
61 out_lines = []
62 SpawnSSH(user,
63 host,
64 command,
65 None,
66 collect_lines(out_lines),
67 None).run()
68 return out_lines
69
70
73
75
76 _install_dir = None
77 _config_file = None
78 _host_counter = None
79 _ui = None
80
81
82
85
86
87
88
91
93 osh.core.RemoteOp.setup(self)
94 self._install_dir = self.args().string_arg('-d')
95 if self.args().has_next():
96 self._config_file = self.args().next_string()
97 else:
98 self._config_file = '%s/%s' % (os.environ['HOME'], _CONFIG_FILE)
99 self._host_counter = 0
100 self._ui = progtrack.ProgressTrackingUI('installosh')
101 self._ui.add_column('host', 25)
102 self._ui.add_column(['create', 'osh dir'], 10)
103 self._ui.add_column(['copy', 'package'], 10)
104 self._ui.add_column(['copy', 'installer'], 10)
105 self._ui.add_column(['run', 'installer'], 10)
106 self._ui.add_column(['copy', 'conf file'], 10)
107 for host in self.hosts():
108 self._ui.add_row(host.name)
109
110
111
113 self._ui.start()
114 try:
115 osh.core.RemoteOp.execute(self)
116 finally:
117 self._ui.stop()
118
119
120
121
123 stage = 0
124 try:
125
126 stage += 1
127 _ssh(self.user(),
128 host.address,
129 '"rm -rf %s"' % _PACKAGE_HOME)
130
131 _ssh(self.user(),
132 host.address,
133 '"mkdir %s"' % _PACKAGE_HOME)
134 self._ui.ok(host.name, stage)
135
136 stage += 1
137 _scp(self.user(),
138 host.address,
139 '%s/%s' % (_PACKAGE_HOME, _DISTRIBUTION_FILENAME),
140 _PACKAGE_HOME)
141 self._ui.ok(host.name, stage)
142
143 stage += 1
144 _scp(self.user(),
145 host.address,
146 '%s/remoteinstall' % _PACKAGE_HOME,
147 _PACKAGE_HOME)
148 self._ui.ok(host.name, stage)
149
150 stage += 1
151 if self._install_dir:
152 _ssh(self.user(),
153 host.address,
154 '"%s/remoteinstall %s %s"' % (_PACKAGE_HOME, _PACKAGE_HOME, self._install_dir))
155 else:
156 _ssh(self.user(),
157 host.address,
158 '"%s/remoteinstall %s"' % (_PACKAGE_HOME, _PACKAGE_HOME))
159 self._ui.ok(host.name, stage)
160
161 stage += 1
162 ls_oshrc = _ssh(self.user(),
163 host.address,
164 '"ls /%s/%s"' % (self.user(), _CONFIG_FILE))
165 if len(ls_oshrc) == 0:
166 _scp(self.user(),
167 host.address,
168 self._config_file,
169 '~')
170 self._ui.ok(host.name, stage)
171 except:
172 (exc_type, exc_value, exc_traceback) = sys.exc_info()
173 message = str(exc_value).strip()
174 self._ui.error(host.name, stage, message)
175