Пример #1
0
 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ("/usr/sbin/service", "mongodb")
     else:
         initd_script = firstmatched(os.path.exists, ("/etc/init.d/mongodb", "/etc/init.d/mongod"))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME, initd_script=initd_script)
Пример #2
0
 def __init__(self):
     if linux.os.ubuntu and linux.os['version'] >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
Пример #3
0
def _cleanup_after_rebundle():
    cnf = bus.cnf
    pl = bus.platform
    logger = logging.getLogger(__name__)

    if 'volumes' not in pl.features:
        # Destory mysql storages
        if os.path.exists(cnf.private_path(
                'storage/mysql.json')) and pl.name == 'rackspace':
            logger.info('Cleanuping old MySQL storage')
            mysql_bhv = firstmatched(lambda x: x in node.__node__['behavior'],
                                     ('mysql', 'mysql2', 'percona'))
            vol = node.__node__[mysql_bhv]['volume']
            vol.destroy(force=True)

    if os.path.exists('/etc/chef/client.pem'):
        os.remove('/etc/chef/client.pem')
    if os.path.exists('/etc/chef/client.rb'):
        os.remove('/etc/chef/client.rb')

    # Reset private configuration
    priv_path = cnf.private_path()
    for file in os.listdir(priv_path):
        if file in ('.user-data', '.update'):
            continue
        path = os.path.join(priv_path, file)
        coreutils.chmod_r(path, 0700)
        os.remove(path) if (os.path.isfile(path)
                            or os.path.islink(path)) else shutil.rmtree(path)
    if not linux.os.windows_family:
        system2('sync', shell=True)
Пример #4
0
def _cleanup_after_rebundle():
    cnf = bus.cnf
    pl = bus.platform
    logger = logging.getLogger(__name__)
    
    if 'volumes' not in pl.features:
        # Destory mysql storages
        if os.path.exists(cnf.private_path('storage/mysql.json')) and pl.name == 'rackspace':
            logger.info('Cleanuping old MySQL storage')
            mysql_bhv = firstmatched(lambda x: x in node.__node__['behavior'], ('mysql', 'mysql2', 'percona'))
            vol = node.__node__[mysql_bhv]['volume']
            vol.destroy(force=True)

    if os.path.exists('/etc/chef/client.pem'):
        os.remove('/etc/chef/client.pem')
    if os.path.exists('/etc/chef/client.rb'):
        os.remove('/etc/chef/client.rb')
    
    # Reset private configuration
    priv_path = cnf.private_path()
    for file in os.listdir(priv_path):
        if file in ('.user-data', '.update'):
            continue
        path = os.path.join(priv_path, file)
        coreutils.chmod_r(path, 0700)
        os.remove(path) if (os.path.isfile(path) or os.path.islink(path)) else shutil.rmtree(path)
    if not linux.os.windows_family:
        system2('sync', shell=True)
Пример #5
0
    def __init__(self):
        if 'gce' == node.__node__['platform']:
            self.ensure_pid_directory()

        self.mysql_cli = MySQLClient()


        if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            initd_script = ('/usr/sbin/service', 'mysql')
        else:
            initd_script = firstmatched(os.path.exists, ('/etc/init.d/mysqld', '/etc/init.d/mysql'))

        pid_file = None
        try:
            out = system2("my_print_defaults mysqld", shell=True, silent=True)
            m = re.search("--pid[-_]file=(.*)", out[0], re.MULTILINE)
            if m:
                pid_file = m.group(1)
            m = re.search("--socket=(.*)", out[0], re.MULTILINE)
            if m:
                self.socket_file = m.group(1)
        except:
            pass

        initdv2.ParametrizedInitScript.__init__(self, SERVICE_NAME,
                        initd_script, pid_file, socks=[initdv2.SockParam(MYSQL_DEFAULT_PORT, timeout=3600)])
Пример #6
0
 def lv_info(self, lvolume=None, group=None, name=None):
     lvolume = lvolume if lvolume else lvpath(group, name)
     info = firstmatched(lambda inf: inf.lv_path == lvolume,
                         self.lv_status())
     if info:
         return info
     raise LookupError('Logical volume %s not found' % lvolume)
Пример #7
0
            def get_free_devname(device):
                if device:
                    device = ebstool.get_ebs_devname(device)

                used_letters = set(row['device'][-1]
                                        for row in Storage.volume_table()
                                        if row['device'] and ( \
                                                row['state'] == 'attached' or ( \
                                                pl.get_instance_type() == 't1.micro' and row['state'] == 'detached')))

                with self.letters_lock:

                    avail_letters = list(set(self.all_letters) - used_letters - self.acquired_letters)

                    volumes = conn.get_all_volumes(filters={'attachment.instance-id': pl.get_instance_id()})

                    for volume in volumes:
                        volume_device = volume.attach_data.device
                        volume_device = re.sub('\d+', '', volume_device)
                        try:
                            avail_letters.remove(volume_device[-1])
                        except ValueError:
                            pass

                    if not device or not (device[-1] in avail_letters) or os.path.exists(device):
                        letter = firstmatched(
                                lambda l: not os.path.exists(ebstool.real_devname('/dev/sd%s' % l)), avail_letters
                        )
                        if letter:
                            device = '/dev/sd%s' % letter
                            self.acquired_letters.add(letter)
                        else:
                            raise StorageError('No free letters for block device name remains')

                return device
Пример #8
0
    def __init__(self):
        if 'gce' == node.__node__['platform'].name:
            self.ensure_pid_directory()

        self.mysql_cli = MySQLClient()

        if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            initd_script = ('/usr/sbin/service', 'mysql')
        else:
            initd_script = firstmatched(
                os.path.exists, ('/etc/init.d/mysqld', '/etc/init.d/mysql'))

        pid_file = None
        try:
            out = system2("my_print_defaults mysqld", shell=True, silent=True)
            m = re.search("--pid[-_]file=(.*)", out[0], re.MULTILINE)
            if m:
                pid_file = m.group(1)
            m = re.search("--socket=(.*)", out[0], re.MULTILINE)
            if m:
                self.socket_file = m.group(1)
        except:
            pass

        initdv2.ParametrizedInitScript.__init__(
            self,
            SERVICE_NAME,
            initd_script,
            pid_file,
            socks=[initdv2.SockParam(MYSQL_DEFAULT_PORT, timeout=3600)])
Пример #9
0
 def __init__(self):
     initd_script = None
     if linux.os.ubuntu and linux.os['version'] >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
Пример #10
0
 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
Пример #11
0
    def test_1(self):
        v1 = Storage.create(device='/dev/sdo')
        v2 = Storage.create(device='/dev/sdm')
        table = Storage.volume_table()
        self.assertEqual(len(table), 2)
        v1row = firstmatched(lambda row: row['device'] == '/dev/sdo', table)
        self.assertTrue(v1row)
        self.assertEqual(v1row['volume_id'], v1.id)
        self.assertEqual(v1row['device'], v1.device)
        self.assertEqual(v1row['type'], v1.type)
        self.assertEqual(v1row['state'], 'attached')

        v2.detach()
        table = Storage.volume_table()
        self.assertEqual(len(table), 2)
        v2row = firstmatched(lambda row: row['device'] == '/dev/sdm', table)
        self.assertEqual(v2row['state'], 'detached')
Пример #12
0
 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
Пример #13
0
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)
Пример #14
0
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)
Пример #15
0
 def __init__(self):
     initd_script = firstmatched(
         os.path.exists, ('/etc/init.d/mongodb', '/etc/init.d/mongod'))
     if linux.os.ubuntu and linux.os['release'] >= (10, 4):
         initd_script = ('/usr/sbin/service',
                         os.path.basename(initd_script))
     initdv2.ParametrizedInitScript.__init__(self,
                                             name=SERVICE_NAME,
                                             initd_script=initd_script)
Пример #16
0
 def block_devs_mapping(self):
     keys = self._get_property("block-device-mapping").split("\n")
     ret = list()
     for key in keys:
         try:
             ret.append((key, self._get_property("block-device-mapping/" + key)))
         except PlatformError, e:
             if key == 'ephemeral0' and str(e).find('HTTP Error 500') >= 0:
                 ret.append((key, firstmatched(lambda x: os.path.exists(x), ('/dev/sda2', '/dev/sdb'))))
             else:
                 raise
Пример #17
0
    def _change_master(self, host, user, password, log_file, log_pos, timeout=None):

        LOG.info("Changing replication Master to server %s (log_file: %s, log_pos: %s)",
                        host, log_file, log_pos)

        timeout = timeout or int(__mysql__['change_master_timeout'])

        # Changing replication master
        self.root_client.stop_slave()
        self.root_client.change_master_to(host, user, password, log_file, log_pos)

        # Starting slave
        result = self.root_client.start_slave()
        LOG.debug('Start slave returned: %s' % result)
        if result and 'ERROR' in result:
            raise HandlerError('Cannot start mysql slave: %s' % result)

        time_until = time.time() + timeout
        status = None
        while time.time() <= time_until:
            status = self.root_client.slave_status()
            if status['Slave_IO_Running'] == 'Yes' and \
                    status['Slave_SQL_Running'] == 'Yes':
                break
            time.sleep(5)
        else:
            if status:
                if not status['Last_Error']:
                    logfile = firstmatched(lambda p: os.path.exists(p),
                                                            ('/var/log/mysqld.log', '/var/log/mysql.log'))
                    if logfile:
                        gotcha = '[ERROR] Slave I/O thread: '
                        size = os.path.getsize(logfile)
                        fp = open(logfile, 'r')
                        try:
                            fp.seek(max((0, size - 8192)))
                            lines = fp.read().split('\n')
                            for line in lines:
                                if gotcha in line:
                                    status['Last_Error'] = line.split(gotcha)[-1]
                        finally:
                            fp.close()

                msg = "Cannot change replication Master server to '%s'. "  \
                                "Slave_IO_Running: %s, Slave_SQL_Running: %s, " \
                                "Last_Errno: %s, Last_Error: '%s'" % (
                                host, status['Slave_IO_Running'], status['Slave_SQL_Running'],
                                status['Last_Errno'], status['Last_Error'])
                raise HandlerError(msg)
            else:
                raise HandlerError('Cannot change replication master to %s' % (host))


        LOG.debug('Replication master is changed to host %s', host)
Пример #18
0
 def get_block_device_mapping(self):
     keys = self._get_property("block-device-mapping").split("\n")
     ret = {}
     for key in keys:
         try:
             ret[key] = self._get_property('block-device-mapping/' + key)
         except PlatformError, e:
             # Workaround
             if key == 'ephemeral0' and str(e).find('HTTP Error 500') >= 0:
                 ret[key] = firstmatched(lambda x: os.path.exists(x), ('/dev/sda2', '/dev/sdb'))
             else:
                 raise
Пример #19
0
    def test_pv_add_remove_vg(self):
        self.vg0 = self.lvm.create_vg('test', [self.ph_device])
        pvi = self.lvm.pv_info(self.ph_device)
        self.assertEqual(pvi.vg, 'test')

        pvi = firstmatched(lambda pvi: 'test' in pvi.vg, self.lvm.pv_status())
        self.assertEqual(pvi.pv, self.ph_device)

        self.lvm.remove_vg(self.vg0)
        self.vg0 = None
        pvi = self.lvm.pv_info(self.ph_device)
        self.assertEqual(pvi.vg, '')
Пример #20
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        if linux.os.redhat_family:
            init_script = ('/sbin/service', 'sshd')
        elif linux.os.ubuntu and linux.os['version'] >= (10, 4):
            init_script = ('/usr/sbin/service', 'ssh')
        else:
            init_script = firstmatched(os.path.exists, ('/etc/init.d/ssh', '/etc/init.d/sshd'))
        self._sshd_init = ParametrizedInitScript('sshd', init_script)

        bus.on(init=self.on_init)
Пример #21
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        if linux.os.redhat_family:
            init_script = ('/sbin/service', 'sshd')
        elif linux.os.ubuntu and linux.os['version'] >= (10, 4):
            init_script = ('/usr/sbin/service', 'ssh')
        else:
            init_script = firstmatched(os.path.exists, ('/etc/init.d/ssh', '/etc/init.d/sshd'))
        self._sshd_init = ParametrizedInitScript('sshd', init_script)

        bus.on(init=self.on_init)
Пример #22
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        if disttool.is_redhat_based():
            init_script = ('/sbin/service', 'sshd')
        elif disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            init_script = ('/usr/sbin/service', 'ssh')
        else:
            init_script = firstmatched(os.path.exists, ('/etc/init.d/ssh', '/etc/init.d/sshd'))
        self._sshd_init = ParametrizedInitScript('sshd', init_script)

        bus.on(init=self.on_init)
Пример #23
0
 def get_block_device_mapping(self):
     keys = self._get_property("block-device-mapping").split("\n")
     ret = {}
     for key in keys:
         try:
             ret[key] = self._get_property('block-device-mapping/' + key)
         except PlatformError, e:
             # Workaround
             if key == 'ephemeral0' and str(e).find('HTTP Error 500') >= 0:
                 ret[key] = firstmatched(lambda x: os.path.exists(x),
                                         ('/dev/sda2', '/dev/sdb'))
             else:
                 raise
Пример #24
0
 def __init__(self):
     initd_script = None
     # if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
     if linux.os.debian_family:
         initd_script = ('/usr/sbin/service', 'postgresql')
     else:
         initd_script = firstmatched(os.path.exists, (
                     '/etc/init.d/postgresql-9.0', 
                     '/etc/init.d/postgresql-9.1',
                     '/etc/init.d/postgresql-9.2',
                     '/etc/init.d/postgresql'))
     assert initd_script is not None
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME, 
             initd_script=initd_script)
Пример #25
0
 def block_devs_mapping(self):
     keys = self._get_property("block-device-mapping").split("\n")
     ret = list()
     for key in keys:
         try:
             ret.append(
                 (key, self._get_property("block-device-mapping/" + key)))
         except PlatformError, e:
             if key == 'ephemeral0' and str(e).find('HTTP Error 500') >= 0:
                 ret.append((key,
                             firstmatched(lambda x: os.path.exists(x),
                                          ('/dev/sda2', '/dev/sdb'))))
             else:
                 raise
Пример #26
0
 def __init__(self):
     initd_script = None
     # if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
     if linux.os.debian_family:
         initd_script = ('/usr/sbin/service', 'postgresql')
     else:
         initd_script = firstmatched(
             os.path.exists,
             ('/etc/init.d/postgresql-9.0', '/etc/init.d/postgresql-9.1',
              '/etc/init.d/postgresql-9.2', '/etc/init.d/postgresql'))
     assert initd_script is not None
     initdv2.ParametrizedInitScript.__init__(self,
                                             name=SERVICE_NAME,
                                             initd_script=initd_script)
Пример #27
0
 def __init__(self):
     initd_script = None
     if linux.os.debian_family:
         initd_script = ('/usr/sbin/service', 'postgresql')
     elif linux.os.redhat_family and linux.os["release"].version[0] == 7:
         initd_script = ('/sbin/service', 'postgresql-9.3')
     else:
         initd_script = firstmatched(
             os.path.exists,
             ('/etc/init.d/postgresql-9.0', '/etc/init.d/postgresql-9.1',
              '/etc/init.d/postgresql-9.2', '/etc/init.d/postgresql-9.3',
              '/etc/init.d/postgresql'))
     assert initd_script is not None
     initdv2.ParametrizedInitScript.__init__(self,
                                             name=SERVICE_NAME,
                                             initd_script=initd_script)
Пример #28
0
    def _destroy_layout(self, vg, data_lv):
        # Find PV
        pv = None
        pvi = firstmatched(lambda pvi: vg in pvi.vg, self._lvm.pv_status())
        if pvi:
            pv = pvi.pv

        # Remove storage VG
        self._lvm.change_lv(data_lv, available=False)
        self._lvm.remove_vg(vg)

        if pv:
            # Remove PV if it doesn't belongs to any other VG
            pvi = self._lvm.pv_info(pv)
            if not pvi.vg:
                self._lvm.remove_pv(pv)
Пример #29
0
    def _destroy_layout(self, vg, data_lv):
        # Find PV
        pv = None
        pvi = firstmatched(lambda pvi: vg in pvi.vg, self._lvm.pv_status())
        if pvi:
            pv = pvi.pv

        # Remove storage VG
        self._lvm.change_lv(data_lv, available=False)
        self._lvm.remove_vg(vg)

        if pv:
            # Remove PV if it doesn't belongs to any other VG
            pvi = self._lvm.pv_info(pv)
            if not pvi.vg:
                self._lvm.remove_pv(pv)
Пример #30
0
	def _result(self, e=None):
		try:
			msg = self.runnable.create_command_result(self)
			msg.status = all([n.req_ok for n in self.context.nodes]) and self.RESP_OK or self.RESP_ERROR

			if e:
				msg.last_error = str(e)
			else:
				self._logger.debug(str(self.context.results))
				failed_row = firstmatched(lambda row: row.has_key('last_error') and row['last_error'], self.context.results.values())
				if failed_row:
					msg.last_error = failed_row['last_error']
			msg.rows = self.context.results
			self.send_message(msg)
		finally:
			self.context = None
Пример #31
0
    def _result(self, e=None):
        try:
            msg = self.runnable.create_command_result(self)
            msg.status = all([n.req_ok for n in self.context.nodes]) and self.RESP_OK or self.RESP_ERROR

            if e:
                msg.last_error = str(e)
            else:
                self._logger.debug(str(self.context.results))
                failed_row = firstmatched(lambda row: row.has_key('last_error') and row['last_error'], self.context.results.values())
                if failed_row:
                    msg.last_error = failed_row['last_error']
            msg.rows = self.context.results
            self.send_message(msg)
        finally:
            self.context = None
Пример #32
0
	def _handle_response(self, resp_message):
		current_node_respond = resp_message.from_host == self.context.current_node.host
		ndata = firstmatched(lambda n: n.host == resp_message.from_host, self.context.nodes)
		if not ndata:
			self._logger.error('Received response %s from unknown node %s', 
					resp_message.name, getattr(resp_message, 'from_host', '*unknown*'))
			return
		
		if current_node_respond:
			self._stop_node_timer(ndata)

		self.context.results[ndata.index] = resp_message.body
		ndata.req_ok = resp_message.status == self.RESP_OK
		if self.RESP_ERROR == resp_message.status:
			self.context.queue.put(ndata.index)
			
		self._request_next_node()
Пример #33
0
    def _handle_response(self, resp_message):
        current_node_respond = resp_message.from_host == self.context.current_node.host
        ndata = firstmatched(lambda n: n.host == resp_message.from_host, self.context.nodes)
        if not ndata:
            self._logger.error('Received response %s from unknown node %s',
                            resp_message.name, getattr(resp_message, 'from_host', '*unknown*'))
            return

        if current_node_respond:
            self._stop_node_timer(ndata)

        self.context.results[ndata.index] = resp_message.body
        ndata.req_ok = resp_message.status == self.RESP_OK
        if self.RESP_ERROR == resp_message.status:
            self.context.queue.put(ndata.index)

        self._request_next_node()
Пример #34
0
            def get_free_devname(device):
                if device:
                    device = ebstool.get_ebs_devname(device)

                used_letters = set(row['device'][-1]
                                        for row in Storage.volume_table()
                                        if row['device'] and ( \
                                                row['state'] == 'attached' or ( \
                                                pl.get_instance_type() == 't1.micro' and row['state'] == 'detached')))

                with self.letters_lock:

                    avail_letters = list(
                        set(self.all_letters) - used_letters -
                        self.acquired_letters)

                    volumes = conn.get_all_volumes(
                        filters={
                            'attachment.instance-id': pl.get_instance_id()
                        })

                    for volume in volumes:
                        volume_device = volume.attach_data.device
                        volume_device = re.sub('\d+', '', volume_device)
                        try:
                            avail_letters.remove(volume_device[-1])
                        except ValueError:
                            pass

                    if not device or not (device[-1] in avail_letters
                                          ) or os.path.exists(device):
                        letter = firstmatched(
                            lambda l: not os.path.exists(
                                ebstool.real_devname('/dev/sd%s' % l)),
                            avail_letters)
                        if letter:
                            device = '/dev/sd%s' % letter
                            self.acquired_letters.add(letter)
                        else:
                            raise StorageError(
                                'No free letters for block device name remains'
                            )

                return device
Пример #35
0
    def __init__(self):
        Platform.__init__(self)

        # Find the virtual router.
        eth0leases = util.firstmatched(lambda x: os.path.exists(x),
                                                                ['/var/lib/dhcp/dhclient.eth0.leases',
                                                                '/var/lib/dhcp3/dhclient.eth0.leases',
                                                                '/var/lib/dhclient/dhclient-eth0.leases'],
                                                                '/var/lib/dhclient/dhclient-eth0.leases')
        if not os.path.exists(eth0leases):
            raise PlatformError("Can't find virtual router. file %s not exists" % eth0leases)

        router = None
        for line in open(eth0leases):
            if 'dhcp-server-identifier' in line:
                router = filter(None, line.split(';')[0].split(' '))[2]
        LOG.debug('Meta-data server: %s', router)
        self._router = router

        self._metadata = {}
Пример #36
0
	def __init__(self):
		Platform.__init__(self)
		
		# Find the virtual router.
		eth0leases = util.firstmatched(lambda x: os.path.exists(x), 
									['/var/lib/dhcp/dhclient.eth0.leases',
									'/var/lib/dhcp3/dhclient.eth0.leases',
									'/var/lib/dhclient/dhclient-eth0.leases'],
									'/var/lib/dhclient/dhclient-eth0.leases') 
		if not os.path.exists(eth0leases):
			raise PlatformError("Can't find virtual router. file %s not exists" % eth0leases)
		
		router = None
		for line in open(eth0leases):
			if 'dhcp-server-identifier' in line:
				router = filter(None, line.split(';')[0].split(' '))[2]
		LOG.debug('Meta-data server: %s', router)
		self._router = router
	
		self._metadata = {}
Пример #37
0
 def vg_info(self, group):
     group = os.path.basename(group)
     info = firstmatched(lambda inf: inf.vg == group, self.vg_status())
     if info:
         return info
     raise LookupError('Volume group %s not found' % group)
Пример #38
0
 def _defer_init(self):
     if not __apache__["ssl_conf_path"]:  # SCALARIZR-2220
         __apache__["ssl_conf_path"] = firstmatched(
             os.path.exists,
             ("/etc/apache2/sites-available/default-ssl",
              "/etc/apache2/sites-available/default-ssl.conf"))
Пример #39
0
 def _get_free_md_devname(self):
     return '/dev/md%s' % firstmatched(lambda x: not os.path.exists('/dev/md%s' % x), range(100))
Пример #40
0
 def default(self):
     return firstmatched(lambda p: os.access(p, os.F_OK | os.X_OK),
                         ('/usr/sbin/nginx', '/usr/local/nginx/sbin/nginx'), '')
Пример #41
0
 def pv_info(self, ph_volume):
     info = firstmatched(lambda inf: inf.pv == ph_volume, self.pv_status())
     if info:
         return info
     raise LookupError('Physical volume %s not found' % ph_volume)
Пример #42
0
 def lv_info(self, lvolume=None, group=None, name=None):
     lvolume = lvolume if lvolume else lvpath(group, name)
     info = firstmatched(lambda inf: inf.lv_path == lvolume, self.lv_status())
     if info:
         return info
     raise LookupError('Logical volume %s not found' % lvolume)
Пример #43
0
 def vg_info(self, group):
     group = os.path.basename(group)
     info = firstmatched(lambda inf: inf.vg == group, self.vg_status())
     if info:
         return info
     raise LookupError('Volume group %s not found' % group)
Пример #44
0
 def _get_loopback(self):
     image = '/tmp/device%s' % firstmatched(lambda x: not os.path.exists('/tmp/device%s' % x), range(100))
     system("dd if=/dev/zero of=%s bs=1M count=15" % image)
     loop_dev = system('/sbin/losetup -f --show %s' % image)[0].strip()
     return loop_dev
Пример #45
0
from scalarizr.util import system2, firstmatched, initdv2, wait_until, PopenError, software
from scalarizr.util.initdv2 import wait_sock, InitdError
from scalarizr import linux
from scalarizr.linux.coreutils import chown_r
from scalarizr.libs import metaconf
from scalarizr.linux.rsync import rsync
from scalarizr.linux import pkgmgr
from scalarizr.util import Singleton


LOG = logging.getLogger(__name__)

MYSQL_DEFAULT_PORT=3306
MYSQL_PATH  = '/usr/bin/mysql' # old mysql_path
MYCNF_PATH      = '/etc/mysql/my.cnf' if linux.os.debian_family else '/etc/my.cnf'
MYSQLD_PATH = firstmatched(lambda x: os.access(x, os.X_OK), ('/usr/sbin/mysqld', '/usr/libexec/mysqld'))
MYSQLDUMP_PATH = '/usr/bin/mysqldump'
DEFAULT_DATADIR = "/var/lib/mysql"
DEFAULT_OWNER = "mysql"
STORAGE_DATA_DIR = "mysql-data"
STORAGE_BINLOG = "mysql-misc/binlog"
SU_EXEC = '/bin/su'
BASH = '/bin/bash'
PRESET_FNAME = 'my.cnf'

BEHAVIOUR = SERVICE_NAME = BuiltinBehaviours.MYSQL


class MySQL(BaseService):

    service = None
Пример #46
0
from scalarizr.config import BuiltinBehaviours
from scalarizr.services import BaseService, ServiceError, BaseConfig, lazy, PresetProvider
from scalarizr.util import system2, disttool, firstmatched, initdv2, wait_until, PopenError, software
from scalarizr.util.initdv2 import wait_sock, InitdError
from scalarizr import linux
from scalarizr.linux.coreutils import chown_r
from scalarizr.libs import metaconf
from scalarizr.linux.rsync import rsync
from scalarizr.linux import pkgmgr

LOG = logging.getLogger(__name__)

MYSQL_DEFAULT_PORT = 3306
MYSQL_PATH = '/usr/bin/mysql'  # old mysql_path
MYCNF_PATH = '/etc/mysql/my.cnf' if linux.os.debian_family else '/etc/my.cnf'
MYSQLD_PATH = firstmatched(lambda x: os.access(x, os.X_OK),
                           ('/usr/sbin/mysqld', '/usr/libexec/mysqld'))
MYSQLDUMP_PATH = '/usr/bin/mysqldump'
DEFAULT_DATADIR = "/var/lib/mysql"
DEFAULT_OWNER = "mysql"
STORAGE_DATA_DIR = "mysql-data"
STORAGE_BINLOG = "mysql-misc/binlog"
SU_EXEC = '/bin/su'
BASH = '/bin/bash'
PRESET_FNAME = 'my.cnf'

BEHAVIOUR = SERVICE_NAME = BuiltinBehaviours.MYSQL


class MySQL(BaseService):

    service = None
Пример #47
0
from scalarizr import handlers, linux
from scalarizr.bus import bus
from scalarizr.linux import pkgmgr, execute
from scalarizr.messaging import Messages
from scalarizr.util import initdv2, firstmatched
from scalarizr.node import __node__


LOG = logging.getLogger(__name__)

__tomcat__ = __node__['tomcat']
__tomcat__.update({
    'catalina_home_dir': None,
    'java_home': firstmatched(lambda path: os.access(path, os.X_OK), [
            linux.system('echo $JAVA_HOME', shell=True)[0].strip(),
            '/usr/java/default'], 
            '/usr'),
    'config_dir': None,
    'install_type': None
})

def get_handlers():
    return [TomcatHandler()]


class KeytoolExec(execute.BaseExec):
    executable = '{0}/bin/keytool'.format(__tomcat__['java_home'])

    # keytool uses long args with a short prefix
    def _default_handler(self, key, value, cmd_args):
        cmd_args.append('-{0}'.format(key))
Пример #48
0
 def pv_info(self, ph_volume):
     info = firstmatched(lambda inf: inf.pv == ph_volume, self.pv_status())
     if info:
         return info
     raise LookupError('Physical volume %s not found' % ph_volume)
Пример #49
0
 def _get_free_md_devname(self):
     return '/dev/md%s' % firstmatched(
         lambda x: not os.path.exists('/dev/md%s' % x), range(100))
Пример #50
0
 def _get_loopback(self):
     image = "/tmp/device%s" % firstmatched(lambda x: not os.path.exists("/tmp/device%s" % x), range(100))
     system("dd if=/dev/zero of=%s bs=1M count=15" % image)
     loop_dev = system("/sbin/losetup -f --show %s" % image)[0].strip()
     return loop_dev
Пример #51
0
 def __init__(self):
     initd_script = firstmatched(os.path.exists, ("/etc/init.d/mongodb", "/etc/init.d/mongod"))
     if linux.os.ubuntu and linux.os.release >= (10, 4):
         initd_script = ("/usr/sbin/service", os.path.basename(initd_script))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME, initd_script=initd_script)
Пример #52
0
from scalarizr import handlers, linux
from scalarizr.bus import bus
from scalarizr.linux import pkgmgr, execute
from scalarizr.messaging import Messages
from scalarizr.util import initdv2, firstmatched
from scalarizr.node import __node__

LOG = logging.getLogger(__name__)

__tomcat__ = __node__['tomcat']
__tomcat__.update({
    'catalina_home_dir':
    None,
    'java_home':
    firstmatched(lambda path: os.access(path, os.X_OK), [
        linux.system('echo $JAVA_HOME', shell=True)[0].strip(),
        '/usr/java/default'
    ], '/usr'),
    'config_dir':
    None,
    'install_type':
    None
})


def get_handlers():
    return [TomcatHandler()]


class KeytoolExec(execute.BaseExec):
    executable = '{0}/bin/keytool'.format(__tomcat__['java_home'])
Пример #53
0
    'cloud_location':
    IniOption(private_dir + '/config.ini', 'general', 'region'),
}
if linux.os.windows_family:
    node['install_dir'] = r'C:\Program Files\Scalarizr'
    node['etc_dir'] = os.path.join(node['install_dir'], 'etc')
    node['log_dir'] = os.path.join(node['install_dir'], r'var\log')
else:
    node['install_dir'] = '/opt/scalarizr'
    node['etc_dir'] = '/etc/scalr'
    node['log_dir'] = '/var/log'
node['embedded_bin_dir'] = os.path.join(node['install_dir'], 'embedded', 'bin')

node['share_dir'] = util.firstmatched(
    lambda p: os.access(p, os.F_OK), [
        os.path.join(node['install_dir'], 'share'), '/usr/share/scalr',
        '/usr/local/share/scalr'
    ], os.path.join(node['install_dir'], 'share'))

node['defaults'] = {'base': {'api_port': 8010, 'messaging_port': 8013}}

node['base'] = {}

for behavior in ('mysql', 'mysql2', 'percona', 'mariadb'):
    section = 'mysql2' if behavior in ('percona', 'mariadb') else behavior
    node[behavior] = Compound({
        'volume,volume_config':
        Json('%s/storage/%s.json' % (private_dir, 'mysql'),
             'scalarizr.storage2.volume'),
        'root_password,repl_password,stat_password,log_file,log_pos,replication_master':
        Ini('%s/%s.ini' % (private_dir, behavior), section),
Пример #54
0
    'bash': '/bin/bash',
    'db_filename': 'dump.rdb',
    'aof_filename': 'appendonly.aof',
    'preset_filename': 'redis.conf'
})
if linux.os.debian_family:
    __redis__.update({
        'redis-server': '/usr/bin/redis-server',
        'pid_file': os.path.join(__redis__['pid_dir'], 'redis-server.pid')
    })
    __redis__['defaults'].update({
        'redis.conf': '/etc/redis/redis.conf',
    })
else:
    # [SCALARIZR-1776]
    redis_bin_path = firstmatched(os.path.exists, ('/usr/sbin/redis-server', '/usr/bin/redis-server'))

    __redis__.update({
        'redis-server': redis_bin_path,
        'pid_file': os.path.join(__redis__['pid_dir'], 'redis.pid')
    })
    __redis__['defaults'].update({
        'redis.conf': '/etc/redis.conf',
    })

__redis__.update({
    'config_dir': os.path.dirname(__redis__['defaults']['redis.conf']),
    'ports_range': range(__redis__['defaults']['port'], 
                         __redis__['defaults']['port'] + 16)
})