Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
formating
Browse files Browse the repository at this point in the history
  • Loading branch information
uberj committed Aug 7, 2013
1 parent 863c1d4 commit 99deea5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
60 changes: 33 additions & 27 deletions invtool/search_dispatch.py
@@ -1,4 +1,5 @@
import requests import requests
import sys


try: try:
import simplejson as json import simplejson as json
Expand All @@ -25,14 +26,15 @@ def build_parser(self, base_parser):
) )


search.add_argument( search.add_argument(
'--range', '-r', dest='irange', type=str, help="Get information and " '--range', '-r', dest='irange', type=str, help="Get information "
"statistics about an IP range. Specify the range using: " "and statistics about an IP range. Specify the range using: "
"<ip-start>,<ip-end> format (no spaces)", default=None, required=False "<ip-start>,<ip-end> format (no spaces)", default=None,
required=False
) )


search.add_argument( search.add_argument(
'--display-integers', dest='d_integers', help="Return integers when " '--display-integers', dest='d_integers', help="Return integers "
"showing free ip ranges.", action='store_true', default=False, "when showing free ip ranges.", action='store_true', default=False,
required=False required=False
) )


Expand All @@ -57,27 +59,29 @@ def irange(self, nas):
search = {'start': start, 'end': end} search = {'start': start, 'end': end}
if nas.d_integers: if nas.d_integers:
search['format'] = 'integers' search['format'] = 'integers'
resp = requests.get(url, params=search, headers=headers, resp = requests.get(url, params=search, headers=headers, auth=auth)
auth=auth()) if nas.DEBUG:
if resp.status_code == 500: sys.stderr.write('method: {0}\nurl: {1}\nparams:{2}\n'.format(
resp_list = [ 'get', url, search
"CLIENT ERROR! (Please email this output to a code monkey)" ))
] was_json = nas.p_json
self.error_out(nas, search, resp, resp_list=resp_list) nas.p_json = True # Do this so we can play with the response
return ret_code, raw_results = self.handle_resp(nas, search, resp)
results = self.get_resp_dict(resp) if ret_code:
return (ret_code, raw_results) # repack and go home


def display_ranges(free_ranges): def display_ranges(free_ranges):
ret_list = [] ret_list = []
for fstart, fend in free_ranges: for fstart, fend in free_ranges:
ret_list.append("{0} to {1}".format(fstart, fend)) ret_list.append("{0} to {1}".format(fstart, fend))
return ret_list return ret_list


results = json.loads(raw_results[0], 'unicode')
if not results: if not results:
return 1, [] return 1, []
else: else:
if nas.p_json: if was_json:
return 0, [json.dumps(results, indent=2)] return 0, raw_results
resp_list = ["# of Used IPs: {0}".format(results['used']), resp_list = ["# of Used IPs: {0}".format(results['used']),
"# of Unused IPs: {0}".format(results['unused']), "# of Unused IPs: {0}".format(results['unused']),
"------ Vacant IP ranges ------"] "------ Vacant IP ranges ------"]
Expand All @@ -89,20 +93,22 @@ def query(self, nas):
url = "{0}{1}".format(REMOTE, tmp_url) url = "{0}{1}".format(REMOTE, tmp_url)
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
search = {'search': nas.query} search = {'search': nas.query}
resp = requests.get(url, params=search, headers=headers, resp = requests.get(url, params=search, headers=headers, auth=auth)
auth=auth()) if nas.DEBUG:
if resp.status_code == 500: sys.stderr.write('method: {0}\nurl: {1}\nparams:{2}\n'.format(
resp_list = [ 'get', url, search
"CLIENT ERROR! (Please email this output to a code monkey)" ))
] was_json = nas.p_json
self.error_out(nas, search, resp, resp_list=resp_list) nas.p_json = True # Do this so we can play with the response
return ret_code, raw_results = self.handle_resp(nas, search, resp)
results = self.get_resp_dict(resp) if ret_code:
return (ret_code, raw_results) # repack and go home
results = json.loads(raw_results[0], 'unicode')
if 'text_response' not in results: if 'text_response' not in results:
return 1, [] return 1, []
else: else:
if nas.p_json: if was_json:
return 0, [json.dumps(results, indent=2)] return 0, raw_results
return 0, [results['text_response']] return 0, [results['text_response']]




Expand Down
1 change: 1 addition & 0 deletions invtool/tests/kv_tests.py
Expand Up @@ -23,6 +23,7 @@ class _TestCase(unittest.TestCase):


def place_holder(self): def place_holder(self):
# This should create an object that we can use to associate KV's to # This should create an object that we can use to associate KV's to
print "testing {0} ...".format(dispatch.dtype)
obj_pk = dispatch.do_test_setup(self) obj_pk = dispatch.do_test_setup(self)


# List the object's KV store and remember the count # List the object's KV store and remember the count
Expand Down

0 comments on commit 99deea5

Please sign in to comment.