def add_endpoint(self, group_name, endpoint):
     if re.match("^\w+://", endpoint) is None:
         # TODO: Default to https when our tutorials show setting up a ssl certificate as well
         endpoint = 'http://' + endpoint
     if not is_valid_endpoint(endpoint):
         raise Exception("Endpoint is not a valid URL")
     if (not self.is_group_name_exists(group_name)):
         raise Exception("the group %s is not present"%str(group_name))
     if (endpoint in self.get_all_endpoints()):
         raise Exception("the endpoint %s is already present"%str(endpoint))
     self.m["endpoints"] += [{"group_name" : group_name, "endpoint"   : endpoint}]
Exemple #2
0
    def add_endpoint_to_group(self, group_name, endpoint):
        if re.match("^\w+://", endpoint) is None:
            # TODO: Default to https when our tutorials show setting up a ssl certificate as well
            endpoint = 'http://' + endpoint
        if not is_valid_endpoint(endpoint):
            raise Exception("Endpoint is not a valid URL")
        if (not self.is_group_name_exists(group_name)):
            raise Exception("the group %s is not present" % str(group_name))
        if (endpoint in self.get_all_endpoints_for_group(group_name)):
            raise Exception("the endpoint %s is already present" %
                            str(endpoint))

        groups = self.m["groups"]
        for group in groups:
            if (group["group_name"] == group_name):
                if 'endpoints' in group:
                    group['endpoints'].append(endpoint)
                else:
                    group['endpoints'] = [endpoint]