From 87b002144574c7169b1eed81d6e5edae0ba99bdf Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Mon, 30 Nov 2015 11:59:16 -0800 Subject: [PATCH] pixicore: Add libvirt Pixiecore Vagrantfile --- README.md | 8 +++-- pixiecore/.gitignore | 1 + pixiecore/Vagrantfile | 33 ++++++++++++++++++ pixiecore/config.rb | 9 +++++ pixiecore/scripts/pixiecore.sh | 61 ++++++++++++++++++++++++++++++++++ pxe/Vagrantfile | 3 +- pxe/config.rb | 2 +- pxe/scripts/pxe.sh | 6 ++-- 8 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 pixiecore/.gitignore create mode 100644 pixiecore/Vagrantfile create mode 100644 pixiecore/config.rb create mode 100644 pixiecore/scripts/pixiecore.sh diff --git a/README.md b/README.md index a915f253..7c3f7cca 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ `pxe` provides a Vagrantfile and scripts for setting up a PXE server in libvirt or on physical hardware. +`pixiecore` provides a Vagrantfile and scripts for setting up a Pixiecore server in libvirt or on physical hardware. + ## Setup -To develop with with Vagrant, install the dependencies +To develop with Vagrant, install the dependencies # Fedora 22/23 dnf install vagrant vagrant-libvirt virt-manager ## Usage -The Vagrantfile will setup a `pxe_default` VM running a PXE server with a configured static IP address, DHCP range, CoreOS kernel image, and cloud-config. The VM will be connected to a network called `vagrant-libvirt`. +The Vagrantfile will setup a `pxe_default` VM running a PXE server with a configured static IP address, DHCP range, CoreOS kernel image, and cloud-config. The VM will be connected to a network called `vagrant-pxe`. ### libvirt Provider @@ -39,4 +41,4 @@ If you change the Vagrantfile or a configuration variable, reload the VM with To try a new cloud-config, you can also scp the file onto the dev PXE server. - scp new-config.yml core@NODE_IP:/var/www/html/pxe-cloud-config.yml + scp new-config.yml core@NODE_IP:/var/www/html/cloud-config.yml diff --git a/pixiecore/.gitignore b/pixiecore/.gitignore new file mode 100644 index 00000000..997ca2f8 --- /dev/null +++ b/pixiecore/.gitignore @@ -0,0 +1 @@ +.vagrant \ No newline at end of file diff --git a/pixiecore/Vagrantfile b/pixiecore/Vagrantfile new file mode 100644 index 00000000..05f042da --- /dev/null +++ b/pixiecore/Vagrantfile @@ -0,0 +1,33 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +require 'fileutils' + +CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "user-data") +CONFIG = File.join(File.dirname(__FILE__), "config.rb") + +if File.exist?(CONFIG) + require CONFIG +end + +Vagrant.configure(2) do |config| + config.vm.box = "fedora/23-cloud-base" + + # Create a public network with a static IP address + config.vm.network "public_network", ip: $pixiecore_server_ip, dev: "wlp3s0" + + # Provider Specific Configuration + config.vm.provider :libvirt do |libvirt| + libvirt.cpus = 1 + libvirt.memory = 1024 + libvirt.management_network_name = "vagrant-pixiecore" + libvirt.management_network_address = $network_range + end + + # Provision a Pixiecore Server + config.vm.provision :shell do |s| + s.privileged = true + s.path = "scripts/pixiecore.sh" + s.args = [$pixiecore_server_ip, $ssh_authorized_key] + end +end diff --git a/pixiecore/config.rb b/pixiecore/config.rb new file mode 100644 index 00000000..b1b5a276 --- /dev/null +++ b/pixiecore/config.rb @@ -0,0 +1,9 @@ + +# Vagrant Network CIDR +$network_range="192.168.33.0/24" + +# Pixiecore Server IP, must be in the network_range +$pixiecore_server_ip="192.168.33.10" + +# SSH Authorized Key for client CoreOS instances +$ssh_authorized_key="AAAAB3NzaC1yc2EAAAADAQABAAABAQC9oRIjXKgC1It3U22INv9sDbQjzZNbY6fdzN28hl2gnWf7b4/KJjbCE8cldAiV6qiLwnaqnINgoAy8JN718qos8VsLRdB/GvhlVOQvjJf6gSI9WcG1kVbbYuZ7WV1cxnxjE21+oHHz4IZyGKP6rEv0ODcFWokJt13zpK9isG7iQyBi51KNFPgox/jfM0uDCf+yzSsCX2HUUxmqKDUXD9XDihrGRpbqL6gH5VDYzDmVAHq5e3er1Sz2n+Gx/wUSXzNk9TdCY/cS6k2C6H3+dwA45HFADjmeK+k3dE+cDrXkLsB9GTXnvcmtdoVAFoHBZo8GqRKocaejVgDaRo+prQyJ dghubble@Mars" \ No newline at end of file diff --git a/pixiecore/scripts/pixiecore.sh b/pixiecore/scripts/pixiecore.sh new file mode 100644 index 00000000..0ce11b8c --- /dev/null +++ b/pixiecore/scripts/pixiecore.sh @@ -0,0 +1,61 @@ +#!/bin/bash -e +# Usage: Setup a Pixiecore Server + +# ./pxe.sh IP SSH_KEY +# ./pixiecore.sh "192.168.33.10" "AABC.... name" + +PIXIECORE_SERVER_IP=$1 +SSH_AUTHORIZED_KEYS=$2 + +# Pixiecore kernel and init RAM disk +dnf install -yq wget +mkdir -p /var/lib/image +wget -q -O /var/lib/image/coreos_production_pxe.vmlinuz http://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz +wget -q -O /var/lib/image/coreos_production_pxe_image.cpio.gz http://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz +chcon -Rt svirt_sandbox_file_t /var/lib/image + +# Docker +dnf install -yq docker +systemctl enable docker.service +systemctl start docker.service + +# HTTP + +# static cloud-config HTTP server +dnf install -yq httpd + +cat << EOF > "/var/www/html/cloud-config.yml" +#cloud-config +coreos: + units: + - name: etcd2.service + command: start + - name: fleet.service + command: start +ssh_authorized_keys: + - ssh-rsa $SSH_AUTHORIZED_KEYS +EOF + +systemctl enable httpd +systemctl start httpd + +# Pixiecore +docker pull danderson/pixiecore +#docker run -v /var/lib/image:/image --net=host danderson/pixiecore -kernel /image/coreos_production_pxe.vmlinuz -initrd /image/coreos_production_pxe_image.cpio.gz --cmdline cloud-config-url=http://$PIXIECORE_SERVER_IP/cloud-config.yml + +cat << EOF > /etc/systemd/system/pixiecore.service +[Unit] +Description=Pixicore Service + +[Service] +Type=simple +ExecStart=/usr/bin/docker run -v /var/lib/image:/image --net=host danderson/pixiecore -kernel /image/coreos_production_pxe.vmlinuz -initrd /image/coreos_production_pxe_image.cpio.gz --cmdline cloud-config-url=http://$PIXIECORE_SERVER_IP/cloud-config.yml + +[Install] +WantedBy=multi-user.target +EOF + +systemctl enable pixiecore.service +systemctl start pixiecore.service + +echo "Done" diff --git a/pxe/Vagrantfile b/pxe/Vagrantfile index 72bdbd36..7e944270 100644 --- a/pxe/Vagrantfile +++ b/pxe/Vagrantfile @@ -19,7 +19,7 @@ Vagrant.configure(2) do |config| config.vm.provider :libvirt do |libvirt| libvirt.cpus = 1 libvirt.memory = 1024 - libvirt.management_network_name = "vagrant-libvirt" + libvirt.management_network_name = "vagrant-pxe" libvirt.management_network_address = $network_range end @@ -29,5 +29,4 @@ Vagrant.configure(2) do |config| s.path = "scripts/pxe.sh" s.args = [$pxe_server_ip, $dhcp_range, $ssh_authorized_key] end - end diff --git a/pxe/config.rb b/pxe/config.rb index 7f284ec9..8eae6c92 100644 --- a/pxe/config.rb +++ b/pxe/config.rb @@ -9,4 +9,4 @@ $pxe_server_ip="192.168.32.10" $dhcp_range="192.168.32.2,192.168.32.254,12h" # SSH Authorized Key for client CoreOS instances -$ssh_authorized_key="AAAAB3NzaC1yc2EAAAADAQABAAACAQDp9dypy87zDQgoMm9tk9aKVNDXemN2bp+taQzY4I2BS74H850SjvxVqMHbTcZVi+gMmUev9DPo5xfDOeTPeaT5fnNaKTLNGLezGM0pjMtKWOrZSQqK2YywjT/VdnBvNG6zKHE/MgpexLdkqiPJGPSHhRB+rQ5JX1FL3Qpt9prD2tW8audLmZ6PorC8/HLIwgBIrlh8JFbVFYGEy4dFImz2eyTqNUxDhP2hx17Drvssy/D6HR4zehgP1MGJWOKGfFlE2xe+hy+S6fjkPK5Nc7MR0uqhCkJHpCfVFjbHyZsQK3oi30Afe9t/CdRfPgQW+daeA7yBd1d/56A8QEbRf7W8wO5/CaSBoomA3bufJwwtT50oQwi3r0+hapivvmlUo3WhXwFoPV/XLyQUNGMWKmOWEqqmREFpi/NVnfItU8CenowvDoly0FkreztO4bAAhMd0w4/bAUisRHlucXXifqFEZr5NUt0BIaZmjavbXDadajzhwbK5mWpijuLoiuYCsa+5pQjFVlZRo5f3F3dQ5nREgRSWJPkxzllHygdEeKqxcE4slZJwZbrBgV4OT2nwGjBpfHsbBKBZRM6eKOiDIOVf/hh4+9+GirHWKosv3HRKHH9TisfIFlZoxzxY6E87oPvlf+7rEwHhuaPUoThSXxB6JS9LiOcqxjgL1ltfapgLqQ== dghubble@gmail.com" \ No newline at end of file +$ssh_authorized_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9oRIjXKgC1It3U22INv9sDbQjzZNbY6fdzN28hl2gnWf7b4/KJjbCE8cldAiV6qiLwnaqnINgoAy8JN718qos8VsLRdB/GvhlVOQvjJf6gSI9WcG1kVbbYuZ7WV1cxnxjE21+oHHz4IZyGKP6rEv0ODcFWokJt13zpK9isG7iQyBi51KNFPgox/jfM0uDCf+yzSsCX2HUUxmqKDUXD9XDihrGRpbqL6gH5VDYzDmVAHq5e3er1Sz2n+Gx/wUSXzNk9TdCY/cS6k2C6H3+dwA45HFADjmeK+k3dE+cDrXkLsB9GTXnvcmtdoVAFoHBZo8GqRKocaejVgDaRo+prQyJ dghubble" \ No newline at end of file diff --git a/pxe/scripts/pxe.sh b/pxe/scripts/pxe.sh index 36b699a7..7bc6b796 100644 --- a/pxe/scripts/pxe.sh +++ b/pxe/scripts/pxe.sh @@ -40,7 +40,7 @@ display boot.msg label coreos menu default kernel coreos_production_pxe.vmlinuz - append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$PXE_SERVER_IP/pxe-cloud-config.yml + append initrd=coreos_production_pxe_image.cpio.gz cloud-config-url=http://$PXE_SERVER_IP/cloud-config.yml EOF # TFTP ldlinux.c32 pxelinux.0 @@ -48,7 +48,7 @@ dnf install -yq syslinux ln -s /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux.0 ln -s /usr/share/syslinux/ldlinux.c32 /var/lib/tftpboot/ldlinux.c32 -# TFTP kernel image and options +# TFTP kernel image and init RAM disk dnf install -yq wget wget -q -O /var/lib/tftpboot/coreos_production_pxe.vmlinuz http://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz wget -q -O /var/lib/tftpboot/coreos_production_pxe_image.cpio.gz http://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz @@ -63,7 +63,7 @@ systemctl start dnsmasq # static cloud-config HTTP server dnf install -yq httpd -cat << EOF > "/var/www/html/pxe-cloud-config.yml" +cat << EOF > "/var/www/html/cloud-config.yml" #cloud-config coreos: units: