Skip to content
  • Thomas Haller's avatar
    ifcfg: add read/write support for user-data · 79be44d9
    Thomas Haller authored
    The user data values are encoded in shell variables named
    prefix "NM_USER_". The variable name is an encoded form of the
    data key, consisting only of upper-case letters, digits, and underscore.
    
    The alternative would be something like
    
      NM_USER_1_KEY=my.keys.1
      NM_USER_1_VAL='some value'
      NM_USER_2_KEY=my.other.KEY.42
      NM_USER_2_VAL='other value'
    
    contary to
    
      NM_USER_MY__KEYS__1='some value'
      NM_USER_MY__OTHER___K_E_Y__42='other value'
    
    The advantage of the former, numbered scheme is that it may be easier to
    find the key of a user-data entry. With the current implementation, the
    shell script would have to decode the key, like the ifcfg-rh plugin
    does.
    
    However, user data keys are opaque identifers for values. Usually, you
    are not concerned with a certain name of the key, you already know it.
    Hence, you don't need to write a shell script to decode the key name,
    instead, you can use it directly:
    
      if [ -z ${NM_USER_MY__OTHER___K_E_Y__42+x} ]; then
          do_something_with_key "$NM_USER_MY__OTHER___K_E_Y__42"
      fi
    
    Otherwise, you'd first have to search write a shell script to search
    for the interesting key -- in this example "$NM_USER_2_KEY", before being
    able to access the value "$NM_USER_2_VAL".
    79be44d9