mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Format code according to pep8
This commit is contained in:
+18
-13
@@ -1,11 +1,16 @@
|
||||
import urllib2, json, os, time
|
||||
import urllib2
|
||||
import json
|
||||
import time
|
||||
import logging
|
||||
|
||||
from helpers.errors import CurrentLeaderError
|
||||
from urllib import urlencode
|
||||
import helpers.errors
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Etcd:
|
||||
|
||||
def __init__(self, config):
|
||||
self.scope = config["scope"]
|
||||
self.host = config["host"]
|
||||
@@ -49,7 +54,7 @@ class Etcd:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404:
|
||||
return None
|
||||
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
|
||||
raise CurrentLeaderError("Etcd is not responding properly")
|
||||
|
||||
def members(self):
|
||||
try:
|
||||
@@ -63,17 +68,17 @@ class Etcd:
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404:
|
||||
return None
|
||||
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
|
||||
raise CurrentLeaderError("Etcd is not responding properly")
|
||||
|
||||
def touch_member(self, member, connection_string):
|
||||
self.put_client_path("/members/%s" % member, {"value": connection_string})
|
||||
|
||||
def take_leader(self, value):
|
||||
return self.put_client_path("/leader", {"value": value, "ttl": self.ttl}) == None
|
||||
return self.put_client_path("/leader", {"value": value, "ttl": self.ttl}) is None
|
||||
|
||||
def attempt_to_acquire_leader(self, value):
|
||||
try:
|
||||
return self.put_client_path("/leader", {"value": value, "ttl": self.ttl, "prevExist": False}) == None
|
||||
return self.put_client_path("/leader", {"value": value, "ttl": self.ttl, "prevExist": False}) is None
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 412:
|
||||
logger.info("Could not take out TTL lock: %s" % e)
|
||||
@@ -98,15 +103,15 @@ class Etcd:
|
||||
return False
|
||||
|
||||
def am_i_leader(self, value):
|
||||
#try:
|
||||
reponse = self.get_client_path("/leader")
|
||||
logger.info("Lock owner: %s; I am %s" % (reponse["node"]["value"], value))
|
||||
return reponse["node"]["value"] == value
|
||||
#except Exception as e:
|
||||
#return False
|
||||
# try:
|
||||
reponse = self.get_client_path("/leader")
|
||||
logger.info("Lock owner: %s; I am %s" % (reponse["node"]["value"], value))
|
||||
return reponse["node"]["value"] == value
|
||||
# except Exception as e:
|
||||
# return False
|
||||
|
||||
def race(self, path, value):
|
||||
try:
|
||||
return self.put_client_path(path, {"prevExist": False, "value": value}) == None
|
||||
return self.put_client_path(path, {"prevExist": False, "value": value}) is None
|
||||
except urllib2.HTTPError:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user