from __future__ import with_statement
import sys
-import os
+import os, errno
import logging
import datetime
+from multiprocessing import Process
+from time import sleep
import boto
from boto.ec2.regioninfo import RegionInfo
from sfa.util.faults import *
from sfa.util.xrn import urn_to_hrn, Xrn
-from sfa.util.rspec import RSpec
-from sfa.server.registry import Registries
-from sfa.trust.credential import Credential
-from sfa.plc.api import SfaAPI
-from sfa.plc.aggregate import Aggregate
-from sfa.plc.slices import *
from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
from sfa.util.callids import Callids
from sfa.util.sfalogging import logger
-from sfa.rspecs.sfa_rspec import sfa_rspec_version
from sfa.util.version import version_core
-from multiprocessing import Process
-from time import sleep
+from sfa.trust.credential import Credential
+
+from sfa.server.sfaapi import SfaApi
+
+from sfa.plc.aggregate import Aggregate
+from sfa.plc.slices import *
+from sfa.rspecs.sfa_rspec import sfa_rspec_version
+
##
# The data structure used to represent a cloud.
#
EUCALYPTUS_RSPEC_SCHEMA='/etc/sfa/eucalyptus.rng'
-api = SfaAPI()
-
##
# Meta data of an instance.
#
rspecValidator = ET.RelaxNG(schemaXML)
rspecXML = ET.XML(xml)
for network in rspecXML.iterfind("./network"):
- if network.get('id') != cloud['name']:
+ if network.get('name') != cloud['name']:
# Throw away everything except my own RSpec
# sfa_logger().error("CreateSliver: deleting %s from rspec"%network.get('id'))
network.getparent().remove(network)
# 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.
#
logger.debug('[update process] dbResults: %s' % dbResults)
instids = []
for r in dbResults:
+ if not r.instance:
+ continue
instids.append(r.instance.instance_id)
logger.debug('[update process] Instance Id: %s' % ', '.join(instids))
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)]
}
return version_core(version_more)
-def main():
- init_server()
-
- #theRSpec = None
- #with open(sys.argv[1]) as xml:
- # theRSpec = xml.read()
- #CreateSliver(None, 'planetcloud.pc.test', theRSpec, 'call-id-cloudtest')
-
- #rspec = ListResources('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
- #print rspec
-
- server_key_file = '/var/lib/sfa/authorities/server.key'
- server_cert_file = '/var/lib/sfa/authorities/server.cert'
- api = SfaAPI(key_file = server_key_file, cert_file = server_cert_file, interface='aggregate')
- print getKeysForSlice(api, 'gc.gc.test1')
-
-if __name__ == "__main__":
- main()
+#def main():
+# init_server()
+#
+# #theRSpec = None
+# #with open(sys.argv[1]) as xml:
+# # theRSpec = xml.read()
+# #CreateSliver(None, 'planetcloud.pc.test', theRSpec, 'call-id-cloudtest')
+#
+# #rspec = ListResources('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
+# #print rspec
+#
+# server_key_file = '/var/lib/sfa/authorities/server.key'
+# server_cert_file = '/var/lib/sfa/authorities/server.cert'
+# api = PlcSfaApi(key_file = server_key_file, cert_file = server_cert_file, interface='aggregate')
+# print getKeysForSlice(api, 'gc.gc.test1')
+#
+#if __name__ == "__main__":
+# main()