mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 23:55:24 +00:00
Rebuilt bootstrap libvirt
This commit is contained in:
parent
e312fafc3c
commit
23b4d22a72
5 changed files with 147 additions and 69 deletions
47
conf/daemon/gstfsd
Normal file
47
conf/daemon/gstfsd
Normal 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()
|
7
conf/supervisor/gstfsd.conf
Normal file
7
conf/supervisor/gstfsd.conf
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[program:gstfsd]
|
||||||
|
command=/usr/bin/python /usr/local/bin/gstfsd
|
||||||
|
directory=/usr/local/bin
|
||||||
|
user=root
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
redirect_stderr=true
|
53
dev/gstfsd
53
dev/gstfsd
|
@ -1,53 +0,0 @@
|
||||||
#!/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):
|
|
||||||
try:
|
|
||||||
# recive data
|
|
||||||
data = json.loads(self.request.recv(1024).strip())
|
|
||||||
dom_name = data['vname']
|
|
||||||
passwd_hash = data['passwd']
|
|
||||||
|
|
||||||
# GuestFS
|
|
||||||
gfs = guestfs.GuestFS (python_return_dict=True)
|
|
||||||
try:
|
|
||||||
gfs.add_domain(dom_name)
|
|
||||||
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:" + passwd_hash + ":"
|
|
||||||
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}))
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
print "Exception wile receiving message: ", e
|
|
||||||
|
|
||||||
server = MyTCPServer((ADDRESS, PORT), MyTCPServerHandler)
|
|
||||||
server.serve_forever()
|
|
|
@ -375,7 +375,7 @@ __check_end_of_life_versions
|
||||||
#
|
#
|
||||||
install_centos() {
|
install_centos() {
|
||||||
if [ $DISTRO_MAJOR_VERSION -ge 6 ]; then
|
if [ $DISTRO_MAJOR_VERSION -ge 6 ]; then
|
||||||
yum -y install qemu-kvm libvirt bridge-utils || return 1
|
yum -y install qemu-kvm libvirt bridge-utils python-libguestfs supervisor || return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -401,6 +401,23 @@ install_centos_post() {
|
||||||
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ $DISTRO_MAJOR_VERSION -lt 7 ]; then
|
||||||
|
if [ -f /etc/supervisord.conf ]; then
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/daemon/gstfsd > /usr/local/bin/gstfsd
|
||||||
|
chmod +x /usr/local/bin/gstfsd
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/supervisor/gstfsd.conf >> /etc/supervisor.conf
|
||||||
|
else
|
||||||
|
echoerror "Supervisor not found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
else:
|
||||||
|
if [ -f /etc/supervisord.conf ]; then
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/daemon/gstfsd > /usr/local/bin/gstfsd
|
||||||
|
chmod +x /usr/local/bin/gstfsd
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/supervisor/gstfsd.conf > /etc/supervisor.d/gstfsd.ini
|
||||||
|
else
|
||||||
|
echoerror "Supervisor not found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,6 +438,14 @@ daemons_running_centos() {
|
||||||
systemctl stop libvirt-guests.service > /dev/null 2>&1
|
systemctl stop libvirt-guests.service > /dev/null 2>&1
|
||||||
systemctl start libvirt-guests.service
|
systemctl start libvirt-guests.service
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/init.d/supervisord ]; then
|
||||||
|
service supervisord stop > /dev/null 2>&1
|
||||||
|
service supervisord start
|
||||||
|
fi
|
||||||
|
if [ -f /usr/lib/systemd/system/supervisord.service ]; then
|
||||||
|
systemctl stop supervisord.service > /dev/null 2>&1
|
||||||
|
systemctl start supervisord.service
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
|
@ -433,7 +458,7 @@ daemons_running_centos() {
|
||||||
# Fedora Install Functions
|
# Fedora Install Functions
|
||||||
#
|
#
|
||||||
install_fedora() {
|
install_fedora() {
|
||||||
yum -y install kvm libvirt bridge-utils || return 1
|
yum -y install kvm libvirt bridge-utils python-libguestfs supervisor || return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,6 +483,14 @@ install_fedora_post() {
|
||||||
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/supervisord.conf ]; then
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/daemon/gstfsd > /usr/local/bin/gstfsd
|
||||||
|
chmod +x /usr/local/bin/gstfsd
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/supervisor/gstfsd.conf > /etc/supervisor.d/gstfsd.ini
|
||||||
|
else:
|
||||||
|
echoerror "Supervisor not found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,6 +503,10 @@ daemons_running_fedora() {
|
||||||
systemctl stop libvirt-guests.service > /dev/null 2>&1
|
systemctl stop libvirt-guests.service > /dev/null 2>&1
|
||||||
systemctl start libvirt-guests.service
|
systemctl start libvirt-guests.service
|
||||||
fi
|
fi
|
||||||
|
if [ -f /usr/lib/systemd/system/supervisord.service ]; then
|
||||||
|
systemctl stop supervisord.service > /dev/null 2>&1
|
||||||
|
systemctl start supervisord.service
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
|
@ -482,7 +519,7 @@ daemons_running_fedora() {
|
||||||
# Opensuse Install Functions
|
# Opensuse Install Functions
|
||||||
#
|
#
|
||||||
install_opensuse() {
|
install_opensuse() {
|
||||||
zypper -n install -l kvm libvirt bridge-utils || return 1
|
zypper -n install -l kvm libvirt bridge-utils python-libguestfs supervisor || return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,6 +544,14 @@ install_opensuse_post() {
|
||||||
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/supervisord.conf ]; then
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/daemon/gstfsd > /usr/local/bin/gstfsd
|
||||||
|
chmod +x /usr/local/bin/gstfsd
|
||||||
|
curl https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/supervisor/gstfsd.conf > /etc/supervisor.d/gstfsd.ini
|
||||||
|
else:
|
||||||
|
echoerror "Supervisor not found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,6 +564,10 @@ daemons_running_opensuse() {
|
||||||
systemctl stop libvirt-guests.service > /dev/null 2>&1
|
systemctl stop libvirt-guests.service > /dev/null 2>&1
|
||||||
systemctl start libvirt-guests.service
|
systemctl start libvirt-guests.service
|
||||||
fi
|
fi
|
||||||
|
if [ -f /usr/lib/systemd/system/supervisord.service ]; then
|
||||||
|
systemctl stop supervisord.service > /dev/null 2>&1
|
||||||
|
systemctl start supervisord.service
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
|
@ -532,7 +581,7 @@ daemons_running_opensuse() {
|
||||||
#
|
#
|
||||||
install_ubuntu() {
|
install_ubuntu() {
|
||||||
apt-get update || return 1
|
apt-get update || return 1
|
||||||
apt-get -y install kvm libvirt-bin bridge-utils sasl2-bin || return 1
|
apt-get -y install kvm libvirt-bin bridge-utils sasl2-bin python-guestfs || return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,6 +610,14 @@ install_ubuntu_post() {
|
||||||
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/supervisor/supervisor.conf ]; then
|
||||||
|
wget -O /usr/local/bin/gstfsd https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/daemon/gstfsd
|
||||||
|
chmod +x /usr/local/bin/gstfsd
|
||||||
|
wget -O /etc/supervisor/conf.d/gstfsd.conf https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/supervisor/gstfsd.conf
|
||||||
|
else:
|
||||||
|
echoerror "Supervisor not found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,6 +627,11 @@ daemons_running_ubuntu() {
|
||||||
service libvirt-bin stop > /dev/null 2>&1
|
service libvirt-bin stop > /dev/null 2>&1
|
||||||
service libvirt-bin start
|
service libvirt-bin start
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/supervisor/supervisord.conf ]; then
|
||||||
|
# Still in SysV init!?
|
||||||
|
service supervisor stop > /dev/null 2>&1
|
||||||
|
service supervisor start
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
|
@ -583,7 +645,7 @@ daemons_running_ubuntu() {
|
||||||
#
|
#
|
||||||
install_debian() {
|
install_debian() {
|
||||||
apt-get update || return 1
|
apt-get update || return 1
|
||||||
apt-get -y install kvm libvirt-bin bridge-utils sasl2-bin || return 1
|
apt-get -y install kvm libvirt-bin bridge-utils sasl2-bin python-guestfs supervisor || return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,6 +681,14 @@ install_debian_post() {
|
||||||
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
echoerror "/etc/libvirt/qemu.conf not found. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/supervisor/supervisor.conf ]; then
|
||||||
|
wget -O /usr/local/bin/gstfsd https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/daemon/gstfsd
|
||||||
|
chmod +x /usr/local/bin/gstfsd
|
||||||
|
wget -O /etc/supervisor/conf.d/gstfsd.conf https://raw.githubusercontent.com/retspen/webvirtcloud/master/conf/supervisor/gstfsd.conf
|
||||||
|
else:
|
||||||
|
echoerror "Supervisor not found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,6 +702,10 @@ daemons_running_debian() {
|
||||||
/etc/init.d/$LIBVIRTSVC stop > /dev/null 2>&1
|
/etc/init.d/$LIBVIRTSVC stop > /dev/null 2>&1
|
||||||
/etc/init.d/$LIBVIRTSVC start
|
/etc/init.d/$LIBVIRTSVC start
|
||||||
fi
|
fi
|
||||||
|
if [ -f /etc/supervisor/supervisord.conf ]; then
|
||||||
|
service supervisor stop > /dev/null 2>&1
|
||||||
|
service supervisor start
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
|
|
|
@ -269,19 +269,22 @@ def instance(request, compute_id, vname):
|
||||||
passwd_hash = crypt.crypt(passwd, '$6$kgPoiREy')
|
passwd_hash = crypt.crypt(passwd, '$6$kgPoiREy')
|
||||||
data = {'passwd': passwd_hash, 'vname': vname}
|
data = {'passwd': passwd_hash, 'vname': vname}
|
||||||
|
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
if conn.get_status() == 5:
|
||||||
s.connect((compute.hostname, 16510))
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.send(json.dumps(data))
|
s.connect((compute.hostname, 16510))
|
||||||
result = json.loads(s.recv(1024))
|
s.send(json.dumps(data))
|
||||||
s.close()
|
result = json.loads(s.recv(1024))
|
||||||
|
s.close()
|
||||||
|
msg = _("Reset root password")
|
||||||
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
|
||||||
msg = _("Reset root password")
|
if result['return'] == 'success':
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
messages.append(msg)
|
||||||
|
else:
|
||||||
if result['return'] == 'success':
|
error_messages.append(msg)
|
||||||
messages.append(msg)
|
|
||||||
else:
|
else:
|
||||||
error_messages(msg)
|
msg = _("Please shutdow down your instance and then try again")
|
||||||
|
error_messages.append(msg)
|
||||||
|
|
||||||
if 'resize' in request.POST:
|
if 'resize' in request.POST:
|
||||||
vcpu = request.POST.get('vcpu', '')
|
vcpu = request.POST.get('vcpu', '')
|
||||||
|
|
Loading…
Reference in a new issue