Don't crash if we don't have slapos.cfg file.

It won't change the hostname to readable one, but, hey, who cares now?
-> future improvement.
parent 9064829c
...@@ -30,6 +30,7 @@ from optparse import OptionParser, Option ...@@ -30,6 +30,7 @@ from optparse import OptionParser, Option
import os import os
import pkg_resources import pkg_resources
from shutil import move from shutil import move
import socket
from subprocess import call as subprocessCall from subprocess import call as subprocessCall
import sys import sys
import urllib2 import urllib2
...@@ -135,13 +136,16 @@ def suse_version(): ...@@ -135,13 +136,16 @@ def suse_version():
# Parse certificate to get computer name and return it # Parse certificate to get computer name and return it
def get_computer_name(slapos_configuration): def get_computer_name(slapos_configuration):
conf_file=open(slapos_configuration,"r") try:
for line in conf_file: conf_file=open(slapos_configuration, "r")
if "computer_id" in line: for line in conf_file:
i=line.find("COMP-") if "computer_id" in line:
conf_file.close() i=line.find("COMP-")
return line[i:] conf_file.close()
return -1 return line[i:]
except IOError:
print "Warning: slapos.cfg doesn't exist. Using current hostname."
return socket.gethostname()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment