Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates to reflect changes made to documentation

  • Loading branch information...
commit 57d1ae2f406e59b45d5de65bfe7bde257fb7da08 1 parent 2ca33f9
Davis Barber barberdt authored
66 invitations.py
View
@@ -6,7 +6,7 @@
import json
def usage(script_name):
- print "%s [send|list_sent_invitations|list_received_invitations|respond] \n"%(script_name)
+ print "%s [send|respond|list_sent|list_received] \n"%(script_name)
print "Use '%s [method] --help for a method's usage and options."%(script_name)
sys.exit()
@@ -22,33 +22,33 @@ def send(hostname, api_key, swarm_id, to, resource_id, resource_type, descriptio
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-def list_sent_invitations(hostname, api_key, swarm_id):
+def respond(hostname, api_key, resource_id, invitation_id, status):
conn = httplib.HTTPConnection(hostname)
- conn.request("GET", "/swarms/%s/invitations"%(swarm_id), None, {"x-bugswarmapikey":api_key})
+ if status != "accept" and status != "reject":
+ print "Invalid status. Must be 'accept' or 'reject'."
+ sys.exit()
+ response = {"status": status}
+ response_json = json.dumps(response)
+ conn.request("PUT", "/resources/%s/invitations/%s"%(resource_id, invitation_id), response_json, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
txt = resp.read()
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-def list_received_invitations(hostname, api_key, resource_id):
+def list_sent(hostname, api_key, swarm_id):
conn = httplib.HTTPConnection(hostname)
- if resource_id != None:
- conn.request("GET", "/resources/%s/invitations"%(resource_id), None, {"x-bugswarmapikey":api_key})
- else:
- conn.request("GET", "/invitations", None, {"x-bugswarmapikey":api_key})
+ conn.request("GET", "/swarms/%s/invitations"%(swarm_id), None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
txt = resp.read()
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-def respond(hostname, api_key, resource_id, invitation_id, status):
+def list_received(hostname, api_key, resource_id):
conn = httplib.HTTPConnection(hostname)
- if status != "accept" and status != "reject":
- print "Invalid status. Must be 'accept' or 'reject'."
- sys.exit()
- response = {"status": status}
- response_json = json.dumps(response)
- conn.request("PUT", "/resources/%s/invitations/%s"%(resource_id, invitation_id), response_json, {"x-bugswarmapikey":api_key})
+ if resource_id != None:
+ conn.request("GET", "/resources/%s/invitations"%(resource_id), None, {"x-bugswarmapikey":api_key})
+ else:
+ conn.request("GET", "/invitations", None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
txt = resp.read()
conn.close()
@@ -76,7 +76,21 @@ def main():
resource_id = args[3]
resource_type = args[4]
send(server_info["hostname"], keys["configuration"], swarm_id, to, resource_id, resource_type, options.description)
- elif sys.argv[1] == "list_sent_invitations":
+ elif sys.argv[1] == "respond":
+ opt_usage = "usage: \n %s RESOURCE_ID INVITATION_ID STATUS"%(sys.argv[1])
+ opt_usage += "\n\n *RESOURCE_ID: The ID of the resource who's invitation is being responded to." \
+ +"\n *INVITATION_ID: The ID of the invitation being responded to." \
+ +"\n *STATUS: The respose status. Valid types; 'accept', 'reject'."
+ parser = OptionParser(usage = opt_usage)
+ (options, args) = parser.parse_args()
+ if len(args) != 4:
+ print "Invalid number of args. See --help for correct usage."
+ sys.exit()
+ resource_id = args[1]
+ invitation_id = args[2]
+ status = args[3]
+ respond(server_info["hostname"], keys["configuration"], resource_id, invitation_id, status)
+ elif sys.argv[1] == "list_sent":
opt_usage = "usage: \n %s SWARM_ID"%(sys.argv[1])
opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's associated invitations will be listed."
parser = OptionParser(usage = opt_usage)
@@ -85,8 +99,8 @@ def main():
print "Invalid number of args. See --help for correct usage."
sys.exit()
swarm_id = args[1]
- list_sent_invitations(server_info["hostname"], keys["configuration"], swarm_id)
- elif sys.argv[1] == "list_received_invitations":
+ list_sent(server_info["hostname"], keys["configuration"], swarm_id)
+ elif sys.argv[1] == "list_received":
opt_usage = "usage: \n %s"%(sys.argv[1])
parser = OptionParser(usage = opt_usage)
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():
if len(args) != 1:
print "Invalid number of args. See --help for correct usage."
sys.exit()
- list_received_invitations(server_info["hostname"], keys["configuration"], options.resource_id)
- elif sys.argv[1] == "respond":
- opt_usage = "usage: \n %s RESOURCE_ID INVITATION_ID STATUS"%(sys.argv[1])
- opt_usage += "\n\n *RESOURCE_ID: The ID of the resource who's invitation is being responded to." \
- +"\n *INVITATION_ID: The ID of the invitation being responded to." \
- +"\n *STATUS: The respose status. Valid types; 'accept', 'reject'."
- parser = OptionParser(usage = opt_usage)
- (options, args) = parser.parse_args()
- if len(args) != 4:
- print "Invalid number of args. See --help for correct usage."
- sys.exit()
- resource_id = args[1]
- invitation_id = args[2]
- status = args[3]
- respond(server_info["hostname"], keys["configuration"], resource_id, invitation_id, status)
+ list_received(server_info["hostname"], keys["configuration"], options.resource_id)
else:
usage(sys.argv[0])
main()
18 user_resources.py → resources.py
View
@@ -6,7 +6,7 @@
import json
def usage(script_name):
- print "%s [create|update|destroy|list|get_resource_info|list_swarms_with_resource] \n"%(script_name)
+ print "%s [create|update|destroy|list|get_info|list_swarms] \n"%(script_name)
print "Use '%s [method] --help for a method's usage and options."%(script_name)
sys.exit()
@@ -59,7 +59,7 @@ def destroy(hostname, api_key, resource_id):
else:
print "Something went wrong! :("
-def list_user_resources(hostname, api_key):
+def list_resources(hostname, api_key):
conn = httplib.HTTPConnection(hostname)
conn.request("GET", "/resources", None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
@@ -67,7 +67,7 @@ def list_user_resources(hostname, api_key):
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-def get_resource_info(hostname, api_key, resource_id):
+def get_info(hostname, api_key, resource_id):
conn = httplib.HTTPConnection(hostname)
conn.request("GET", "/resources/%s"%(resource_id), None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
@@ -75,7 +75,7 @@ def get_resource_info(hostname, api_key, resource_id):
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-def list_swarms_with_resource(hostname, api_key, resource_id):
+def list_swarms(hostname, api_key, resource_id):
conn = httplib.HTTPConnection(hostname)
conn.request("GET", "/resources/%s/swarms"%(resource_id), None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
@@ -133,8 +133,8 @@ def main():
if len(args) != 1:
print "Invalid number of args. See --help for correct usage."
sys.exit()
- list_user_resources(server_info["hostname"], keys["configuration"])
- elif sys.argv[1] == "get_resource_info":
+ list_resources(server_info["hostname"], keys["configuration"])
+ elif sys.argv[1] == "get_info":
opt_usage = "usage: \n %s RESOURCE_ID"%(sys.argv[1])
opt_usage += "\n\n *RESOURCE_ID: The ID of the resource who's info is desired."
parser = OptionParser(usage = opt_usage)
@@ -143,8 +143,8 @@ def main():
print "Invalid number of args. See --help for correct usage."
sys.exit()
resource_id = args[1]
- get_resource_info(server_info["hostname"], keys["configuration"], resource_id)
- elif sys.argv[1] == "list_swarms_with_resource":
+ get_info(server_info["hostname"], keys["configuration"], resource_id)
+ elif sys.argv[1] == "list_swarms":
opt_usage = "usage: \n %s RESOURCE_ID"%(sys.argv[1])
opt_usage += "\n\n *RESOURCE_ID: The ID of the resource. The swarms that the resource is a member of will be listed."
parser = OptionParser(usage = opt_usage)
@@ -153,7 +153,7 @@ def main():
print "Invalid number of args. See --help for correct usage."
sys.exit()
resource_id = args[1]
- list_swarms_with_resource(server_info["hostname"], keys["configuration"], resource_id)
+ list_swarms(server_info["hostname"], keys["configuration"], resource_id)
else:
usage(sys.argv[0])
main()
96 swarm_resources.py
View
@@ -1,96 +0,0 @@
-#!/usr/bin/python
-from optparse import OptionParser
-from lib import swarmtoolscore
-import sys
-import httplib
-import json
-
-def usage(script_name):
- print "%s [add|remove|list] \n"%(script_name)
- print "Use '%s [method] --help for a method's usage and options."%(script_name)
- sys.exit()
-
-def add(hostname, api_key, swarm_id, resource_id, resource_type):
- add_resource = {"resource_id": resource_id, "resource_type": resource_type}
- add_resource_json = json.dumps(add_resource)
- conn = httplib.HTTPConnection(hostname)
- conn.request("POST", "/swarms/%s/resources"%(swarm_id), add_resource_json, {"x-bugswarmapikey":api_key})
- resp = conn.getresponse()
- txt = resp.read()
- conn.close()
- if txt != "Created":
- print json.dumps(json.loads(txt), sort_keys=True, indent=4)
- else:
- print "Great success! :)"
-
-def remove(hostname, api_key, swarm_id, resource_id, resource_type):
- remove_resource = {"resource_id": resource_id, "resource_type": resource_type}
- remove_resource_json = json.dumps(remove_resource)
- conn = httplib.HTTPConnection(hostname)
- conn.request("DELETE", "/swarms/%s/resources"%(swarm_id), remove_resource_json, {"x-bugswarmapikey":api_key})
- resp = conn.getresponse()
- txt = resp.read()
- conn.close()
- if txt != "":
- print json.dumps(json.loads(txt), sort_keys=True, indent=4)
- else:
- print "Great success! :)"
-
-def list_swarm_resources(hostname, api_key, swarm_id, resource_type):
- conn = httplib.HTTPConnection(hostname)
- if resource_type != None:
- conn.request("GET", "/swarms/%s/resources?type=%s"%(swarm_id, resource_type), None, {"x-bugswarmapikey":api_key})
- else:
- conn.request("GET", "/swarms/%s/resources"%(swarm_id), None, {"x-bugswarmapikey":api_key})
- resp = conn.getresponse()
- txt = resp.read()
- conn.close()
- print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-
-def main():
- server_info = swarmtoolscore.get_server_info()
- keys = swarmtoolscore.get_keys()
- if len(sys.argv) == 1:
- usage(sys.argv[0])
- elif sys.argv[1] == "add":
- opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
- opt_usage += "\n\n *SWARM_ID: The ID of the swarm to add to." \
- +"\n *RESOURCE_ID: The ID of the resource to add." \
- +"\n *RESOURCE_TYPE: The type of the resource to add. Valid types; 'producer', 'consumer'."
- parser = OptionParser(usage = opt_usage)
- (options, args) = parser.parse_args()
- if len(args) != 4:
- print "Invalid number of args. See --help for correct usage."
- sys.exit()
- swarm_id = args[1]
- resource_id = args[2]
- resource_type = args[3]
- add(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
- elif sys.argv[1] == "remove":
- opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
- opt_usage += "\n\n *SWARM_ID: The ID of the rwarm remove from." \
- +"\n *RESOURCE_ID: The ID of the resource to remove." \
- +"\n *RESOURCE_TYPE: The type of the resource to remove. Valid types; 'producer', 'consumer'."
- parser = OptionParser(usage = opt_usage)
- (options, args) = parser.parse_args()
- if len(args) != 4:
- print "Invalid number of args. See --help for correct usage."
- sys.exit()
- swarm_id = args[1]
- resource_id = args[2]
- resource_type = args[3]
- remove(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
- elif sys.argv[1] == "list":
- opt_usage = "usage: \n %s SWARM_ID [options]"%(sys.argv[1])
- opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's resources will be listed."
- parser = OptionParser(usage = opt_usage)
- parser.add_option("-t", "--type", dest="type", help="Limit the list. Valid types; 'producer', 'consumer'.", metavar="TYPE")
- (options, args) = parser.parse_args()
- if len(args) != 2:
- print "Invalid number of args. See --help for correct usage."
- sys.exit()
- swarm_id = args[1]
- list_swarm_resources(server_info["hostname"], keys["configuration"], swarm_id, options.type)
- else:
- usage(sys.argv[0])
-main()
88 swarms.py
View
@@ -7,7 +7,7 @@
import ast
def usage(script_name):
- print "%s [create|update|destroy|list|get_swarm_info] \n"%(script_name)
+ print "%s [create|update|destroy|list|get_info|add_resource|remove_resource|list_resources] \n"%(script_name)
print "Use '%s [method] --help for a method's usage and options."%(script_name)
sys.exit()
@@ -64,7 +64,7 @@ def destroy(hostname, api_key, swarm_id):
print txt
print "Something went wrong! :("
-def list_user_swarms(hostname, api_key):
+def list_swarms(hostname, api_key):
conn = httplib.HTTPConnection(hostname)
conn.request("GET", "/swarms", None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
@@ -72,7 +72,7 @@ def list_user_swarms(hostname, api_key):
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
-def get_swarm_info(hostname, api_key, swarm_id):
+def get_info(hostname, api_key, swarm_id):
conn = httplib.HTTPConnection(hostname)
conn.request("GET", "/swarms/%s"%(swarm_id), None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
@@ -80,6 +80,43 @@ def get_swarm_info(hostname, api_key, swarm_id):
conn.close()
print json.dumps(json.loads(txt), sort_keys=True, indent=4)
+def add_resource(hostname, api_key, swarm_id, resource_id, resource_type):
+ add_resource = {"resource_id": resource_id, "resource_type": resource_type}
+ add_resource_json = json.dumps(add_resource)
+ conn = httplib.HTTPConnection(hostname)
+ conn.request("POST", "/swarms/%s/resources"%(swarm_id), add_resource_json, {"x-bugswarmapikey":api_key})
+ resp = conn.getresponse()
+ txt = resp.read()
+ conn.close()
+ if txt != "Created":
+ print json.dumps(json.loads(txt), sort_keys=True, indent=4)
+ else:
+ print "Great success! :)"
+
+def remove_resource(hostname, api_key, swarm_id, resource_id, resource_type):
+ remove_resource = {"resource_id": resource_id, "resource_type": resource_type}
+ remove_resource_json = json.dumps(remove_resource)
+ conn = httplib.HTTPConnection(hostname)
+ conn.request("DELETE", "/swarms/%s/resources"%(swarm_id), remove_resource_json, {"x-bugswarmapikey":api_key})
+ resp = conn.getresponse()
+ txt = resp.read()
+ conn.close()
+ if txt != "":
+ print json.dumps(json.loads(txt), sort_keys=True, indent=4)
+ else:
+ print "Great success! :)"
+
+def list_resources(hostname, api_key, swarm_id, resource_type):
+ conn = httplib.HTTPConnection(hostname)
+ if resource_type != None:
+ conn.request("GET", "/swarms/%s/resources?type=%s"%(swarm_id, resource_type), None, {"x-bugswarmapikey":api_key})
+ else:
+ conn.request("GET", "/swarms/%s/resources"%(swarm_id), None, {"x-bugswarmapikey":api_key})
+ resp = conn.getresponse()
+ txt = resp.read()
+ conn.close()
+ print json.dumps(json.loads(txt), sort_keys=True, indent=4)
+
def main():
server_info = swarmtoolscore.get_server_info()
keys = swarmtoolscore.get_keys()
@@ -129,8 +166,8 @@ def main():
if len(args) != 1:
print "Invalid number of args. See --help for correct usage."
sys.exit()
- list_user_swarms(server_info["hostname"], keys["configuration"])
- elif sys.argv[1] == "get_swarm_info":
+ list_swarms(server_info["hostname"], keys["configuration"])
+ elif sys.argv[1] == "get_info":
opt_usage = "usage: \n %s SWARM_ID"%(sys.argv[1])
opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's info is desired."
parser = OptionParser(usage = opt_usage)
@@ -139,7 +176,46 @@ def main():
print "Invalid number of args. See --help for correct usage."
sys.exit()
swarm_id = args[1]
- get_swarm_info(server_info["hostname"], keys["configuration"], swarm_id)
+ get_info(server_info["hostname"], keys["configuration"], swarm_id)
+ elif sys.argv[1] == "add_resource":
+ opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
+ opt_usage += "\n\n *SWARM_ID: The ID of the swarm to add to." \
+ +"\n *RESOURCE_ID: The ID of the resource to add." \
+ +"\n *RESOURCE_TYPE: The type of the resource to add. Valid types; 'producer', 'consumer'."
+ parser = OptionParser(usage = opt_usage)
+ (options, args) = parser.parse_args()
+ if len(args) != 4:
+ print "Invalid number of args. See --help for correct usage."
+ sys.exit()
+ swarm_id = args[1]
+ resource_id = args[2]
+ resource_type = args[3]
+ add_resource(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
+ elif sys.argv[1] == "remove_resource":
+ opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID RESOURCE_TYPE"%(sys.argv[1])
+ opt_usage += "\n\n *SWARM_ID: The ID of the rwarm remove from." \
+ +"\n *RESOURCE_ID: The ID of the resource to remove." \
+ +"\n *RESOURCE_TYPE: The type of the resource to remove. Valid types; 'producer', 'consumer'."
+ parser = OptionParser(usage = opt_usage)
+ (options, args) = parser.parse_args()
+ if len(args) != 4:
+ print "Invalid number of args. See --help for correct usage."
+ sys.exit()
+ swarm_id = args[1]
+ resource_id = args[2]
+ resource_type = args[3]
+ remove_resource(server_info["hostname"], keys["configuration"], swarm_id, resource_id, resource_type)
+ elif sys.argv[1] == "list_resources":
+ opt_usage = "usage: \n %s SWARM_ID [options]"%(sys.argv[1])
+ opt_usage += "\n\n *SWARM_ID: The ID of the swarm who's resources will be listed."
+ parser = OptionParser(usage = opt_usage)
+ parser.add_option("-t", "--type", dest="type", help="Limit the list. Valid types; 'producer', 'consumer'.", metavar="TYPE")
+ (options, args) = parser.parse_args()
+ if len(args) != 2:
+ print "Invalid number of args. See --help for correct usage."
+ sys.exit()
+ swarm_id = args[1]
+ list_resources(server_info["hostname"], keys["configuration"], swarm_id, options.type)
else:
usage(sys.argv[0])
main()
Please sign in to comment.
Something went wrong with that request. Please try again.