GENICLOUD-26
authorAndy Bavier <acb@cs.princeton.edu>
Thu, 29 Sep 2011 20:28:41 +0000 (16:28 -0400)
committerAndy Bavier <acb@cs.princeton.edu>
Thu, 29 Sep 2011 20:28:41 +0000 (16:28 -0400)
Export information about Eucalyptus instances

sfa/managers/aggregate_manager_eucalyptus.py

index 9a18046..2b86b58 100644 (file)
@@ -1,7 +1,7 @@
 from __future__ import with_statement 
 
 import sys
-import os
+import os, errno
 import logging
 import datetime
 
@@ -630,6 +630,34 @@ def CreateSliver(api, slice_xrn, creds, xml, users, call_id):
     # with enough data for the client to understand what's happened
     return xml
 
+##
+# Return information on the IP addresses bound to each slice's instances
+#
+def dumpInstanceInfo():
+    logger = logging.getLogger('EucaMeta')
+    outdir = "/var/www/html/euca/"
+    outfile = outdir + "instances.txt"
+
+    try:
+        os.makedirs(outdir)
+    except OSError, e:
+        if e.errno != errno.EEXIST:
+            raise
+
+    dbResults = Meta.select(
+        AND(Meta.q.pri_addr != None,
+            Meta.q.state    == 'running')
+        )
+    dbResults = list(dbResults)
+    f = open(outfile, "w")
+    for r in dbResults:
+        instId = r.instance.instance_id
+        ipaddr = r.pri_addr
+        hrn = r.instance.slice.slice_hrn
+        logger.debug('[dumpInstanceInfo] %s %s %s' % (instId, ipaddr, hrn))
+        f.write("%s %s %s\n" % (instId, ipaddr, hrn))
+    f.close()
+
 ##
 # A separate process that will update the meta data.
 #
@@ -678,6 +706,8 @@ def updateMeta():
             dbInst.meta.pub_addr = ipData['pub_addr']
             dbInst.meta.state    = 'running'
 
+        dumpInstanceInfo()
+
 def GetVersion(api):
     xrn=Xrn(api.hrn)
     request_rspec_versions = [dict(sfa_rspec_version)]