- Timestamp:
- Feb 5, 2009, 3:19:30 AM (16 years ago)
- Location:
- trunk/packages
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-base/debian/changelog
r2061 r2095 1 invirt-base (0.0.21) unstable; urgency=low 2 3 * Get rid of confusing err=True option to invirt.remctl.remctl 4 5 -- Evan Broder <broder@mit.edu> Fri, 30 Jan 2009 19:49:46 -0500 6 1 7 invirt-base (0.0.20) unstable; urgency=low 2 8 -
trunk/packages/invirt-base/python/invirt/common.py
r1935 r2095 76 76 class CodeError(Exception): 77 77 """Exception for internal errors or bad faith input.""" 78 pass 78 def __init__(self, message, code=None): 79 Exception.__init__(self, message) 80 self.code = code 79 81 80 82 # -
trunk/packages/invirt-base/python/invirt/remctl.py
r1621 r2095 37 37 stderr=subprocess.PIPE) 38 38 v = p.wait() 39 if kws.get('err'):40 return p.stdout.read(), p.stderr.read()41 39 if v: 42 print >> sys.stderr, 'Error', v, 'on remctl', args, ':' 43 print >> sys.stderr, p.stderr.read() 44 raise CodeError('ERROR on remctl') 40 raise CodeError('ERROR on remctl %s:\n%s' % (args, p.stderr.read()), v) 45 41 return p.stdout.read() -
trunk/packages/invirt-web/code/controls.py
r2020 r2095 65 65 id of the CD (e.g. 'gutsy_i386') 66 66 """ 67 if cdtype is not None: 68 out, err = remctl('control', machine.name, 'create', 69 cdtype, err=True) 70 else: 71 out, err = remctl('control', machine.name, 'create', 72 err=True) 73 if 'already running' in err: 74 raise InvalidInput('action', 'create', 75 'VM %s is already on' % machine.name) 76 elif err: 67 try: 68 if cdtype is not None: 69 out = remctl('control', machine.name, 'create', 70 cdtype) 71 else: 72 out = remctl('control', machine.name, 'create') 73 except CodeError, e: 74 if 'already running' in e.message: 75 raise InvalidInput('action', 'create', 76 'VM %s is already on' % machine.name) 77 else: 77 78 raise CodeError('"%s" on "control %s create %s' 78 79 % (err, machine.name, cdtype)) … … 157 158 Gets and parses xm list --long 158 159 """ 159 value_string, err_string = remctl('control', machine.name, 'list-long', 160 err=True) 161 if 'Unknown command' in err_string: 162 raise CodeError("ERROR in remctl list-long %s is not registered" % 163 (machine.name,)) 164 elif 'is not on' in err_string: 165 return None 166 elif err_string: 167 raise CodeError("ERROR in remctl list-long %s: %s" % 168 (machine.name, err_string)) 160 try: 161 value_string = remctl('control', machine.name, 'list-long') 162 except CodeError, e: 163 if 'is not on' in e.message: 164 return None 165 else: 166 raise 169 167 status = parseStatus(value_string) 170 168 return status … … 172 170 def listHost(machine): 173 171 """Return the host a machine is running on""" 174 out, err = remctl('control', machine.name, 'listhost', err=True) 175 if err: 172 try: 173 out = remctl('control', machine.name, 'listhost') 174 except CodeError, e: 176 175 return None 177 176 return out.strip() … … 179 178 def vnctoken(machine): 180 179 """Return a time-stamped VNC token""" 181 out, err = remctl('control', machine.name, 'vnctoken', err=True) 182 if err: 180 try: 181 out = remctl('control', machine.name, 'vnctoken') 182 except CodeError, e: 183 183 return None 184 184 return out.strip() … … 186 186 def deleteVM(machine): 187 187 """Delete a VM.""" 188 remctl('control', machine.name, 'destroy', err=True) 188 try: 189 remctl('control', machine.name, 'destroy') 190 except CodeError: 191 pass 189 192 session.begin() 190 193 delete_disk_pairs = [(machine.name, d.guest_device_name) … … 216 219 raise CodeError("Invalid action '%s'" % action) 217 220 if action == 'Reboot': 218 if cdrom is not None: 219 out, err = remctl('control', machine.name, 'reboot', cdrom, 220 err=True) 221 else: 222 out, err = remctl('control', machine.name, 'reboot', 223 err=True) 224 if err: 225 if re.match("machine '.*' is not on", err): 221 try: 222 if cdrom is not None: 223 out = remctl('control', machine.name, 'reboot', cdrom) 224 else: 225 out = remctl('control', machine.name, 'reboot') 226 except CodeError, e: 227 if re.match("machine '.*' is not on", e.message): 226 228 raise InvalidInput("action", "reboot", 227 229 "Machine is not on") 228 230 else: 229 print >> sys.stderr, 'Error on reboot:' 230 print >> sys.stderr, err 231 raise CodeError('ERROR on remctl') 231 raise 232 232 233 233 elif action == 'Power on': … … 238 238 bootMachine(machine, cdrom) 239 239 elif action == 'Power off': 240 out, err = remctl('control', machine.name, 'destroy', err=True) 241 if err: 242 if re.match("machine '.*' is not on", err): 240 try: 241 out = remctl('control', machine.name, 'destroy') 242 except CodeError, e: 243 if re.match("machine '.*' is not on", e.message): 243 244 raise InvalidInput("action", "Power off", 244 245 "Machine is not on.") 245 246 else: 246 print >> sys.stderr, 'Error on power off:' 247 print >> sys.stderr, err 248 raise CodeError('ERROR on remctl') 247 raise 249 248 elif action == 'Shutdown': 250 out, err = remctl('control', machine.name, 'shutdown', err=True) 251 if err: 252 if re.match("machine '.*' is not on", err): 249 try: 250 out = remctl('control', machine.name, 'shutdown') 251 except CodeError, e: 252 if re.match("machine '.*' is not on", e.message): 253 253 raise InvalidInput("action", "Shutdown", 254 254 "Machine is not on.") 255 255 else: 256 print >> sys.stderr, 'Error on Shutdown:' 257 print >> sys.stderr, err 258 raise CodeError('ERROR on remctl') 256 raise 259 257 elif action == 'Delete VM': 260 258 deleteVM(machine)
Note: See TracChangeset
for help on using the changeset viewer.