distil/artifice/clerk_mixins.py
adriant 67aaf5f5ab Basic fixes to get artifice working. Most just hacky workarounds to get it running for demo purposes.
Some few useful bug fixes such as replacement of password without "\n", and issues with "flavor.name" vs "instance_type".
2014-01-06 14:25:33 +13:00

33 lines
1.0 KiB
Python

import requests
from decimal import Decimal
from artifice import NotFound
class ClerkNamesMixin(object):
def pretty_name(self, name):
url = self.config["clerk"]["url"]
url = url + "service_types/" + name + "/"
response = requests.get(url,
headers={"Content-Type": "application/json"})
if response.status_code == 200:
return str(response.json()['pretty_name'])
elif response.status_code == 404:
print "not found"
raise NotFound
class ClerkRatesMixin(object):
def rate(self, name, loc_name):
url = self.config["clerk"]["url"]
url = (url + "locations/" + loc_name +
"/services/" + name + "/rates/current/")
response = requests.get(url,
headers={"Content-Type": "application/json"})
if response.status_code == 200:
return Decimal(response.json()['rate'])
elif response.status_code == 404:
print "not found"
raise NotFound