コード例 #1
0
ファイル: web.py プロジェクト: codemeow5/spider2
	def post(self):
		body = self.request.body
		obj = json.loads(body)
		instance = obj.get('instance')
		eip_id = obj.get('eip_id')
		eip = obj.get('eip')
		id_ = obj.get('ids')
		token = obj.get('token')
		if token == TOKEN:
			d = {}
			d['hostname'] = instance
			d['in_ipaddr'] = eip
			d['ex_ipaddr'] = eip
			d['port'] = 22
			d['username'] = '******'
			d['password'] = '******'
			ds = []
			ds.append(d)
			ssh = SSH(ds)
			localdir = os.path.join(os.path.abspath('.'), 'all')
			for _ in id_:
				ssh.cmd('tar zcvf /tmp/%s.tar.gz /tmp/data' % _, True)
				ssh.download('/tmp/%s.tar.gz' % _, localdir + ('/%s.tar.gz' % _))
			
			conn.terminate_instances(
				instances = [instance]
			)
			time.sleep(10)
			conn.release_eips(
				eips = [eip_id]
			)
			for _ in id_:
				manifest.remove(_)
			thread.start_new_thread(Worker, (manifest,))
コード例 #2
0
ファイル: web.py プロジェクト: codemeow5/spider2
def Worker(manifest):
	uname = 'ubuntu'
	passwd = '1qazxcvbNM'
	port = 22
	ret = conn.run_instances(
		image_id='trustysrvx64e',
		cpu=1,
		memory=1024,
		login_mode='passwd',
		login_passwd='1qazxcvbNM',
		vxnets=['vxnet-0']
	)
	instance = ret.get('instances')[0]
	time.sleep(10)
	ret = conn.allocate_eips(
		bandwidth=bandwidth_limit,
		billing_mode='bandwidth'
	)
	eip_id = ret.get('eips')[0]
	time.sleep(10)
	ret = conn.associate_eip(
		eip=eip_id,
		instance=instance,
	)
	time.sleep(10)
	ret = conn.describe_eips(
		eips = [eip_id]
	)
	eip = ret.get('eip_set')[0].get('eip_addr')
	time.sleep(10)
	d = {}
	d['hostname'] = instance
	d['in_ipaddr'] = eip
	d['ex_ipaddr'] = eip
	d['port'] = 22
	d['username'] = uname
	d['password'] = passwd
	ds = []
	ds.append(d)
	ssh = SSH(ds)
	ssh.upload(join(__file__, 'Spider.py'), '/tmp/Spider.py')
	ret = manifest.pop(1)
	for _ in ret:
		ssh.cmd('echo "%s" >> /tmp/manifest.txt' % _, True)
	if std:
		ssh.cmd('python /tmp/Spider.py -h %s -i %s -t %s -p %s -e %s -w %s' % (instance, eip_id, TOKEN, eip, me_ip, mwp), True)
	else:
		ssh.cmd('python /tmp/Spider.py -h %s -i %s -t %s -p %s -e %s -w %s' % (instance, eip_id, TOKEN, eip, me_ip, mwp), True)