2013-04-12 17:55:54 +00:00
|
|
|
import json
|
|
|
|
import httplib2
|
|
|
|
import logging
|
2013-09-20 19:00:46 +00:00
|
|
|
import os
|
|
|
|
from .config import config
|
2013-04-12 17:55:54 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-09-20 19:00:46 +00:00
|
|
|
|
2013-04-12 17:55:54 +00:00
|
|
|
def send_request(method, url, body=None, headers=None):
|
|
|
|
http = httplib2.Http()
|
|
|
|
resp, content = http.request(url, method=method, body=body, headers=headers)
|
|
|
|
if resp.status == 200:
|
|
|
|
return (True, content, resp.status)
|
|
|
|
log.info("%s request to '%s' with body '%s' failed with response code %d",
|
|
|
|
method, url, body, resp.status)
|
|
|
|
return (False, None, resp.status)
|
|
|
|
|
2013-09-20 19:00:46 +00:00
|
|
|
|
2013-04-12 17:55:54 +00:00
|
|
|
def get_status(ctx, name):
|
2013-09-20 19:00:46 +00:00
|
|
|
success, content, _ = send_request('GET', os.path.join(config.lock_server, name))
|
2013-04-12 17:55:54 +00:00
|
|
|
if success:
|
|
|
|
return json.loads(content)
|
|
|
|
return None
|