(self)
Initialize configuration file, move SSH pubkey into place.
Initialize configuration file, move SSH pubkey into place.
Initialize configuration file move SSH pubkey into place .
def walmgr_init_slave(self):
        """
        Initialize configuration file, move SSH pubkey into place.
        """
        self.guess_locations()

        self.override_cf_option('slave_bin', self.postgres_bin)
        self.override_cf_option('slave_data', self.pgdata)
        self.override_cf_option('slave_config_dir', os.path.dirname(self.postgres_conf))

        if self.initd_script:
            self.override_cf_option('slave_start_cmd', "%s start" % self.initd_script)
            self.override_cf_option('slave_stop_cmd', "%s stop" % self.initd_script)

        slave_config = """[walmgr]
job_name             = %(job_name)s
logfile              = %(logfile)s
use_skylog           = %(use_skylog)s

slave_data           = %(slave_data)s
slave_bin            = %(slave_bin)s
slave_stop_cmd       = %(slave_stop_cmd)s
slave_start_cmd      = %(slave_start_cmd)s
slave_config_dir     = %(slave_config_dir)s

walmgr_data          = %(walmgr_data)s
completed_wals       = %(completed_wals)s
partial_wals         = %(partial_wals)s
full_backup          = %(full_backup)s
config_backup        = %(config_backup)s
"""

        if self.options.primary_conninfo:
            self.override_cf_option('primary_conninfo', self.options.primary_conninfo)
            slave_config += """
primary_conninfo     = %(primary_conninfo)s
"""

        try:
            opt_dict = dict([(k, self.cf.get(k)) for k in self.cf.options()])
            slave_config = slave_config % opt_dict
        except KeyError, e:
            die(1, 'Required setting missing: %s' % e)

        self.write_walmgr_config(slave_config)

        if self.options.ssh_add_key:
            # add the named public key to authorized hosts
            ssh_dir = os.path.expanduser("~/.ssh")
            auth_file = os.path.join(ssh_dir, "authorized_keys")

            if not os.path.isdir(ssh_dir):
                self.log.info("Creating directory: %s", ssh_dir)
                if not self.not_really:
                    os.mkdir(ssh_dir)

            self.log.debug("Reading public key from %s", self.options.ssh_add_key)
            master_pubkey = open(self.options.ssh_add_key).read()

            key_present = False
            if os.path.isfile(auth_file):
                for key in open(auth_file):
                    if key == master_pubkey:
                        self.log.info("Key already present in %s, skipping", auth_file)
                        key_present = True

            if not key_present:
                self.log.info("Adding %s to %s", self.options.ssh_add_key, auth_file)
                if not self.not_really:
                    af = open(auth_file, "a")
                    af.write(master_pubkey)
                    af.close()

        if self.options.add_password and self.options.primary_conninfo:
            # add password to pgpass

            self.log.debug("Reading password from file %s", self.options.add_password)
            pwd = open(self.options.add_password).readline().rstrip('\n\r')

            pg = Pgpass('~/.pgpass')
            host, port, user, _ = self.parse_conninfo(self.options.primary_conninfo)
            pg.ensure_user(host, port, user, pwd)
            pg.write()

            self.log.info("Added password from %s to .pgpass", self.options.add_password)
def walmgr_init_slave ( self ) : self . guess_locations ( ) self . override_cf_option ( 'slave_bin' , self . postgres_bin ) self . override_cf_option ( 'slave_data' , self . pgdata ) self . override_cf_option ( 'slave_config_dir' , os . path . dirname ( self . postgres_conf ) ) if self . initd_script : self . override_cf_option ( 'slave_start_cmd' , "%s start" % self . initd_script ) self . override_cf_option ( 'slave_stop_cmd' , "%s stop" % self . initd_script ) slave_config = """[walmgr]
job_name             = %(job_name)s
logfile              = %(logfile)s
use_skylog           = %(use_skylog)s

slave_data           = %(slave_data)s
slave_bin            = %(slave_bin)s
slave_stop_cmd       = %(slave_stop_cmd)s
slave_start_cmd      = %(slave_start_cmd)s
slave_config_dir     = %(slave_config_dir)s

walmgr_data          = %(walmgr_data)s
completed_wals       = %(completed_wals)s
partial_wals         = %(partial_wals)s
full_backup          = %(full_backup)s
config_backup        = %(config_backup)s
""" if self . options . primary_conninfo : self . override_cf_option ( 'primary_conninfo' , self . options . primary_conninfo ) slave_config += """
primary_conninfo     = %(primary_conninfo)s
""" try : opt_dict = dict ( [ ( k , self . cf . get ( k ) ) for k in self . cf . options ( ) ] ) slave_config = slave_config % opt_dict except KeyError , e : die ( 1 , 'Required setting missing: %s' % e ) self . write_walmgr_config ( slave_config ) if self . options . ssh_add_key : # add the named public key to authorized hosts ssh_dir = os . path . expanduser ( "~/.ssh" ) auth_file = os . path . join ( ssh_dir , "authorized_keys" ) if not os . path . isdir ( ssh_dir ) : self . log . info ( "Creating directory: %s" , ssh_dir ) if not self . not_really : os . mkdir ( ssh_dir ) self . log . debug ( "Reading public key from %s" , self . options . ssh_add_key ) master_pubkey = open ( self . options . ssh_add_key ) . read ( ) key_present = False if os . path . isfile ( auth_file ) : for key in open ( auth_file ) : if key == master_pubkey : self . log . info ( "Key already present in %s, skipping" , auth_file ) key_present = True if not key_present : self . log . info ( "Adding %s to %s" , self . options . ssh_add_key , auth_file ) if not self . not_really : af = open ( auth_file , "a" ) af . write ( master_pubkey ) af . close ( ) if self . options . add_password and self . options . primary_conninfo : # add password to pgpass self . log . debug ( "Reading password from file %s" , self . options . add_password ) pwd = open ( self . options . add_password ) . readline ( ) . rstrip ( '\n\r' ) pg = Pgpass ( '~/.pgpass' ) host , port , user , _ = self . parse_conninfo ( self . options . primary_conninfo ) pg . ensure_user ( host , port , user , pwd ) pg . write ( ) self . log . info ( "Added password from %s to .pgpass" , self . options . add_password )