from sqlobject import *
from sfa.util.faults import *
-from sfa.util.xrn import urn_to_hrn
+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.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
##
# The data structure used to represent a cloud.
# @param sliceHRN The hunman readable name of the slice.
# @return sting()
#
-def getKeysForSlice(sliceHRN):
- try:
- # convert hrn to slice name
- plSliceName = hrn_to_pl_slicename(sliceHRN)
- except IndexError, e:
- print >>sys.stderr, 'Invalid slice name (%s)' % sliceHRN
- return []
-
- # Get the slice's information
- sliceData = api.plshell.GetSlices(api.plauth, {'name':plSliceName})
- if not sliceData:
- print >>sys.stderr, 'Cannot get any data for slice %s' % plSliceName
+def getKeysForSlice(api, sliceHRN):
+ 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
return []
- # It should only return a list with len = 1
- sliceData = sliceData[0]
+ # Find who can log into this slice
+ persons = records[0]['persons']
- keys = []
- person_ids = sliceData['person_ids']
- if not person_ids:
- print >>sys.stderr, 'No users in slice %s' % sliceHRN
- return []
+ # Extract the keys from persons records
+ for p in persons:
+ sliceUser = registry.Resolve(p, cred)
+ userKeys = sliceUser[0]['keys']
+ keys += userKeys
- 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)
##
xml = self.eucaRSpec
cloud = self.cloudInfo
with xml.RSpec(type='eucalyptus'):
- with xml.cloud(id=cloud['name']):
+ with xml.network(id=cloud['name']):
with xml.ipv4:
xml << cloud['ip']
#self.__keyPairsXML(cloud['keypairs'])
return clusterList
-def get_rspec(api, creds, options, call_id):
- if not Callids().should_handle_call_id(call_id): return ""
+def ListResources(api, creds, options, call_id):
+ if Callids().already_handled(call_id): return ""
global cloud
# get slice's hrn from options
xrn = options.get('geni_slice_urn', '')
# get hrn of the original caller
origin_hrn = options.get('origin_hrn', None)
if not origin_hrn:
- origin_hrn = Credential(string=creds[0]).get_gid_caller().get_hrn()
+ origin_hrn = Credential(string=creds).get_gid_caller().get_hrn()
+ # origin_hrn = Credential(string=creds[0]).get_gid_caller().get_hrn()
conn = getEucaConnection()
"""
Hook called via 'sfi.py create'
"""
-def create_slice(api, xrn, creds, xml, users):
+def CreateSliver(api, xrn, creds, xml, users, call_id):
+ if Callids().already_handled(call_id): return ""
+
global cloud
hrn = urn_to_hrn(xrn)[0]
conn = getEucaConnection()
if not conn:
print >>sys.stderr, 'Error: Cannot create a connection to Eucalyptus'
- return False
+ return ""
# Validate RSpec
schemaXML = ET.parse(EUCALYPTUS_RSPEC_SCHEMA)
rspecValidator = ET.RelaxNG(schemaXML)
rspecXML = ET.XML(xml)
+ for network in rspecXML.iterfind("./network"):
+ if network.get('id') != cloud['name']:
+ # Throw away everything except my own RSpec
+ # sfa_logger().error("CreateSliver: deleting %s from rspec"%network.get('id'))
+ network.getparent().remove(network)
if not rspecValidator(rspecXML):
error = rspecValidator.error_log.last_error
message = '%s (line %s)' % (error.message, error.line)
pendingRmInst = []
for sliceInst in s.instances:
pendingRmInst.append(sliceInst.instance_id)
- existingInstGroup = rspecXML.findall('.//euca_instances')
+ existingInstGroup = rspecXML.findall(".//euca_instances")
for instGroup in existingInstGroup:
for existingInst in instGroup:
if existingInst.get('id') in pendingRmInst:
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()
for req in requests:
inst_type = instType)
eucaInst.reserveInstance(conn, pubKeys)
- return True
+ # xxx - should return altered rspec
+ # with enough data for the client to understand what's happened
+ return xml
+
+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()
#theRSpec = None
#with open(sys.argv[1]) as xml:
# theRSpec = xml.read()
- #create_slice(None, 'planetcloud.pc.test', theRSpec)
+ #CreateSliver(None, 'planetcloud.pc.test', theRSpec, 'call-id-cloudtest')
- #rspec = get_rspec('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
+ #rspec = ListResources('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
#print rspec
- print getKeysForSlice('gc.gc.test1')
+
+ 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()