def validate_template()

in hostfactory/host_provider/src/cyclecloud_provider.py [0:0]


    def validate_template(self):
        cluster_status = self.cluster.status()
        nodearrays = cluster_status["nodearrays"]
        pro_conf_dir = os.getenv('PRO_CONF_DIR', os.getcwd())
        conf_path = os.path.join(pro_conf_dir, "conf", "azureccprov_templates.json")
        with open(conf_path, 'r') as json_file:
            templates_json = json.load(json_file)
        if "templates" not in templates_json:
            print("List templates not present in azureccprov_templates.json", file=sys.stderr)
            return False
        templates_json = templates_json["templates"]
        if len(templates_json) == 0:
            print("Length of list templates is 0", file=sys.stderr)
            return False
        template_name_found = False
        for template in templates_json:
           for nodearray_root in nodearrays:
               template_name_found = False
               if template["templateId"].strip() == nodearray_root.get("name").strip():
                   template_name_found = True
                   bucket_machineType = [bucket.get("definition")["machineType"].strip() for bucket in nodearray_root.get("buckets")]
                   if "vmTypes" not in template:
                       print("Template validation failed", file=sys.stderr)  
                       print("vmTypes not present in template %s" % template["templateId"], file=sys.stderr)
                       return False
                   vmTypes = [key.strip() for key in template["vmTypes"].keys()]
                   bucket_machineType = set(bucket_machineType)
                   vmTypes = set(vmTypes)
                   diff = bucket_machineType.symmetric_difference(vmTypes)
                   if len(diff) > 0:
                       print("Template validation failed", file=sys.stderr)   
                       print(f"Difference in vmTypes and buckets {diff} for template {template['templateId']}", file=sys.stderr)
                       return False
                   break
           if not template_name_found:
               print("Template validation failed", file=sys.stderr)
               print("Template %s does not exist in nodearray" % template["templateId"], file=sys.stderr)
               return False
        print("Template validation passed")
        return True