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:
conf_file=open(slapos_configuration, "r")
for line in conf_file: for line in conf_file:
if "computer_id" in line: if "computer_id" in line:
i=line.find("COMP-") i=line.find("COMP-")
conf_file.close() conf_file.close()
return line[i:] return line[i:]
return -1 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