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.address,
122 '"rm -rf %s"' % _PACKAGE_HOME)
123
124 ssh(host.user,
125 host.address,
126 '"mkdir %s"' % _PACKAGE_HOME)
127 ui.ok(host.name, stage)
128
129 stage += 1
130 scp(host.user,
131 host.address,
132 None,
133 '%s/%s' % (_PACKAGE_HOME, _DISTRIBUTION_FILENAME),
134 _PACKAGE_HOME)
135 ui.ok(host.name, stage)
136
137 stage += 1
138 scp(host.user,
139 host.address,
140 None,
141 '%s/%s' % (_PACKAGE_HOME, _REMOTE_INSTALL),
142 _PACKAGE_HOME)
143 ui.ok(host.name, stage)
144
145 stage += 1
146 if self._install_dir:
147 ssh(host.user,
148 host.address,
149 '"%s/%s %s %s"' % (_PACKAGE_HOME, _REMOTE_INSTALL, _PACKAGE_HOME, self._install_dir))
150 else:
151 ssh(host.user,
152 host.address,
153 '"%s/%s %s"' % (_PACKAGE_HOME, _REMOTE_INSTALL, _PACKAGE_HOME))
154 ui.ok(host.name, stage)
155
156 stage += 1
157 ls_oshrc, errors = ssh(host.user,
158 host.address,
159 '"ls /%s/%s"' % (host.user, _CONFIG_FILE))
160 if len(ls_oshrc) == 0:
161 scp(host.user,
162 host.address,
163 None,
164 self._config_file,
165 '~')
166 ui.ok(host.name, stage)
167 except:
168 (exc_type, exc_value, exc_traceback) = sys.exc_info()
169 message = str(exc_value).strip()
170 ui.error(host.name, stage, message)
171