def _remove_add_servers_from_queryenv(self): cnf = ScalarizrCnf(bus.etc_path) cnf.bootstrap() globals()['ini'] = cnf.rawini key_path = os.path.join(bus.etc_path, ini.get('general', 'crypto_key_path')) server_id = ini.get('general', 'server_id') url = ini.get('general','queryenv_url') queryenv = QueryEnvService(url, server_id, key_path) result = queryenv.list_roles() running_servers = [] bnds = [] for elem in self.api.list_listeners(): bnds.append(elem['backend']) bnds = list(set(bnds)) for bnd in bnds: for srv in self.api.list_servers(backend=bnd): self.api.remove_server(ipaddr=srv, backend=bnd) for d in result: behaviour=', '.join(d.behaviour) for host in d.hosts: try: if 'role:%s' % d.farm_role_id in bnds: self.api.add_server(ipaddr=host.internal_ip, backend='role:%s' % d.farm_role_id) except: LOG.warn('HAProxyHandler.on_before_host_up.Failed add_server `%s` in' ' backend=`role:%s`, details: %s' % ( host.internal_ip.replace('.', '-'), d.farm_role_id, sys.exc_info()[1])) running_servers.append([d.farm_role_id, host.internal_ip]) LOG.debug('running_servers: `%s`', running_servers)
def setUp(self): bus.etc_path = os.path.join(RESOURCE_PATH, 'etc') cnf = ScalarizrCnf(bus.etc_path) cnf.load_ini('ip_list_builder') bus.cnf = cnf bus.queryenv_service = _QueryEnv() bus.define_events("before_host_up", "init") self.ip_lb = ip_list_builder.IpListBuilder()
def setUp(self): bus.etc_path = os.path.join(RESOURCE_PATH, 'etc') cnf = ScalarizrCnf(bus.etc_path) cnf.load_ini('www') bus.cnf = cnf self._cnf = bus.cnf bus.base_path = os.path.realpath(RESOURCE_PATH + "/../../..") bus.share_path = os.path.join(bus.base_path, 'share') bus.queryenv_service = _EmptyQueryEnv() bus.define_events("before_host_down", "init")
def setUp(self): bus.etc_path = os.path.join(RESOURCE_PATH, 'etc') cnf = ScalarizrCnf(bus.etc_path) cnf.load_ini('app') bus.cnf = cnf self._cnf = bus.cnf bus.base_path = os.path.realpath(RESOURCE_PATH + "/../../..") bus.share_path = os.path.join(bus.base_path, 'share') bus.queryenv_service = qe bus.define_events("before_host_down", "init") '''
def _init(): optparser = bus.optparser bus.base_path = os.path.realpath(os.path.dirname(__file__) + "/../..") #dynimp.setup() _init_logging() logger = logging.getLogger(__name__) # Initialize configuration if not bus.etc_path: etc_places = [ "/etc/scalr", "/etc/scalarizr", "/usr/etc/scalarizr", "/usr/local/etc/scalarizr", os.path.join(bus.base_path, 'etc') ] if optparser and optparser.values.etc_path: # Insert command-line passed etc_path into begining etc_places.insert(0, optparser.values.etc_path) bus.etc_path = firstmatched(lambda p: os.access(p, os.F_OK), etc_places) if not bus.etc_path: raise ScalarizrError( 'Cannot find scalarizr configuration dir. Search path: %s' % ':'.join(etc_places)) cnf = ScalarizrCnf(bus.etc_path) if not os.path.exists(cnf.private_path()): os.makedirs(cnf.private_path()) bus.cnf = cnf # Find shared resources dir if not bus.share_path: share_places = [ '/usr/share/scalr', '/usr/local/share/scalr', os.path.join(bus.base_path, 'share') ] bus.share_path = firstmatched(lambda p: os.access(p, os.F_OK), share_places) if not bus.share_path: raise ScalarizrError( 'Cannot find scalarizr share dir. Search path: %s' % ':'.join(share_places)) # Registering in init.d initdv2.explore("scalarizr", ScalarizrInitScript)
def _init(): optparser = bus.optparser bus.base_path = os.path.realpath(os.path.dirname(__file__) + "/../..") #dynimp.setup() _init_logging() logger = logging.getLogger(__name__) # Initialize configuration if not bus.etc_path: etc_places = [ "/etc/scalr", "/etc/scalarizr", "/usr/etc/scalarizr", "/usr/local/etc/scalarizr", os.path.join(bus.base_path, 'etc') ] if optparser and optparser.values.etc_path: # Insert command-line passed etc_path into begining etc_places.insert(0, optparser.values.etc_path) bus.etc_path = firstmatched(lambda p: os.access(p, os.F_OK), etc_places) if not bus.etc_path: raise ScalarizrError('Cannot find scalarizr configuration dir. Search path: %s' % ':'.join(etc_places)) cnf = ScalarizrCnf(bus.etc_path) if not os.path.exists(cnf.private_path()): os.makedirs(cnf.private_path()) bus.cnf = cnf # Find shared resources dir if not bus.share_path: share_places = [ '/usr/share/scalr', '/usr/local/share/scalr', os.path.join(bus.base_path, 'share') ] bus.share_path = firstmatched(lambda p: os.access(p, os.F_OK), share_places) if not bus.share_path: raise ScalarizrError('Cannot find scalarizr share dir. Search path: %s' % ':'.join(share_places)) # Registering in init.d initdv2.explore("scalarizr", ScalarizrInitScript)
def _init(): optparser = bus.optparser bus.base_path = os.path.realpath(os.path.dirname(__file__) + "/../..") _init_logging() logger = logging.getLogger(__name__) # Initialize configuration if not bus.etc_path: bus.etc_path = __node__['etc_dir'] cnf = ScalarizrCnf(bus.etc_path) if not os.path.exists(cnf.private_path()): os.makedirs(cnf.private_path()) bus.cnf = cnf # Find shared resources dir if not bus.share_path: bus.share_path = __node__['share_dir'] # Registering in init.d initdv2.explore("scalarizr", ScalarizrInitScript)
def _setup_environment(self): platform = __node__['platform'] cnf = ScalarizrCnf(etc_dir) cert, pk = platform.get_cert_pk() access_key, secret_key = platform.get_access_keys() cert_path = cnf.write_key('ec2-cert.pem', cert) pk_path = cnf.write_key('ec2-pk.pem', pk) cloud_cert_path = cnf.write_key('ec2-cloud-cert.pem', platform.get_ec2_cert()) self.environ.update({ 'EC2_CERT': cert_path, 'EC2_PRIVATE_KEY': pk_path, 'EC2_USER_ID': platform.get_account_id(), 'AWS_ACCESS_KEY': access_key, 'AWS_SECRET_KEY': secret_key}) self.credentials = { 'cert': cert_path, 'key': pk_path, 'user': self.environ['EC2_USER_ID'], 'access_key': access_key, 'secret_key': secret_key}
def _remove_add_servers_from_queryenv(self): cnf = ScalarizrCnf(bus.etc_path) cnf.bootstrap() globals()['ini'] = cnf.rawini key_path = os.path.join(bus.etc_path, ini.get('general', 'crypto_key_path')) server_id = ini.get('general', 'server_id') url = ini.get('general', 'queryenv_url') queryenv = QueryEnvService(url, server_id, key_path) result = queryenv.list_roles() running_servers = [] bnds = [] for elem in self.api.list_listeners(): bnds.append(elem['backend']) bnds = list(set(bnds)) for bnd in bnds: for srv in self.api.list_servers(backend=bnd): self.api.remove_server(ipaddr=srv, backend=bnd) for d in result: behaviour = ', '.join(d.behaviour) for host in d.hosts: try: if 'role:%s' % d.farm_role_id in bnds: self.api.add_server(ipaddr=host.internal_ip, backend='role:%s' % d.farm_role_id) except: LOG.warn( 'HAProxyHandler.on_before_host_up.Failed add_server `%s` in' ' backend=`role:%s`, details: %s' % (host.internal_ip.replace( '.', '-'), d.farm_role_id, sys.exc_info()[1])) running_servers.append([d.farm_role_id, host.internal_ip]) LOG.debug('running_servers: `%s`', running_servers)
def _init(): global _meta _meta = metadata.Metadata() optparser = bus.optparser bus.base_path = os.path.realpath(os.path.dirname(__file__) + "/../..") _init_logging() logger = logging.getLogger(__name__) # Initialize configuration if not bus.etc_path: bus.etc_path = __node__['etc_dir'] cnf = ScalarizrCnf(bus.etc_path) if not os.path.exists(cnf.private_path()): os.makedirs(cnf.private_path()) bus.cnf = cnf # Find shared resources dir if not bus.share_path: bus.share_path = __node__['share_dir'] # Registering in init.d initdv2.explore("scalarizr", ScalarizrInitScript)
def init_cnf(): cnf = ScalarizrCnf(bus.etc_path) cnf.bootstrap() globals()['ini'] = cnf.rawini
def finalize(self, operation, name): cnf = ScalarizrCnf(__node__['etc_dir']) for key_name in ('ec2-cert.pem', 'ec2-pk.pem', 'ec2-cloud-cert.pem'): path = cnf.key_path(key_name) linux.system('chmod 755 %s' % path, shell=True) linux.system('rm -f %s' % path, shell=True)
def finalize(self, operation, name): cnf = ScalarizrCnf(etc_dir) for key_name in ('ec2-cert.pem', 'ec2-pk.pem', 'ec2-cloud-cert.pem'): path = cnf.key_path(key_name) linux.system('chmod 755 %s' % path, shell=True) linux.system('rm -f %s' % path, shell=True)