Merge branch 'master' into eucalyptus-devel
authorMarco Yuen <marcoy@gmail.com>
Mon, 25 Jul 2011 16:05:31 +0000 (12:05 -0400)
committerMarco Yuen <marcoy@gmail.com>
Mon, 25 Jul 2011 16:05:31 +0000 (12:05 -0400)
Conflicts:
sfa/managers/aggregate_manager_eucalyptus.py

1  2 
sfa/managers/aggregate_manager_eucalyptus.py

@@@ -21,10 -19,10 +21,13 @@@ from sfa.trust.credential import Creden
  from sfa.plc.api import SfaAPI
  from sfa.util.plxrn import hrn_to_pl_slicename, slicename_to_hrn
  from sfa.util.callids import Callids
+ from sfa.util.sfalogging import sfa_logger
+ from sfa.rspecs.sfa_rspec import sfa_rspec_version
+ from sfa.util.version import version_core
  
 +from threading import Thread
 +from time import sleep
 +
  ##
  # The data structure used to represent a cloud.
  # It contains the cloud name, its ip address, image information,
@@@ -215,36 -191,26 +218,27 @@@ def getEucaConnection()
  # @param sliceHRN The hunman readable name of the slice.
  # @return sting()
  #
- def getKeysForSlice(sliceHRN):
-     logger = logging.getLogger('EucaAggregate')
-     try:
-         # convert hrn to slice name
-         plSliceName = hrn_to_pl_slicename(sliceHRN)
-     except IndexError, e:
-         logger.error('Invalid slice name (%s)' % sliceHRN)
+ def getKeysForSlice(api, sliceHRN):
++    logger   = logging.getLogger('EucaAggregate')
+     cred     = api.getCredential()
+     registry = api.registries[api.hrn]
+     keys     = []
+     # Get the slice record
+     records = registry.Resolve(sliceHRN, cred)
+     if not records:
 -        print >>sys.stderr, 'Cannot find any record for slice %s' % sliceHRN
++        logging.warn('Cannot find any record for slice %s' % sliceHRN)
          return []
  
-     # Get the slice's information
-     sliceData = api.plshell.GetSlices(api.plauth, {'name':plSliceName})
-     if not sliceData:
-         logger.warn('Cannot get any data for slice %s' % plSliceName)
-         return []
+     # Find who can log into this slice
+     persons = records[0]['persons']
  
-     # It should only return a list with len = 1
-     sliceData = sliceData[0]
+     # Extract the keys from persons records
+     for p in persons:
+         sliceUser = registry.Resolve(p, cred)
+         userKeys = sliceUser[0]['keys']
+         keys += userKeys
  
-     keys = []
-     person_ids = sliceData['person_ids']
-     if not person_ids: 
-         logger.warn('No users in slice %s' % sliceHRN)
-         return []
-     persons = api.plshell.GetPersons(api.plauth, person_ids)
-     for person in persons:
-         pkeys = api.plshell.GetKeys(api.plauth, person['key_ids'])
-         for key in pkeys:
-             keys.append(key['key'])
-  
      return ''.join(keys)
  
  ##
@@@ -566,11 -533,12 +566,11 @@@ def CreateSliver(api, xrn, creds, xml, 
      conn.terminate_instances(pendingRmInst)
  
      # Process new instance requests
-     requests = rspecXML.findall('.//request')
+     requests = rspecXML.findall(".//request")
      if requests:
          # Get all the public keys associate with slice.
-         pubKeys = getKeysForSlice(s.slice_hrn)
+         pubKeys = getKeysForSlice(api, s.slice_hrn)
 -        print >>sys.stderr, "Passing the following keys to the instance:\n%s" % pubKeys
 -        sys.stderr.flush()
 +        logger.debug('Passing the following keys to the instance:\n%s' % pubKeys)
      for req in requests:
          vmTypeElement = req.getparent()
          instType = vmTypeElement.get('name')
      # with enough data for the client to understand what's happened
      return xml
  
 +##
 +# A thread that will update the meta data.
 +#
 +def updateMeta():
 +    logger = logging.getLogger('EucaAggregate')
 +    while True:
 +        sleep(120)
 +
 +        # Get IDs of the instances that don't have IPs yet.
 +        dbResults = Meta.select(
 +                      AND(Meta.q.pri_addr == None,
 +                          Meta.q.state    != 'deleted')
 +                    )
 +        dbResults = list(dbResults)
 +        logger.debug('[update thread] dbResults: %s' % dbResults)
 +        instids = []
 +        for r in dbResults:
 +            instids.append(r.instance.instance_id)
 +        logger.debug('[update thread] Instance Id: %s' % ', '.join(instids))
 +
 +        # Get instance information from Eucalyptus
 +        conn = getEucaConnection()
 +        vmInstances = []
 +        reservations = conn.get_all_instances(instids)
 +        for reservation in reservations:
 +            vmInstances += reservation.instances
 +
 +        # Check the IPs
 +        instIPs = [ {'id':i.id, 'pri_addr':i.private_dns_name, 'pub_addr':i.public_dns_name}
 +                    for i in vmInstances if i.private_dns_name != '0.0.0.0' ]
 +        logger.debug('[update thread] IP dict: %s' % str(instIPs))
 +
 +        # Update the local DB
 +        for ipData in instIPs:
 +            dbInst = EucaInstance.select(EucaInstance.q.instance_id == ipData['id']).getOne(None)
 +            if not dbInst:
 +                logger.info('[update thread] Could not find %s in DB' % ipData['id'])
 +                continue
 +            dbInst.meta.pri_addr = ipData['pri_addr']
 +            dbInst.meta.pub_addr = ipData['pub_addr']
 +            dbInst.meta.state    = 'running'
 +
+ def GetVersion(api):
+     xrn=Xrn(api.hrn)
+     request_rspec_versions = [dict(sfa_rspec_version)]
+     ad_rspec_versions = [dict(sfa_rspec_version)]
+     version_more = {'interface':'aggregate',
+                     'testbed':'myplc',
+                     'hrn':xrn.get_hrn(),
+                     'request_rspec_versions': request_rspec_versions,
+                     'ad_rspec_versions': ad_rspec_versions,
+                     'default_ad_rspec': dict(sfa_rspec_version)
+                     }
+     return version_core(version_more)
  def main():
      init_server()