Changeset d49c11c for fedd


Ignore:
Timestamp:
Aug 23, 2010 6:23:51 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
4875e93
Parents:
5c35160
Message:

Move to v2 PG CM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/protogeni_access.py

    r5c35160 rd49c11c  
    931931            slice_cred = segment_commands.pg_call(self.sa_url, 'Register',
    932932                    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)
    936946            # Populate the ssh keys (let PG format them)
    937947            param = {
     
    940950            keys =  segment_commands.pg_call(self.sa_url, 'GetKeys', param,
    941951                    ctxt)
    942             # Grab and redeem a ticket
     952            # Create a Sliver
    943953            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,
    956958                    }
    957959            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)
    970961        except segment_commands.ProtoGENIError, e:
    971962            raise service_error(service_error.federant,
    972963                    "ProtoGENI: %s %s" % (e.code, e))
    973964
    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):
    977969        """
    978970        Wait for the given slice to finish its startup.  Return the final
    979971        status.
    980972        """
    981         status = 'notready'
     973        completed_states = ('failed', 'ready')
     974        status = 'changing'
    982975        if timeout is not None:
    983976            end = time.time() + timeout
    984977        try:
    985             while status == 'notready':
     978            while status not in completed_states:
    986979                param = {
    987                         'credential': slice_cred
     980                        'credentials': [ sliver_cred ],
     981                        'slice_urn': slice_urn,
    988982                        }
    989983                r = segment_commands.pg_call(self.cm_url,
    990                         'SliceStatus', 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:
    993987                    if timeout is not None and time.time() > end:
    994988                        return 'timeout'
     
    1000994        return status
    1001995
    1002     def delete_slice(self, segment_commands, slice_cred, ctxt):
     996    def delete_slice(self, segment_commands, slice_cred, slice_urn, ctxt):
    1003997        """
    1004998        Delete the slice resources.  An error from the service is ignores,
     
    10061000        """
    10071001        try:
    1008             param = { 'credential': slice_cred }
     1002            param = {
     1003                    'credentials': [ slice_cred, ],
     1004                    'slice_urn': slice_urn,
     1005                    }
    10091006            segment_commands.pg_call(self.cm_url, 'DeleteSlice',
    10101007                    param, ctxt)
     
    10371034        slicename = self.get_free_slicename(segment_commands, user, gcred, ctxt)
    10381035        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(
    10401037                segment_commands, slicename, rspec, gcred, ctxt)
    10411038
     
    10621059
    10631060        # Now we wait for the nodes to start on PG
    1064         status = self.wait_for_slice(segment_commands, slice_cred, ctxt,
    1065                 timeout=300)
     1061        status = self.wait_for_slice(segment_commands, sliver_cred, slice_urn,
     1062                ctxt, timeout=300)
    10661063        if status == 'failed':
    10671064            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)
    10691066            return False
    10701067        elif status == 'timeout':
    10711068            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)
    10731070            return False
    10741071        else:
    10751072            # All good: save ProtoGENI info in shared state
    10761073            self.state_lock.acquire()
     1074            self.allocation[aid]['slice_urn'] = slice_urn
    10771075            self.allocation[aid]['slice_name'] = slicename
    10781076            self.allocation[aid]['slice_credential'] = slice_cred
     
    13551353
    13561354    def stop_segment(self, segment_commands, user, stagingdir, slice_cred,
    1357             certfile, certpw):
     1355            slice_urn, certfile, certpw):
    13581356        """
    13591357        Stop a sub experiment by calling swapexp on the federant
     
    13681366                self.log.error('Removing Sliver on ProtoGENI')
    13691367                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)
    13711369            return True
    13721370        except self.ssh_cmd_timeout:
     
    13901388            cf, user, ssh_key, cpw = self.allocation[aid]['credentials']
    13911389            slice_cred = self.allocation[aid].get('slice_credential', None)
     1390            slice_urn = self.allocation[aid].get('slice_urn', None)
    13921391            ename = self.allocation[aid].get('experiment', None)
    13931392        else:
     
    14061405                debug=self.create_debug, ch_url = self.ch_url,
    14071406                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)
    14091409        return { 'allocID': req['allocID'] }
    14101410
    1411     def renew_segment(self, segment_commands, name, scred, interval,
     1411    def renew_segment(self, segment_commands, name, scred, slice_urn, interval,
    14121412            certfile, certpw):
    14131413        """
     
    14451445            new_scred = segment_commands.pg_call(self.sa_url, 'GetCredential',
    14461446                    param, ctxt)
    1447             #f = open('./new_slice_cred', 'w')
    1448             #print >>f, new_scred
    1449             #f.close()
    14501447
    14511448        except segment_commands.ProtoGENIError, e:
     
    14551452            print 'Calling RenewSlice (CM)'
    14561453            param = {
    1457                     'credential': new_scred,
     1454                    'credentials': [new_scred,],
     1455                    'slice_urn': slice_urn,
    14581456                    }
    14591457            r = segment_commands.pg_call(self.cm_url, 'RenewSlice', param, ctxt)
     
    14751473                name = self.allocation[aid].get('slice_name', None)
    14761474                scred = self.allocation[aid].get('slice_credential', None)
     1475                slice_urn = self.allocation[aid].get('slice_urn', None)
    14771476                cf, user, ssh_key, cpw = self.allocation[aid]['credentials']
    14781477            else:
     
    14871486
    14881487            # There's a ProtoGENI slice associated with the segment; renew it.
    1489             if name and scred:
     1488            if name and scred and slice_urn:
    14901489                segment_commands = protogeni_proxy(log=self.log,
    14911490                        debug=self.create_debug, keyfile=ssh_key,
     
    14931492                        ch_url = self.ch_url)
    14941493                new_scred = self.renew_segment(segment_commands, name, scred,
    1495                         self.renewal_interval, cf, cpw)
     1494                        slice_urn, self.renewal_interval, cf, cpw)
    14961495                if new_scred:
    14971496                    self.log.info("Slice %s renewed until %s GMT" % \
Note: See TracChangeset for help on using the changeset viewer.