TEXT   56

status

Guest on 17th May 2022 01:31:52 AM

  1. cloud-init will keep a 'status' file up to date for other applications
  2. wishing to use it to determine cloud-init status.
  3.  
  4. It will manage 2 files:
  5.  status.json
  6.  result.json
  7.  
  8. The files will be written to /var/lib/cloud/data/ .
  9. A symlink will be created in /run/cloud-init. The link from /run is to ensure
  10. that if the file exists, it is not stale for this boot.
  11.  
  12. status.json's format is:
  13.    {
  14.     'v1': {
  15.      'init': {
  16.        errors: []      # list of strings for each error that occurred
  17.        start: float # time.time() that this stage started or None
  18.        end: float # time.time() that this stage finished or None
  19.      },
  20.      'init-local': {
  21.        'errors': [], 'start': <float>, 'end' <float> # (same as 'init' above)
  22.      },
  23.      'modules-config': {
  24.        'errors': [], 'start': <float>, 'end' <float> # (same as 'init' above)
  25.      },
  26.      'modules-final': {
  27.        'errors': [], 'start': <float>, 'end' <float> # (same as 'init' above)
  28.      },
  29.      'datasource': string describing datasource found or None
  30.      'stage': string representing stage that is currently running
  31.               ('init', 'init-local', 'modules-final', 'modules-config', None)
  32.               if None, then no stage is running.  Reader must read the start/end
  33.               of each of the above stages to determine the state.
  34.    }
  35.  
  36. result.json's format is:
  37.    {
  38.     'v1': {
  39.      'datasource': string describing the datasource found
  40.      'errors': [] # list of errors reported
  41.     }
  42.    }
  43.  
  44. Thus, to determine if cloud-init is finished:
  45.  fin = "/run/cloud-init/result.json"
  46.  if os.path.exists(fin):
  47.    ret = json.load(open(fin, "r"))
  48.    if len(ret['v1']['errors']):
  49.      print "Finished with errors:" + "\n".join(ret['v1']['errors'])
  50.    else:
  51.      print "Finished no errors"
  52.  else:
  53.    print "Not Finished"

Raw Paste


Login or Register to edit or fork this paste. It's free.