- Timestamp:
- Aug 23, 2010 6:23:51 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 4875e93
- Parents:
- 5c35160
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/protogeni_access.py
r5c35160 rd49c11c 931 931 slice_cred = segment_commands.pg_call(self.sa_url, 'Register', 932 932 param, ctxt) 933 #f = open("./slice_cred", "w") 934 #print >>f, slice_cred 935 #f.close() 933 # Resolve the slice to get the URN that PG has assigned it. 934 param = { 935 'credential': gcred, 936 'type': 'Slice', 937 'hrn': slicename 938 } 939 data = segment_commands.pg_call(self.sa_url, 'Resolve', param, 940 ctxt) 941 if 'urn' in data: 942 slice_urn = data['urn'] 943 else: 944 raise service_error(service_error.federant, 945 "No URN returned for slice %s" % hrn) 936 946 # Populate the ssh keys (let PG format them) 937 947 param = { … … 940 950 keys = segment_commands.pg_call(self.sa_url, 'GetKeys', param, 941 951 ctxt) 942 # Grab and redeem a ticket952 # Create a Sliver 943 953 param = { 944 'credential': slice_cred, 945 'rspec': rspec, 946 } 947 ticket = segment_commands.pg_call(self.cm_url, 'GetTicket', param, 948 ctxt) 949 #f = open("./ticket", "w") 950 #print >>f, ticket 951 #f.close() 952 param = { 953 'credential': slice_cred, 954 'keys': keys, 955 'ticket': ticket, 954 'credentials': [ slice_cred ], 955 'rspec': rspec, 956 'keys': keys, 957 'slice_urn': slice_urn, 956 958 } 957 959 sliver_cred, manifest = segment_commands.pg_call(self.cm_url, 958 'RedeemTicket', param, ctxt) 959 #f = open("./sliver_cred", "w") 960 #print >>f, sliver_cred 961 #f.close() 962 #f = open("./manifest", "w") 963 #print >>f, manifest 964 #f.close() 965 # start 'em up 966 param = { 967 'credential': sliver_cred, 968 } 969 segment_commands.pg_call(self.cm_url, 'StartSliver', param, ctxt) 960 'CreateSliver', param, ctxt) 970 961 except segment_commands.ProtoGENIError, e: 971 962 raise service_error(service_error.federant, 972 963 "ProtoGENI: %s %s" % (e.code, e)) 973 964 974 return (slice_cred, sliver_cred, manifest) 975 976 def wait_for_slice(self, segment_commands, slice_cred, ctxt, timeout=None): 965 return (slice_urn, slice_cred, sliver_cred, manifest) 966 967 def wait_for_slice(self, segment_commands, sliver_cred, slice_urn, ctxt, 968 timeout=None): 977 969 """ 978 970 Wait for the given slice to finish its startup. Return the final 979 971 status. 980 972 """ 981 status = 'notready' 973 completed_states = ('failed', 'ready') 974 status = 'changing' 982 975 if timeout is not None: 983 976 end = time.time() + timeout 984 977 try: 985 while status == 'notready':978 while status not in completed_states: 986 979 param = { 987 'credential': slice_cred 980 'credentials': [ sliver_cred ], 981 'slice_urn': slice_urn, 988 982 } 989 983 r = segment_commands.pg_call(self.cm_url, 990 'Sli ceStatus', param, ctxt)991 status = r.get('status', ' notready')992 if status == 'notready':984 'SliverStatus', param, ctxt) 985 status = r.get('status', 'changing') 986 if status not in completed_states: 993 987 if timeout is not None and time.time() > end: 994 988 return 'timeout' … … 1000 994 return status 1001 995 1002 def delete_slice(self, segment_commands, slice_cred, ctxt):996 def delete_slice(self, segment_commands, slice_cred, slice_urn, ctxt): 1003 997 """ 1004 998 Delete the slice resources. An error from the service is ignores, … … 1006 1000 """ 1007 1001 try: 1008 param = { 'credential': slice_cred } 1002 param = { 1003 'credentials': [ slice_cred, ], 1004 'slice_urn': slice_urn, 1005 } 1009 1006 segment_commands.pg_call(self.cm_url, 'DeleteSlice', 1010 1007 param, ctxt) … … 1037 1034 slicename = self.get_free_slicename(segment_commands, user, gcred, ctxt) 1038 1035 self.log.info("Creating %s" % slicename) 1039 slice_ cred, sliver_cred, manifest = self.allocate_slice(1036 slice_urn, slice_cred, sliver_cred, manifest = self.allocate_slice( 1040 1037 segment_commands, slicename, rspec, gcred, ctxt) 1041 1038 … … 1062 1059 1063 1060 # Now we wait for the nodes to start on PG 1064 status = self.wait_for_slice(segment_commands, sli ce_cred, ctxt,1065 timeout=300)1061 status = self.wait_for_slice(segment_commands, sliver_cred, slice_urn, 1062 ctxt, timeout=300) 1066 1063 if status == 'failed': 1067 1064 self.log.error('Sliver failed to start on ProtoGENI') 1068 self.delete_slice(segment_commands, slice_cred, ctxt)1065 self.delete_slice(segment_commands, slice_cred, slice_urn, ctxt) 1069 1066 return False 1070 1067 elif status == 'timeout': 1071 1068 self.log.error('Sliver failed to start on ProtoGENI (timeout)') 1072 self.delete_slice(segment_commands, slice_cred, ctxt)1069 self.delete_slice(segment_commands, slice_cred, slice_urn, ctxt) 1073 1070 return False 1074 1071 else: 1075 1072 # All good: save ProtoGENI info in shared state 1076 1073 self.state_lock.acquire() 1074 self.allocation[aid]['slice_urn'] = slice_urn 1077 1075 self.allocation[aid]['slice_name'] = slicename 1078 1076 self.allocation[aid]['slice_credential'] = slice_cred … … 1355 1353 1356 1354 def stop_segment(self, segment_commands, user, stagingdir, slice_cred, 1357 certfile, certpw):1355 slice_urn, certfile, certpw): 1358 1356 """ 1359 1357 Stop a sub experiment by calling swapexp on the federant … … 1368 1366 self.log.error('Removing Sliver on ProtoGENI') 1369 1367 ctxt = fedd_ssl_context(my_cert=certfile, password=certpw) 1370 self.delete_slice(segment_commands, slice_cred, ctxt)1368 self.delete_slice(segment_commands, slice_cred, slice_urn, ctxt) 1371 1369 return True 1372 1370 except self.ssh_cmd_timeout: … … 1390 1388 cf, user, ssh_key, cpw = self.allocation[aid]['credentials'] 1391 1389 slice_cred = self.allocation[aid].get('slice_credential', None) 1390 slice_urn = self.allocation[aid].get('slice_urn', None) 1392 1391 ename = self.allocation[aid].get('experiment', None) 1393 1392 else: … … 1406 1405 debug=self.create_debug, ch_url = self.ch_url, 1407 1406 sa_url=self.sa_url, cm_url=self.cm_url) 1408 self.stop_segment(segment_commands, user, staging, slice_cred, cf, cpw) 1407 self.stop_segment(segment_commands, user, staging, slice_cred, 1408 slice_urn, cf, cpw) 1409 1409 return { 'allocID': req['allocID'] } 1410 1410 1411 def renew_segment(self, segment_commands, name, scred, interval,1411 def renew_segment(self, segment_commands, name, scred, slice_urn, interval, 1412 1412 certfile, certpw): 1413 1413 """ … … 1445 1445 new_scred = segment_commands.pg_call(self.sa_url, 'GetCredential', 1446 1446 param, ctxt) 1447 #f = open('./new_slice_cred', 'w')1448 #print >>f, new_scred1449 #f.close()1450 1447 1451 1448 except segment_commands.ProtoGENIError, e: … … 1455 1452 print 'Calling RenewSlice (CM)' 1456 1453 param = { 1457 'credential': new_scred, 1454 'credentials': [new_scred,], 1455 'slice_urn': slice_urn, 1458 1456 } 1459 1457 r = segment_commands.pg_call(self.cm_url, 'RenewSlice', param, ctxt) … … 1475 1473 name = self.allocation[aid].get('slice_name', None) 1476 1474 scred = self.allocation[aid].get('slice_credential', None) 1475 slice_urn = self.allocation[aid].get('slice_urn', None) 1477 1476 cf, user, ssh_key, cpw = self.allocation[aid]['credentials'] 1478 1477 else: … … 1487 1486 1488 1487 # There's a ProtoGENI slice associated with the segment; renew it. 1489 if name and scred :1488 if name and scred and slice_urn: 1490 1489 segment_commands = protogeni_proxy(log=self.log, 1491 1490 debug=self.create_debug, keyfile=ssh_key, … … 1493 1492 ch_url = self.ch_url) 1494 1493 new_scred = self.renew_segment(segment_commands, name, scred, 1495 s elf.renewal_interval, cf, cpw)1494 slice_urn, self.renewal_interval, cf, cpw) 1496 1495 if new_scred: 1497 1496 self.log.info("Slice %s renewed until %s GMT" % \
Note: See TracChangeset
for help on using the changeset viewer.