def get_and_replace_parent_variables(self): """ Checks the particles desired state definition and checks to see if there are values that dependent on one of its parents. The format should look like $flavor:pcf_name$key_in_parent_current_state_definition. If there are values then this function looks for the corresponding parents and adds those values to this particles desired_state_definition. """ var_lookup_list = pcf_util.find_nested_vars( self.desired_state_definition, var_list=[]) for (nested_key, id_var) in var_lookup_list: if id_var[0] == "inherit": pcf_id = id_var[1] parent_var = id_var[2] try: parent = next(p for p in self.parents if p.pcf_id == pcf_id) except StopIteration: raise pcf_exceptions.InvalidValueReplaceException( "{} parent was not found".format(pcf_id)) else: var = pcf_util.find_nested_dict_value( curr_dict=parent.current_state_definition, list_nested_keys=parent_var.split('.')) if not var: raise pcf_exceptions.InvalidValueReplaceException( "{} var was not found in {}".format( parent_var, pcf_id)) pcf_util.replace_value_nested_dict( curr_dict=self.desired_state_definition, list_nested_keys=nested_key.split('.'), new_value=var)
def id_replace(self): """ Looks through the particle definition for $lookup and replaces them with specified resource with given name """ var_lookup_list = pcf_util.find_nested_vars( self.desired_state_definition, var_list=[]) for (nested_key, id_var) in var_lookup_list: if id_var[0] == "lookup": resource = id_var[1] names = id_var[2].split(':') var = self.lookup(resource, names).get_id() pcf_util.replace_value_nested_dict( curr_dict=self.desired_state_definition, list_nested_keys=nested_key.split('.'), new_value=var)