def get_yaml(self, key): raw_value = (self.get_raw_item(key)) data_value = (yamlx.parse(raw_value.data)) return EtcdYamlItem(self, raw_value, data_value)
def get_all_list_slow(self): if not self.client.exists(self.path): return [] ret = [] for record_key, record_yaml \ in self.client.get_tree (self.path): if not record_key.endswith("/data"): continue record_name = record_key[1:-5] try: record_data = yamlx.parse(record_yaml) except: raise Exception("Error parsing %s" % record_key) ret.append((record_name, record_data)) return ret
def get_all_dictionary_slow(self): if not self.client.exists(self.path): return {} ret = {} for record_key, record_yaml \ in self.client.get_tree (self.path): if not record_key.endswith("/data"): continue record_name = record_key[1:-5] try: record_data = yamlx.parse(record_yaml) except: raise Exception("Error parsing %s" % record_key) ret[record_name] = record_data return ret
def update_cache (self): if not self.client.exists (self.path): self.cache = freeze ({}) self.data_cache = freeze ({}) self.all_list_cache = freeze ([]) return cache = dict (self.client.get_tree (self.path)) data_cache = OrderedDict () all_list_cache = [] for key, string_value in sorted (cache.items ()): if not key.endswith ("/data"): continue name = key [ 1 : len (key) - 5 ] value = yamlx.parse (string_value) data_cache [name] = value all_list_cache.append (( name, value )) self.cache = freeze (cache) self.data_cache = freeze (data_cache) self.all_list_cache = freeze (all_list_cache)
def get_all_dictionary_slow (self): if not self.client.exists (self.path): return {} ret = {} for record_key, record_yaml \ in self.client.get_tree (self.path): if not record_key.endswith ("/data"): continue record_name = record_key [1:-5] try: record_data = yamlx.parse (record_yaml) except: raise Exception ( "Error parsing %s" % record_key) ret [record_name] = record_data return ret
def get_all_list_slow (self): if not self.client.exists (self.path): return [] ret = [] for record_key, record_yaml \ in self.client.get_tree (self.path): if not record_key.endswith ("/data"): continue record_name = record_key [1:-5] try: record_data = yamlx.parse (record_yaml) except: raise Exception ( "Error parsing %s" % record_key) ret.append ((record_name, record_data)) return ret
def get_yaml (self, key): raw_value = ( self.get_raw_item ( key)) data_value = ( yamlx.parse ( raw_value.data)) return EtcdYamlItem ( self, raw_value, data_value)
def get_all_values_slow(self): if not self.client.exists(self.path): return [] ret = [] for record_key, record_yaml \ in self.client.get_tree (self.path): if not record_key.endswith("/data"): continue record_data = yamlx.parse(record_yaml) ret.append(record_data) return ret
def get_all_values_slow (self): if not self.client.exists (self.path): return [] ret = [] for record_key, record_yaml \ in self.client.get_tree (self.path): if not record_key.endswith ("/data"): continue record_data = yamlx.parse (record_yaml) ret.append (record_data) return ret
def do_edit (self, context, args): collection = self.helper.get_collection (context) if not collection.exists_slow (args.name): raise Exception ( "%s does not exist: %s" % ( self.helper.name.title (), args.name)) record = ( collection.get_slow ( args.name)) with tempfile.NamedTemporaryFile () as temp_file: temp_file.write (record.raw_data) temp_file.flush () if "VISUAL" in os.environ: editor = os.environ ["VISUAL"] elif "EDITOR" in os.environ: editor = os.environ ["EDITOR"] else: raise ReportableError ( "editor_not_configured") os.system ("%s %s" % (editor, temp_file.name)) with open (temp_file.name, "r") as temp_file_again: record.data = ( yamlx.parse ( temp_file_again.read ())) record.save ()
def update_cache(self): if not self.client.exists(self.path): self.cache = freeze({}) self.data_cache = freeze({}) self.all_list_cache = freeze([]) return cache = dict(self.client.get_tree(self.path)) data_cache = (collections.OrderedDict()) all_list_cache = [] for key, string_value in sorted(cache.items()): if not key.endswith("/data"): continue name = key[1:len(key) - 5] try: value = yamlx.parse(string_value) except Exception as error: raise Exception("Error loading %s" % (key), error) data_cache[name] = value all_list_cache.append((name, value)) self.cache = freeze(cache) self.data_cache = freeze(data_cache) self.all_list_cache = freeze(all_list_cache)
def do_create (self, context, args): collection = self.helper.get_collection (context) # determine name unique_name = self.helper.create_unique_name (context, args) if collection.exists_slow (unique_name): if not args.update_existing: raise Exception ( "%s already exists: %s" % ( self.helper.name.title (), unique_name)) record_data = collection.get_slow (unique_name) already_exists = True else: record_data = { "identity": { "type": collection.type, "name": args.name, }, } already_exists = False # set provided values # edit resource if args.edit: temp_file = tempfile.NamedTemporaryFile () record_yaml = collection.to_yaml (record_data) temp_file.write (record_yaml) temp_file.flush () os.system ("%s %s" % (os.environ ["EDITOR"], temp_file.name)) temp_again = open (temp_file.name, "r") record_yaml = temp_again.read () record_data = yamlx.parse (record_yaml) temp_again.close () self.helper.update_record (context, args, record_data) # verify resource self.helper.verify (context, unique_name, record_data) # create resource collection.set (unique_name, record_data) self.helper.update_files (context, args, unique_name, collection) # display a message if already_exists: print ("Updated %s %s" % ( self.helper.name, unique_name)) else: print ("Created %s %s" % ( self.helper.name, unique_name))
def get_yaml(self, key): value_yaml = self.get_raw(key) value = yamlx.parse(value_yaml) return value
def get_yaml (self, key): value_yaml = self.get_raw (key) value = yamlx.parse (value_yaml) return value