pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc Autoconfigure NetBSD VM on OpenStack
details: https://anonhg.NetBSD.org/pkgsrc/rev/694f0e3ccbe8
branches: trunk
changeset: 634182:694f0e3ccbe8
user: manu <manu%pkgsrc.org@localhost>
date: Sat May 10 16:38:03 2014 +0000
description:
Autoconfigure NetBSD VM on OpenStack
diffstat:
doc/CHANGES-2014 | 3 +-
sysutils/Makefile | 3 +-
sysutils/openstack_init/DESCR | 2 +
sysutils/openstack_init/MESSAGE | 12 +++
sysutils/openstack_init/Makefile | 29 ++++++++
sysutils/openstack_init/PLIST | 5 +
sysutils/openstack_init/files/openstack_init.py | 89 +++++++++++++++++++++++++
sysutils/openstack_init/files/openstack_init.sh | 19 +++++
sysutils/openstack_init/files/xen_network.py | 59 ++++++++++++++++
sysutils/openstack_init/files/xen_network.sh | 18 +++++
10 files changed, 237 insertions(+), 2 deletions(-)
diffs (296 lines):
diff -r 67a547751acb -r 694f0e3ccbe8 doc/CHANGES-2014
--- a/doc/CHANGES-2014 Sat May 10 15:46:52 2014 +0000
+++ b/doc/CHANGES-2014 Sat May 10 16:38:03 2014 +0000
@@ -1,4 +1,4 @@
-$NetBSD: CHANGES-2014,v 1.1808 2014/05/10 15:19:40 nonaka Exp $
+$NetBSD: CHANGES-2014,v 1.1809 2014/05/10 16:39:07 manu Exp $
Changes to the packages collection and infrastructure in 2014:
@@ -2528,3 +2528,4 @@
Added devel/py-jaraco_util version 10.0.2 [imil 2014-05-09]
Updated net/py-irclib to 8.9 [imil 2014-05-09]
Updated fonts/koruri-ttf to 20140510 [nonaka 2014-05-10]
+ Added sysutils/openstack_init 0.1 [manu 2014-05-10]
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/Makefile
--- a/sysutils/Makefile Sat May 10 15:46:52 2014 +0000
+++ b/sysutils/Makefile Sat May 10 16:38:03 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.596 2014/05/03 19:11:08 wiz Exp $
+# $NetBSD: Makefile,v 1.597 2014/05/10 16:39:06 manu Exp $
#
COMMENT= System utilities
@@ -334,6 +334,7 @@
SUBDIR+= nvramtool
SUBDIR+= oak
SUBDIR+= open-vm-tools
+SUBDIR+= openstack_init
SUBDIR+= openxenmanager
SUBDIR+= osname
SUBDIR+= p5-File-Copy-Recursive
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/DESCR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/DESCR Sat May 10 16:38:03 2014 +0000
@@ -0,0 +1,2 @@
+This package provides two startup scripts to autoconfigure
+a NetBSD VM on Openstack.
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/MESSAGE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/MESSAGE Sat May 10 16:38:03 2014 +0000
@@ -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
+
+===========================================================================
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/Makefile Sat May 10 16:38:03 2014 +0000
@@ -0,0 +1,29 @@
+# $NetBSD: Makefile,v 1.1 2014/05/10 16:38:03 manu Exp $
+#
+
+DISTNAME= openstack_init-1.0
+#PKGREVISION= 1
+CATEGORIES= sysutils
+MASTER_SITES= # none
+DISTFILES= # none
+
+MAINTAINER= pkgsrc-users%NetBSD.org@localhost
+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"
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/PLIST
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/PLIST Sat May 10 16:38:03 2014 +0000
@@ -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
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/files/openstack_init.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/files/openstack_init.py Sat May 10 16:38:03 2014 +0000
@@ -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")
+
+
+
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/files/openstack_init.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/files/openstack_init.sh Sat May 10 16:38:03 2014 +0000
@@ -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"
+
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/files/xen_network.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/files/xen_network.py Sat May 10 16:38:03 2014 +0000
@@ -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)
diff -r 67a547751acb -r 694f0e3ccbe8 sysutils/openstack_init/files/xen_network.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/openstack_init/files/xen_network.sh Sat May 10 16:38:03 2014 +0000
@@ -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"
+
Home |
Main Index |
Thread Index |
Old Index