1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
# marathon-python
[](https://travis-ci.org/thefactory/marathon-python)
This is a Python library for interfacing with [Marathon](https://github.com/mesosphere/marathon) servers via Marathon's [REST API](https://mesosphere.github.io/marathon/docs/rest-api.html).
#### Compatibility
* For Marathon 1.9.x and 1.10.x, use at least 0.13.0
* For Marathon 1.6.x, use at least 0.10.0
* For Marathon 1.4.1, use at least 0.8.13
* For Marathon 1.1.1, use at least 0.8.1
* For all version changes, please see `CHANGELOG.md`
If you find a feature that is broken, please submit a PR that adds a test for
it so it will be fixed and will continue to stay fixed as Marathon changes over
time.
Just because this library is tested against a specific version of Marathon,
doesn't necessarily mean that it supports every feature and API Marathon
provides.
## Installation
#### From PyPi (recommended)
```bash
pip install marathon
```
#### From GitHub
```bash
pip install -e git+git@github.com:thefactory/marathon-python.git#egg=marathon
```
#### From source
```bash
git clone git@github.com:thefactory/marathon-python
python marathon-python/setup.py install
```
## Testing
`marathon-python` uses Travis to test the code against different versions of Marathon.
You can run the tests locally on a Linux machine that has docker on it:
### Running The Tests
```bash
make itests
```
### Running The Tests Against a Specific Version of Marathon
```bash
MARATHONVERSION=v1.6.322 make itests
```
## Documentation
API documentation is [here](http://thefactory.github.io/marathon-python).
Or you can build the documentation yourself:
```bash
pip install sphinx
pip install sphinx_rtd_theme
cd docs/
make html
```
The documentation will be in `<project-root>/gh-pages/html`:
```bash
open gh-pages/html/index.html
```
## Basic Usage
Create a `MarathonClient()` instance pointing at your Marathon server(s):
```python
>>> from marathon import MarathonClient
>>> c = MarathonClient('http://localhost:8080')
>>> # or multiple servers:
>>> c = MarathonClient(['http://host1:8080', 'http://host2:8080'])
```
Then try calling some methods:
```python
>>> c.list_apps()
[MarathonApp::myapp1, MarathonApp::myapp2]
```
```python
>>> from marathon.models import MarathonApp
>>> c.create_app('myapp3', MarathonApp(cmd='sleep 100', mem=16, cpus=1))
MarathonApp::myapp3
```
```python
>>> app = c.get_app('myapp3')
>>> app.ports
[19671]
>>> app.mem = 32
>>> c.update_app('myapp3', app)
{'deploymentId': '83b215a6-4e26-4e44-9333-5c385eda6438', 'version': '2014-08-26T07:37:50.462Z'}
>>> c.get_app('myapp3').mem
32.0
```
```python
>>> c.get_app('myapp3').instances
1
>>> c.scale_app('myapp3', instances=3)
{'deploymentId': '611b89e3-99f2-4d8a-afe1-ec0b83fdbb88', 'version': '2014-08-26T07:40:20.121Z'}
>>> c.get_app('myapp3').instances
3
>>> c.scale_app('myapp3', delta=-1)
{'deploymentId': '1081a99c-55e8-4404-907b-4a3697059848', 'version': '2014-08-26T07:43:30.232Z'}
>>> c.get_app('myapp3').instances
2
```
```python
>>> c.list_tasks('myapp1')
[MarathonTask:myapp1-1398201790254]
>>> c.kill_tasks('myapp1', scale=True)
[MarathonTask:myapp1-1398201790254]
>>> c.list_tasks('myapp1')
[]
```
## License
Open source under the MIT License. See [LICENSE](LICENSE).
|