Skip to content

Commit

Permalink
pools: add method to rebalance a pool
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsmedina committed Nov 23, 2015
1 parent b16a369 commit a8b0b3c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
30 changes: 30 additions & 0 deletions tests/test_pools.py
@@ -0,0 +1,30 @@
from tsuruclient import client

import json
import unittest
import httpretty


class PoolsTestCase(unittest.TestCase):
def setUp(self):
httpretty.enable()

def tearDown(self):
httpretty.disable()
httpretty.reset()

def test_rebalance(self):
url = "http://target/docker/containers/rebalance"
httpretty.register_uri(
httpretty.POST,
url,
body=json.dumps("{}"),
status=200
)

cl = client.Client("http://target", "abc123")
cl.pools.rebalance("dev")

result = json.loads(httpretty.last_request().body)
expected = {"metadataFilter": {"pool": "dev"}}
self.assertDictEqual(expected, result)
3 changes: 2 additions & 1 deletion tsuruclient/client.py
@@ -1,8 +1,9 @@
from tsuruclient import apps, nodes, templates
from tsuruclient import apps, nodes, templates, pools


class Client(object):
def __init__(self, target, token):
self.apps = apps.Manager(target, token)
self.nodes = nodes.Manager(target, token)
self.templates = templates.Manager(target, token)
self.pools = pools.Manager(target, token)
22 changes: 22 additions & 0 deletions tsuruclient/pools.py
@@ -0,0 +1,22 @@
import json
import requests

from base import Manager as Base


class Manager(Base):
"""
Manage pool resources.
"""

def rebalance(self, pool):
"""
Rebalance a pool.
"""
data = {"metadataFilter": {"pool": pool}}
response = requests.post(
"{}/docker/containers/rebalance".format(self.target),
data=json.dumps(data),
headers=self.headers
)
return response.json()

0 comments on commit a8b0b3c

Please sign in to comment.