Beispiel #1
0
def get_ticket(api, xrn, creds, rspec, users):

    reg_objects = __get_registry_objects(xrn, creds, users)

    slice_hrn, type = urn_to_hrn(xrn)
    slices = Slices(api)
    peer = slices.get_peer(slice_hrn)
    sfa_peer = slices.get_sfa_peer(slice_hrn)

    # get the slice record
    registry = api.registries[api.hrn]
    credential = api.getCredential()
    records = registry.Resolve(xrn, credential)

    # similar to CreateSliver, we must verify that the required records exist
    # at this aggregate before we can issue a ticket
    site_id, remote_site_id = slices.verify_site(registry, credential, slice_hrn,
                                                 peer, sfa_peer, reg_objects)
    slice = slices.verify_slice(registry, credential, slice_hrn, site_id,
                                remote_site_id, peer, sfa_peer, reg_objects)

    # make sure we get a local slice record
    record = None
    for tmp_record in records:
        if tmp_record['type'] == 'slice' and \
           not tmp_record['peer_authority']:
            record = SliceRecord(dict=tmp_record)
    if not record:
        raise RecordNotFound(slice_hrn)

    # get sliver info
    slivers = Slices(api).get_slivers(slice_hrn)
    if not slivers:
        raise SliverDoesNotExist(slice_hrn)

    # get initscripts
    initscripts = []
    data = {
        'timestamp': int(time.time()),
        'initscripts': initscripts,
        'slivers': slivers
    }

    # create the ticket
    object_gid = record.get_gid_object()
    new_ticket = SfaTicket(subject = object_gid.get_subject())
    new_ticket.set_gid_caller(api.auth.client_gid)
    new_ticket.set_gid_object(object_gid)
    new_ticket.set_issuer(key=api.key, subject=api.hrn)
    new_ticket.set_pubkey(object_gid.get_pubkey())
    new_ticket.set_attributes(data)
    new_ticket.set_rspec(rspec)
    #new_ticket.set_parent(api.auth.hierarchy.get_auth_ticket(auth_hrn))
    new_ticket.encode()
    new_ticket.sign()

    return new_ticket.save_to_string(save_parents=True)
Beispiel #2
0
def prepare_slice(api, slice_xrn, creds, users):
    reg_objects = __get_registry_objects(slice_xrn, creds, users)
    (hrn, type) = urn_to_hrn(slice_xrn)
    slices = Slices(api)
    peer = slices.get_peer(hrn)
    sfa_peer = slices.get_sfa_peer(hrn)
    slice_record=None
    if users:
        slice_record = users[0].get('slice_record', {})
    registry = api.registries[api.hrn]
    credential = api.getCredential()
    # ensure site record exists
    site = slices.verify_site(hrn, slice_record, peer, sfa_peer)
    # ensure slice record exists
    slice = slices.verify_slice(hrn, slice_record, peer, sfa_peer)
    # ensure person records exists
    persons = slices.verify_persons(hrn, slice, users, peer, sfa_peer)
def CreateSliver(api, xrn, creds, xml, users, call_id):
    """
    Verify HRN and initialize the slice record in PLC if necessary.
    """

    if Callids().already_handled(call_id): return ""

    hrn, type = urn_to_hrn(xrn)
    peer = None
    reg_objects = __get_registry_objects(xrn, creds, users)
    slices = Slices(api)
    peer = slices.get_peer(hrn)
    sfa_peer = slices.get_sfa_peer(hrn)
    registries = Registries(api)
    registry = registries[api.hrn]
    credential = api.getCredential()
    site_id, remote_site_id = slices.verify_site(registry, credential, hrn, 
                                                 peer, sfa_peer, reg_objects)
    slice = slices.verify_slice(registry, credential, hrn, site_id, 
                                remote_site_id, peer, sfa_peer, reg_objects)

    network = ViniNetwork(api)

    slice = network.get_slice(api, hrn)
    current = __get_hostnames(slice.get_nodes())

    network.addRSpec(xml, "/var/www/html/schemas/vini.rng")
    #network.addRSpec(xml, "/root/SVN/sfa/trunk/sfa/managers/vini/vini.rng")
    request = __get_hostnames(network.nodesWithSlivers())
    
    # remove nodes not in rspec
    deleted_nodes = list(set(current).difference(request))

    # add nodes from rspec
    added_nodes = list(set(request).difference(current))

    api.plshell.AddSliceToNodes(api.plauth, slice.name, added_nodes) 
    api.plshell.DeleteSliceFromNodes(api.plauth, slice.name, deleted_nodes)
    network.updateSliceTags()

    # xxx - check this holds enough data for the client to understand what's happened
    return network.toxml()
Beispiel #4
0
def CreateSliver(api, slice_xrn, creds, rspec_string, users, call_id):
    """
    Create the sliver[s] (slice) at this aggregate.    
    Verify HRN and initialize the slice record in PLC if necessary.
    """
    if Callids().already_handled(call_id): return ""

    aggregate = Aggregate(api)
    slices = Slices(api)
    (hrn, type) = urn_to_hrn(slice_xrn)
    peer = slices.get_peer(hrn)
    sfa_peer = slices.get_sfa_peer(hrn)
    slice_record=None    
    if users:
        slice_record = users[0].get('slice_record', {})

    # parse rspec
    rspec = RSpec(rspec_string)
    requested_attributes = rspec.version.get_slice_attributes()
    
    # ensure site record exists
    site = slices.verify_site(hrn, slice_record, peer, sfa_peer)
    # ensure slice record exists
    slice = slices.verify_slice(hrn, slice_record, peer, sfa_peer)
    # ensure person records exists
    persons = slices.verify_persons(hrn, slice, users, peer, sfa_peer)
    # ensure slice attributes exists
    slices.verify_slice_attributes(slice, requested_attributes)
    
    # add/remove slice from nodes
    requested_slivers = [str(host) for host in rspec.version.get_nodes_with_slivers()]
    slices.verify_slice_nodes(slice, requested_slivers, peer) 

    # hanlde MyPLC peer association.
    # only used by plc and ple.
    slices.handle_peer(site, slice, persons, peer)
    
    return aggregate.get_rspec(slice_xrn=slice_xrn, version=rspec.version)