mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Pass arguments as list, and also more sanely touch /etc/machine-info
This commit is contained in:
parent
9b71ff7ba4
commit
c17a8cb239
@ -496,7 +496,10 @@ def get_computer_desc():
|
|||||||
desc = None
|
desc = None
|
||||||
hostname_cmd = salt.utils.which('hostnamectl')
|
hostname_cmd = salt.utils.which('hostnamectl')
|
||||||
if hostname_cmd:
|
if hostname_cmd:
|
||||||
desc = __salt__['cmd.run']('{0} status --pretty'.format(hostname_cmd))
|
desc = __salt__['cmd.run'](
|
||||||
|
[hostname_cmd, 'status', '--pretty'],
|
||||||
|
python_shell=False
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
|
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
|
||||||
try:
|
try:
|
||||||
@ -537,12 +540,15 @@ def set_computer_desc(desc):
|
|||||||
desc = desc.encode('string_escape').replace('"', '\\"')
|
desc = desc.encode('string_escape').replace('"', '\\"')
|
||||||
hostname_cmd = salt.utils.which('hostnamectl')
|
hostname_cmd = salt.utils.which('hostnamectl')
|
||||||
if hostname_cmd:
|
if hostname_cmd:
|
||||||
result = __salt__['cmd.retcode']('{0} set-hostname --pretty "{1}"'.format(hostname_cmd, desc))
|
result = __salt__['cmd.retcode'](
|
||||||
|
[hostname_cmd, 'set-hostname', '--pretty', desc],
|
||||||
|
python_shell=False
|
||||||
|
)
|
||||||
return True if result == 0 else False
|
return True if result == 0 else False
|
||||||
|
|
||||||
if not os.path.isfile('/etc/machine-info'):
|
if not os.path.isfile('/etc/machine-info'):
|
||||||
f = salt.utils.fopen('/etc/machine-info', 'a')
|
with salt.utils.fopen('/etc/machine-info', 'w'):
|
||||||
f.close()
|
pass
|
||||||
|
|
||||||
is_pretty_hostname_found = False
|
is_pretty_hostname_found = False
|
||||||
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
|
pattern = re.compile(r'^\s*PRETTY_HOSTNAME=(.*)$')
|
||||||
|
Loading…
Reference in New Issue
Block a user