Exemplo n.º 1
0
    def add_maintenance_service(name, backend_guid, abm_name):
        """
        Add a maintenance service with a specific name
        :param name: Name of the service to add
        :type name: str
        :param backend_guid: Backend for which the maintenance service needs to run
        :type backend_guid: str
        :param abm_name: Name of the ABM cluster
        :type abm_name: str
        """
        if ServiceManager.has_service(name, MaintenanceController._local_client) is False:
            config_location = '/ovs/alba/backends/{0}/maintenance/config'.format(backend_guid)
            alba_config = Configuration.get_configuration_path(config_location)
            node_id = os.environ.get('ASD_NODE_ID')
            params = {'ALBA_CONFIG': alba_config,
                      'LOG_SINK': LogHandler.get_sink_path('alba_maintenance')}
            Configuration.set(config_location, json.dumps({
                'log_level': 'info',
                'albamgr_cfg_url': Configuration.get_configuration_path('/ovs/arakoon/{0}/config'.format(abm_name)),
                'read_preference': [] if node_id is None else [node_id]
            }, indent=4), raw=True)

            ServiceManager.add_service(name=MaintenanceController.MAINTENANCE_PREFIX,
                                       client=MaintenanceController._local_client,
                                       params=params,
                                       target_name=name)
        ServiceManager.start_service(name, MaintenanceController._local_client)
 def write_config(self, ip=None):
     """
     Writes the configuration down to in the format expected by Arakoon
     """
     contents = self.export_ini()
     if self.filesystem is False:
         Configuration.set(self.config_path, contents, raw=True)
     else:
         client = self._load_client(ip)
         client.file_write(self.config_path, contents)
Exemplo n.º 3
0
 def register_service(node_name, service_metadata):
     """
     Register the metadata of the service to the configuration management
     :param node_name: Unused
     :type node_name: str
     :param service_metadata: Metadata of the service
     :type service_metadata: dict
     :return: None
     """
     _ = node_name
     service_name = service_metadata['SERVICE_NAME']
     with open(Toolbox.BOOTSTRAP_FILE, 'r') as bs_file:
         node_id = json.load(bs_file)['node_id']
         Configuration.set(key='/ovs/alba/asdnodes/{0}/services/{1}'.format(node_id, Toolbox.remove_prefix(service_name, 'ovs-')),
                           value=service_metadata)
Exemplo n.º 4
0
    CONFIG_ROOT = '/ovs/alba/asdnodes/{0}/config'.format(NODE_ID)
    CURRENT_VERSION = 1

    _logger = LogHandler.get('asd-manager', name='post-update')

    _logger.info('Executing post-update logic of package openvstorage-sdm')
    with file_mutex('package_update_pu'):
        client = LocalClient('127.0.0.1', username='******')

        key = '{0}/versions'.format(CONFIG_ROOT)
        version = Configuration.get(key) if Configuration.exists(key) else 0

        service_name = 'asd-manager'
        if ServiceManager.has_service(service_name, client) and ServiceManager.get_service_status(service_name, client)[0] is True:
            _logger.info('Stopping asd-manager service')
            ServiceManager.stop_service(service_name, client)

        if version < CURRENT_VERSION:
            try:
                # Put migration code here
                pass
            except:
                pass
        Configuration.set(key, CURRENT_VERSION)

        if ServiceManager.has_service(service_name, client) and ServiceManager.get_service_status(service_name, client)[0] is False:
            _logger.info('Starting asd-manager service')
            ServiceManager.start_service(service_name, client)

    _logger.info('Post-update logic executed')
Exemplo n.º 5
0
 def set_net():
     """ Set IP information """
     API._logger.info('Setting network information')
     Configuration.set('{0}/network|ips'.format(API.CONFIG_ROOT), json.loads(request.form['ips']))
Exemplo n.º 6
0
    def create_asd(partition_alias):
        """
        Creates and starts an ASD on a given disk
        :param partition_alias: Alias of the partition of a disk  (eg: /dev/disk/by-id/scsi-1ATA_TOSHIBA_MK2002TSKB_92M1KDMHF-part1)
        :type partition_alias: str
        :return: None
        """
        all_asds = {}
        mountpoint = None
        for alias, mtpt in FSTab.read().iteritems():
            all_asds.update(ASDController.list_asds(mtpt))
            if alias == partition_alias:
                mountpoint = mtpt
        if mountpoint is None:
            raise RuntimeError('Failed to retrieve the mountpoint for partition with alias: {0}'.format(partition_alias))

        # Fetch disk information
        disk_size = int(ASDController._local_client.run(['df', '-B', '1', '--output=size', mountpoint]).splitlines()[1])

        # Find out appropriate disk size
        asds = 1.0
        for asd_id in os.listdir(mountpoint):
            if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                asds += 1
        asd_size = int(math.floor(disk_size / asds))
        for asd_id in os.listdir(mountpoint):
            if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                config = json.loads(Configuration.get(ASDController.ASD_CONFIG.format(asd_id), raw=True))
                config['capacity'] = asd_size
                config['rocksdb_block_cache_size'] = int(asd_size / 1024 / 4)
                Configuration.set(ASDController.ASD_CONFIG.format(asd_id), json.dumps(config, indent=4), raw=True)
                try:
                    ServiceManager.send_signal(ASDController.ASD_SERVICE_PREFIX.format(asd_id),
                                               signal.SIGUSR1,
                                               ASDController._local_client)
                except Exception as ex:
                    ASDController._logger.info('Could not send signal to ASD for reloading the quota: {0}'.format(ex))

        # Prepare & start service
        asd_id = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32))
        ASDController._logger.info('Setting up service for disk {0}'.format(partition_alias))
        homedir = '{0}/{1}'.format(mountpoint, asd_id)
        base_port = Configuration.get('{0}/network|port'.format(ASDController.CONFIG_ROOT))
        ips = Configuration.get('{0}/network|ips'.format(ASDController.CONFIG_ROOT))
        used_ports = []
        for asd in all_asds.itervalues():
            used_ports.append(asd['port'])
            if 'rora_port' in asd:
                used_ports.append(asd['rora_port'])
        asd_port = base_port
        rora_port = base_port + 1
        while asd_port in used_ports:
            asd_port += 1
        used_ports.append(asd_port)
        while rora_port in used_ports:
            rora_port += 1

        asd_config = {'home': homedir,
                      'node_id': ASDController.NODE_ID,
                      'asd_id': asd_id,
                      'capacity': asd_size,
                      'log_level': 'info',
                      'port': asd_port,
                      'transport': 'tcp',
                      'rocksdb_block_cache_size': int(asd_size / 1024 / 4)}
        if Configuration.get('/ovs/framework/rdma'):
            asd_config['rora_port'] = rora_port
            asd_config['rora_transport'] = 'rdma'
        if ips is not None and len(ips) > 0:
            asd_config['ips'] = ips

        if Configuration.exists('{0}/extra'.format(ASDController.CONFIG_ROOT)):
            data = Configuration.get('{0}/extra'.format(ASDController.CONFIG_ROOT))
            asd_config.update(data)

        Configuration.set(ASDController.ASD_CONFIG.format(asd_id), json.dumps(asd_config, indent=4), raw=True)

        service_name = ASDController.ASD_SERVICE_PREFIX.format(asd_id)
        params = {'CONFIG_PATH': Configuration.get_configuration_path('/ovs/alba/asds/{0}/config'.format(asd_id)),
                  'SERVICE_NAME': service_name,
                  'LOG_SINK': LogHandler.get_sink_path('alba_asd')}
        os.mkdir(homedir)
        ASDController._local_client.run(['chown', '-R', 'alba:alba', homedir])
        ServiceManager.add_service('alba-asd', ASDController._local_client, params, service_name)
        ASDController.start_asd(asd_id)