Skip to content

CP-49900: Moved scripts/templates to python3/templates directory #5758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ install:
$(IPROG) plugins/disk-space $(DESTDIR)$(PLUGINDIR)
$(IPROG) plugins/install-supp-pack $(DESTDIR)$(PLUGINDIR)
$(IPROG) plugins/echo.py $(DESTDIR)$(PLUGINDIR)/echo
# templates
$(IPROG) templates/debian $(DESTDIR)$(OPTDIR)/packages/post-install-scripts/debian-etch
$(IPROG) templates/debug $(DESTDIR)$(OPTDIR)/packages/post-install-scripts

# poweron
$(IPROG) poweron/wlan.py $(DESTDIR)$(PLUGINDIR)/wlan.py
Expand Down
83 changes: 55 additions & 28 deletions scripts/templates/debian → python3/templates/debian
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Copyright (c) 2005-2007 XenSource, Inc

# Code ripped out of 'xgt' script for now
from __future__ import print_function
import commands, xmlrpclib, os, sys, httplib, socket, urllib2, signal

import os
import signal
import socket
import sys

import commands
import httplib
import urllib2
import xmlrpclib

verbose = True


##### begin hack. Provide xmlrpc over UNIX domain socket (cut+pasted from eliloader):
class UDSHTTPConnection(httplib.HTTPConnection):
""" Stupid hacked up HTTPConnection subclass to allow HTTP over Unix domain
sockets. """
"""Stupid hacked up HTTPConnection subclass to allow HTTP over Unix domain
sockets."""

def connect(self):
path = self.host.replace("_", "/")
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(path)


class UDSHTTP(httplib.HTTP):
_connection_class = UDSHTTPConnection


class UDSTransport(xmlrpclib.Transport):
def make_connection(self, host):
return UDSHTTP(host)


def xapi_local():
return xmlrpclib.Server("http://_var_xapi_xapi/", transport=UDSTransport())


##### end hack.


Expand All @@ -36,81 +52,90 @@ def run(cmd, *args):
debug("+ " + cmd % args)
(ret, out) = commands.getstatusoutput(cmd % args)
if verbose:
try:
try:
for line in out.split("\n"):
log("| " + line)
except TypeError as e:
pass
if ret != 0:
debug ("run - command %s failed with %d" , cmd, ret)
debug("run - command %s failed with %d", cmd, ret)
raise CommandException(out)
return out


def log(fmt, *args):
print(fmt % args)


def debug(msg, *args):
if verbose:
print(msg % args)


def create_partition(lvpath):
# 1. write a partition table:
pipe = os.popen('/sbin/fdisk %s' % lvpath, 'w')
pipe = os.popen("/sbin/fdisk %s" % lvpath, "w")

pipe.write('n\n') # new partition
pipe.write('p\n') # primary
pipe.write("1\n") # 1st partition
pipe.write('\n') # default start cylinder
pipe.write('\n') # size: as big as image
pipe.write('w\n') # write partition table
pipe.write("n\n") # new partition
pipe.write("p\n") # primary
pipe.write("1\n") # 1st partition
pipe.write("\n") # default start cylinder
pipe.write("\n") # size: as big as image
pipe.write("w\n") # write partition table

# XXX we must ignore certain errors here as fdisk will
# sometimes return non-zero signalling error conditions
# we don't care about. Should fix to detect these cases
# specifically.
rc = pipe.close()
if rc == None:
if rc == None:
rc = 0
log("fdisk exited with rc %d (some non-zero exits can be ignored safely)." % rc)


def map_partitions(lvpath):
run("/sbin/kpartx -a %s", lvpath)
ps = []
for line in run("/sbin/kpartx -l %s" % lvpath).split("\n"):
ps.append("/dev/mapper/" + line.split()[0])
return ps


def unmap_partitions(lvpath):
run("/sbin/kpartx -d %s", lvpath)


def umount(mountpoint):
run("umount -l %s",mountpoint)
run("umount -l %s", mountpoint)


if __name__ == "__main__":
#os.setpgrp()
# os.setpgrp()
xvda = os.getenv("xvda")
xvdb = os.getenv("xvdb")
debug("Guest's xvda is on %s" % xvda)
debug("Guest's xvdb is on %s" % xvdb)
if xvda == None or xvdb == None:
raise "Need to pass in device names for xvda and xvdb through the environment"
raise ValueError ("Need to pass in device names for xvda and xvdb through the environment")

vm = os.getenv("vm")

server = xapi_local ()
server = xapi_local()
try:
session_id = server.session.login_with_password('','','1.0','xen-api-scripts-debian')['Value']
uuid = server.VM.get_uuid(session_id, vm)['Value']
session_id = server.session.login_with_password(
"", "", "1.0", "xen-api-scripts-debian"
)["Value"]
uuid = server.VM.get_uuid(session_id, vm)["Value"]
mountpoint = "/tmp/installer/%s" % (uuid)
finally:
server.session.logout(session_id)

def sighandler(signum, frame):
umount(mountpoint)
os.killpg(0,signal.SIGKILL)
exit(1)
umount(mountpoint)
os.killpg(0, signal.SIGKILL)
exit(1)

signal.signal(signal.SIGTERM,sighandler)
signal.signal(signal.SIGTERM, sighandler)

create_partition(xvda)
create_partition(xvdb)
Expand All @@ -132,10 +157,12 @@ if __name__ == "__main__":
run("/usr/bin/unzip -p %s swap.img | dd of=%s oflag=direct bs=1M", xgt, xvdb)

try:
session_id = server.session.login_with_password('','','1.0','xen-api-scripts-debian')['Value']
vbds = server.VM.get_VBDs(session_id, vm)['Value']
session_id = server.session.login_with_password(
"", "", "1.0", "xen-api-scripts-debian"
)["Value"]
vbds = server.VM.get_VBDs(session_id, vm)["Value"]
for i in vbds:
dev = server.VBD.get_userdevice(session_id, i)['Value']
dev = server.VBD.get_userdevice(session_id, i)["Value"]
if dev == "0":
server.VBD.set_bootable(session_id, i, True)
finally:
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ install:
mkdir -p $(DESTDIR)/etc/cron.d
$(IDATA) xapi-tracing-log-trim.cron $(DESTDIR)/etc/cron.d/xapi-tracing-log-trim.cron
mkdir -p $(DESTDIR)/opt/xensource/gpg
# templates
$(IPROG) templates/debian $(DESTDIR)$(OPTDIR)/packages/post-install-scripts/debian-etch
$(IPROG) templates/debug $(DESTDIR)$(OPTDIR)/packages/post-install-scripts
# host-backup-restore
$(IPROG) host-backup-restore/host-backup $(DESTDIR)$(LIBEXECDIR)
$(IPROG) host-backup-restore/host-restore $(DESTDIR)$(LIBEXECDIR)
Expand Down
Loading