1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Rebuilt bootstrap libvirt

This commit is contained in:
Retspen 2015-05-21 11:52:10 +03:00
parent e312fafc3c
commit 23b4d22a72
5 changed files with 147 additions and 69 deletions

47
conf/daemon/gstfsd Normal file
View file

@ -0,0 +1,47 @@
#!/usr/bin/env python
import SocketServer
import json
import guestfs
import re
PORT = 16510
ADDRESS = "0.0.0.0"
class MyTCPServer(SocketServer.ThreadingTCPServer):
allow_reuse_address = True
class MyTCPServerHandler(SocketServer.BaseRequestHandler):
def handle(self):
# recive data
data = json.loads(self.request.recv(1024).strip())
# GuestFS
gfs = guestfs.GuestFS (python_return_dict=True)
try:
gfs.add_domain(data['vname'])
gfs.launch()
parts = gfs.list_partitions()
for part in parts:
try:
gfs.mount(part, '/')
if gfs.is_file('/etc/shadow'):
file_shadow = gfs.cat('/etc/shadow')
new_root_hash = "root:" + data['passwd'] + ":"
file_shadow_new = re.sub('^root:.*?:', new_root_hash, file_shadow)
gfs.write("/etc/shadow", file_shadow_new)
gfs.chmod(640, '/etc/shadow')
gfs.umount(part)
self.request.sendall(json.dumps({'return': 'success'}))
except RuntimeError:
pass
gfs.shutdown()
gfs.close()
except RuntimeError, err:
self.request.sendall(json.dumps({'return': 'error', 'message': err.message}))
server = MyTCPServer((ADDRESS, PORT), MyTCPServerHandler)
server.serve_forever()