Find and replace
[certmaster.git] / certmaster / utils.py
index 7927c55..a470aad 100755 (executable)
@@ -75,7 +75,7 @@ def is_error(result):
         return True
     return False
 
-def get_hostname():
+def get_hostname(talk_to_certmaster=True):
     """
     "localhost" is a lame hostname to use for a key, so try to get
     a more meaningful hostname. We do this by connecting to the certmaster
@@ -94,23 +94,23 @@ def get_hostname():
     if ip != "127.0.0.1":
         return hostname
 
+    if talk_to_certmaster:
+        config_file = '/etc/certmaster/minion.conf'
+        config = read_config(config_file, MinionConfig)
 
-    config_file = '/etc/certmaster/minion.conf'
-    config = read_config(config_file, MinionConfig)
-
-    server = config.certmaster
-    port = 51235
+        server = config.certmaster
+        port = 51235
 
-    try:
-        s = socket.socket()
-        s.settimeout(5)
-        s.connect((server, port))
-        (intf, port) = s.getsockname()
-        hostname = socket.gethostbyaddr(intf)[0]
-        s.close()
-    except:
-        s.close()
-        raise
+        try:
+            s = socket.socket()
+            s.settimeout(5)
+            s.connect((server, port))
+            (intf, port) = s.getsockname()
+            hostname = socket.gethostbyaddr(intf)[0]
+            s.close()
+        except:
+            s.close()
+            raise
 
     return hostname
     
@@ -151,7 +151,7 @@ def create_minion_keys():
             csr = certs.make_csr(keypair, dest=csr_file)
     except Exception, e:
         traceback.print_exc()
-        raise codes.FuncException, "Could not create local keypair or csr for session"
+        raise codes.CMException, "Could not create local keypair or csr for session"
 
     result = False
     log = logger.Logger().logger
@@ -161,7 +161,7 @@ def create_minion_keys():
             log.debug("submitting CSR to certmaster %s" % master_uri)
             result, cert_string, ca_cert_string = submit_csr_to_master(csr_file, master_uri)
         except socket.gaierror, e:
-            raise codes.FuncException, "Could not locate certmaster at %s" % master_uri
+            raise codes.CMException, "Could not locate certmaster at %s" % master_uri
 
         # logging here would be nice
         if not result: