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