def test2Status(self): testfile = '%s/test2-vagstatus' % os.path.dirname(__file__) ret = vagstatus.vagrant_status('.', testfile) self.assertEqual( ret['cluster'], 'running') self.assertEqual( ret['pm1'], 'running') self.assertEqual( ret['pm2'], 'running') self.assertEqual( ret['um1'], 'running')
def do_box(boxname, do_local = False, do_remote = False, do_destroy = False, do_skip = False, do_check = False): print 'INFO: Handling box %s' % boxname ret = 0 cwd = os.getcwd() os.chdir(boxname) try: if not os.path.exists('Vagrantfile'): raise Exception("ERROR: no VagrantFile found in %s" % boxname) if not do_skip: if do_destroy: syscall('vagrant destroy -f') else: status = vagrant_status('.') if status['cluster'] != "not created" and status['cluster'] != "poweroff": print "INFO: machine appears to be running or suspended, shutting down for clean restart" syscall('vagrant halt') (rc, out, err) = syscall('vagrant up') sshportpatt = re.compile('SSH address: 127.0.0.1:([0-9]+)') mat = sshportpatt.search( out ) if not mat: raise Exception('ERROR: could not locate SSH address in %s' % out) sshport = mat.group(1) print 'INFO: vagrant box %s is on port %s' % (boxname, sshport) java_file = os.path.join('..','jdk-7u55-linux-x64.gz') syscall('cp %s .' % java_file) cmd = 'ansible-playbook -i ../inventory ../makebox.yml -e "ansible_ssh_port=%s boxdir=%s"' % (sshport,boxname) rc = os.system(cmd) >> 8 if rc != 0: raise Exception("Ansible command (%s) failed: %s!" % (cmd, rc)) syscall('vagrant halt') if not do_check: if os.path.exists('%s.box' % boxname): os.remove('%s.box' % boxname) syscall('vagrant package --output %s.box' % boxname) if do_local: (rc, out, err) = syscall('vagrant box list') for b in out.split('\n'): box = b.split(' ')[0] if box == boxname: syscall('vagrant box remove %s' % boxname) break syscall('vagrant box add %s ./%s.box' % (boxname, boxname)) if do_remote: print 'INFO: going to scp the new box to srvengcm1...this may prompt for a password' rc = os.system('scp %s.box [email protected]:/Calpont/exports/vagrant_boxes/.' % (boxname)) >> 8 if rc != 0: raise Exception("scp command failed: %s!" % (rc)) except Exception, exc: print exc ret = 1