Ejemplo n.º 1
0
 def get_endpoints(self):
     """Return a list of all Endpoints from Asterisk."""
     result = self._api.call('endpoints', http_method='GET')
     # Temporary until method is implemented
     result_list = [Endpoint(self._api), Endpoint(self._api)]
     #endpoints = [Endpoint(x) for x in result]
     return result_list
Ejemplo n.º 2
0
 def _parse_scenarios(scenarios, lab):
     result = {}
     for line in scenarios.splitlines():
         try:
             _, flow = line.split('From ')
             from_, to_ = flow.split(' to ')
             from_point = Endpoint(from_)
             to_point = Endpoint(to_)
             result.setdefault(from_point, []).append(to_point)
         except:
             print('*** Failed to parse scenario {}'.format(line))
             raise
     return result
Ejemplo n.º 3
0
 def setUp(self):
     self.videos = [Video(0, 50), Video(1, 30)]
     self.cache_servers = [CacheServer(0, 40)]
     self.endpoints = [
         Endpoint(0, {
             0: 100,
             1: 200
         }, [(10, self.cache_servers[0])]),
         Endpoint(0, {
             0: 100,
             1: 50
         })
     ]
Ejemplo n.º 4
0
    def __init__(self,
                 hostname,
                 username,
                 password,
                 port_or_endpoint=None,
                 path=None):
        self.isql = ISQLWrapper(hostname, username, password)

        if type(port_or_endpoint) == str:  #full endpoint path
            self.endpoint = Endpoint(port_or_endpoint)
        elif type(port_or_endpoint) == int:  #just the port
            self.endpoint = Endpoint(hostname, port_or_endpoint, path)
        else:
            raise Exception("Incorrect endpoint url or port.")
Ejemplo n.º 5
0
 def test_mock_request(self):
     endpoint = Endpoint("mock")
     response = endpoint.make_request(None, "warfarin")
     obj = response.json()
     self.assertTrue("200", response.status_code)
     # print(obj["results"][0]["brand_name"])
     self.assertEqual("Warfarin Sodium", obj["results"][0]["brand_name"])
Ejemplo n.º 6
0
def get_endpoints(urls, config):
    """
        get all endpoints from config
    """

    endpoints = []
    for e in urls:
        try:
            # now before we create the endpoint object lets see if we specified credentials
            # if not we will add the credentials from the environment by default
            if not 'credentials' in e or not 'username' in e[
                    'credentials'] or not 'password' in e['credentials']:
                e['credentials'] = {
                    'username': config.http_user,
                    'password': config.http_pass
                }
            # add the timezone info to the endpoint (to render the correct date/time)
            e['timezone'] = config.timezone
            # create an endpoint object
            endpoints.append(Endpoint(**e))
        except:
            logger.warn(
                "Not able to load entrypoint definition for '{}'.".format(
                    e['id']))
            pass

    return endpoints
    def parse(self):
        with open(self.filename, 'r') as input_f:
            lines = [line.strip('\n') for line in input_f.readlines()]
            # Global parameters.
            self.n_videos, self.n_endpoints, self.n_requests, self.n_caches, self.cache_size = to_int(
                lines[0])
            self.video_sizes = to_int(lines[1])
            self.videos = [Video(i) for i in range(self.n_videos)]
            # Endpoints
            number_handled = 0
            i = 2
            while number_handled != self.n_endpoints:
                dc_latency, caches = to_int(lines[i])
                i += caches
                # Register the latencies for this datacenter.
                latencies = {}
                for j in range(1, 1 + caches):
                    info = to_int(lines[i + j])
                    latencies[info[0]] = info[1]
                self.endpoints.append(
                    Endpoint(number_handled, dc_latency, latencies))
                number_handled += 1
                i += 1

            number_handled = 0
            for j in range(i, self.n_requests + i):
                video, source, qty = to_int(lines[j])
                self.endpoints[source].requests.append(
                    Request(number_handled, source, video, qty))
                self.videos[video].requests.append(
                    Request(number_handled, source, video, qty))
Ejemplo n.º 8
0
 def __init__(self, endpoint, timestamp=None, value=None):
     if isinstance(endpoint, Endpoint):
         self.endpoint = endpoint
     elif isinstance(endpoint, dict):
         self.endpoint = Endpoint(endpoint["service_name"], endpoint["ipv4"])
     self.timestamp = timestamp
     self.value = value
Ejemplo n.º 9
0
 def __init__(self):
     parser = Parser(CONFIG_PATH)
     self._host = parser.server()['host']
     self._port = parser.server()['port']
     self._endpoints = {}
     for ep in parser.endpoints():
         self._endpoints[ep['endpoint_url']] = Endpoint(ep)
    def load_data(self, input_file):
        with open(input_file, 'r') as f:
            self.n_videos, self.n_endpoints, self.n_requests, self.n_caches, self.s_caches = list(
                map(int,
                    f.readline().split()))
            self.video_sizes = list(map(int, f.readline().split()))

            for i in range(self.n_endpoints):
                datacenter_latency, num_connected_caches = list(
                    map(int,
                        f.readline().split()))
                e = Endpoint(datacenter_latency)
                for j in range(num_connected_caches):
                    id_cache, latency_cache = list(
                        map(int,
                            f.readline().split()))
                    conn = CacheConnection(id_cache, latency_cache)
                    e.connected_caches.append(conn)
                self.endpoints.append(e)

            for i in range(self.n_requests):
                video, endpoint, num_requests = list(
                    map(int,
                        f.readline().split()))
                r = VideoRequest(video, endpoint, num_requests)
                self.endpoints[endpoint].video_requests.append(r)
                self.requests.append(r)
Ejemplo n.º 11
0
def add_endpoint(my_request):

    if not my_request.pmh_url:
        return None

    endpoint_with_this_id = Endpoint.query.filter(
        Endpoint.repo_request_id == my_request.id).first()
    if endpoint_with_this_id:
        print u"one already matches {}".format(my_request.id)
        return None

    raw_endpoint = my_request.pmh_url
    clean_endpoint = raw_endpoint.strip()
    clean_endpoint = clean_endpoint.strip("?")
    clean_endpoint = re.sub(u"\?verb=.*$", "", clean_endpoint, re.IGNORECASE)
    print u"raw endpoint is {}, clean endpoint is {}".format(
        raw_endpoint, clean_endpoint)

    matching_endpoint = Endpoint()
    matching_endpoint.pmh_url = clean_endpoint

    repo_matches = my_request.matching_repositories()
    if repo_matches:
        matching_repo = repo_matches[0]
        print u"yay! for {} {} matches repository {}".format(
            my_request.institution_name, my_request.repo_name, matching_repo)
    else:
        print u"no matching repository for {}: {}".format(
            my_request.institution_name, my_request.repo_name)
        matching_repo = Repository()

    # overwrite stuff with request
    matching_repo.institution_name = my_request.institution_name
    matching_repo.repository_name = my_request.repo_name
    matching_repo.home_page = my_request.repo_home_page
    matching_endpoint.repo_unique_id = matching_repo.id
    matching_endpoint.email = my_request.email
    matching_endpoint.repo_request_id = my_request.id
    matching_endpoint.ready_to_run = True
    matching_endpoint.set_identify_and_initial_query()

    db.session.merge(matching_endpoint)
    db.session.merge(matching_repo)
    print u"added {} {}".format(matching_endpoint, matching_repo)
    print u"see at url http://unpaywall.org/sources/repository/{}".format(
        matching_endpoint.id)
    safe_commit(db)
    print "saved"

    print "now sending email"
    # get the endpoint again, so it gets with all the meta info etc
    matching_endpoint = Endpoint.query.get(matching_endpoint.id)
    matching_endpoint.contacted_text = "automated welcome email"
    matching_endpoint.contacted = datetime.datetime.utcnow().isoformat()
    safe_commit(db)
    send_announcement_email(matching_endpoint)

    print "email sent"

    return matching_endpoint
Ejemplo n.º 12
0
def read_data(filename):
    with open('../inputs/%s.in' % filename) as f:
        fl = line_to_int_list(f)
        num_endpoint = fl[1]
        num_request = fl[2]
        num_cache = fl[3]
        cache_size = fl[4]

        cache_servers = [CacheServer(i, cache_size) for i in range(num_cache)]

        vidoe_sizes = line_to_int_list(f)
        vidoes = [Video(i, s) for i, s in enumerate(vidoe_sizes)]

        end_points = list()
        for i in range(num_endpoint):
            l = line_to_int_list(f)
            endpoint = Endpoint(i)
            for j in range(l[1]):
                ll = line_to_int_list(f)
                cache_serv = cache_servers[ll[0]]
                endpoint.latency.append((ll[1], cache_serv))
            end_points.append(endpoint)

        for i in range(num_request):
            lr = line_to_int_list(f)
            vi = vidoes[lr[0]]
            end_points[lr[1]].requests.append((lr[2], vi))

        return (cache_servers, vidoes, end_points)
Ejemplo n.º 13
0
 def get_endpoint(self, object_id):
     """Return Endpoint specified by object_id."""
     result = self._api.call('endpoints', http_method='GET',
                             object_id=object_id)
     # Temporary until method is implemented
     result = Endpoint(self._api)
     #endpoint = Endpoint(result)
     return result
Ejemplo n.º 14
0
    def test_other_queries(self):
        endpoint_cache = Endpoint("mock")
        endpoint_cache.create_cache()

        results = endpoint_cache.query_cache('Aspirin', 'brand_name',
                                             ['product_ndc', 'dosage_form'])
        self.assertEqual(results[0]['product_ndc'], '0615-8058')
        self.assertEqual(results[1]['dosage_form'], 'TABLET, COATED')
Ejemplo n.º 15
0
 def test_part_2_lookup_pharm_classes_warfarin(self):
     # TODO: Complete test by adding call to method to look up pharm classes for warfarin
     endpoint = Endpoint("mock")
     pharm_classes = endpoint.get_pharm_class("warfarin")
     expected_mappings = {
         'EPC': ['Vitamin K Antagonist'],
         'MoA': ['Vitamin K Inhibitors']
     }
     self.assertDictEqual(pharm_classes, expected_mappings)
Ejemplo n.º 16
0
 def __init__(self, host, port):
     """
     Define the main components useful for the
     loop
     """
     
     self.__endpoint = Endpoint(host, port)
     self.__connections = []
     self.__pendings = []
Ejemplo n.º 17
0
    def __init__(self, argv):
        logger = Logger().logger
        self.appConfig = AppConfig(logger)
        self.logger = logger
        self.quitting = False
        self.handling_events = False
        self.accounts = {}

        self.logger.debug("Creating the Endpoint")
        self.endpoint = Endpoint(self)
Ejemplo n.º 18
0
    def test_part_4_look_up_all_product_ndc_for_ingredients(self):
        # TODO: Complete test by adding call to look up the 'product_ndc' for the drugs which have
        #  `CLOPIDOGREL BISULFATE` as an 'active_ingredients'
        # Example: lookup_method('CLOPIDOGREL BISULFATE', 'active_ingredients', ['product_ndc'])
        endpoint_cache = Endpoint("mock")
        endpoint_cache.create_cache()

        results = endpoint_cache.query_cache('CLOPIDOGREL BISULFATE',
                                             'active_ingredients',
                                             ['product_ndc'])
        self.assertEqual(results[0]['product_ndc'], '21695-665')
Ejemplo n.º 19
0
    def __init__(self, name, version, context, service_url=None, **kwargs):
        super().__init__()
        self.client = None  # REST API Client
        self.id = None
        self._data = None

        self.name = name
        self.context = context
        self.version = version
        self.endpoint = DotDict()
        if service_url:
            inline_endpoint_name = "{}_{}".format(Endpoint.CONST.TYPES.SANDBOX,
                                                  name)
            self.endpoint[Endpoint.CONST.TYPES.SANDBOX] = Endpoint(
                inline_endpoint_name, 'http', service_url)
            inline_endpoint_name = "{}_{}".format(
                Endpoint.CONST.TYPES.PRODUCTION, name)
            self.endpoint[Endpoint.CONST.TYPES.PRODUCTION] = Endpoint(
                inline_endpoint_name, 'http', service_url)
        if kwargs:
            self._parse_json(kwargs)
Ejemplo n.º 20
0
    def test_part_4_look_up_active_ingredients_for_product_ndc(self):
        # TODO: Complete test by adding call to look up the 'active_ingredients' for the product_ndc: '21695-665'
        # Example lookup_method('21695-665', 'product_ndc', ['active_ingredients'])
        endpoint_cache = Endpoint("mock")
        endpoint_cache.create_cache()

        results = endpoint_cache.query_cache('21695-665', 'product_ndc',
                                             ['active_ingredients'])
        self.assertEqual(results[0]['active_ingredients'],
                         [{
                             "strength": "75 mg/1",
                             "name": "CLOPIDOGREL BISULFATE"
                         }])
Ejemplo n.º 21
0
 def parse(self):
     flows = [line for line in self.flows.split('\n') if line and not line.startswith('#')]
     for line in flows:
         if 'Failed' in line and line[0].isdigit():
             scenario = dict()
             seq, actions = self.split_strip(line, 'Failed')
             parsed_action = [Endpoint(word) for word in self.split_strip(actions, ',')]
             flow_key = (seq, tuple(parsed_action))
             self.parsed_flows[flow_key] = scenario
         elif all([token in line for token in ['From', 'to', 'via']]):
             _, rule = self.split_strip(line, 'From')
             from_device, to_via = self.split_strip(rule, 'to')
             from_point = Endpoint(from_device)
             to_device, flow = self.split_strip(to_via, 'via')
             to_point = Endpoint(to_device)
             flow_and = self.split_strip(flow, ',')
             flow_and_or = [['OR', self.split_strip(word, 'or')] if 'or' in word else word for word in flow_and]
             flow_and_or_not = [word.split() if 'not' in word else word for word in flow_and_or]
             flow_final = [['AND', word] if type(word) is str else word for word in flow_and_or_not]
             scenario_key = (from_point, to_point)
             scenario[scenario_key] = {'text': flow, 'parsed': flow_final}
         else:
             raise Exception('Incorrect traffic flow syntax in {}'.format(line))
     return self.parsed_flows
Ejemplo n.º 22
0
    def set_endpoints(self):
        """
        Sets API endpoints

        This function initializes one endpoint per region.
        """

        self.engines = {}

        for region in self.get_regions():

            self.engines[region] = Endpoint(
                key=self.get_user_name(),
                secret=self.get_user_password(),
                region=region)
Ejemplo n.º 23
0
 def populate_global_endpoints(self, count=20):
     endpoint_types = ['basic', 'digest']
     endpoints = []
     for index in range(count):
         random_char = random.choice(
             string.ascii_lowercase) + random.choice(string.ascii_lowercase)
         name = "{}_sample_endpoint_{}".format(random_char, index)
         service_url = "https://sample.knnect.com/api/endpoint/" + name
         max_tps = random.randint(1, 1000)
         endpoint = Endpoint(name, "http", service_url, max_tps)
         rand_endpoint = endpoint_types[random.randint(0, 1)]
         endpoint.set_security(rand_endpoint, name, "sample_password")
         endpoint.set_rest_client(self.client)
         endpoint.save()
         endpoints.append(endpoint)
     return endpoints
Ejemplo n.º 24
0
 def parse(self):
     self.trace = [line for line in self.trace.split('\n') if line]
     seq, ip = None, None
     for line in self.trace:
         try:
             trace_match = self.trace_re.search(line)
             if trace_match:
                 ip = trace_match.group(3)
                 if trace_match.group(1):
                     seq = trace_match.group(1)
                 if seq and ip:
                     self.parsed_result.setdefault(int(seq), []).append(Endpoint(ip))
         except AttributeError:
             print('Cannot parse traceroute output {}'.format(line))
             raise
     return self.parsed_result
Ejemplo n.º 25
0
    def __init__(self, apiurl='http://localhost/api', username=None, password=None, token=None):
        self.apiurl = apiurl
        self.username = username
        self.password = password
        self.token = token

        self.headers = {}
        self.headers['Content-Type'] = 'application/json'
        self.headers['Accept'] = "application/json; indent=4"
        if token:
            self.headers['Authorization'] = token
        self.auth=None
        if username and password:
            self.auth = (username,password)

        self.tenants = Endpoint('tenants')
Ejemplo n.º 26
0
    def test_node(self):

        print('***** Test get_node_by_id ***')

        handle = Endpoint(key='k', secret='s', region='dd-eu', orgId='*org')

        node = handle.get_node_by_id(body=node_1_body)
        self.assertEqual(node, node_1_dict)

        node = handle.get_node_by_id(body=node_2_body)
        self.assertEqual(node, node_2_dict)

        node = handle.get_node_by_id(body=node_3_body)
        self.assertEqual(node, node_3_dict)

        node = handle.get_node_by_id(body=node_4_body)
        self.assertEqual(node, node_4_dict)
Ejemplo n.º 27
0
    def __init__(self, f):
        # First line
        params = f.readline().split(" ")
        videoCount = int(params[0])
        endpointCount = int(params[1])
        requestCount = int(params[2])
        cacheCount = int(params[3])
        cacheCapacity = int(params[4])

        # Chaches
        self.caches = []
        for i in range(cacheCount):
            self.caches.append(Cache(i, cacheCapacity))

        # Videos line
        videoSizes = f.readline().split(" ")
        self.videos = []
        for i in range(videoCount):
            self.videos.append(Video(i, int(videoSizes[i])))

        # Endpoints section
        self.endpoints = []
        for i in range(endpointCount):
            endpointLine = f.readline().split(" ")
            latency = int(endpointLine[0])
            availableCacheCount = int(endpointLine[1])
            caches = []
            for j in range(availableCacheCount):
                cacheLine = f.readline().split(" ")
                cacheTuple = (self.caches[int(cacheLine[0])],
                              int(cacheLine[1]))
                caches.append(cacheTuple)
            self.endpoints.append(Endpoint(latency, caches))

        # Requests section
        self.requests = []
        for i in range(requestCount):
            requestLine = f.readline().split(" ")
            videoId = int(requestLine[0])
            endpointId = int(requestLine[1])
            requestCount = int(requestLine[2])
            request = Request(self.videos[videoId], self.endpoints[endpointId],
                              requestCount)
            self.requests.append(request)
            self.endpoints[endpointId].requests.append(request)
Ejemplo n.º 28
0
    def test_part_2_lookup_pharm_classes_aspirin(self):
        # TODO: Complete test by adding call to method to look up pharm classes for aspirin
        endpoint = Endpoint("mock")
        pharm_classes = endpoint.get_pharm_class("aspirin")
        expected_mappings = {
            'Chemical/Ingredient':
            ['Nonsteroidal Anti-inflammatory Compounds'],
            'PE': [
                'Decreased Prostaglandin Production',
                'Decreased Platelet Aggregation'
            ],
            'EPC': [
                'Nonsteroidal Anti-inflammatory Drug',
                'Platelet Aggregation Inhibitor'
            ],
            'MoA': ['Cyclooxygenase Inhibitors']
        }

        self.assertDictEqual(pharm_classes, expected_mappings)
Ejemplo n.º 29
0
def read(input):
    f = open(input, 'r')
    conf = [int(x) for x in f.readline().replace('\n', '').split(' ')]
    video_sizes = [int(x) for x in f.readline().replace('\n', '').split(' ')]

    endpoints = []
    for i in range(0, conf[INDEX_NUMBER_OF_ENDPOINTS]):
        endpoint_raw = [int(x) for x in f.readline().replace('\n', '').split(' ')]
        endpoint = Endpoint(i, endpoint_raw[0])
        for j in range(0, endpoint_raw[1]):
            cache_raw = [int(x) for x in f.readline().replace('\n', '').split(' ')]
            endpoint.add_cache(cache_raw[0], cache_raw[1])
        endpoints.append(endpoint)

    for i in range(0, int(conf[INDEX_NUMBER_OF_REQUESTS])):
        request_raw = [int(x) for x in f.readline().replace('\n', '').split(' ')]
        endpoints[request_raw[1]].add_request(request_raw[0], request_raw[2])
    f.close()
    return conf, video_sizes, endpoints
Ejemplo n.º 30
0
 def get_show_cts_role_based_sgtmaps_all(self):
     self.ise.get_sgts()
     self.sgts = self.ise.sgts
     net_connect = ConnectHandler(**self.cisco_switch)
     for vrf in self.vrfs:
         command = 'show cts role-based sgt-map vrf ' + vrf + ' all'
         cts_sgt_maps_output = net_connect.send_command(command)
         f = open(
             os.path.join(
                 os.path.dirname(os.path.dirname(
                     os.path.abspath(__file__))),
                 'templates/cts_role_based_sgt_map_all.templ'), 'r')
         template = textfsm.TextFSM(f)
         output = template.ParseText(cts_sgt_maps_output)
         for o in output:
             e = Endpoint(self.arp[o[0]])
             e.set_ip(o[0])
             e.set_vrf(vrf)
             e.set_sgt(self.sgts[int(o[1])])
             self.endpoints[self.arp[o[0]]] = e