def _syscall(self, cmd, retrycnt=1, retrywait=1, timeout=-1, polling=False): '''issue a system call.''' if not polling: Log.info('Executing: %s' % cmd) ret = 1 attempts = 0 while ret and attempts < retrycnt: attempts += 1 ret = utils.syscall_log(cmd, self._outfile, timeout=timeout)[0] if ret: if not polling: Log.error('%s returned %d' % (cmd, ret)) if attempts < retrywait: utils.sleep(retrywait) return ret
def _vboxmanage(self, op, args, role, retrycnt=3): ''' This method makes one or more calls to vboxmanage of the form: vboxmanage <op> <vm uuid> <args> Parameters are as follows: @param op - vboxmanage operation to issue (see template call above) @param args - additional arguments to pass (see template call above) @param role - optional argument - if None then issue one command for each node in the cluster, otherwise issue a single command to the named node @param retrycnt - optional argument - specifies how many times the command should be retried before aborting. VirtualBox is sensitive of timing of various operations so just because it failed the first time is not necessarily indicative of a real failure ''' vagstat = '%s/.vagrant' % self._rundir if not os.path.exists(vagstat): Log.error("cluster not created - %s does not exist" % vagstat) return -1 vsfile = open(vagstat) vs = json.load(vsfile) if role: if not vs['active'].has_key(role): raise Exception("role %s does not exist" % role) affected_roles = [ role ] else: affected_roles = sorted(vs['active'].keys()) ret = 0 for r in affected_roles: cmd = 'vboxmanage %s %s %s' % (op, vs['active'][r], args) tmp = self._syscall(cmd, retrycnt=retrycnt, retrywait=1) # the vboxmanage command does not seem to like back-to-back # commands so sleep for 1 utils.sleep(1) if tmp != 0: ret = tmp return ret