def GetVenueDataStore(venueURL, connectionId):
    """
    Return the default venue datastore for the given venue URL.
    """

    vproxy = VenueIW(venueURL)
    #vproxy = Client.SecureHandle(venueURL).GetProxy()
    #log.info("Connecting to venue %s, to get datastore information.", venueURL)

    try:
        ds = vproxy.GetDataStoreInformation()
    except:
        log.exception("Couldn't get data store information from the venue.")
        return None

    # Catch failed return
    if not ds:
        return None

    upload = ds[0]
    store = ds[1]

    dsc = DataStoreClient(upload, venueURL, connectionId)

    return dsc
 def __init__(self, uploadURL, venueUrl, connectionId=None):
     self.venueUrl = venueUrl
     self.uploadURL = uploadURL
     self.venueProxy = VenueIW(
         venueUrl)  #Client.SecureHandle(venueUrl).GetProxy()
     self.connectionId = connectionId
     self.LoadData()
    def RegisterWithVenues(self, urls):
        '''
        Registers this network service with venues contained in the urls list.
        If no url list is specified, use venue url command line option.

        ** Arguments **

        * urls * list of venue urls. 
        '''
        if type(urls) != list:
            raise Exception, 'AGNetworkService.RegisterWithVenues: urls argument has to be a list of venue urls.'
        
        # Create a NetworkServiceDescription and register with the venue. 
        for url in urls:
            self.venueProxies[url] = VenueIW(url)
            nsd = self.CreateDescription()

            try:
                self.venueProxies[url].RegisterNetworkService(nsd)
                self.log.debug("AGNetworkService.Register: Register with venue %s" %(url))
            except:
                self.log.exception("AGNetworkService.Register: RegisterNetworkService with venue %s failed for %s"%(url, nsd))
def main():
    """
    This is the function that does all the real work.
    """
    app = CmdlineApplication.instance()
    app.Initialize("CreateVenues")

    venueServerUri = "https://localhost:8000/VenueServer"

    if len(sys.argv) > 2:
        venueServerUri = sys.argv[2]

    configFile = sys.argv[1]

    venueServer = VenueServerIW(venueServerUri, tracefile=sys.stdout)
    #venueServer.SetEncryptAllMedia(0)

    config = ConfigParser.ConfigParser()
    config.read(configFile)
    venues = {}

    # Start up the logging
    log = Log.GetLogger("CreateVenues")
    hdlr = Log.StreamHandler()
    hdlr.setLevel(Log.INFO)
    Log.HandleLoggers(hdlr, Log.GetDefaultLoggers())

    # We do this in two iterations because we need valid URLs for connections
    for sec in config.sections():
        # Build Venue Descriptions
        vdesc = VenueDescription3(config.get(sec, 'name'),
                                  config.get(sec, 'description'))
        vdesc.streams = []

        # Static Video
        if config.has_option(sec, 'video'):
            (host, port) = string.split(config.get(sec, 'video'), ':')
            vcap = Capability3(Capability.PRODUCER, Capability.VIDEO)
            vsd = StreamDescription3(
                vdesc.name,
                MulticastNetworkLocation(host.strip(), int(port), 127), vcap,
                0, None, 1)
            vdesc.streams.append(vsd)

        # Static Audio
        if config.has_option(sec, 'audio'):
            (host, port) = string.split(config.get(sec, 'audio'), ':')
            acap = Capability3(Capability3.PRODUCER, Capability3.AUDIO)
            asd = StreamDescription3(
                vdesc.name,
                MulticastNetworkLocation(host.strip(), int(port), 127), acap,
                0, None, 1)
            vdesc.streams.append(asd)

        # Make the venue, then store the resulting URL
        print "VD #%s : %s" % (sec, vdesc.name)
        vdesc.uri = venueServer.AddVenue(vdesc)
        config.set(sec, 'uri', vdesc.uri)

        if config.has_option(sec, 'default'):
            venueServer.SetDefaultVenue(vdesc.id)

        venues[sec] = vdesc

    for sec in config.sections():
        # Build up connections
        exits = string.split(config.get(sec, 'exits'), ', ')
        for vexit in exits:
            if venues.has_key(vexit):
                toVenue = venues[vexit]
                uri = toVenue.uri
                conn = ConnectionDescription(toVenue.name, toVenue.description,
                                             toVenue.uri)
                venues[sec].connections.append(conn)
            else:
                print "Error making connection to venue: ", vexit

        # Set the connections on the given venue
        print "CD #%s/%s: %s" % (sec, venues[sec].name, config.get(
            sec, 'exits'))

        # venue = Client.Handle(venues[sec].uri).GetProxy()
        print "URL: %s" % venues[sec].uri
        venue = VenueIW(venues[sec].uri, tracefile=sys.stdout)
        venue.SetConnections(venues[sec].connections)
               
        def Transform(self, streamList):
            """
            Method for legacy support for AG 3.0.2. clients
            """
            return []

        def Transform3(self, streamList):
            return []


    # Create the network service.
    service = FakeService('FakeService')

    # Test venue soap interface.
    vProxy = VenueIW('https://localhost:8000/Venues/default')
    nsd = AGNetworkServiceDescription(service.name, service.description, service.url,
                                              service.capabilities, service.version)
            
    vProxy.RegisterNetworkService(nsd)
    services = vProxy.GetNetworkServices()
    if services[0].url != nsd.url:
        raise Exception, 'venue.RegisterNetworkService failed'

    vProxy.UnRegisterNetworkService(nsd)
    services = vProxy.GetNetworkServices()
    if len(services) != 0:
        raise Exception, 'venue.UnRegisterNetworkService failed'
    
    # Test network service interface.
    service.RegisterWithVenueServer('https://localhost:8000/VenueServer')
Exemplo n.º 6
0
import socket
from AccessGrid.Toolkit import CmdlineApplication
from AccessGrid.interfaces.Venue_client import VenueIW

from AccessGrid.hosting import HostingException
from AccessGrid.hosting import GetHostingExceptionModuleAndClassName, ReraiseHostingException, GetHostingException, NotAuthorized, NoSuchService

app = CmdlineApplication.instance()
app.Initialize("ServiceTest")

try:
    url = sys.argv[1]
except:
    url = "https://localhost:8000/Venues/defa"  # last letter is missing so an exception is raised

proxy = VenueIW(url)

try:
    desc = proxy.AsVenueDescription()
    print "Description:?", desc
except HostingException, e:
    #print e
    print "++++"
    print GetHostingExceptionModuleAndClassName(e)
    print "===="
    print GetHostingException(e)
    print "****"
    try:
        ReraiseHostingException(e)
    except NotAuthorized, e:
        print "caught reraised NotAuthorized exception"
class DataStoreClient:
    """
    Client interface API for a venue datastore.

    Currently we wrap the basic datastore upload/download and
    file listing methods.
    """
    def __init__(self, uploadURL, venueUrl, connectionId=None):
        self.venueUrl = venueUrl
        self.uploadURL = uploadURL
        self.venueProxy = VenueIW(
            venueUrl)  #Client.SecureHandle(venueUrl).GetProxy()
        self.connectionId = connectionId
        self.LoadData()

    def LoadData(self):
        """
        Load the local data descriptor cache from the datastore.
        """

        descList = self.venueProxy.GetDataDescriptions()

        self.dataCache = []
        self.dataIndex = {}

        #
        # the data index is keyed on the name.
        # this will break with duplicate names, so we need
        # to fix that when that becomes possible.
        #
        if descList:

            for desc in descList:
                self.dataCache.append(desc)
                self.dataIndex[desc.name] = desc

    def QueryMatchingFilesMultiple(self, patternList):

        fnames = {}
        for pat in patternList:
            match = self.QueryMatchingFiles(pat)
            for m in match:
                fnames[m] = 1
        files = fnames.keys()

        return files

    def QueryMatchingFiles(self, pattern):
        """
        Return a list of filenames that match the given pattern.
        Pattern is a unix-style filename wildcard.
        """
        ret = []
        for data in self.dataCache:
            fname = data.name
            if fnmatch.fnmatchcase(fname, pattern):
                ret.append(str(fname))

        return ret

    def GetFileData(self, filename):
        if filename in self.dataIndex:
            return self.dataIndex[filename]
        else:
            raise FileNotFound

    def Download(self, filename, localFile):
        """
        Download filename to local file localFile.
        """

        if filename in self.dataIndex:
            data = self.dataIndex[filename]
            url = data.uri
            print "URL: ", url
            my_identity = str(Application.instance().GetDefaultSubject())
            user = str(url.split('/')[3])
            passw = str(self.connectionId)
            DataStore.DownloadFile(my_identity, url, localFile, data.size,
                                   data.checksum, user, passw)
        else:
            raise FileNotFound

    def Upload(self, localFile):
        """
        Upload localFile to the venue datastore.
        """

        try:
            #log.debug("Upload %s to %s", localFile, self.uploadURL)
            my_identity = str(Application.instance().GetDefaultSubject())
            user = str(self.uploadURL.split('/')[-1])
            passw = str(self.connectionId)
            DataStore.UploadFiles(my_identity, self.uploadURL, [localFile],
                                  user, passw)
        except DataStore.UploadFailed, e:
            #rc, errlist = e.args[0]
            #for err in errlist:
            #    print err
            raise e