From 7e3c2ffec31ad366d40f77426afa89256a6373f5 Mon Sep 17 00:00:00 2001 From: adriant Date: Fri, 21 Feb 2014 14:15:37 +1300 Subject: [PATCH] adding a try except in client --- client/client.py | 39 +++++++++++++++++++++++++-------------- client/shell.py | 2 ++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/client/client.py b/client/client.py index ac2b676..189bfc2 100644 --- a/client/client.py +++ b/client/client.py @@ -1,4 +1,5 @@ import requests +from requests.exceptions import ConnectionError class Client(object): @@ -10,21 +11,31 @@ class Client(object): def usage(self, tenants): url = self.endpoint + "usage" data = {"tenants": tenants} - response = requests.post(url, - headers={"Content-Type": "application/json", - "token": self.auth_token}, - data=data) - if response.status_code != 200: - raise AttributeError("Usage cycle failed: " + response.text + - " code: " + str(response.status_code)) + try: + response = requests.post(url, + headers={"Content-Type": + "application/json", + "token": self.auth_token}, + data=data) + if response.status_code != 200: + raise AttributeError("Usage cycle failed: " + response.text + + " code: " + str(response.status_code)) + + except ConnectionError: + pass def sales_order(self, tenants): url = self.endpoint + "sales_order" data = {"tenants": tenants} - response = requests.post(url, - headers={"Content-Type": "application/json", - "token": self.auth_token}, - data=data) - if response.status_code != 200: - raise AttributeError("Sales order cycle failed: " + response.text + - " code: " + str(response.status_code)) + try: + response = requests.post(url, + headers={"Content-Type": + "application/json", + "token": self.auth_token}, + data=data) + if response.status_code != 200: + raise AttributeError("Sales order cycle failed: " + + response.text + " code: " + + str(response.status_code)) + except ConnectionError: + pass diff --git a/client/shell.py b/client/shell.py index edb8806..52870f7 100644 --- a/client/shell.py +++ b/client/shell.py @@ -9,6 +9,7 @@ if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() + #main args: parser.add_argument('--os-username', default=os.environ.get('OS_USERNAME'), help='Defaults to env[OS_USERNAME]') @@ -41,6 +42,7 @@ if __name__ == '__main__': help="Config file", default="/etc/artifice/conf.yaml") + # commands: subparsers = parser.add_subparsers(help='commands', dest='command') usage_parser = subparsers.add_parser('usage', help=('process usage' +