Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updates to reflect changes made to documentation

  • Loading branch information...
commit 57d1ae2f406e59b45d5de65bfe7bde257fb7da08 1 parent 2ca33f9
Davis Barber barberdt authored
66 invitations.py
@@ -6,7 +6,7 @@
6 6 import json
7 7
8 8 def usage(script_name):
9   - print "%s [send|list_sent_invitations|list_received_invitations|respond] \n"%(script_name)
  9 + print "%s [send|respond|list_sent|list_received] \n"%(script_name)
10 10 print "Use '%s [method] --help for a method's usage and options."%(script_name)
11 11 sys.exit()
12 12
@@ -22,33 +22,33 @@ def send(hostname, api_key, swarm_id, to, resource_id, resource_type, descriptio
22 22 conn.close()
23 23 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
24 24
25   -def list_sent_invitations(hostname, api_key, swarm_id):
  25 +def respond(hostname, api_key, resource_id, invitation_id, status):
26 26 conn = httplib.HTTPConnection(hostname)
27   - conn.request("GET", "/swarms/%s/invitations"%(swarm_id), None, {"x-bugswarmapikey":api_key})
  27 + if status != "accept" and status != "reject":
  28 + print "Invalid status. Must be 'accept' or 'reject'."
  29 + sys.exit()
  30 + response = {"status": status}
  31 + response_json = json.dumps(response)
  32 + conn.request("PUT", "/resources/%s/invitations/%s"%(resource_id, invitation_id), response_json, {"x-bugswarmapikey":api_key})
28 33 resp = conn.getresponse()
29 34 txt = resp.read()
30 35 conn.close()
31 36 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
32 37
33   -def list_received_invitations(hostname, api_key, resource_id):
  38 +def list_sent(hostname, api_key, swarm_id):
34 39 conn = httplib.HTTPConnection(hostname)
35   - if resource_id != None:
36   - conn.request("GET", "/resources/%s/invitations"%(resource_id), None, {"x-bugswarmapikey":api_key})
37   - else:
38   - conn.request("GET", "/invitations", None, {"x-bugswarmapikey":api_key})
  40 + conn.request("GET", "/swarms/%s/invitations"%(swarm_id), None, {"x-bugswarmapikey":api_key})
39 41 resp = conn.getresponse()
40 42 txt = resp.read()
41 43 conn.close()
42 44 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
43 45
44   -def respond(hostname, api_key, resource_id, invitation_id, status):
  46 +def list_received(hostname, api_key, resource_id):
45 47 conn = httplib.HTTPConnection(hostname)
46   - if status != "accept" and status != "reject":
47   - print "Invalid status. Must be 'accept' or 'reject'."
48   - sys.exit()
49   - response = {"status": status}
50   - response_json = json.dumps(response)
51   - conn.request("PUT", "/resources/%s/invitations/%s"%(resource_id, invitation_id), response_json, {"x-bugswarmapikey":api_key})
  48 + if resource_id != None:
  49 + conn.request("GET", "/resources/%s/invitations"%(resource_id), None, {"x-bugswarmapikey":api_key})
  50 + else:
  51 + conn.request("GET", "/invitations", None, {"x-bugswarmapikey":api_key})
52 52 resp = conn.getresponse()
53 53 txt = resp.read()
54 54 conn.close()
@@ -76,7 +76,21 @@ def main():
76 76 resource_id = args[3]
77 77 resource_type = args[4]
78 78 send(server_info["hostname"], keys["configuration"], swarm_id, to, resource_id, resource_type, options.description)
79   - elif sys.argv[1] == "list_sent_invitations":
  79 + elif sys.argv[1] == "respond":
  80 + opt_usage = "usage: \n %s RESOURCE_ID INVITATION_ID STATUS"%(sys.argv[1])
  81 + opt_usage += "\n\n *RESOURCE_ID: The ID of the resource who's invitation is being responded to." \
  82 + +"\n *INVITATION_ID: The ID of the invitation being responded to." \
  83 + +"\n *STATUS: The respose status. Valid types; 'accept', 'reject'."
  84 + parser = OptionParser(usage = opt_usage)
  85 + (options, args) = parser.parse_args()
  86 + if len(args) != 4:
  87 + print "Invalid number of args. See --help for correct usage."
  88 + sys.exit()
  89 + resource_id = args[1]
  90 + invitation_id = args[2]
  91 + status = args[3]
  92 + respond(server_info["hostname"], keys["configuration"], resource_id, invitation_id, status)
  93 + elif sys.argv[1] == "list_sent":
80 94 opt_usage = "usage: \n %s SWARM_ID"%(sys.argv[1])
81 95 opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's associated invitations will be listed."
82 96 parser = OptionParser(usage = opt_usage)
@@ -85,8 +99,8 @@ def main():
85 99 print "Invalid number of args. See --help for correct usage."
86 100 sys.exit()
87 101 swarm_id = args[1]
88   - list_sent_invitations(server_info["hostname"], keys["configuration"], swarm_id)
89   - elif sys.argv[1] == "list_received_invitations":
  102 + list_sent(server_info["hostname"], keys["configuration"], swarm_id)
  103 + elif sys.argv[1] == "list_received":
90 104 opt_usage = "usage: \n %s"%(sys.argv[1])
91 105 parser = OptionParser(usage = opt_usage)
92 106 parser.add_option("-r", "--resource", dest="resource_id", help="Specify a resource who's invitations you want to list.", metavar="RESOURCE_ID")
@@ -94,21 +108,7 @@ def main():
94 108 if len(args) != 1:
95 109 print "Invalid number of args. See --help for correct usage."
96 110 sys.exit()
97   - list_received_invitations(server_info["hostname"], keys["configuration"], options.resource_id)
98   - elif sys.argv[1] == "respond":
99   - opt_usage = "usage: \n %s RESOURCE_ID INVITATION_ID STATUS"%(sys.argv[1])
100   - opt_usage += "\n\n *RESOURCE_ID: The ID of the resource who's invitation is being responded to." \
101   - +"\n *INVITATION_ID: The ID of the invitation being responded to." \
102   - +"\n *STATUS: The respose status. Valid types; 'accept', 'reject'."
103   - parser = OptionParser(usage = opt_usage)
104   - (options, args) = parser.parse_args()
105   - if len(args) != 4:
106   - print "Invalid number of args. See --help for correct usage."
107   - sys.exit()
108   - resource_id = args[1]
109   - invitation_id = args[2]
110   - status = args[3]
111   - respond(server_info["hostname"], keys["configuration"], resource_id, invitation_id, status)
  111 + list_received(server_info["hostname"], keys["configuration"], options.resource_id)
112 112 else:
113 113 usage(sys.argv[0])
114 114 main()
18 user_resources.py → resources.py
@@ -6,7 +6,7 @@
6 6 import json
7 7
8 8 def usage(script_name):
9   - print "%s [create|update|destroy|list|get_resource_info|list_swarms_with_resource] \n"%(script_name)
  9 + print "%s [create|update|destroy|list|get_info|list_swarms] \n"%(script_name)
10 10 print "Use '%s [method] --help for a method's usage and options."%(script_name)
11 11 sys.exit()
12 12
@@ -59,7 +59,7 @@ def destroy(hostname, api_key, resource_id):
59 59 else:
60 60 print "Something went wrong! :("
61 61
62   -def list_user_resources(hostname, api_key):
  62 +def list_resources(hostname, api_key):
63 63 conn = httplib.HTTPConnection(hostname)
64 64 conn.request("GET", "/resources", None, {"x-bugswarmapikey":api_key})
65 65 resp = conn.getresponse()
@@ -67,7 +67,7 @@ def list_user_resources(hostname, api_key):
67 67 conn.close()
68 68 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
69 69
70   -def get_resource_info(hostname, api_key, resource_id):
  70 +def get_info(hostname, api_key, resource_id):
71 71 conn = httplib.HTTPConnection(hostname)
72 72 conn.request("GET", "/resources/%s"%(resource_id), None, {"x-bugswarmapikey":api_key})
73 73 resp = conn.getresponse()
@@ -75,7 +75,7 @@ def get_resource_info(hostname, api_key, resource_id):
75 75 conn.close()
76 76 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
77 77
78   -def list_swarms_with_resource(hostname, api_key, resource_id):
  78 +def list_swarms(hostname, api_key, resource_id):
79 79 conn = httplib.HTTPConnection(hostname)
80 80 conn.request("GET", "/resources/%s/swarms"%(resource_id), None, {"x-bugswarmapikey":api_key})
81 81 resp = conn.getresponse()
@@ -133,8 +133,8 @@ def main():
133 133 if len(args) != 1:
134 134 print "Invalid number of args. See --help for correct usage."
135 135 sys.exit()
136   - list_user_resources(server_info["hostname"], keys["configuration"])
137   - elif sys.argv[1] == "get_resource_info":
  136 + list_resources(server_info["hostname"], keys["configuration"])
  137 + elif sys.argv[1] == "get_info":
138 138 opt_usage = "usage: \n %s RESOURCE_ID"%(sys.argv[1])
139 139 opt_usage += "\n\n *RESOURCE_ID: The ID of the resource who's info is desired."
140 140 parser = OptionParser(usage = opt_usage)
@@ -143,8 +143,8 @@ def main():
143 143 print "Invalid number of args. See --help for correct usage."
144 144 sys.exit()
145 145 resource_id = args[1]
146   - get_resource_info(server_info["hostname"], keys["configuration"], resource_id)
147   - elif sys.argv[1] == "list_swarms_with_resource":
  146 + get_info(server_info["hostname"], keys["configuration"], resource_id)
  147 + elif sys.argv[1] == "list_swarms":
148 148 opt_usage = "usage: \n %s RESOURCE_ID"%(sys.argv[1])
149 149 opt_usage += "\n\n *RESOURCE_ID: The ID of the resource. The swarms that the resource is a member of will be listed."
150 150 parser = OptionParser(usage = opt_usage)
@@ -153,7 +153,7 @@ def main():
153 153 print "Invalid number of args. See --help for correct usage."
154 154 sys.exit()
155 155 resource_id = args[1]
156   - list_swarms_with_resource(server_info["hostname"], keys["configuration"], resource_id)
  156 + list_swarms(server_info["hostname"], keys["configuration"], resource_id)
157 157 else:
158 158 usage(sys.argv[0])
159 159 main()
96 swarm_resources.py
... ... @@ -1,96 +0,0 @@
1   -#!/usr/bin/python
2   -from optparse import OptionParser
3   -from lib import swarmtoolscore
4   -import sys
5   -import httplib
6   -import json
7   -
8   -def usage(script_name):
9   - print "%s [add|remove|list] \n"%(script_name)
10   - print "Use '%s [method] --help for a method's usage and options."%(script_name)
11   - sys.exit()
12   -
13   -def add(hostname, api_key, swarm_id, resource_id, resource_type):
14   - add_resource = {"resource_id": resource_id, "resource_type": resource_type}
15   - add_resource_json = json.dumps(add_resource)
16   - conn = httplib.HTTPConnection(hostname)
17   - conn.request("POST", "/swarms/%s/resources"%(swarm_id), add_resource_json, {"x-bugswarmapikey":api_key})
18   - resp = conn.getresponse()
19   - txt = resp.read()
20   - conn.close()
21   - if txt != "Created":
22   - print json.dumps(json.loads(txt), sort_keys=True, indent=4)
23   - else:
24   - print "Great success! :)"
25   -
26   -def remove(hostname, api_key, swarm_id, resource_id, resource_type):
27   - remove_resource = {"resource_id": resource_id, "resource_type": resource_type}
28   - remove_resource_json = json.dumps(remove_resource)
29   - conn = httplib.HTTPConnection(hostname)
30   - conn.request("DELETE", "/swarms/%s/resources"%(swarm_id), remove_resource_json, {"x-bugswarmapikey":api_key})
31   - resp = conn.getresponse()
32   - txt = resp.read()
33   - conn.close()
34   - if txt != "":
35   - print json.dumps(json.loads(txt), sort_keys=True, indent=4)
36   - else:
37   - print "Great success! :)"
38   -
39   -def list_swarm_resources(hostname, api_key, swarm_id, resource_type):
40   - conn = httplib.HTTPConnection(hostname)
41   - if resource_type != None:
42   - conn.request("GET", "/swarms/%s/resources?type=%s"%(swarm_id, resource_type), None, {"x-bugswarmapikey":api_key})
43   - else:
44   - conn.request("GET", "/swarms/%s/resources"%(swarm_id), None, {"x-bugswarmapikey":api_key})
45   - resp = conn.getresponse()
46   - txt = resp.read()
47   - conn.close()
48   - print json.dumps(json.loads(txt), sort_keys=True, indent=4)
49   -
50   -def main():
51   - server_info = swarmtoolscore.get_server_info()
52   - keys = swarmtoolscore.get_keys()
53   - if len(sys.argv) == 1:
54   - usage(sys.argv[0])
55   - elif sys.argv[1] == "add":
56   - opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
57   - opt_usage += "\n\n *SWARM_ID: The ID of the swarm to add to." \
58   - +"\n *RESOURCE_ID: The ID of the resource to add." \
59   - +"\n *RESOURCE_TYPE: The type of the resource to add. Valid types; 'producer', 'consumer'."
60   - parser = OptionParser(usage = opt_usage)
61   - (options, args) = parser.parse_args()
62   - if len(args) != 4:
63   - print "Invalid number of args. See --help for correct usage."
64   - sys.exit()
65   - swarm_id = args[1]
66   - resource_id = args[2]
67   - resource_type = args[3]
68   - add(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
69   - elif sys.argv[1] == "remove":
70   - opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
71   - opt_usage += "\n\n *SWARM_ID: The ID of the rwarm remove from." \
72   - +"\n *RESOURCE_ID: The ID of the resource to remove." \
73   - +"\n *RESOURCE_TYPE: The type of the resource to remove. Valid types; 'producer', 'consumer'."
74   - parser = OptionParser(usage = opt_usage)
75   - (options, args) = parser.parse_args()
76   - if len(args) != 4:
77   - print "Invalid number of args. See --help for correct usage."
78   - sys.exit()
79   - swarm_id = args[1]
80   - resource_id = args[2]
81   - resource_type = args[3]
82   - remove(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
83   - elif sys.argv[1] == "list":
84   - opt_usage = "usage: \n %s SWARM_ID [options]"%(sys.argv[1])
85   - opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's resources will be listed."
86   - parser = OptionParser(usage = opt_usage)
87   - parser.add_option("-t", "--type", dest="type", help="Limit the list. Valid types; 'producer', 'consumer'.", metavar="TYPE")
88   - (options, args) = parser.parse_args()
89   - if len(args) != 2:
90   - print "Invalid number of args. See --help for correct usage."
91   - sys.exit()
92   - swarm_id = args[1]
93   - list_swarm_resources(server_info["hostname"], keys["configuration"], swarm_id, options.type)
94   - else:
95   - usage(sys.argv[0])
96   -main()
88 swarms.py
@@ -7,7 +7,7 @@
7 7 import ast
8 8
9 9 def usage(script_name):
10   - print "%s [create|update|destroy|list|get_swarm_info] \n"%(script_name)
  10 + print "%s [create|update|destroy|list|get_info|add_resource|remove_resource|list_resources] \n"%(script_name)
11 11 print "Use '%s [method] --help for a method's usage and options."%(script_name)
12 12 sys.exit()
13 13
@@ -64,7 +64,7 @@ def destroy(hostname, api_key, swarm_id):
64 64 print txt
65 65 print "Something went wrong! :("
66 66
67   -def list_user_swarms(hostname, api_key):
  67 +def list_swarms(hostname, api_key):
68 68 conn = httplib.HTTPConnection(hostname)
69 69 conn.request("GET", "/swarms", None, {"x-bugswarmapikey":api_key})
70 70 resp = conn.getresponse()
@@ -72,7 +72,7 @@ def list_user_swarms(hostname, api_key):
72 72 conn.close()
73 73 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
74 74
75   -def get_swarm_info(hostname, api_key, swarm_id):
  75 +def get_info(hostname, api_key, swarm_id):
76 76 conn = httplib.HTTPConnection(hostname)
77 77 conn.request("GET", "/swarms/%s"%(swarm_id), None, {"x-bugswarmapikey":api_key})
78 78 resp = conn.getresponse()
@@ -80,6 +80,43 @@ def get_swarm_info(hostname, api_key, swarm_id):
80 80 conn.close()
81 81 print json.dumps(json.loads(txt), sort_keys=True, indent=4)
82 82
  83 +def add_resource(hostname, api_key, swarm_id, resource_id, resource_type):
  84 + add_resource = {"resource_id": resource_id, "resource_type": resource_type}
  85 + add_resource_json = json.dumps(add_resource)
  86 + conn = httplib.HTTPConnection(hostname)
  87 + conn.request("POST", "/swarms/%s/resources"%(swarm_id), add_resource_json, {"x-bugswarmapikey":api_key})
  88 + resp = conn.getresponse()
  89 + txt = resp.read()
  90 + conn.close()
  91 + if txt != "Created":
  92 + print json.dumps(json.loads(txt), sort_keys=True, indent=4)
  93 + else:
  94 + print "Great success! :)"
  95 +
  96 +def remove_resource(hostname, api_key, swarm_id, resource_id, resource_type):
  97 + remove_resource = {"resource_id": resource_id, "resource_type": resource_type}
  98 + remove_resource_json = json.dumps(remove_resource)
  99 + conn = httplib.HTTPConnection(hostname)
  100 + conn.request("DELETE", "/swarms/%s/resources"%(swarm_id), remove_resource_json, {"x-bugswarmapikey":api_key})
  101 + resp = conn.getresponse()
  102 + txt = resp.read()
  103 + conn.close()
  104 + if txt != "":
  105 + print json.dumps(json.loads(txt), sort_keys=True, indent=4)
  106 + else:
  107 + print "Great success! :)"
  108 +
  109 +def list_resources(hostname, api_key, swarm_id, resource_type):
  110 + conn = httplib.HTTPConnection(hostname)
  111 + if resource_type != None:
  112 + conn.request("GET", "/swarms/%s/resources?type=%s"%(swarm_id, resource_type), None, {"x-bugswarmapikey":api_key})
  113 + else:
  114 + conn.request("GET", "/swarms/%s/resources"%(swarm_id), None, {"x-bugswarmapikey":api_key})
  115 + resp = conn.getresponse()
  116 + txt = resp.read()
  117 + conn.close()
  118 + print json.dumps(json.loads(txt), sort_keys=True, indent=4)
  119 +
83 120 def main():
84 121 server_info = swarmtoolscore.get_server_info()
85 122 keys = swarmtoolscore.get_keys()
@@ -129,8 +166,8 @@ def main():
129 166 if len(args) != 1:
130 167 print "Invalid number of args. See --help for correct usage."
131 168 sys.exit()
132   - list_user_swarms(server_info["hostname"], keys["configuration"])
133   - elif sys.argv[1] == "get_swarm_info":
  169 + list_swarms(server_info["hostname"], keys["configuration"])
  170 + elif sys.argv[1] == "get_info":
134 171 opt_usage = "usage: \n %s SWARM_ID"%(sys.argv[1])
135 172 opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's info is desired."
136 173 parser = OptionParser(usage = opt_usage)
@@ -139,7 +176,46 @@ def main():
139 176 print "Invalid number of args. See --help for correct usage."
140 177 sys.exit()
141 178 swarm_id = args[1]
142   - get_swarm_info(server_info["hostname"], keys["configuration"], swarm_id)
  179 + get_info(server_info["hostname"], keys["configuration"], swarm_id)
  180 + elif sys.argv[1] == "add_resource":
  181 + opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
  182 + opt_usage += "\n\n *SWARM_ID: The ID of the swarm to add to." \
  183 + +"\n *RESOURCE_ID: The ID of the resource to add." \
  184 + +"\n *RESOURCE_TYPE: The type of the resource to add. Valid types; 'producer', 'consumer'."
  185 + parser = OptionParser(usage = opt_usage)
  186 + (options, args) = parser.parse_args()
  187 + if len(args) != 4:
  188 + print "Invalid number of args. See --help for correct usage."
  189 + sys.exit()
  190 + swarm_id = args[1]
  191 + resource_id = args[2]
  192 + resource_type = args[3]
  193 + add_resource(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
  194 + elif sys.argv[1] == "remove_resource":
  195 + opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
  196 + opt_usage += "\n\n *SWARM_ID: The ID of the rwarm remove from." \
  197 + +"\n *RESOURCE_ID: The ID of the resource to remove." \
  198 + +"\n *RESOURCE_TYPE: The type of the resource to remove. Valid types; 'producer', 'consumer'."
  199 + parser = OptionParser(usage = opt_usage)
  200 + (options, args) = parser.parse_args()
  201 + if len(args) != 4:
  202 + print "Invalid number of args. See --help for correct usage."
  203 + sys.exit()
  204 + swarm_id = args[1]
  205 + resource_id = args[2]
  206 + resource_type = args[3]
  207 + remove_resource(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
  208 + elif sys.argv[1] == "list_resources":
  209 + opt_usage = "usage: \n %s SWARM_ID [options]"%(sys.argv[1])
  210 + opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's resources will be listed."
  211 + parser = OptionParser(usage = opt_usage)
  212 + parser.add_option("-t", "--type", dest="type", help="Limit the list. Valid types; 'producer', 'consumer'.", metavar="TYPE")
  213 + (options, args) = parser.parse_args()
  214 + if len(args) != 2:
  215 + print "Invalid number of args. See --help for correct usage."
  216 + sys.exit()
  217 + swarm_id = args[1]
  218 + list_resources(server_info["hostname"], keys["configuration"], swarm_id, options.type)
143 219 else:
144 220 usage(sys.argv[0])
145 221 main()

0 comments on commit 57d1ae2

Please sign in to comment.
Something went wrong with that request. Please try again.