From 30b8c09cecce09fcb4cfdf9d98458ec299948177 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 27 Sep 2025 00:32:39 +0900 Subject: [PATCH] Refactor api service management Drop validation of service name which is not implemented for the other daemons, to simplify handling of the provided service name. This allows us to more easily offload the service name definition to hiera data in the near future. Change-Id: Id241996b862c8cc564ebbc2fb001fe13635ffc08 Signed-off-by: Takashi Kajinami --- manifests/api.pp | 54 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index ddce89bf..8fcfe994 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -122,7 +122,7 @@ class octavia::api ( Boolean $enabled = true, Boolean $manage_service = true, - $service_name = $octavia::params::api_service_name, + String[1] $service_name = $octavia::params::api_service_name, $host = '0.0.0.0', $port = '9876', $package_ensure = 'present', @@ -163,36 +163,36 @@ class octavia::api ( } if $manage_service { - if $enabled { - $service_ensure = 'running' - } else { - $service_ensure = 'stopped' - } + case $service_name { + 'httpd': { + Service<| title == 'httpd' |> { tag +> 'octavia-service' } - if $service_name == $octavia::params::api_service_name { - service { 'octavia-api': - ensure => $service_ensure, - name => $octavia::params::api_service_name, - enable => $enabled, - hasstatus => true, - hasrestart => true, - tag => 'octavia-service', + service { 'octavia-api': + ensure => 'stopped', + name => $octavia::params::api_service_name, + enable => false, + tag => 'octavia-service', + } + Service['octavia-api'] -> Service[$service_name] } + default: { + $service_ensure = $enabled ? { + true => 'running', + default => 'stopped', + } - # On any uwsgi config change, we must restart Octavia API. - Octavia_api_uwsgi_config<||> ~> Service['octavia-api'] - } elsif $service_name == 'httpd' { - service { 'octavia-api': - ensure => 'stopped', - name => $octavia::params::api_service_name, - enable => false, - tag => 'octavia-service', + service { 'octavia-api': + ensure => $service_ensure, + name => $octavia::params::api_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => 'octavia-service', + } + + # On any uwsgi config change, we must restart Octavia API. + Octavia_api_uwsgi_config<||> ~> Service['octavia-api'] } - Service['octavia-api'] -> Service[$service_name] - Service<| title == 'httpd' |> { tag +> 'octavia-service' } - } else { - fail("Invalid service_name. Either octavia-api/openstack-octavia-api for \ -running as a standalone service, or httpd for being run by a httpd server") } }