Import of pkgsrc-2015Q1

This commit is contained in:
2015-04-22 14:34:26 +02:00
committed by Lionel Sambuc
parent 9a8c06dafb
commit 4af1cdf7a9
25114 changed files with 870550 additions and 795435 deletions

View File

@@ -0,0 +1,2 @@
This package provides two startup scripts to autoconfigure
a NetBSD VM on Openstack.

View File

@@ -0,0 +1,12 @@
===========================================================================
$NetBSD: MESSAGE,v 1.1 2014/05/10 16:38:03 manu Exp $
Add the following in /etc/rc.conf
# to configure hostname, root password and SSH keys from CD-ROM (run once)
openstack_init=YES
# to autoconfigure the network from hypervisor information (run on each boot)
xen_network=YES
===========================================================================

View File

@@ -0,0 +1,30 @@
# $NetBSD: Makefile,v 1.2 2014/05/17 16:10:49 wiz Exp $
#
DISTNAME= openstack_init-1.0
#PKGREVISION= 1
PKGREVISION= 1
CATEGORIES= sysutils
MASTER_SITES= # none
DISTFILES= # none
MAINTAINER= pkgsrc-users@NetBSD.org
COMMENT= Autoconfigure NetBSD VM on OpenStack
LICENSE= original-bsd
WRKSRC= ${WRKDIR}
NO_BUILD= yes
USE_LANGUAGES= # none
do-extract:
cd ${FILESDIR} && cp *.py *.sh ${WRKSRC}/
RCD_SCRIPTS= xen_network openstack_init
do-install:
${INSTALL_PROGRAM_DIR} ${DESTDIR}${PREFIX}/sbin
${INSTALL_SCRIPT} ${WRKSRC}/xen_network.py ${DESTDIR}${PREFIX}/sbin/
${INSTALL_SCRIPT} ${WRKSRC}/openstack_init.py ${DESTDIR}${PREFIX}/sbin/
.include "../../lang/python/application.mk"
.include "../../mk/bsd.pkg.mk"

View File

@@ -0,0 +1,5 @@
@comment $NetBSD: PLIST,v 1.1 2014/05/10 16:38:03 manu Exp $
sbin/xen_network.py
share/examples/rc.d/xen_network
sbin/openstack_init.py
share/examples/rc.d/openstack_init

View File

@@ -0,0 +1,89 @@
#!/usr/pkg/bin/python2.7
import json
import base64
import subprocess
import tempfile
import os
import sys
def printf(format, *args):
sys.stdout.write(format % args)
disks = list()
config = dict()
# shut down /dev/stderr
os.close(2)
cmd = "/sbin/sysctl -n hw.disknames"
for disk in subprocess.check_output(cmd.split(" ")).split(" "):
cmd = "/sbin/disklabel " + disk
p = subprocess.Popen(cmd.split(" "), stdout=subprocess.PIPE)
disklabel = p.communicate()[0].split("\n")
for line in disklabel:
if line and line.find("ISO9660") != -1:
letter = line.split(":")[0].replace(" ", "")
disks.append("/dev/" + disk + letter)
for n, dev in enumerate(disks):
mount_cmd = "/sbin/mount " + dev + " /mnt"
umount_cmd = "/sbin/umount " + dev
meta_data_file = "/mnt/openstack/latest/meta_data.json"
try:
subprocess.call(mount_cmd.split(" "))
except:
next
try:
config = json.load(open(meta_data_file))
except:
try:
subprocess.call(umount_cmd.split(" "))
except:
next
next
try:
subprocess.call(umount_cmd.split(" "))
except:
next
# or hostname?
if "name" in config:
printf("hostname %s;\n", config["name"])
printf("echo '%s' > /etc/myname;\n", config["name"])
if "random_seed" in config:
tmp = tempfile.mkstemp()
os.write(tmp[0], base64.b64decode(config["random_seed"]))
printf("rndctl -L %s;\n", tmp[1])
os.close(tmp[0])
if "public_keys" in config:
printf("mkdir -p /root/.ssh\n");
for n, k in enumerate(config['public_keys']):
cmd = "echo '%s %s' >> /root/.ssh/authorized_keys;\n"
printf(cmd, config['public_keys'][k], k)
if "admin_pass" in config:
key = config["admin_pass"] + "\n"
PIPE = subprocess.PIPE
p = subprocess.Popen("pwhash", stdin=PIPE, stdout=PIPE)
hash = p.communicate(key)[0].replace("\n", "")
ptmp = open("/etc/ptmp", "wx")
pwd = open("/etc/master.passwd", "r")
lines = pwd.readlines()
pwd.close()
for line in lines:
if line.find("root:") == 0:
fields = line.split(":")
fields[1] = hash
line = ":".join(fields)
ptmp.write(line)
ptmp.close()
printf("pwd_mkdb -p /etc/ptmp;\n")

View File

@@ -0,0 +1,19 @@
#!/bin/sh
# PROVIDE: openstack_init
# REQUIRE: mountcritlocal
# BEFORE: SERVERS
$_rc_subr_loaded . /etc/rc.subr
name="openstack_init"
start_cmd="openstack_init"
openstack_init()
{
test "x`hostname`" = "x" && eval $( /usr/pkg/sbin/openstack_init.py )
}
load_rc_config $name
run_rc_command "$1"

View File

@@ -0,0 +1,59 @@
#!/usr/pkg/bin/python2.7
import json
import subprocess
import time
import sys
def printf(format, *args):
sys.stdout.write(format % args)
ifs = dict()
dns = list()
for line in subprocess.check_output(["/sbin/ifconfig", "-a"]).split("\n"):
if line and line[0] != "\t":
ifname = line.split(":")[0]
mac = None
if line and line.find("address:") != -1:
mac = line.split(": ")[1].replace(":", "").upper()
ifs[mac] = ifname
for n, k in enumerate(ifs):
cmd = "/usr/pkg/bin/xenstore-read"
path = "vm-data/networking/" + k
ifconfig = json.loads(subprocess.check_output([cmd, path]))
if "dns" in ifconfig:
for p, l in enumerate(ifconfig["dns"]):
if not l in dns:
dns.append(l)
if "ips" in ifconfig:
for p, l in enumerate(ifconfig['ips']):
if l['enabled']:
cmd = "ifconfig %s inet %s netmask %s;\n"
printf(cmd, ifs[k], l['ip'], l['netmask'])
if "ip6s" in ifconfig:
for p, l in enumerate(ifconfig['ip6s']):
if l['enabled']:
cmd = "ifconfig %s inet6 %s/%d;\n"
printf(cmd, ifs[k], l['ip'], l['netmask'])
if "routes" in ifconfig:
for p, l in enumerate(ifconfig["routes"]):
cmd = "route add -net %s -netmask %s %s;\n"
printf(cmd, l["route"], l["netmask"], l["gateway"])
if "gateway" in ifconfig and ifconfig["gateway"]:
printf("route add default %s;\n", ifconfig["gateway"])
if "gateway_v6" in ifconfig:
printf("route add -inet6 default %s;\n", ifconfig["gateway_v6"])
date = time.strftime("%Y-%m-%d %H:%M:%S")
printf("echo '# autogenerated on %s' > /etc/resolv.conf;\n", date)
for n, k in enumerate(dns):
printf("echo 'nameserver %s' >> /etc/resolv.conf;\n", k)

View File

@@ -0,0 +1,18 @@
#!/bin/sh
# PROVIDE: xen_network
# REQUIRE: xenguest network
$_rc_subr_loaded . /etc/rc.subr
name="xen_network"
start_cmd="network_start"
network_start()
{
eval $( @PREFIX@/sbin/xen_network.py )
}
load_rc_config $name
run_rc_command "$1"