Merge pull request #22017 from basepi/tmpfile-ilo

[2015.2] Move tmpfile to cachedir for ilo module
This commit is contained in:
Thomas S Hatch 2015-03-26 08:30:32 -06:00
commit b160ec1c7a

View File

@ -9,6 +9,7 @@ from __future__ import absolute_import
import xml.etree.cElementTree as ET
import salt.utils
import os
import tempfile
import logging
@ -32,15 +33,20 @@ def __execute_cmd(name, xml):
ret = {name.replace('_', ' '): {}}
id_num = 0
with salt.utils.fopen('/tmp/{0}.{1}'.format(name, os.getpid()), 'w') as fh:
tmp_dir = os.path.join(__opts__['cachedir'], 'tmp')
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
with tempfile.NamedTemporaryFile(dir=tmp_dir,
prefix=name,
suffix=os.getpid(),
delete=False) as fh:
tmpfilename = fh.name
fh.write(xml)
cmd = __salt__['cmd.run_all']('hponcfg -f /tmp/{0}.{1}'.format(
name, os.getpid())
)
cmd = __salt__['cmd.run_all']('hponcfg -f {0}'.format(tmpfilename))
# Clean up the temp file
__salt__['file.remove']('/tmp/{0}.{1}'.format(name, os.getpid()))
__salt__['file.remove'](tmpfilename)
if cmd['retcode'] != 0:
for i in cmd['stderr'].splitlines():