def get_resource_apis_list(self):
        self._execute_http_request(method='GET',
                                   url=self.api_list_url.format(
                                       variables.ODL_SYSTEM_IP_1,
                                       variables.RESTCONFPORT))

        response_json = json_loader.load(self.odlrest_conn.response_as_text)
        api_list = []
        for apis in response_json["apis"]:
            api_list.append(apis["path"])
        return api_list
Exemplo n.º 2
0
def generate_resource_class(template_file, json_file, class_file):

    class_attrs = json_loader.dict_to_class_attrs(json_loader.load(json_file))

    env = Environment(loader=BaseLoader(), trim_blocks=True)
    env.filters['format_attribute_name'] = template_utils.format_attribute_name
    template = env.from_string(open(template_file).read())
    class_code = template.render(class_attrs=class_attrs)

    with open(class_file, "w") as fh:
        fh.write(class_code)
    def get_config_type_params(self, url, http_method="POST"):
        config_object_list = []

        self.odlrest_conn.send_get_request(url=url)
        response_json = json_loader.load(self.odlrest_conn.response_as_text)
        if "apis" in response_json:
            for api in response_json["apis"]:
                if api["path"] == "/config/":
                    for oper in api["operations"]:
                        if oper["method"] == http_method:
                            config_object_list = [
                                param["type"] for param in oper["parameters"]
                            ]
        return config_object_list
    def get_config_properties_for_model(self, model_name, url):

        self.odlrest_conn.send_get_request(url)
        response_json = json_loader.load(self.odlrest_conn.response_as_text)
        properties = {}
        if "models" in response_json:
            for prop in response_json["models"].keys():
                # Process properties with and without POST. $ is used in order to skip the plural(s)
                regexp1 = "\(config\){0}POST".format(
                    model_name.replace("(config)", ""))
                regexp2 = "\(config\){0}$".format(
                    model_name.replace("(config)", ""))
                if re.search('{0}|{1}'.format(regexp1, regexp2),
                             prop) is not None:
                    properties.update(
                        response_json["models"][prop]["properties"])

        return properties
 def test_json_loader(self):
     json_file = os.path.join(os.getcwd(), r'data\vpn_instance.json')
     pprint(json_loader.load(json_file))
 def test_json_to_dot_notation(self):
     json_file = os.path.join(os.getcwd(), r'data\vpn_instance.json')
     json_params = json_loader.convert_json_to_param_dot_notation(
         json_loader.load(json_file))
     pprint(json_params)
 def test_dict_to_class_attrs(self):
     json_file = os.path.join(os.getcwd(), r'data\vpn_instance.json')
     json_loader.dict_to_class_attrs(json_loader.load(json_file))