Coder Social home page Coder Social logo

ppetko / gopxe Goto Github PK

View Code? Open in Web Editor NEW
77.0 4.0 16.0 103.75 MB

PXE Booting/Kickstart - Container running dhcpd, tftpd and golang APIs

License: MIT License

Go 66.86% Shell 6.82% Dockerfile 4.01% Makefile 5.21% HTML 17.10%
pxe-boot dhcpd tftpd docker golang build-system apis

gopxe's Introduction

GoPXE Project

CircleCI

Introduction

GoPXE is a dynamic build system for installing various operating systems on virtual machines and bare metal servers using pxe boot, tftp and dhcp wrapped into docker container orchestrated by APIs.

Quickstart

Download docker image

docker pull ppetko/gopxe

Configuration - edit the configuration files accordingly. Sample configs has been provided in the repo.

curl -s https://raw.githubusercontent.com/ppetko/GoPXE/master/conf/dhcpd.conf -b dhcpd.conf
curl -s https://raw.githubusercontent.com/ppetko/GoPXE/master/conf/tftpd.conf -b tftpd.conf
vi dhcpd.conf # and edit accordingly.

Start GoPXE using Docker image

sudo docker run --rm --net=host --name goPXE -td \
            --mount type=bind,source="$(pwd)"/dhcpd.conf,target=/etc/dhcp/dhcpd.conf \
            --mount type=bind,source="$(pwd)"/tftpd.conf,target=/etc/xinetd.d/tftp \
            ppetko/gopxe

Build your own docker image

go get github.com/ppetko/gopxe
cd $GOPATH/src/github.com/ppetko/gopxe
sudo make docker-build

How PXE works?

  • The target host (the PXE client) is booted.
  • The target host makes a DHCP request.
  • The DHCP server responds with the IP information and provides information about the location of a TFTP server.
  • When the client receives the information, it contacts the TFTP server requesting the file that the DHCP server specified (in this case, the network boot loader).
  • The TFTP server sends the network boot loader, and the client executes it.
  • PXELINUX searches for a configuration file on the TFTP server, and boots a kernel according to that configuration file (centos7/vmlinux and centos7/vmlizimage). In this case, the configuration file instructs PXE to load the kernel (vmlinuz) and a ramdisk (initrd.img).
  • The client downloads the files it needs and then loads them.
  • The system boots the OS installer using our Kickstart service.
  • The installer runs interactively or scripted, as directed by the PXE configuration file.
  • The installer uses remote repository, or locally content from ISO file.
  • OS is installed.

APIs Reference Examples

Note: Parameters are specific to your environment.

Create BootAction

  • PXEBoot images are already configured for centos7 in pxebootImages/centos7, so these options are valid kernel:centos7/vmlinux and initrd:centos7/vmlizimage. You can add different specific version or different OS images in pxebootImages.
  • myfirstbootaction is the name of your boot action. You can create many bootactions with specific parameters as long as the names are different.
curl -vv -H "Content-Type: application/json" -d \
'{
  "default": "linux",
  "label": "linux",
  "menu": "centos7",
  "kernel": "centos7/vmlinuz",
  "ksdevice": "link",
  "ip": "dhcp",
  "load_ramdisk": "1",
  "initrd":"centos7/initrd.img"
}' -X POST localhost:9090/bootaction/myfirstbootaction

  • bootaction: myfirstbootaction will reference your bootaction created earlier.
  • ksfile - this will reference the default kickstart which is preload. You can add you own kickstart file in ksTempl/
  • os and version - will be used to build repository in the default kickstart. If you are not using the default kickstart file, leave these options empty.
  • If you want to PXEBoot using mac address instead of UUID, use "uuid": "01-YOUR-MAC-ADDRESS" option.

Create basic PXEBoot record

curl -vv  -H "Content-Type: application/json" -d \
'{
  "bootaction": "myfirstbootaction",
  "ksfile": "default",
  "os": "centos-7",
  "version": "7.5.1804",
  "hostname": "test-myvm.local",
  "uuid": "42330d5a-0ead-f7fa-4e3a-ae3bdcb08c69"
}' http://localhost:9090/pxeboot

  • hostname, ip, mask, ns1, ns2, gw, will be used to build network configuration in the default kickstart

Create PXEBoot record with network options

curl -vv  -H "Content-Type: application/json" -d \
'{
  "bootaction": "vmtemplate",
  "ksfile": "default",
  "os": "centos-7",
  "version": "7.5.1804",
  "hostname": "test-myvm1.local",
  "ip": "10.1.20.50",
  "mask": "255.255.255.0",
  "ns1": "8.8.8.8",
  "ns2": "8.8.4.4",
  "gw": "10.1.20.1",
  "uuid": "42330d5a-0ead-f7fa-4e3a-ae3bdcb08c69"
}' http://localhost:9090/pxeboot

Results

default linux
 label linux
 MENU LABEL centos7
 KERNEL centos7/vmlinuz
 APPEND ksdevice=link ip=dhcp load_ramdisk=1 initrd=centos7/initrd.img ks=http://localhost:9090/kickstart/?name=default&os=centos-7&version=7.5.1804&fqdn=test-myvm1.local&ip=10.1.20.50&mask=255.255.255.0&gw=255.255.255.0&ns1=8.8.8.8&ns2=8.8.4.4

Setup local install images

# wget http://mirror.cc.columbia.edu/pub/linux/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso
# mkdir /mnt/iso
# mount -t iso9660 -o loop CentOS-7-x86_64-Minimal-1804.iso  /mnt/iso/

Once you have all files in /mnt/iso/, start and mount /mnt/iso/ inside the docker container.

sudo docker run --rm --net=host --name goPXE -td \
            --mount type=bind,source="$(pwd)"/conf/dhcpd.conf,target=/etc/dhcp/dhcpd.conf \
            --mount type=bind,source="$(pwd)"/conf/tftpd.conf,target=/etc/xinetd.d/tftp \
            --mount type=bind,source="/mnt/iso/",target=/opt/localrepo \
            ppetko/gopxe

TODO

  • Add function documentation and godocs generation.
  • Add test code coverage for the rest of the code base.
  • Add piplene build for the project.

RoadMap

  • Create Ansible hook - API endpoint that accepts ansible run configs per specific host.
  • Create status output of the job and perhaps synch the results back to the db.
  • Add Status dashboard
  • Manage(start, stop, restart) dhcpd and tftpd processes from the main application instead of bash
  • Output logs to html web page from dhcpd and the rest of the app so the user could easily troubleshoot.
  • Add Notifications/Status API (calling home with errors type)
  • Add multi OS support. Add paramerts for pxelinux.0. Currenly we can configure only one OS at the time.

Notes

  • Currently suported OS is CentOS/RedHat by the default installation. But you could reconfigure GoPXE for any other OS of choice.

Pull requests welcome!

If you'd like to contribute to the project, refer to the contributing documentation.

License

Creative Commons Attribution License

gopxe's People

Contributors

ppetko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gopxe's Issues

how to prevent pxe boot looping

How can I setup the tool to do pxe installation for only one time ?

My server boot order is PXE first, so after installation is done and on next reboot, it may fail into the pxe installation again. And this loop may go forever.

If there is some similiar setting like cobbler pxe_just_once

unable to perform lint, cause of errors

Hi.
I was trying to build your package, since I was curious how good Golang fits for developing Ops infrastructure tools.
I am using gollvm

I tried to

$make lint

and got

/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:4:2: a blank import should be only in a main or test package, or have a comment justifying it
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:10:1: comment on exported type BoltDB should be of the form "BoltDB ..." (with optional leading article)
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:33:1: comment on exported function GetSession should be of the form "GetSession ..."
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:43:1: comment on exported method BoltDB.CreateBucket should be of the form "CreateBucket ..."
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:71:1: comment on exported method BoltDB.PutBootAction should be of the form "PutBootAction ..."
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:84:1: comment on exported method BoltDB.GetBootAction should be of the form "GetBootAction ..."
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:85:1: error should be the last type when returning multiple items
/home/oceanfish81/go/src/github.com/ppetko/gopxe/bbolt/db.go:101:1: error should be the last type when returning multiple items
/home/oceanfish81/go/src/github.com/ppetko/gopxe/conf/conf.go:15:1: exported function Setup should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:23:6: exported type PXEBOOTTYPE should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:37:6: exported type ACTIONTYPE should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:48:1: exported function LoadTemplates should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:73:1: exported function KsGenerate should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:95:1: exported function GetAllBA should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:117:1: exported function GetBA should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:137:1: exported function PutBA should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:183:1: exported function StatusHandler should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:189:1: exported function Index should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:196:1: exported function BootactionHandler should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:204:1: exported function PxebootHandler should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:230:1: exported function PXEBOOT should have comment or be unexported
/home/oceanfish81/go/src/github.com/ppetko/gopxe/handlers/handlers.go:286:9: if block ends with a return statement, so drop this else and outdent its block
/home/oceanfish81/go/src/github.com/ppetko/gopxe/routes/routes.go:13:1: exported function New should have comment or be unexported
Found 23 lint suggestions; failing.

I am using

$ go version
go version go1.15.2 gollvm LLVM 12.0.0git linux/amd64

and my environment looks like this:

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/oceanfish81/.cache/go-build"
GOENV="/home/oceanfish81/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/oceanfish81/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/oceanfish81/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/oceanfish81/gollvm_dist"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/oceanfish81/gollvm_dist/tools"
GCCGO="/home/oceanfish81/gollvm_dist/bin/llvm-goc"
AR="ar"
CC="/usr/bin/clang"
CXX="/usr/bin/clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build542436827=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

.
I am working on Ubuntu 20.04.1 x86_64 and you can take my "release" build, from here, to reproduce this bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.