Skip to content

Commit efc36a6

Browse files
committed
Merge pull request #32 from virtapi/update-docs
Update docs
2 parents 304396c + 5b45136 commit efc36a6

File tree

3 files changed

+139
-10
lines changed

3 files changed

+139
-10
lines changed

README.md

+121-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Monkeying around with virtual machines and pxe configs.
1616
- [HTTP PXE](#http-pxe)
1717
- [HTTP VM](#http-vm)
1818
- [HTTP installimage](#http-installimage)
19+
- [HTTP DHCP](#http-dhcp)
1920
+ [Issues](#issues)
2021
+ [Copyright](#copyright)
2122
+ [Name origin](#name-origin)
@@ -24,10 +25,26 @@ Monkeying around with virtual machines and pxe configs.
2425

2526
## Setup
2627

27-
Create `marmoset.conf` before using marmoset! See `Configuration` for details.
28+
Clone the repo into /opt, then copy the service file into the systemd directory and reload systemd to recognize the file:
29+
```bash
30+
cd /opt
31+
git clone https://github.com/virtapi/marmoset.git
32+
cd marmoset
33+
cp ext/marmoset.service /etc/systemd/system/
34+
systemctl daemon-reload
35+
```
2836
Copy the `marmoset.conf.example` to `marmoset.conf` and adjust the settings to your needs.
2937
Checkout the Comments in the file our our [Configuration](#configuration) section.
3038

39+
Now we need to setup a virtualenv and install the required python packages (remove libvirt from the requirements.txt and `pkg-config libvirt gcc` from the list of packages to install if you don't want to manage VMs with marmoset):
40+
```bash
41+
pacman -Syu python-virtualenv pkg-config libvirt gcc
42+
virtualenv prod
43+
source prod/bin/activate
44+
pip install --upgrade pip
45+
pip install -r requirements.txt
46+
```
47+
3148
---
3249

3350
## Requirements
@@ -49,6 +66,7 @@ Please checkout our [requirements.txt](requirements.txt) for a complete and auth
4966
* wheel
5067

5168
In addition to these python packages, you also need Python 3. This project originally started with Python 3.3, we are currently developing and testing on 3.5 but we plan to support Python 3.3 and 3.4 as well.
69+
We also need pkg-config and libvirt, which you need to install via your system-wide package manager (these aren't python packages).
5270

5371
---
5472

@@ -128,9 +146,11 @@ Start it like this:
128146

129147
$ ./marmoset.py server
130148

131-
Or with gunicorn:
149+
Or use our systemd service:
150+
151+
$ systemctl start marmoset
132152

133-
$ gunicorn marmoset.app:app
153+
A third solution is to use nginx + uwsgi to power the app. This is the recommended way if you expect a high amount of requests.
134154

135155
### HTTP PXE
136156

@@ -381,7 +401,7 @@ Remove a VM:
381401
This endpoint is meant to work together with our [installimage](https://github.com/virtapi/installimage). We identify each dataset by its MAC address and store the key:value config pairs for the installimage.
382402

383403
#### List Entries
384-
curl -u admin:secret http://localhost:8080/v1/installimage
404+
curl -u admin:secret http://localhost:5000/v1/installimage
385405

386406
```json
387407
[
@@ -414,7 +434,7 @@ This endpoint is meant to work together with our [installimage](https://github.c
414434
```
415435

416436
#### List a single Entry
417-
curl -u admin:secret http://localhost:8080/v1/installimage/b8:ac:6f:97:7e:77
437+
curl -u admin:secret http://localhost:5000/v1/installimage/b8:ac:6f:97:7e:77
418438

419439
```json
420440
{
@@ -434,7 +454,7 @@ This endpoint is meant to work together with our [installimage](https://github.c
434454
```
435455

436456
#### List a single Entry in the installimage format
437-
curl -u admin:secret http://localhost:8080/v1/installimage/b8:ac:6f:97:7e:77/config
457+
curl -u admin:secret http://localhost:5000/v1/installimage/b8:ac:6f:97:7e:77/config
438458

439459
```
440460
PART / ext4 all
@@ -449,7 +469,7 @@ HOSTNAME CentOS-71-64-minimal
449469
```
450470

451471
#### Create a record
452-
curl -u admin:secret --data "drive1=/dev/sda&bootloader=grub&hostname=CentOS-71-64-minimal&PART=/ ext4 all&image=/root/.installimage/../images/CentOS-71-64-minimal.tar.gz" http://localhost:8080/v1/installimage/b8:ac:6f:97:7e:77
472+
curl -u admin:secret --data "drive1=/dev/sda&bootloader=grub&hostname=CentOS-71-64-minimal&PART=/ ext4 all&image=/root/.installimage/../images/CentOS-71-64-minimal.tar.gz" http://localhost:5000/v1/installimage/b8:ac:6f:97:7e:77
453473

454474
Returns the created record:
455475
```json
@@ -470,7 +490,7 @@ Returns the created record:
470490
```
471491

472492
#### Delete a Record
473-
curl -u admin:secret -X DELETE http://localhost:8080/v1/installimage/b8:ac:6f:97:7e:77
493+
curl -u admin:secret -X DELETE http://localhost:5000/v1/installimage/b8:ac:6f:97:7e:77
474494

475495
Errormessage if you want to delete or list a nonexistent entry:
476496
```json
@@ -479,6 +499,99 @@ Errormessage if you want to delete or list a nonexistent entry:
479499
}
480500
```
481501

502+
### HTTP DHCP
503+
This endpoint allows us the throw static IP/MAC combinations into a ldap database. Currently tested is only the [openldap](http://www.openldap.org/) backend. This database is connected to an isc-dhcpd. We can identify an object by its IP or MAC address.
504+
505+
#### List Entries
506+
curl -u admin:secret http://localhost:5000/v1/dhcp
507+
```json
508+
[
509+
{
510+
"additional_statements": {},
511+
"dhcp_hostname": "odin.fritz.box",
512+
"gateway": "192.168.10.1",
513+
"ip_address": "192.168.10.5",
514+
"mac": "00:00:00:00:00:00",
515+
"networkmask": "255.255.255.0"
516+
},
517+
{
518+
"additional_statements": {},
519+
"dhcp_hostname": "odin.fritz.box",
520+
"gateway": "10.3.7.1",
521+
"ip_address": "10.3.7.41",
522+
"mac": "00:00:00:00:00:00",
523+
"networkmask": "255.255.255.0"
524+
}
525+
]
526+
```
527+
528+
#### List One Entry based on MAC
529+
curl -u admin:secret http://localhost:5000/v1/dhcp/mac/00:00:00:00:00:00
530+
```json
531+
{
532+
"additional_statements": {},
533+
"dhcp_hostname": "odin.fritz.box",
534+
"gateway": "10.3.7.1",
535+
"ip_address": "10.3.7.41",
536+
"mac": "00:00:00:00:00:00",
537+
"networkmask": "255.255.255.0"
538+
}
539+
```
540+
541+
or:
542+
curl -u admin:secret http://localhost:5000/v1/dhcp/mac/23.45.67.8
543+
```
544+
"please provide a valid mac address"
545+
```
546+
547+
#### List one Entry based on IP
548+
curl -u admin:secret http://localhost:5000/v1/dhcp/ipv4/10.3.7.41
549+
```json
550+
{
551+
"additional_statements": {},
552+
"dhcp_hostname": "odin.fritz.box",
553+
"gateway": "10.3.7.1",
554+
"ip_address": "10.3.7.41",
555+
"mac": "00:00:00:00:00:00",
556+
"networkmask": "255.255.255.0"
557+
}
558+
```
559+
560+
or:
561+
curl -u admin:secret http://localhost:5000/v1/dhcp/ipv4/23.45.67.888
562+
```
563+
"please provide a valid ipv4 address"
564+
```
565+
566+
#### Create a new Entry:
567+
this will return the new created entry:
568+
curl -u admin:secret --data 'ip_address=10.3.7.41&mac=b8:ac:6f:97:7e:77&gateway=10.3.7.1&networkmask=255.255.255.0' http://localhost:5000/v1/dhcp
569+
```json
570+
{
571+
"additional_statements": {},
572+
"dhcp_hostname": "example.com",
573+
"gateway": "10.3.7.1",
574+
"ip_address": "10.3.7.41",
575+
"mac": "b8:ac:6f:97:7e:77",
576+
"networkmask": "255.255.255.0"
577+
}
578+
```
579+
580+
an update works the same way, just submit the command again and change new updated params, again the API will respond with the updated entry.
581+
582+
#### Delete an Entry:
583+
curl -u admin:secret -X DELETE http://localhost:5000/v1/dhcp/ipv4/10.3.7.41
584+
585+
Deleting a nonexistent entry:
586+
curl -u admin:secret -X DELETE http://localhost:5000/v1/dhcp/ipv4/10.3.7.41
587+
588+
will return:
589+
```json
590+
{
591+
"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. You have requested this URI [/v1/dhcp/ipv4/10.3.7.41] but did you mean /v1/dhcp/ipv4/<ipv4> ?"
592+
}
593+
```
594+
482595
---
483596

484597
## Setup LDAP + isc-dhcpd

marmoset.conf.example

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
[Modules]
66
PXE: True
77
VM: True
8-
INSTALLIMAGE: True
8+
Webserver: True
9+
Installimage: True
10+
DHCP: True
911

1012
[Webserver]
1113
# Settings for HTTP Basic Auth
@@ -34,9 +36,13 @@ Network:
3436
# storage name is given.
3537
Storage:
3638

39+
# this will be used for storing PXE options
3740
[PXEConfig]
3841
ConfigDirectory: /srv/tftp/pxelinux.cfg/
3942

43+
# this will be used for storing installimage options
44+
[Config]
45+
ConfigDirectory: /srv/tftp/config/
4046
# The PXELabel section has no defaults, as its entries depend on
4147
# the PXE configuration. The syntax is `label: callbackmethod`.
4248
# If the entry doesn't need any callback, just let callbackmethod
@@ -47,3 +53,13 @@ ConfigDirectory: /srv/tftp/pxelinux.cfg/
4753
#freebsd: createpwhashfile
4854
#openbsd:
4955

56+
[DHCPConfig]
57+
# list of all statements that we allow
58+
# see https://github.com/virtapi/marmoset/issues/7#issuecomment-175262281
59+
# and see https://github.com/virtapi/marmoset/issues/7#issuecomment-175275522
60+
additional_statements = option domain-name-servers,option domain-name,max-lease-time,default-lease-time,option ntp-servers
61+
ldap_server = localhost
62+
ldap_port = 389
63+
ldap_bind_dn = cn=root,dc=example,dc=com
64+
ldap_passwort = secret
65+
ldap_client_base_dn = cn=static,cn=DHCP Service Config,dc=example,dc=com

marmoset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python3
1+
#!/usr/bin/env python3
22

33
import marmoset
44

0 commit comments

Comments
 (0)