def write_to_file(self, filename): json_list = [r.json_dict for r in self.iter_resources()] # TODO: we should integrate the resource_utils classes more tightly ru_resource_list = [ru.ResourceDef.from_json(r) for r in json_list] with open(filename, "wb") as f: f.write(ru.pp_resource_defs(ru_resource_list, RESOURCE_DEF_VERSION)) f.write("\n")
raise Exception("Invalid format for resource file %s" % ref_file) for f in extension_resource_files: add_resources_in_file(f) resource_group_dirs = ifilter(lambda f: \ os.path.isdir(os.path.join(drivers_dir, f)) and \ f!='genforma' and f!='data', os.listdir(drivers_dir)) for group_dir in resource_group_dirs: group_path = os.path.join(drivers_dir, group_dir) for f in os.listdir(group_path): add_resources_in_file(os.path.join(os.path.join(group_path, f), "resources.json")) with open(target_resource_file, "wb") as trf: trf.write(ru.pp_resource_defs([ru.ResourceDef.from_json(r) for r in resources], resource_file['resource_def_version'])) trf.write("\n") def parse_raw_install_spec_file(filename): """Parse the un-preprocessed install spec file and find the dynamic hosts. Returns the parsed json list. """ with open(filename, "rb") as f: json_data = json.load(f) if not isinstance(json_data, list): raise Exception("Invalid format for install spec file %s: expecting a list of resources" % filename) return json_data def query_install_spec(spec, inside=None, **kwargs): """The keyword args should contain key/value pairs to machine instance keys