mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Remove usage of AWS.py from Patroni
Functionality provided by that module will be achieved via callbacks. - fix a typo in aws.py - fix some mixups of old code and new callbacks in postgresql.py
This commit is contained in:
+1
-1
@@ -76,7 +76,7 @@ if __name__ == '__main__':
|
||||
return 1
|
||||
action, role, name = sys.argv[1:]
|
||||
if action in ('on_start', 'on_stop', 'on_role_change'):
|
||||
aws = gAWSConnection({'cluster_name': name})
|
||||
aws = AWSConnection({'cluster_name': name})
|
||||
aws.on_role_change(role)
|
||||
return 0
|
||||
return 2
|
||||
|
||||
+3
-10
@@ -35,7 +35,7 @@ def parseurl(url):
|
||||
|
||||
class Postgresql:
|
||||
|
||||
def __init__(self, config, on_change_callback=None):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.name = config['name']
|
||||
self.listen_addresses, self.port = config['listen'].split(':')
|
||||
@@ -66,7 +66,6 @@ class Postgresql:
|
||||
self._connection = None
|
||||
self._cursor_holder = None
|
||||
self.members = [] # list of already existing replication slots
|
||||
self.on_change_callback = on_change_callback
|
||||
|
||||
def get_local_address(self):
|
||||
listen_addresses = self.listen_addresses.split(',')
|
||||
@@ -265,8 +264,6 @@ class Postgresql:
|
||||
self.save_configuration_files()
|
||||
if ret and 'on_start' in self.callback:
|
||||
self.call_nowait('on_start')
|
||||
if self.on_change_callback:
|
||||
self.on_change_callback('replica' if os.path.exists(self.recovery_conf) else 'master')
|
||||
return ret
|
||||
|
||||
def stop(self):
|
||||
@@ -372,10 +369,8 @@ primary_conninfo = '{}'
|
||||
if not self.check_recovery_conf(leader):
|
||||
self.write_recovery_conf(leader)
|
||||
self.restart()
|
||||
if self.on_change_callback['on_role_change']:
|
||||
if 'on_role_change' in self.callback:
|
||||
self.call_nowait('on_role_change')
|
||||
if self.on_change_callback:
|
||||
self.on_change_callback('replica')
|
||||
|
||||
def save_configuration_files(self):
|
||||
"""
|
||||
@@ -395,10 +390,8 @@ primary_conninfo = '{}'
|
||||
|
||||
def promote(self):
|
||||
self.is_promoted = subprocess.call(self._pg_ctl + ['promote']) == 0
|
||||
if self.is_promoted and self.on_change_callback['on_role_change']:
|
||||
if self.is_promoted and 'on_role_change' in self.callback:
|
||||
self.call_nowait('on_role_change')
|
||||
if self.on_change_callback:
|
||||
self.on_change_callback('master')
|
||||
return self.is_promoted
|
||||
|
||||
def demote(self, leader):
|
||||
|
||||
@@ -6,7 +6,6 @@ import time
|
||||
import yaml
|
||||
|
||||
from helpers.api import RestApiServer
|
||||
from helpers.aws import AWSConnection
|
||||
from helpers.etcd import Etcd
|
||||
from helpers.ha import Ha
|
||||
from helpers.postgresql import Postgresql
|
||||
@@ -18,7 +17,6 @@ class Patroni:
|
||||
|
||||
def __init__(self, config):
|
||||
self.nap_time = config['loop_wait']
|
||||
self.aws = AWSConnection(config)
|
||||
self.postgresql = Postgresql(config['postgresql'])
|
||||
self.ha = Ha(self.postgresql, self.get_dcs(self.postgresql.name, config))
|
||||
host, port = config['restapi']['listen'].split(':')
|
||||
|
||||
Reference in New Issue
Block a user