def __init__(self):
     global hostname, keys, swarm_id, resource_id
     hostname = swarmtoolscore.get_server_info()
     keys = swarmtoolscore.get_keys()
     cf.read("config.cfg")  
     resource_id=cf.get("Swarm", "resource_id")
     swarm_id = cf.get("Swarm", "swarm_id")
Beispiel #2
0
def create_Connection():
    global hostname, keys, swarm_id, resource_id, conn, inputFolderLocation, processingFolderLocation, processedFolderLocation 
    print "in create connection"
    print "sys "+sys.argv[1]
    hostname = swarmtoolscore.get_server_info()
    keys = swarmtoolscore.get_keys()
    api_key=keys["participation"]
    cf.read("config.cfg")  
    #resource_id=cf.get("Swarm", "resource_id")
    resource_id = sys.argv[1]
    print resource_id
    cf1=ConfigParser.ConfigParser()
    cf1.read('stock.cfg')
    inputFolderLocation = cf1.get(resource_id, "inputfolder")
    processingFolderLocation = cf1.get(resource_id, "processingfolder")
    processedFolderLocation = cf1.get(resource_id, "processedfolder")
    swarm_id = cf.get("Swarm", "swarm_id")
    conn = httplib.HTTPConnection(hostname["hostname"])
    sel = "/stream?swarm_id=%s&resource_id=%s"%(swarm_id, resource_id)
    conn.putrequest("POST", sel)
    conn.putheader("x-bugswarmapikey", api_key)
    conn.putheader("transfer-encoding", "chunked")
    conn.putheader("connection", "keep-alive")
    conn.endheaders()
    #Sleep required to allow the swarm server time to respond with header
    time.sleep(1)
    #Send a blank http body to open the connection
    conn.send('2\r\n\n\n\r\n')
Beispiel #3
0
 def __init__(self):
     global hostname, keys, swarm_id
     hostname = swarmtoolscore.get_server_info()
     keys = swarmtoolscore.get_keys()
     cf.read("config.cfg")
     #resource_id=cf.get("Swarm", "resource_id")
     swarm_id = cf.get("Swarm", "swarm_id")
Beispiel #4
0
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] == "create":
        opt_usage = "usage: \n  %s PASSWORD [options]"%(sys.argv[1])
        opt_usage += "\n\n  *PASSWORD: Your Bug Labs account password."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-t", "--type", dest="key_type", help="Specify the type of API key you wish to create. Valid types; 'configuration', 'participation' (both keys are created if no type specified).", metavar="KEY_TYPE")
        (options, args) =  parser.parse_args()
        if len(args) != 2:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        password = args[1]
        user_info = swarmtoolscore.get_user_info()
        create(server_info["hostname"], user_info["user_id"], password, options.key_type)
    elif sys.argv[1] == "list":
        opt_usage = "usage: \n  %s PASSWORD [options]"%(sys.argv[1])
        opt_usage += "\n\n  *PASSWORD: Your Bug Labs account password."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-t", "--type", dest="key_type", help="Specify the type of API key. Valid types; 'configuration', 'participation' (configuration is created by default).", metavar="KEY_TYPE")
        (options, args) = parser.parse_args()
        if len(args) != 2:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        password = args[1]
        user_info = swarmtoolscore.get_user_info()
        list(server_info["hostname"], user_info["user_id"], password, options.key_type)
    else:
        usage(sys.argv[0])
Beispiel #5
0
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] == "send":
        opt_usage = "usage: \n  %s SWARM_ID TO RESOURCE_ID RESOURCE_TYPE [options]"%(sys.argv[1])
        opt_usage += "\n\n  *SWARM_ID: The ID of the swarm that is inviting." \
                    +"\n  *TO: The username of the owner of the resource being invited." \
                    +"\n  *RESOURCE_ID: The ID of the resource being invited." \
                    +"\n  *RESOURCE_TYPE: The type that the invited resource would have presence as in the inviting swarm. Valid types; 'producer', 'consumer', 'both'."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-d", "--description", dest="description", help="Set a descriptive message to accompany the invitation.", metavar="DESCRIPTION")
        (options, args) = parser.parse_args()
        if len(args) != 5:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        swarm_id = args[1]
        to = args[2]
        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] == "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)
        (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_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") 
        (options, args) = parser.parse_args()
        if len(args) != 1:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        list_received(server_info["hostname"], keys["configuration"], options.resource_id)
    else:
        usage(sys.argv[0])
 def __init__(self):
     global hostname, keys, swarm_id
     cf.read("config.cfg")  
     swarm_id = cf.get("Swarm", "swarm_id")
     hostname = swarmtoolscore.get_server_info()
     keys = swarmtoolscore.get_keys()
     
     if not keys["configuration"]:
         print "configuration key not present"
         self.getKeys()
         print "got from server"
     if not keys["participation"]:
         print "participation key not present"
         self.getKeys()
         print "got from server"
    def __init__(self):
        global hostname, keys, swarm_id
        cf.read("config.cfg")
        swarm_id = cf.get("Swarm", "swarm_id")
        hostname = swarmtoolscore.get_server_info()
        keys = swarmtoolscore.get_keys()

        if not keys["configuration"]:
            print "configuration key not present"
            self.getKeys()
            print "got from server"
        if not keys["participation"]:
            print "participation key not present"
            self.getKeys()
            print "got from server"
def create_Connection():
    global hostname, keys, swarm_id, resource_id, conn
    print "in create connection"
    hostname = swarmtoolscore.get_server_info()
    keys = swarmtoolscore.get_keys()
    api_key=keys["participation"]
    cf.read("config.cfg")  
    resource_id=cf.get("Swarm", "resource_id")
    swarm_id = cf.get("Swarm", "swarm_id")
    conn = httplib.HTTPConnection(hostname["hostname"])
    sel = "/stream?swarm_id=%s&resource_id=%s"%(swarm_id, resource_id)
    conn.putrequest("POST", sel)
    conn.putheader("x-bugswarmapikey", api_key)
    conn.putheader("transfer-encoding", "chunked")
    conn.putheader("connection", "keep-alive")
    conn.endheaders()
    #Sleep required to allow the swarm server time to respond with header
    time.sleep(1)
    #Send a blank http body to open the connection
    conn.send('2\r\n\n\n\r\n')
Beispiel #9
0
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] == "consume":
        signal.signal(signal.SIGINT, signal_handler)
        opt_usage = "usage: \n  %s SWARM_ID RESOURCE_ID" % (sys.argv[1])
        opt_usage += (
            "\n\n  *SWARM_ID: The ID of the swarm to consume."
            + "\n  *RESOURCE_ID: The ID of the resource to use for consumption."
        )
        parser = OptionParser(usage=opt_usage)
        (options, args) = parser.parse_args()
        if len(args) != 3:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        swarm_id = args[1]
        resource_id = args[2]
        consume(server_info["hostname"], keys["participation"], swarm_id, resource_id)
    else:
        usage(sys.argv[0])
Beispiel #10
0
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] == "produce":
        signal.signal(signal.SIGINT, signal_handler)
        opt_usage = "usage: \n  ./produce.py %s SWARM_ID RESOURCE_ID [options]"%(sys.argv[1])
        opt_usage += "\n\n  *SWARM_ID: The ID of the swarm to produce to." \
                    +"\n  *RESOURCE_ID: The ID of the resource to produce with." \
                    +"\n\n  NOTE: Data may also be produced by piping into the function (DATA | ./produce.py produce SWARM_ID RESOURCE_ID [options])."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-r", action="store_true", dest="raw", help="Require that messages be sent in the raw formatting as specified in the 'Sending Messages' section at http://developer.bugswarm.net/participation_api.html.", default=False)
        (options, args) = parser.parse_args()
        if len(args) != 3:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        swarm_id = args[1]
        resource_id = args[2]
        produce(server_info["hostname"], keys['participation'], swarm_id, resource_id, options.raw)
    else:
        usage(sys.argv[0])
Beispiel #11
0
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] == "create":
        opt_usage = "usage: \n  %s NAME MACHINE_TYPE [options]"%(sys.argv[1])
        opt_usage += "\n\n  *NAME: The name of the resource to create." \
                    +"\n  *MACHINE_TYPE: The machine type of the resource to create. Valid types; 'pc', 'smartphone', 'bug'."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-d", "--description", dest="description", help="Set the resource's description", metavar="DESCRIPTION")
        parser.add_option("-p", "--position", dest="position", help="Set the resource's position. Must be a tuple of floats surounded by quotations.", metavar="\"(LATITUDE, LONGITUDE)\"")
        (options, args) = parser.parse_args()
        if len(args) != 3:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        name = args[1]
        machine_type = args[2]
        create(server_info["hostname"], keys["configuration"], name, machine_type, options.description, options.position)
    elif sys.argv[1] == "update":
        opt_usage = "usage: \n  %s RESOURCE_ID [options]"%(sys.argv[1])
        opt_usage += "\n\n  *RESOURCE_ID: The ID of the resource to update."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-n", "--name", dest="name", help="Set the resource's name", metavar="NAME")
        parser.add_option("-t", "--type", dest="machine_type", help="Set the resource's machine type. Valid types; 'pc', 'smartphone', 'bug'.", metavar="MACHINE_TYPE")
        parser.add_option("-d", "--description", dest="description", help="Set the resource's description", metavar="DESCRIPTION")
        parser.add_option("-p", "--position", dest="position", help="Set the resource's position. Must be a tuple of floats surrounded by quotations.", metavar="\"(LATITUDE, LONGITUDE)\"")
        (options, args) = parser.parse_args()
        if len(args) != 2:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        resource_id = args[1]
        update(server_info["hostname"], keys["configuration"], resource_id, options.name, options.machine_type, options.description, options.position)
    elif sys.argv[1] == "destroy":
        opt_usage = "usage: \n  %s RESOURCE_ID"%(sys.argv[1])
        opt_usage += "\n\n  *RESOURCE_ID: The ID of the resource to destroy."
        parser = OptionParser(usage = opt_usage)
        (options, args) = parser.parse_args()
        if len(args) != 2:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        resource_id = args[1]
        destroy(server_info["hostname"], keys["configuration"], resource_id)
    elif sys.argv[1] == "list":
        opt_usage = "usage: \n  %s"%(sys.argv[1])
        parser = OptionParser(usage = opt_usage)
        (options, args) = parser.parse_args()
        if len(args) != 1:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        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)
        (options, args) = parser.parse_args()
        if len(args) != 2:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        resource_id = args[1]
        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)
        (options, args) = parser.parse_args()
        if len(args) != 2:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        resource_id = args[1]
        list_swarms(server_info["hostname"], keys["configuration"], resource_id)
    else:
        usage(sys.argv[0])
Beispiel #12
0
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] == "create":
        opt_usage = "usage: \n  %s NAME DESCRIPTION [options]"%(sys.argv[1])
        opt_usage += "\n\n  *NAME: The name of the swarm being created." \
                    +"\n  *DESCRIPTION: The description of the swarm being created."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-p", "--public", dest="public", help="Set whether the swarm is public or not. Valid types; 'true', 'false'.", metavar="PUBLIC")
        parser.add_option("-r", "--resources", dest="resources", help="Input resources you wish to add to the swarm by default. Format the resources as a dictionary of \"resource_id\":\"resource_type\" key:value pairs. If you wish for a resource to be added as both a consumer and a producer, set the \"resource_type\" to \"both\". Example: '{\"c35b44419f7b2717f25c6022d04af72a492cd892\":\"consumer\",\"b09df0ea0323073b05a1ddd9b2d44c769d8fa7c2\":\"both\"}'", metavar="RESOURCES")
        (options, args) = parser.parse_args()
        if len(args) != 3:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        name = args[1]
        description = args[2]
        create(server_info["hostname"], keys["configuration"], name, description, options.public, options.resources)     
    elif sys.argv[1] == "update":
        opt_usage = "usage: \n  %s SWARM_ID [options]"%(sys.argv[1])
        opt_usage += "\n\n  *SWARM_ID: The ID of the swarm being updated."
        parser = OptionParser(usage = opt_usage)
        parser.add_option("-n", "--name", dest="name", help="Set the swarm's name", metavar="NAME")
        parser.add_option("-d", "--description", dest="description", help="Set the swarm's description", metavar="DESCRIPTION")
        parser.add_option("-p", "--public", dest="public", help="Set whether the swarm is public or not. Valid types; 'true', 'false'.", metavar="PUBLIC")
        (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]
        update(server_info["hostname"], keys["configuration"], swarm_id, options.name, options.description, options.public)
    elif sys.argv[1] == "destroy":
        opt_usage = "usage: \n  %s SWARM_ID"%(sys.argv[1])
        opt_usage += "\n\n  *SWARM_ID: The ID of the swarm to destroy."
        parser = OptionParser(usage = opt_usage)
        (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]
        destroy(server_info["hostname"], keys["configuration"], swarm_id)
    elif sys.argv[1] == "list":
        opt_usage = "usage: \n  %s"%(sys.argv[1])
        parser = OptionParser(usage = opt_usage)
        (options, args) = parser.parse_args()
        if len(args) != 1:
            print "Invalid number of args. See --help for correct usage."
            sys.exit()
        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)
        (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]
        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])