4 # This wrapper implements the Geni Registry and Slice Interfaces on PLC.
6 # There are several items that need to be done before starting the wrapper
9 # 1) Update util/config.py to match the parameters of your PLC installation.
11 # 2) Import the existing planetlab database, creating the
12 # appropriate geni records. This is done by running the "import.py" tool.
14 # 3) Create a "trusted_roots" directory and place the certificate of the root
15 # authority in that directory. Given the defaults in import.py, this certificate
16 # would be named "planetlab.gid". For example,
18 # mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/
28 from geniserver import *
30 from trustedroot import *
31 from hierarchy import *
34 from genitable import *
35 from geniticket import *
38 # Convert geni fields to PLC fields for use when registering up updating
39 # registry record in the PLC database
41 # @param type type of record (user, slice, ...)
42 # @param hrn human readable name
43 # @param geni_fields dictionary of geni fields
44 # @param pl_fields dictionary of PLC fields (output)
46 def geni_fields_to_pl_fields(type, hrn, geni_fields, pl_fields):
48 if not "email" in pl_fields:
49 if not "email" in geni_fields:
50 raise MissingGeniInfo("email")
51 pl_fields["email"] = geni_fields["email"]
53 if not "first_name" in pl_fields:
54 pl_fields["first_name"] = "geni"
56 if not "last_name" in pl_fields:
57 pl_fields["last_name"] = hrn
60 if not "instantiation" in pl_fields:
61 pl_fields["instantiation"] = "plc-instantiated"
62 if not "name" in pl_fields:
63 pl_fields["name"] = hrn_to_pl_slicename(hrn)
64 if not "max_nodes" in pl_fields:
65 pl_fields["max_nodes"] = 10
68 if not "hostname" in pl_fields:
69 if not "dns" in geni_fields:
70 raise MissingGeniInfo("dns")
71 pl_fields["hostname"] = geni_fields["dns"]
73 if not "model" in pl_fields:
74 pl_fields["model"] = "geni"
77 pl_fields["login_base"] = hrn_to_pl_login_base(hrn)
79 if not "name" in pl_fields:
80 pl_fields["name"] = hrn
82 if not "abbreviated_name" in pl_fields:
83 pl_fields["abbreviated_name"] = hrn
85 if not "enabled" in pl_fields:
86 pl_fields["enabled"] = True
88 if not "is_public" in pl_fields:
89 pl_fields["is_public"] = True
92 # Registry is a GeniServer that serves registry and slice operations at PLC.
94 class Registry(GeniServer):
96 # Create a new registry object.
98 # @param ip the ip address to listen on
99 # @param port the port to listen on
100 # @param key_file private key filename of registry
101 # @param cert_file certificate filename containing public key (could be a GID file)
103 def __init__(self, ip, port, key_file, cert_file):
104 GeniServer.__init__(self, ip, port, key_file, cert_file)
106 # get PL account settings from config module
107 self.pl_auth = get_pl_auth()
109 # connect to planetlab
110 if "Url" in self.pl_auth:
111 self.connect_remote_shell()
113 self.connect_local_shell()
116 # Connect to a remote shell via XMLRPC
118 def connect_remote_shell(self):
120 self.shell = remoteshell.RemoteShell()
123 # Connect to a local shell via local API functions
125 def connect_local_shell(self):
127 self.shell = PLC.Shell.Shell(globals = globals())
130 # Register the server RPCs for the registry
132 def register_functions(self):
133 GeniServer.register_functions(self)
135 self.server.register_function(self.create_gid)
136 self.server.register_function(self.get_self_credential)
137 self.server.register_function(self.get_credential)
138 self.server.register_function(self.get_gid)
139 self.server.register_function(self.register)
140 self.server.register_function(self.remove)
141 self.server.register_function(self.update)
142 self.server.register_function(self.list)
143 self.server.register_function(self.resolve)
146 self.server.register_function(self.get_ticket)
147 self.server.register_function(self.start_slice)
148 self.server.register_function(self.stop_slice)
149 self.server.register_function(self.reset_slice)
150 self.server.register_function(self.delete_slice)
153 # Given an authority name, return the information for that authority. This
154 # is basically a stub that calls the hierarchy module.
156 # @param auth_hrn human readable name of authority
158 def get_auth_info(self, auth_hrn):
159 return AuthHierarchy.get_auth_info(auth_hrn)
162 # Given an authority name, return the database table for that authority. If
163 # the database table does not exist, then one will be automatically
166 # @param auth_name human readable name of authority
168 def get_auth_table(self, auth_name):
169 auth_info = self.get_auth_info(auth_name)
171 table = GeniTable(hrn=auth_name,
172 cninfo=auth_info.get_dbinfo())
174 # if the table doesn't exist, then it means we haven't put any records
175 # into this authority yet.
177 if not table.exists():
178 report.trace("Registry: creating table for authority " + auth_name)
184 # Verify that an authority belongs to this registry. This is basically left
185 # up to the implementation of the hierarchy module. If the specified name
186 # does not belong to this registry, an exception is thrown indicating the
187 # caller should contact someone else.
189 # @param auth_name human readable name of authority
191 def verify_auth_belongs_to_me(self, name):
192 # get_auth_info will throw an exception if the authority does not
194 self.get_auth_info(name)
197 # Verify that an object belongs to this registry. By extension, this implies
198 # that the authority that owns the object belongs to this registry. If the
199 # object does not belong to this registry, then an exception is thrown.
201 # @param name human readable name of object
203 def verify_object_belongs_to_me(self, name):
204 auth_name = get_authority(name)
206 # the root authority belongs to the registry by default?
207 # TODO: is this true?
209 self.verify_auth_belongs_to_me(auth_name)
212 # Verify that the object_gid that was specified in the credential allows
213 # permission to the object 'name'. This is done by a simple prefix test.
214 # For example, an object_gid for planetlab.us.arizona would match the
215 # objects planetlab.us.arizona.slice1 and planetlab.us.arizona.
217 # @param name human readable name to test
219 def verify_object_permission(self, name):
220 object_hrn = self.object_gid.get_hrn()
221 if object_hrn == name:
223 if name.startswith(object_hrn + "."):
225 raise PermissionError(name)
228 # Fill in the planetlab-specific fields of a Geni record. This involves
229 # calling the appropriate PLC methods to retrieve the database record for
232 # PLC data is filled into the pl_info field of the record.
234 # @param record record to fill in fields (in/out param)
236 def fill_record_pl_info(self, record):
237 type = record.get_type()
238 pointer = record.get_pointer()
240 # records with pointer==-1 do not have plc info associated with them.
241 # for example, the top level authority records which are
242 # authorities, but not PL "sites"
246 if (type == "sa") or (type == "ma"):
247 pl_res = self.shell.GetSites(self.pl_auth, [pointer])
248 elif (type == "slice"):
249 pl_res = self.shell.GetSlices(self.pl_auth, [pointer])
250 elif (type == "user"):
251 pl_res = self.shell.GetPersons(self.pl_auth, [pointer])
252 elif (type == "node"):
253 pl_res = self.shell.GetNodes(self.pl_auth, [pointer])
255 raise UnknownGeniType(type)
258 # the planetlab record no longer exists
259 # TODO: delete the geni record ?
260 raise PlanetLabRecordDoesNotExist(record.get_name())
262 record.set_pl_info(pl_res[0])
265 # Look up user records given PLC user-ids. This is used as part of the
266 # process for reverse-mapping PLC records into Geni records.
268 # @param auth_table database table for the authority that holds the user records
269 # @param user_id_list list of user ids
270 # @param role either "*" or a string describing the role to look for ("pi", "user", ...)
272 # TODO: This function currently only searches one authority because it would
273 # be inefficient to brute-force search all authorities for a user id. The
274 # solution would likely be to implement a reverse mapping of user-id to
277 def lookup_users(self, auth_table, user_id_list, role="*"):
279 for person_id in user_id_list:
280 user_records = auth_table.find("user", person_id, "pointer")
281 for user_record in user_records:
282 self.fill_record_info(user_record)
284 user_roles = user_record.get_pl_info().get("roles")
285 if (role=="*") or (role in user_roles):
286 record_list.append(user_record.get_name())
290 # Fill in the geni-specific fields of the record.
292 # Note: It is assumed the fill_record_pl_info() has already been performed
295 def fill_record_geni_info(self, record):
297 type = record.get_type()
299 if (type == "slice"):
300 auth_table = self.get_auth_table(get_authority(record.get_name()))
301 person_ids = record.pl_info.get("person_ids", [])
302 researchers = self.lookup_users(auth_table, person_ids)
303 geni_info['researcher'] = researchers
306 auth_table = self.get_auth_table(record.get_name())
307 person_ids = record.pl_info.get("person_ids", [])
308 pis = self.lookup_users(auth_table, person_ids, "pi")
309 geni_info['pi'] = pis
310 # TODO: OrganizationName
313 auth_table = self.get_auth_table(record.get_name())
314 person_ids = record.pl_info.get("person_ids", [])
315 operators = self.lookup_users(auth_table, person_ids, "tech")
316 geni_info['operator'] = operators
317 # TODO: OrganizationName
319 auth_table = self.get_auth_table(record.get_name())
320 person_ids = record.pl_info.get("person_ids", [])
321 owners = self.lookup_users(auth_table, person_ids, "admin")
322 geni_info['owner'] = owners
324 elif (type == "node"):
325 geni_info['dns'] = record.pl_info.get("hostname", "")
326 # TODO: URI, LatLong, IP, DNS
328 elif (type == "user"):
329 geni_info['email'] = record.pl_info.get("email", "")
330 # TODO: PostalAddress, Phone
332 record.set_geni_info(geni_info)
335 # Given a Geni record, fill in the PLC-specific and Geni-specific fields
338 def fill_record_info(self, record):
339 self.fill_record_pl_info(record)
340 self.fill_record_geni_info(record)
345 # Register an object with the registry. In addition to being stored in the
346 # Geni database, the appropriate records will also be created in the
349 # @param cred credential string
350 # @param record_dict dictionary containing record fields
352 def register(self, cred, record_dict):
353 self.decode_authentication(cred, "register")
355 record = GeniRecord(dict = record_dict)
356 type = record.get_type()
357 name = record.get_name()
359 auth_name = get_authority(name)
360 self.verify_object_permission(auth_name)
361 auth_info = self.get_auth_info(auth_name)
362 table = self.get_auth_table(auth_name)
366 # check if record already exists
367 existing_records = table.resolve(type, name)
369 raise ExistingRecord(name)
371 if (type == "sa") or (type=="ma"):
373 if not AuthHierarchy.auth_exists(name):
374 AuthHierarchy.create_auth(name)
376 # authorities are special since they are managed by the registry
377 # rather than by the caller. We create our own GID for the
378 # authority rather than relying on the caller to supply one.
380 # get the GID from the newly created authority
381 child_auth_info = self.get_auth_info(name)
382 gid = auth_info.get_gid_object()
383 record.set_gid(gid.save_to_string(save_parents=True))
385 geni_fields = record.get_geni_info()
386 site_fields = record.get_pl_info()
388 # if registering a sa, see if a ma already exists
389 # if registering a ma, see if a sa already exists
391 other_rec = table.resolve("ma", record.get_name())
393 other_rec = table.resolve("sa", record.get_name())
396 print "linking ma and sa to the same plc site"
397 pointer = other_rec[0].get_pointer()
399 geni_fields_to_pl_fields(type, name, geni_fields, site_fields)
400 print "adding site with fields", site_fields
401 pointer = self.shell.AddSite(self.pl_auth, site_fields)
403 record.set_pointer(pointer)
405 elif (type == "slice"):
406 geni_fields = record.get_geni_info()
407 slice_fields = record.get_pl_info()
409 geni_fields_to_pl_fields(type, name, geni_fields, slice_fields)
411 pointer = self.shell.AddSlice(self.pl_auth, slice_fields)
412 record.set_pointer(pointer)
414 elif (type == "user"):
415 geni_fields = record.get_geni_info()
416 user_fields = record.get_pl_info()
418 geni_fields_to_pl_fields(type, name, geni_fields, user_fields)
420 pointer = self.shell.AddPerson(self.pl_auth, user_fields)
421 record.set_pointer(pointer)
423 elif (type == "node"):
424 geni_fields = record.get_geni_info()
425 node_fields = record.get_pl_info()
427 geni_fields_to_pl_fields(type, name, geni_fields, node_fields)
429 login_base = hrn_to_pl_login_base(auth_name)
431 print "calling addnode with", login_base, node_fields
432 pointer = self.shell.AddNode(self.pl_auth, login_base, node_fields)
433 record.set_pointer(pointer)
436 raise UnknownGeniType(type)
440 return record.get_gid_object().save_to_string(save_parents=True)
445 # Remove an object from the registry. If the object represents a PLC object,
446 # then the PLC records will also be removed.
448 # @param cred credential string
449 # @param record_dict dictionary containing record fields. The only relevant
450 # fields of the record are 'name' and 'type', which are used to lookup
451 # the current copy of the record in the Geni database, to make sure
452 # that the appopriate record is removed.
454 def remove(self, cred, record_dict):
455 self.decode_authentication(cred, "remove")
457 record = GeniRecord(dict = record_dict)
458 type = record.get_type()
460 self.verify_object_permission(record.get_name())
462 auth_name = get_authority(record.get_name())
463 table = self.get_auth_table(auth_name)
465 # let's not trust that the caller has a well-formed record (a forged
466 # pointer field could be a disaster), so look it up ourselves
467 record_list = table.resolve(type, record.get_name())
469 raise RecordNotFound(name)
470 record = record_list[0]
474 self.shell.DeletePerson(self.pl_auth, record.get_pointer())
475 elif type == "slice":
476 self.shell.DeleteSlice(self.pl_auth, record.get_pointer())
478 self.shell.DeleteNode(self.pl_auth, record.get_pointer())
479 elif (type == "sa") or (type == "ma"):
481 other_rec = table.resolve("ma", record.get_name())
483 other_rec = table.resolve("sa", record.get_name())
486 # sa and ma both map to a site, so if we are deleting one
487 # but the other still exists, then do not delete the site
488 print "not removing site", record.get_name(), "because either sa or ma still exists"
491 print "removing site", record.get_name()
492 self.shell.DeleteSite(self.pl_auth, record.get_pointer())
494 raise UnknownGeniType(type)
503 # Update an object in the registry. Currently, this only updates the
504 # PLC information associated with the record. The Geni fields (name, type,
507 # The record is expected to have the pl_info field filled in with the data
508 # that should be updated.
510 # TODO: The geni_info member of the record should be parsed and the pl_info
511 # adjusted as necessary (add/remove users from a slice, etc)
513 # @param cred credential string specifying rights of the caller
514 # @param record a record dictionary to be updated
516 def update(self, cred, record_dict):
517 self.decode_authentication(cred, "update")
519 record = GeniRecord(dict = record_dict)
520 type = record.get_type()
522 self.verify_object_permission(record.get_name())
524 auth_name = get_authority(record.get_name())
525 table = self.get_auth_table(auth_name)
527 # make sure the record exists
528 existing_record_list = table.resolve(type, record.get_name())
529 if not existing_record_list:
530 raise RecordNotFound(record.get_name())
532 existing_record = existing_record_list[0]
533 pointer = existing_record.get_pointer()
535 # update the PLC information that was specified with the record
537 if (type == "sa") or (type == "ma"):
538 self.shell.UpdateSite(self.pl_auth, pointer, record.get_pl_info())
540 elif type == "slice":
541 self.shell.UpdateSlice(self.pl_auth, pointer, record.get_pl_info())
544 self.shell.UpdatePerson(self.pl_auth, pointer, record.get_pl_info())
547 self.shell.UpdateNode(self.pl_auth, pointer, record.get_pl_info())
550 raise UnknownGeniType(type)
553 # List the records in an authority. The objectGID in the supplied credential
554 # should name the authority that will be listed.
556 # TODO: List doesn't take an hrn and uses the hrn contained in the
557 # objectGid of the credential. Does this mean the only way to list an
558 # authority is by having a credential for that authority?
560 # @param cred credential string specifying rights of the caller
562 # @return list of record dictionaries
563 def list(self, cred):
564 self.decode_authentication(cred, "list")
566 auth_name = self.object_gid.get_hrn()
567 table = self.get_auth_table(auth_name)
569 records = table.list()
572 for record in records:
574 self.fill_record_info(record)
575 good_records.append(record)
576 except PlanetLabRecordDoesNotExist:
577 # silently drop the ones that are missing in PL.
578 # is this the right thing to do?
579 report.error("ignoring geni record " + record.get_name() + " because pl record does not exist")
583 for record in good_records:
584 dicts.append(record.as_dict())
591 # Resolve a record. This is an internal version of the Resolve API call
592 # and returns records in record object format rather than dictionaries
593 # that may be sent over XMLRPC.
595 # @param type type of record to resolve (user | sa | ma | slice | node)
596 # @param name human readable name of object
597 # @param must_exist if True, throw an exception if no records are found
599 # @return a list of record objects, or an empty list []
601 def resolve_raw(self, type, name, must_exist=True):
602 auth_name = get_authority(name)
604 table = self.get_auth_table(auth_name)
606 records = table.resolve(type, name)
608 if (not records) and must_exist:
609 raise RecordNotFound(name)
612 for record in records:
614 self.fill_record_info(record)
615 good_records.append(record)
616 except PlanetLabRecordDoesNotExist:
617 # silently drop the ones that are missing in PL.
618 # is this the right thing to do?
619 report.error("ignoring geni record " + record.get_name() + " because pl record does not exist")
627 # This is a wrapper around resolve_raw that converts records objects into
628 # dictionaries before returning them to the user.
630 # @param cred credential string authorizing the caller
631 # @param name human readable name to resolve
633 # @return a list of record dictionaries, or an empty list
635 def resolve(self, cred, name):
636 self.decode_authentication(cred, "resolve")
638 records = self.resolve_raw("*", name)
640 for record in records:
641 dicts.append(record.as_dict())
648 # Retrieve the GID for an object. This function looks up a record in the
649 # registry and returns the GID of the record if it exists.
650 # TODO: Is this function needed? It's a shortcut for Resolve()
652 # @param name hrn to look up
654 # @return the string representation of a GID object
656 def get_gid(self, name):
657 self.verify_object_belongs_to_me(name)
658 records = self.resolve_raw("*", name)
660 for record in records:
661 gid = record.get_gid()
662 gid_string_list.append(gid.save_to_string(save_parents=True))
663 return gid_string_list
666 # Determine tje rights that an object should have. The rights are entirely
667 # dependent on the type of the object. For example, users automatically
668 # get "refresh", "resolve", and "info".
670 # @param type the type of the object (user | sa | ma | slice | node)
671 # @param name human readable name of the object (not used at this time)
673 # @return RightList object containing rights
675 def determine_rights(self, type, name):
678 # rights seem to be somewhat redundant with the type of the credential.
679 # For example, a "sa" credential implies the authority right, because
680 # a sa credential cannot be issued to a user who is not an owner of
691 elif type == "slice":
696 elif type == "component":
702 # GENI API: Get_self_credential
704 # Get_self_credential a degenerate version of get_credential used by a
705 # client to get his initial credential when he doesn't have one. This is
706 # the same as get_credential(..., cred=None,...).
708 # The registry ensures that the client is the principal that is named by
709 # (type, name) by comparing the public key in the record's GID to the
710 # private key used to encrypt the client-side of the HTTPS connection. Thus
711 # it is impossible for one principal to retrieve another principal's
712 # credential without having the appropriate private key.
714 # @param type type of object (user | slice | sa | ma | node
715 # @param name human readable name of object
717 # @return the string representation of a credential object
719 def get_self_credential(self, type, name):
720 self.verify_object_belongs_to_me(name)
722 auth_hrn = get_authority(name)
723 auth_info = self.get_auth_info(auth_hrn)
725 # find a record that matches
726 records = self.resolve_raw(type, name, must_exist=True)
729 gid = record.get_gid_object()
730 peer_cert = self.server.peer_cert
731 if not peer_cert.is_pubkey(gid.get_pubkey()):
732 raise ConnectionKeyGIDMismatch(gid.get_subject())
734 # create the credential
735 gid = record.get_gid_object()
736 cred = Credential(subject = gid.get_subject())
737 cred.set_gid_caller(gid)
738 cred.set_gid_object(gid)
739 cred.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
740 cred.set_pubkey(gid.get_pubkey())
742 rl = self.determine_rights(type, name)
743 cred.set_privileges(rl)
745 cred.set_parent(AuthHierarchy.get_auth_cred(auth_hrn))
750 return cred.save_to_string(save_parents=True)
753 # GENI API: Get_credential
755 # Retrieve a credential for an object.
757 # If cred==None, then the behavior reverts to get_self_credential()
759 # @param cred credential object specifying rights of the caller
760 # @param type type of object (user | slice | sa | ma | node)
761 # @param name human readable name of object
763 # @return the string representation of a credental object
765 def get_credential(self, cred, type, name):
767 return get_self_credential(self, type, name)
769 self.decode_authentication(cred, "getcredential")
771 self.verify_object_belongs_to_me(name)
773 auth_hrn = get_authority(name)
774 auth_info = self.get_auth_info(auth_hrn)
776 records = self.resolve_raw(type, name, must_exist=True)
779 # TODO: Check permission that self.client_cred can access the object
781 object_gid = record.get_gid_object()
782 new_cred = Credential(subject = object_gid.get_subject())
783 new_cred.set_gid_caller(self.client_gid)
784 new_cred.set_gid_object(object_gid)
785 new_cred.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
786 new_cred.set_pubkey(object_gid.get_pubkey())
788 rl = self.determine_rights(type, name)
789 new_cred.set_privileges(rl)
791 new_cred.set_parent(AuthHierarchy.get_auth_cred(auth_hrn))
796 return new_cred.save_to_string(save_parents=True)
799 # GENI_API: Create_gid
801 # Create a new GID. For MAs and SAs that are physically located on the
802 # registry, this allows a owner/operator/PI to create a new GID and have it
803 # signed by his respective authority.
805 # @param cred credential of caller
806 # @param name hrn for new GID
807 # @param uuid unique identifier for new GID
808 # @param pkey_string public-key string (TODO: why is this a string and not a keypair object?)
810 # @return the string representation of a GID object
812 def create_gid(self, cred, name, uuid, pubkey_str):
813 self.decode_authentication(cred, "getcredential")
815 self.verify_object_belongs_to_me(name)
817 self.verify_object_permission(name)
823 pkey.load_pubkey_from_string(pubkey_str)
824 gid = AuthHierarchy.create_gid(name, uuid, pkey)
826 return gid.save_to_string(save_parents=True)
828 # ------------------------------------------------------------------------
831 # All but get_ticket are currently stubbed out
835 # Convert a PLC record into the slice information that will be stored in
836 # a ticket. There are two parts to this information: attributes and
839 # Attributes are non-resource items, such as keys and the initscript
840 # Rspec is a set of resource specifications
842 # @param record a record object
844 # @return a tuple (attrs, rspec) of dictionaries
846 def record_to_slice_info(self, record):
848 # get the user keys from the slice
850 persons = self.shell.GetPersons(self.pl_auth, record.pl_info['person_ids'])
851 for person in persons:
852 person_keys = self.shell.GetKeys(self.pl_auth, person["key_ids"])
853 for person_key in person_keys:
854 keys = keys + [person_key['key']]
857 attributes['name'] = record.pl_info['name']
858 attributes['keys'] = keys
859 attributes['instantiation'] = record.pl_info['instantiation']
860 attributes['vref'] = 'default'
861 attributes['timestamp'] = time.time()
865 # get the PLC attributes and separate them into slice attributes and
868 filter['slice_id'] = record.pl_info['slice_id']
869 plc_attrs = self.shell.GetSliceAttributes(self.pl_auth, filter)
870 for attr in plc_attrs:
873 # initscripts: lookup the contents of the initscript and store it
874 # in the ticket attributes
875 if (name == "initscript"):
876 filter={'name': attr['value']}
877 initscripts = self.shell.GetInitScripts(self.pl_auth, filter)
879 attributes['initscript'] = initscripts[0]['script']
881 rspec[name] = attr['value']
883 return (attributes, rspec)
886 # GENI API: get_ticket
888 # Retrieve a ticket. This operation is currently implemented on PLC
889 # only (see SFA, engineering decisions); it is not implemented on
892 # The ticket is filled in with information from the PLC database. This
893 # information includes resources, and attributes such as user keys and
896 # @param cred credential string
897 # @param name name of the slice to retrieve a ticket for
898 # @param rspec resource specification dictionary
900 # @return the string representation of a ticket object
902 def get_ticket(self, cred, name, rspec):
903 self.decode_authentication(cred, "getticket")
905 self.verify_object_belongs_to_me(name)
907 self.verify_object_permission(name)
909 # XXX much of this code looks like get_credential... are they so similar
910 # that they should be combined?
912 auth_hrn = get_authority(name)
913 auth_info = self.get_auth_info(auth_hrn)
915 records = self.resolve_raw("slice", name, must_exist=True)
918 object_gid = record.get_gid_object()
919 new_ticket = Ticket(subject = object_gid.get_subject())
920 new_ticket.set_gid_caller(self.client_gid)
921 new_ticket.set_gid_object(object_gid)
922 new_ticket.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
923 new_ticket.set_pubkey(object_gid.get_pubkey())
925 self.fill_record_info(record)
927 (attributes, rspec) = self.record_to_slice_info(record)
929 new_ticket.set_attributes(attributes)
930 new_ticket.set_rspec(rspec)
932 new_ticket.set_parent(AuthHierarchy.get_auth_ticket(auth_hrn))
937 return new_ticket.save_to_string(save_parents=True)
940 # GENI API: stop_slice
944 # @param cred a credential identifying the caller (callerGID) and the slice
947 def stop_slice(self, cred_str):
948 self.decode_authentication(cred_str, "stopslice")
949 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
950 # TODO: stop the slice
953 # GENI API: start_slice
957 # @param cred a credential identifying the caller (callerGID) and the slice
960 def start_slice(self, cred_str):
961 self.decode_authentication(cred_str, "startslice")
962 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
963 # TODO: start the slice
966 # GENI API: reset_slice
970 # @param cred a credential identifying the caller (callerGID) and the slice
973 def reset_slice(self, cred_str):
974 self.decode_authentication(cred_str, "resetslice")
975 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
976 # TODO: reset the slice
979 # GENI API: delete_slice
983 # @param cred a credential identifying the caller (callerGID) and the slice
986 def delete_slice(self, cred_str):
987 self.decode_authentication(cred_str, "deleteslice")
988 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
989 # TODO: delete the slice
993 if __name__ == "__main__":
997 key_file = "server.key"
998 cert_file = "server.cert"
1000 # if no key is specified, then make one up
1001 if (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
1002 key = Keypair(create=True)
1003 key.save_to_file(key_file)
1005 cert = Certificate(subject="registry")
1006 cert.set_issuer(key=key, subject="registry")
1007 cert.set_pubkey(key)
1009 cert.save_to_file(cert_file)
1011 AuthHierarchy = Hierarchy()
1013 TrustedRoots = TrustedRootList()
1015 s = Registry("", 12345, key_file, cert_file)
1016 s.trusted_cert_list = TrustedRoots.get_list()