コード例 #1
0
    def subscribe_service(self, service='foo', instances=None, client_id=None):
        '''POST http://discovery-server-ip:5998/subscribe
            Content-Type: application/json or application/xml
            Body: Service type, instance count, client ID
            JSON: { "service": "control-node", "instances": 1, "client": "6c3f48bf-1098-46e8-8117-5cc745b45983"}
            XML:   <control-node><instances>1</instances><client>UUID</client></control-node>

            Response: TTL, List of <service type, Blob>
            JSON: {"Apiservice": [{"ip_addr": "10.84.13.34", "port": "8082"}], "ttl": 357}
            XML: <response><ttl>300</ttl><control-node><ip_addr>192.168.2.0</ip_addr><port>1682</port></control-node>'''
        resp = None
        try:
            service_url = DiscoveryServerUtils.discovery_subscribe_service_url(
                self._ip, str(self._port))
            print 'url: %s' % service_url
            json_body = '{' + '"service": ' + '"' + service + '"' + \
                ', "instances": ' + \
                str(instances) + ', ' + '"client": "' + client_id + '"}'
            print 'json_body: %s' % json_body
            resp = DiscoveryServerUtils.post_url_http(service_url, json_body)
            if resp:
                resp = json.loads(resp)
        except Exception as e:
            print str(e)
        finally:
            print 'resp: %s' % (resp)
            return resp
コード例 #2
0
 def publish_service(self,
                     service='foo',
                     ip=None,
                     port=None,
                     admin_state=None):
     '''Used to publish service from test { "control-node": {"ip_addr": "192.168.2.0", "port":1682 }}'''
     resp = None
     try:
         service_url = DiscoveryServerUtils.discovery_publish_service_url(
             self._ip, str(self._port))
         print 'url: %s' % service_url
         if not admin_state:
             json_body = '{' + '"' + service + '"' + \
                 ': {' + '"ip-address":' + '"' + \
                 ip + '"' + ',"port":' + str(port) + '}}'
         else:
             json_body = '{' + '"' + service + '"' + \
                 ': {' + '"ip-address":' + '"' + \
                 ip + '"' + ',"port":' + str(port) + \
                 '}, "service-type":' + '"' + service + \
                 '",' + '"admin-state":' + '"' + \
                 admin_state + '"' + '}'
         print 'json_body: %s' % json_body
         resp = DiscoveryServerUtils.post_url_http(service_url, json_body)
         if resp:
             resp = json.loads(resp)
     except Exception as e:
         print str(e)
     finally:
         print 'resp: %s' % (resp)
         return resp
コード例 #3
0
ファイル: ds_introspect_utils.py プロジェクト: hkumarmk/aaa
 def publish_service(self, service='foo', ip=None, port=None, admin_state=None):
     '''Used to publish service from test { "control-node": {"ip_addr": "192.168.2.0", "port":1682 }}'''
     resp = None
     try:
         service_url = DiscoveryServerUtils.discovery_publish_service_url(
             self._ip, str(self._port))
         print 'url: %s' % service_url
         if not admin_state:
             json_body = '{' + '"' + service + '"' + \
                 ': {' + '"ip-address":' + '"' + \
                 ip + '"' + ',"port":' + str(port) + '}}'
         else:
             json_body = '{' + '"' + service + '"' + \
                 ': {' + '"ip-address":' + '"' + \
                 ip + '"' + ',"port":' + str(port) + \
                 '}, "service-type":' + '"' + service + \
                 '",' + '"admin-state":' + '"' + \
                 admin_state + '"' + '}'
         print 'json_body: %s' % json_body
         resp = DiscoveryServerUtils.post_url_http(service_url, json_body)
         if resp:
             resp = json.loads(resp)
     except Exception as e:
         print str(e)
     finally:
         print 'resp: %s' % (resp)
         return resp
コード例 #4
0
 def cleanup_service(self):
     '''GET http://discovery-server-ip:5998/cleanup'''
     resp = None
     try:
         service_url = DiscoveryServerUtils.discovery_cleanup_service_url(
             self._ip, str(self._port))
         print 'url: %s' % service_url
         resp = DiscoveryServerUtils.get_url_http(service_url)
         if resp:
             resp = json.loads(resp)
     except Exception as e:
         print str(e)
     finally:
         print 'resp: %s' % (resp)
         return resp
コード例 #5
0
    def subscribe_service(self, service='foo', instances=None, client_id=None, remote_addr=None, client_type=None, min_instances=0, svc_in_use_list_present = False, svc_in_use_list = []):
        '''POST http://discovery-server-ip:5998/subscribe
            Content-Type: application/json or application/xml
            Body: Service type, instance count, client ID
            JSON: { "service": "control-node", "instances": 1, "client": "6c3f48bf-1098-46e8-8117-5cc745b45983"}
            XML:   <control-node><instances>1</instances><client>UUID</client></control-node>

            Response: TTL, List of <service type, Blob>
            JSON: {"Apiservice": [{"ip_addr": "10.84.13.34", "port": "8082"}], "ttl": 357}
            XML: <response><ttl>300</ttl><control-node><ip_addr>192.168.2.0</ip_addr><port>1682</port></control-node>'''
        resp = None
        try:
            service_url = DiscoveryServerUtils.discovery_subscribe_service_url(
                self._ip, str(self._port))
            print 'url: %s' % service_url
            if svc_in_use_list_present==False:
                json_body = '{' + '"service": ' + '"' + service + '"' + \
                    ', "instances": "' + str(instances) + '"' + \
                    ', "min-instances": "' + str(min_instances) + '"' \
                    ', "client": "' + client_id + '"' + \
                    ', "remote-addr": "' + remote_addr + '"' + \
                    ', "client-type": "' + client_type + '"}' 
            elif svc_in_use_list_present==True:
                counter=1
                svc_in_use_list_data = ''
                for elem in svc_in_use_list:
                    if counter != len(svc_in_use_list):
                        svc_in_use_list_data= svc_in_use_list_data + '"publisher-id": "' + elem +'", '
                        counter =counter+1
                        continue
                    elif counter == len(svc_in_use_list):
                        svc_in_use_list_data=svc_in_use_list_data + '"publisher-id": "' + elem +'"'
                json_body = '{' + '"service": ' + '"' + service + '"' + \
                    ', "instances": "' + str(instances) + '"' + \
                    ', "min-instances": "' + str(min_instances) + '"' \
                    ', "client": "' + client_id + '"' + \
                    ', "service-in-use-list" : {' + svc_in_use_list_data + '}' + \
                    ', "remote-addr": "' + remote_addr + '"' + \
                    ', "client-type": "' + client_type + '"}'
            print 'json_body: %s' % json_body
            resp = DiscoveryServerUtils.post_url_http(service_url, json_body)
            if resp:
                resp = json.loads(resp)
        except Exception as e:
            print str(e)
        finally:
            print 'resp: %s' % (resp)
            return resp