コード例 #1
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def _get_unit_name(name, client):
     try:
         name = Systemd._get_name(name, client, '/opt/OpenvStorage/config/templates/systemd/')
     except ValueError:
         try:
             name = Systemd._get_name(name, client)
         except ValueError:
             name = 'ovs-{0}'.format(name)
     client_ip = FleetCtl._get_client_ip(client)
     fleet_name = "{0}@{1}.service".format(name, client_ip)
     return fleet_name
コード例 #2
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def _get_unit_name(name, client):
     try:
         name = Systemd._get_name(
             name, client, '/opt/OpenvStorage/config/templates/systemd/')
     except ValueError:
         try:
             name = Systemd._get_name(name, client)
         except ValueError:
             name = 'ovs-{0}'.format(name)
     client_ip = FleetCtl._get_client_ip(client)
     fleet_name = "{0}@{1}.service".format(name, client_ip)
     return fleet_name
コード例 #3
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def get_service_status(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         unit = FleetCtl._get_unit(fleet_name)
         FleetCtl._logger.debug('Fleet unit {0} status {1}'.format(fleet_name, unit.as_dict()['currentState']))
         return unit.as_dict()['currentState'] == 'launched'
     return Systemd.get_service_status(name, client)
コード例 #4
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def is_enabled(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         output = client.run(
             'systemctl is-enabled {0} || true'.format(fleet_name))
         return 'enabled' in output
     return Systemd.is_enabled(name, client)
コード例 #5
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def get_service_status(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         unit = FleetCtl._get_unit(fleet_name)
         FleetCtl._logger.debug('Fleet unit {0} status {1}'.format(
             fleet_name,
             unit.as_dict()['currentState']))
         return unit.as_dict()['currentState'] == 'launched'
     return Systemd.get_service_status(name, client)
コード例 #6
0
    def add_service(name,
                    client,
                    params=None,
                    target_name=None,
                    additional_dependencies=None):
        """
        This will generate a .service (temporary) file to feed to fleet to start a service
         service will become "name@<client.ip>.service"
        """
        if params is None:
            params = {}
        if additional_dependencies is None:
            additional_dependencies = []

        client_ip = FleetCtl._get_client_ip(client)

        if FleetCtl.has_service(name, client):
            logger.info('Not re-adding service {0} to machine {1}'.format(
                name, client_ip))
            return

        name = Systemd._get_name(
            name, client, '/opt/OpenvStorage/config/templates/systemd/')
        template_service = '/opt/OpenvStorage/config/templates/systemd/{0}.service'

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

        template_file = client.file_read(template_service.format(name))

        for key, value in params.iteritems():
            template_file = template_file.replace('<{0}>'.format(key), value)
        if '<SERVICE_NAME>' in template_file:
            service_name = name if target_name is None else target_name
            template_file = template_file.replace('<SERVICE_NAME>',
                                                  service_name.lstrip('ovs-'))

        dependencies = ''
        for service in additional_dependencies:
            dependencies += '{0}.service '.format(service)
        template_file = template_file.replace('<ADDITIONAL_DEPENDENCIES>',
                                              dependencies)

        template_file += "\n[X-Fleet]\nMachineID={0}".format(
            FleetCtl._get_id_from_ip(client_ip))
        fleet_name = "{0}@{1}.service".format(name, client_ip)

        logger.debug('Creating fleet unit {0} {1}'.format(
            fleet_name, template_file))
        unit = FleetCtl._create_unit(fleet_name, template_file)
        time.sleep(1)
        FLEET_CLIENT.set_unit_desired_state(unit, 'loaded')
        time.sleep(1)
        unit = FleetCtl._get_unit(fleet_name)
        logger.info('Created unit {0}'.format(unit.as_dict()))
コード例 #7
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
    def add_service(name, client, params=None, target_name=None, additional_dependencies=None):
        """
        This will generate a .service (temporary) file to feed to fleet to start a service
         service will become "name@<client.ip>.service"
        """
        if params is None:
            params = {}
        if additional_dependencies is None:
            additional_dependencies = []

        client_ip = FleetCtl._get_client_ip(client)

        if FleetCtl.has_service(name, client):
            FleetCtl._logger.info('Not re-adding service {0} to machine {1}'.format(name, client_ip))
            return

        name = Systemd._get_name(name, client, '/opt/OpenvStorage/config/templates/systemd/')
        template_service = '/opt/OpenvStorage/config/templates/systemd/{0}.service'

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

        template_file = client.file_read(template_service.format(name))

        for key, value in params.iteritems():
            template_file = template_file.replace('<{0}>'.format(key), value)
        if '<SERVICE_NAME>' in template_file:
            service_name = name if target_name is None else target_name
            template_file = template_file.replace('<SERVICE_NAME>', service_name.lstrip('ovs-'))
        template_file = template_file.replace('<_SERVICE_SUFFIX_>', '@{0}'.format(client_ip))

        dependencies = ''
        for service in additional_dependencies:
            dependencies += '{0}@{1}.service '.format(service, client_ip)
        template_file = template_file.replace('<ADDITIONAL_DEPENDENCIES>', dependencies)

        template_file += "\n[X-Fleet]\nMachineID={0}".format(FleetCtl._get_id_from_ip(client_ip))
        if target_name is not None:
            name = target_name
        fleet_name = "{0}@{1}.service".format(name, client_ip)

        FleetCtl._logger.debug('Creating fleet unit {0} {1}'.format(fleet_name, template_file))
        unit = FleetCtl._create_unit(fleet_name, template_file)
        time.sleep(1)
        FLEET_CLIENT.set_unit_desired_state(unit, 'loaded')
        time.sleep(1)
        unit = FleetCtl._get_unit(fleet_name)
        FleetCtl._logger.info('Created unit {0}'.format(unit.as_dict()))
コード例 #8
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def remove_service(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         unit = FleetCtl._get_unit(fleet_name)
         FleetCtl.stop_service(name, client)
         result = FLEET_CLIENT.destroy_unit(unit)
         start = time.time()
         FleetCtl._logger.debug('Fleet destroy unit {0} {1}'.format(fleet_name, result))
         while time.time() - start < 60:
             time.sleep(1)
             if FleetCtl._has_service(name, client) is False:
                 return
         FleetCtl._logger.warning('Failed to remove unit {0} after 60 seconds'.format(fleet_name))
     else:
         return Systemd.remove_service(name, client)
コード例 #9
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def stop_service(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         start = time.time()
         while time.time() - start < 60:
             unit = FleetCtl._get_unit(fleet_name)
             if unit.as_dict()['currentState'] != 'loaded':
                 FLEET_CLIENT.set_unit_desired_state(unit, 'loaded')
                 time.sleep(1)
             else:
                 break
         unit = FleetCtl._get_unit(fleet_name)
         if unit['currentState'] != 'loaded':
             FleetCtl._logger.warning('Failed to stop unit {0}'.format(unit.as_dict()))
         FleetCtl._logger.debug('Fleet stop unit {0} {1}'.format(fleet_name, unit.as_dict()['currentState']))
         return unit.as_dict()['currentState']
     return Systemd.stop_service(name, client)
コード例 #10
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def remove_service(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         unit = FleetCtl._get_unit(fleet_name)
         FleetCtl.stop_service(name, client)
         result = FLEET_CLIENT.destroy_unit(unit)
         start = time.time()
         FleetCtl._logger.debug('Fleet destroy unit {0} {1}'.format(
             fleet_name, result))
         while time.time() - start < 60:
             time.sleep(1)
             if FleetCtl._has_service(name, client) is False:
                 return
         FleetCtl._logger.warning(
             'Failed to remove unit {0} after 60 seconds'.format(
                 fleet_name))
     else:
         return Systemd.remove_service(name, client)
コード例 #11
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def stop_service(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         start = time.time()
         while time.time() - start < 60:
             unit = FleetCtl._get_unit(fleet_name)
             if unit.as_dict()['currentState'] != 'loaded':
                 FLEET_CLIENT.set_unit_desired_state(unit, 'loaded')
                 time.sleep(1)
             else:
                 break
         unit = FleetCtl._get_unit(fleet_name)
         if unit['currentState'] != 'loaded':
             FleetCtl._logger.warning('Failed to stop unit {0}'.format(
                 unit.as_dict()))
         FleetCtl._logger.debug('Fleet stop unit {0} {1}'.format(
             fleet_name,
             unit.as_dict()['currentState']))
         return unit.as_dict()['currentState']
     return Systemd.stop_service(name, client)
コード例 #12
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def enable_service(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         client.run('systemctl enable {0}'.format(fleet_name))
     else:
         Systemd.enable_service(name, client)
コード例 #13
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def get_service_pid(name, client):
     return Systemd.get_service_pid(name, client)
コード例 #14
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def restart_service(name, client):
     if not FleetCtl.has_service(name, client):
         return Systemd.restart_service(name, client)
     FleetCtl.stop_service(name, client)
     FleetCtl.start_service(name, client)
     return FleetCtl.get_service_status(name, client)
コード例 #15
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def enable_service(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         client.run('systemctl enable {0}'.format(fleet_name))
     else:
         Systemd.enable_service(name, client)
コード例 #16
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def has_service(name, client):
     fleet_has_service = FleetCtl._has_service(name, client)
     if not fleet_has_service:
         return Systemd.has_service(name, client)
     return fleet_has_service
コード例 #17
0
 def prepare_template(base_name, target_name, client):
     return Systemd.prepare_template(base_name, target_name, client)
コード例 #18
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def send_signal(name, signal, client):
     return Systemd.send_signal(name, signal, client)
コード例 #19
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def is_enabled(name, client):
     if FleetCtl._has_service(name, client):
         fleet_name = FleetCtl._get_unit_name(name, client)
         output = client.run('systemctl is-enabled {0} || true'.format(fleet_name))
         return 'enabled' in output
     return Systemd.is_enabled(name, client)
コード例 #20
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def restart_service(name, client):
     if not FleetCtl.has_service(name, client):
         return Systemd.restart_service(name, client)
     FleetCtl.stop_service(name, client)
     FleetCtl.start_service(name, client)
     return FleetCtl.get_service_status(name, client)
コード例 #21
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def has_service(name, client):
     fleet_has_service = FleetCtl._has_service(name, client)
     if not fleet_has_service:
         return Systemd.has_service(name, client)
     return fleet_has_service
コード例 #22
0
ファイル: fleetctl.py プロジェクト: DarumasLegs/framework
 def send_signal(name, signal, client):
     return Systemd.send_signal(name, signal, client)
コード例 #23
0
ファイル: fleetctl.py プロジェクト: th3architect/framework
 def get_service_pid(name, client):
     return Systemd.get_service_pid(name, client)
コード例 #24
0
 def is_enabled(name, client):
     return Systemd.is_enabled(name, client)
コード例 #25
0
 def enable_service(name, client):
     fleet_name = FleetCtl._get_unit_name(name, client)
     return Systemd.enable_service(fleet_name, client)
コード例 #26
0
 def _get_unit_name(name, client):
     name = Systemd._get_name(
         name, client, '/opt/OpenvStorage/config/templates/systemd/')
     client_ip = FleetCtl._get_client_ip(client)
     fleet_name = "{0}@{1}.service".format(name, client_ip)
     return fleet_name