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
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
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()))
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()))
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