1## Installation
2```
3pip install python-nomad
4```
5
6## Examples
7```python
8
9
10import nomad
11# For HTTP Nomad instances
12n = nomad.Nomad(host="172.16.100.10", timeout=5)
13
14# For HTTPS Nomad instances with non-self-signed SSL certificates
15n = nomad.Nomad(host="172.16.100.10", secure=True, timeout=5, verify=True)
16
17# For HTTPS Nomad instances with self-signed SSL certificates and no validate the cert
18n = nomad.Nomad(host="172.16.100.10", secure=True, timeout=5, verify=False)
19
20# For HTTPS Nomad instances with self-signed SSL certificates that must validate with cert
21n = nomad.Nomad(host="172.16.100.10", secure=True, timeout=5, verify=True, cert="/path/to/certfile") # See http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
22
23# For HTTPS Nomad instances with cert file and key
24n = nomad.Nomad(host="https://172.16.100.10", secure=True, timeout=5, verify=True, cert=("/path/to/certfile", "/path/to/key")) # See http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
25
26# For HTTPS Nomad instances with namespace and acl token
27n = nomad.Nomad(host="172.16.100.10", secure=True, timeout=5, verify=False, namespace='Namespace-example',token='3f4a0fcd-7c42-773c-25db-2d31ba0c05fe')
28
29"example" in n.jobs
30
31j = n.jobs["example"]["ID"]
32
33example_allocation = n.job.get_allocations(j)
34
35n.job.deregister_job(j)
36```
37
38## Environment Variables
39
40This library also supports environment variables: `NOMAD_ADDR`, `NOMAD_NAMESPACE`, `NOMAD_TOKEN`, `NOMAD_REGION` for ease of configuration
41and unifying with nomad cli tools and other libraries.
42
43```bash
44NOMAD_ADDR=http://127.0.0.1:4646
45NOMAD_NAMESPACE=default
46NOMAD_TOKEN=xxxx-xxxx-xxxx-xxxx
47NOMAD_REGION=us-east-1a
48```
49
50## Class Dunders
51
52| Class | contains | len | getitem | iter |
53|---|---|---|---|---|
54|agent|N|N|N|N
55|allocation|Y|N|Y|N
56|allocations|N|Y|N|Y
57|client|N|N|N|N
58|evaluation|Y|N|Y|N
59|evaluations|Y|Y|Y|Y
60|job|Y|N|Y|N
61|jobs|Y|Y|Y|Y
62|node|Y|N|Y|N
63|nodes|Y|Y|Y|Y
64|regions|Y|Y|Y|Y
65|status.leader|Y|Y|N|N
66|status.peers|Y|Y|Y|Y
67|system|N|N|N|N
68|validate|N|N|N|N
69|deployments|Y|Y|Y|Y
70|deployment|Y|N|Y|N
71|namespace|Y|N|Y|N
72|namespaces|Y|Y|Y|Y
73|acl|Y|N|Y|N
74|sentinel|Y|N|Y|N
75
76## Development
77* create virtualenv and activate
78* install requirements-dev.txt
79* can either use the Vagrantfile for local integration testing or create environment variables `NOMAD_IP` and `NOMAD_PORT` that are assigned to a nomad binary that is running
80
81```
82virutalenv venv
83source venv/bin/activate
84pip install -r requirements-dev.txt
85```
86
87## Testing with vagrant and virtualbox
88```
89vagrant up --provider virtualbox
90py.test --cov=nomad --cov-report=term-missing --runxfail tests/
91```