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.address, 122 '"rm -rf %s"' % _PACKAGE_HOME) 123 # Create directory /usr/share/osh 124 ssh(host.user, 125 host.address, 126 '"mkdir %s"' % _PACKAGE_HOME) 127 ui.ok(host.name, stage) 128 # Copy package to /usr/share/osh 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 # Copy remoteinstall script to /usr/share/osh 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 # Run remoteinstall script 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 # Copy config file to home directory unless one already exists 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