Exemplo n.º 1
0
    def add_service(name, client, params=None, target_name=None, startup_dependency=None, delay_registration=False):
        """
        Add a service
        :param name: Template name of the service to add
        :type name: str
        :param client: Client on which to add the service
        :type client: source.tools.localclient.LocalClient
        :param params: Additional information about the service
        :type params: dict or None
        :param target_name: Overrule default name of the service with this name
        :type target_name: str or None
        :param startup_dependency: Additional startup dependency
        :type startup_dependency: str or None
        :param delay_registration: Register the service parameters in the config management right away or not
        :type delay_registration: bool
        :return: Parameters used by the service
        :rtype: dict
        """
        if params is None:
            params = {}

        service_name = Systemd._get_name(name, client, '/opt/asd-manager/config/systemd/')
        template_file = '/opt/asd-manager/config/systemd/{0}.service'.format(service_name)

        if not client.file_exists(template_file):
            # Given template doesn't exist so we are probably using system init scripts
            return

        if target_name is not None:
            service_name = target_name

        params.update({'SERVICE_NAME': Toolbox.remove_prefix(service_name, 'ovs-'),
                       'STARTUP_DEPENDENCY': '' if startup_dependency is None else '{0}.service'.format(startup_dependency)})
        template_content = client.file_read(template_file)
        for key, value in params.iteritems():
            template_content = template_content.replace('<{0}>'.format(key), value)
        client.file_write('/lib/systemd/system/{0}.service'.format(service_name), template_content)

        try:
            client.run(['systemctl', 'daemon-reload'])
            client.run(['systemctl', 'enable', '{0}.service'.format(service_name)])
        except CalledProcessError as cpe:
            Systemd._logger.exception('Add {0}.service failed, {1}'.format(service_name, cpe.output))
            raise Exception('Add {0}.service failed, {1}'.format(service_name, cpe.output))

        if delay_registration is False:
            Systemd.register_service(service_metadata=params, node_name='')
        return params
 def list(key):
     """
     List all keys starting with specified key
     :param key: Key to list
     :type key: str
     :return: Generator with all keys
     :rtype: generator
     """
     key = ArakoonConfiguration._clean_key(key)
     client = ArakoonConfiguration.get_client()
     entries = []
     for entry in client.prefix(key):
         if key == '' or entry.startswith(key + '/'):
             cleaned = Toolbox.remove_prefix(entry, key).strip('/').split('/')[0]
             if cleaned not in entries:
                 entries.append(cleaned)
                 yield cleaned
Exemplo n.º 3
0
    def add_service(name, client, params=None, target_name=None, startup_dependency=None, delay_registration=False):
        """
        Add a service
        :param name: Template name of the service to add
        :type name: str
        :param client: Client on which to add the service
        :type client: source.tools.localclient.LocalClient
        :param params: Additional information about the service
        :type params: dict or None
        :param target_name: Overrule default name of the service with this name
        :type target_name: str or None
        :param startup_dependency: Additional startup dependency
        :type startup_dependency: str or None
        :param delay_registration: Register the service parameters in the config management right away or not
        :type delay_registration: bool
        :return: Parameters used by the service
        :rtype: dict
        """
        if params is None:
            params = {}

        service_name = Upstart._get_name(name, client, '/opt/asd-manager/config/upstart/')
        template_file = '/opt/asd-manager/config/upstart/{0}.conf'.format(service_name)

        if not client.file_exists(template_file):
            # Given template doesn't exist so we are probably using system init scripts
            return

        if target_name is not None:
            service_name = target_name

        params.update({'SERVICE_NAME': Toolbox.remove_prefix(service_name, 'ovs-'),
                       'STARTUP_DEPENDENCY': '' if startup_dependency is None else 'started {0}'.format(startup_dependency)})
        template_content = client.file_read(template_file)
        for key, value in params.iteritems():
            template_content = template_content.replace('<{0}>'.format(key), value)
        client.file_write('/etc/init/{0}.conf'.format(service_name), template_content)

        if delay_registration is False:
            Upstart.register_service(service_metadata=params, node_name='')
        return params
Exemplo n.º 4
0
 def get_candidate_versions(client, package_names):
     """
     Retrieve the versions candidate for installation of the packages provided
     :param client: Root client on which to check the candidate versions
     :type client: source.tools.localclient.LocalClient
     :param package_names: Name of the packages to check
     :type package_names: list
     :return: Package candidate versions
     :rtype: dict
     """
     DebianPackage.update(client=client)
     versions = {}
     for package_name in package_names:
         versions[package_name] = ''
         for line in client.run(['apt-cache', 'policy', package_name, DebianPackage.APT_CONFIG_STRING]).splitlines():
             line = line.strip()
             if line.startswith('Candidate:'):
                 candidate = Toolbox.remove_prefix(line, 'Candidate:').strip()
                 if candidate == '(none)':
                     candidate = ''
                 versions[package_name] = candidate
                 break
     return versions
Exemplo n.º 5
0
 def unregister_service(node_name, service_name):
     """
     Un-register the metadata of a service from the configuration management
     :param node_name: Unused
     :type node_name: str
     :param service_name: Name of the service to clean from the configuration management
     :type service_name: str
     :return: None
     """
     _ = node_name
     with open(Toolbox.BOOTSTRAP_FILE, 'r') as bs_file:
         node_id = json.load(bs_file)['node_id']
         Configuration.delete(key='/ovs/alba/asdnodes/{0}/services/{1}'.format(node_id, Toolbox.remove_prefix(service_name, 'ovs-')))
Exemplo n.º 6
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)