def init(user_id, password, hostname): config = ConfigParser.ConfigParser() config.add_section("Server Information") config.add_section("User Information") config.add_section("Keys") with open("swarm.cfg", "wb") as configfile: config.write(configfile) swarmtoolscore.set_server_info(hostname) swarmtoolscore.set_user_info(user_id) swarmtoolscore.set_keys(hostname, user_id, password)
def create(hostname, user_id, password, key_type): conn = httplib.HTTPConnection(hostname) auth_hash = user_id + ":" + password auth_header = "Basic " + base64.b64encode(auth_hash) if (key_type != None): conn.request("POST", "/keys/" + key_type, None, {"Authorization":auth_header}) else: conn.request("POST", "/keys", None, {"Authorization":auth_header}) resp = conn.getresponse() txt = resp.read() conn.close() print json.dumps(json.loads(txt), sort_keys=True, indent=4) swarmtoolscore.set_keys(hostname, user_id, password)