Merge "Improve heat launcher user retrieval"
This commit is contained in:
commit
7426a23614
@ -15,9 +15,11 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import grp
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pwd
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -268,28 +270,26 @@ class HeatDockerLauncher(HeatBaseLauncher):
|
|||||||
cmd = [
|
cmd = [
|
||||||
'docker', 'run', '--rm',
|
'docker', 'run', '--rm',
|
||||||
self.container_image,
|
self.container_image,
|
||||||
'getent', 'passwd'
|
'getent', 'passwd', self.user
|
||||||
]
|
]
|
||||||
log.debug(' '.join(cmd))
|
log.debug(' '.join(cmd))
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
result = p.communicate()[0]
|
result = p.communicate()[0]
|
||||||
for line in result.split("\n"):
|
if result:
|
||||||
if line.startswith('%s:' % self.user):
|
return result.split(':')[2]
|
||||||
return line.split(':')[2]
|
|
||||||
raise Exception('Could not find heat uid')
|
raise Exception('Could not find heat uid')
|
||||||
|
|
||||||
def get_heat_gid(self):
|
def get_heat_gid(self):
|
||||||
cmd = [
|
cmd = [
|
||||||
'docker', 'run', '--rm',
|
'docker', 'run', '--rm',
|
||||||
self.container_image,
|
self.container_image,
|
||||||
'getent', 'group'
|
'getent', 'group', self.user
|
||||||
]
|
]
|
||||||
log.debug(' '.join(cmd))
|
log.debug(' '.join(cmd))
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
result = p.communicate()[0]
|
result = p.communicate()[0]
|
||||||
for line in result.split("\n"):
|
if result:
|
||||||
if line.startswith('%s:' % self.user):
|
return result.split(':')[2]
|
||||||
return line.split(':')[2]
|
|
||||||
raise Exception('Could not find heat gid')
|
raise Exception('Could not find heat gid')
|
||||||
|
|
||||||
def kill_heat(self, pid):
|
def kill_heat(self, pid):
|
||||||
@ -313,14 +313,10 @@ class HeatNativeLauncher(HeatBaseLauncher):
|
|||||||
self.config_file, 'db_sync'])
|
self.config_file, 'db_sync'])
|
||||||
|
|
||||||
def get_heat_uid(self):
|
def get_heat_uid(self):
|
||||||
p = subprocess.Popen(["getent", "passwd", "|", "grep", "heat"],
|
return pwd.getpwnam('heat').pw_uid
|
||||||
stdout=subprocess.PIPE)
|
|
||||||
return p.communicate()[0].rstrip().split(':')[2]
|
|
||||||
|
|
||||||
def get_heat_gid(self):
|
def get_heat_gid(self):
|
||||||
p = subprocess.Popen(["getent", "group", "|", "grep", "heat"],
|
return grp.getgrnam('heat').gr_gid
|
||||||
stdout=subprocess.PIPE)
|
|
||||||
return p.communicate()[0].rstrip().split(':')[2]
|
|
||||||
|
|
||||||
def kill_heat(self, pid):
|
def kill_heat(self, pid):
|
||||||
os.kill(pid, signal.SIGKILL)
|
os.kill(pid, signal.SIGKILL)
|
||||||
|
Loading…
Reference in New Issue
Block a user