Package osh :: Package command :: Module installosh
[frames] | no frames]

Source Code for Module osh.command.installosh

  1  # osh 
  2  # Copyright (C) Jack Orenstein <jao@geophile.com> 
  3  # 
  4  # This program is free software; you can redistribute it and/or modify 
  5  # it under the terms of the GNU General Public License as published by 
  6  # the Free Software Foundation; either version 2 of the License, or 
  7  # (at your option) any later version. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, 
 10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12  # GNU General Public License for more details. 
 13  # 
 14  # You should have received a copy of the GNU General Public License 
 15  # along with this program; if not, write to the Free Software 
 16  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 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  # CLI 
57 -def _installosh():
58 return _InstallOsh()
59
60 -class _InstallOsh(osh.core.RunLocal):
61 62 _install_dir = None 63 _config_file = None 64 65 # object interface 66
67 - def __init__(self):
68 osh.core.RunLocal.__init__(self, 'd:', (0, 1))
69 70 # BaseOp interface 71
72 - def doc(self):
73 return __doc__
74
75 - def create_command_state(self, oshthreads):
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
88 - def setup(self):
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 # Generator interface 97
98 - def execute(self):
99 # UI object actually starts only on first call to start, ignores subsequent calls. 100 self.ui.start() 101 try: 102 self.install() 103 finally: 104 self.ui.stop()
105 106 107 # internals 108 109 ui = property(lambda self: self.command_state()) 110 111 host = property(lambda self: self.thread_state) 112
113 - def install(self):
114 host = self.host 115 ui = self.ui 116 stage = 0 117 try: 118 # Remove existing /usr/share/osh directory 119 stage += 1 120 ssh(host.user, 121 host.identity, 122 host.address, 123 '"rm -rf %s"' % _PACKAGE_HOME) 124 # Create directory /usr/share/osh 125 ssh(host.user, 126 host.identity, 127 host.address, 128 '"mkdir %s"' % _PACKAGE_HOME) 129 ui.ok(host.name, stage) 130 # Copy package to /usr/share/osh 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 # Copy remoteinstall script to /usr/share/osh 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 # Run remoteinstall script 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 # Copy config file to home directory unless one already exists 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