def ifmap_read(mapclient, ifmap_id, srch_meta, result_meta, field_names=None): start_id = str( Identity(name=ifmap_id, type='other', other_type='extended')) def _search(start_id, match_meta=None, result_meta=None, max_depth=1): # set ifmap search parmeters srch_params = {} srch_params['max-depth'] = str(max_depth) srch_params['max-size'] = '50000000' if match_meta is not None: srch_params['match-links'] = match_meta if result_meta is not None: # all => don't set result-filter, so server returns all id + meta if result_meta == "all": pass else: srch_params['result-filter'] = result_meta else: # default to return match_meta metadata types only srch_params['result-filter'] = match_meta srch_req = SearchRequest(mapclient.get_session_id(), start_id, search_parameters=srch_params ) result = mapclient.call('search', srch_req) return result # end _search return _search(start_id, srch_meta, result_meta, max_depth=10)
def subscribe_root(ssrc_mapc): #self._ident_type_subscribe(_CLOUD_IMID, "ct:member-of") ident = str(Identity(name=_ROOT_IMID, type="other", other_type="extended")) subreq = SubscribeRequest( ssrc_mapc.get_session_id(), operations=str(SubscribeUpdateOperation("root", ident, {"max-depth": "255", }))) result = ssrc_mapc.call('subscribe', subreq)
def client_test(): print 'testing ifmap client (this requires a running server)' mapclient = client("https://127.0.0.1:443", 'test', 'test', namespaces) result = mapclient.call('newSession', NewSessionRequest()) mapclient.set_session_id(newSessionResult(result).get_session_id()) mapclient.set_publisher_id(newSessionResult(result).get_publisher_id()) meta = str(Metadata('iperms', 'rwxrwxrwx', {'ifmap-cardinality':'multiValue'}, ns_prefix = "ct", elements = '<ct:mperms>rwxrwxrwx</ct:mperms>')) pubreq = PublishRequest(mapclient.get_session_id(), str(PublishUpdateOperation( id1=str(Identity(name = "ct:cloud", type = "other", other_type = "extended")), metadata=meta, lifetime='forever'))) result = mapclient.call('publish', pubreq) meta = str(Metadata('iperms', 'rwxrwxrwx', {'ifmap-cardinality':'multiValue'}, ns_prefix = "ct", elements = '<ct:mperms>rwxrwxrwx</ct:mperms>')) pubreq = PublishRequest(mapclient.get_session_id(), str(PublishUpdateOperation( id1=str(Identity(name = "ct:tenant:infra", type = "other", other_type = "extended")), metadata=meta, lifetime='forever'))) result = mapclient.call('publish', pubreq) meta = str(Metadata('belongs-to', '', {'ifmap-cardinality':'singleValue'}, ns_prefix = "ct", elements = '<ct:mperms>rwxrwxrwx</ct:mperms>')) pubreq = PublishRequest(mapclient.get_session_id(), str(PublishUpdateOperation( id1=str(Identity(name = "ct:cloud", type = "other", other_type = "extended")), id2=str(Identity(name = "ct:tenant:infra", type = "other", other_type = "extended")), metadata=meta, lifetime='forever'))) result = mapclient.call('publish', pubreq) #meta = str(Metadata('role', 'employee', {'ifmap-cardinality':'multiValue'})) #pubreq = PublishRequest(mapclient.get_session_id(), str(PublishUpdateOperation(id1=str(IPAddress("10.0.0.1")), metadata=meta, lifetime='forever'))) #result = mapclient.call('publish', pubreq) #searchreq = SearchRequest(mapclient.get_session_id(), str(IPAddress("10.0.0.1")), validation="None") #result = mapclient.call('search', searchreq) #subreq = SubscribeRequest(mapclient.get_session_id(), operations=str(SubscribeUpdateOperation('subscription-1',str(IPAddress("10.0.0.1"))))) #result = mapclient.call('subscribe', subreq) #pollreq = PollRequest(mapclient.get_session_id()) #result = mapclient.call('poll', pollreq) #subreq = SubscribeRequest(mapclient.get_session_id(), operations=str(SubscribeDeleteOperation('subscription-1'))) #result = mapclient.call('subscribe', subreq) #purgereq = PurgeRequest(mapclient.get_session_id(), mapclient.get_publisher_id()) #result = mapclient.call('purge', purgereq) #endreq = EndSessionRequest(mapclient.get_session_id()) #result = mapclient.call('endSession', endreq) import time while True: time.sleep(10)