def _validate_vdi_chain(vdi_path):
 def get_parent_path(path):
  query_cmd = ('vhd-util query -n %(path)s -p' % locals())
  query_proc = make_subprocess(query_cmd, stdout=True, stderr=True)
  (out, err) = finish_subprocess(query_proc, query_cmd, ok_exit_codes=[0, 22])
  first_line = out.splitlines()[0].strip()
  if first_line.endswith('.vhd'):
   return first_line
  elif ('has no parent' in first_line):
   return None
  elif ('query failed' in first_line):
   raise Exception(("VDI '%(path)s' not present which breaks the VDI chain, bailing out" % locals()))
  else:
   raise Exception(("Unexpected output '%(out)s' from vhd-util" % locals()))
 cur_path = vdi_path
 while cur_path:
  _validate_footer_timestamp(cur_path)
  cur_path = get_parent_path(cur_path)

def _validate_vdi_chain ( vdi_path ) : def get_parent_path ( path ) : query_cmd = ( 'vhd-util query -n %(path)s -p' % locals ( ) ) query_proc = make_subprocess ( query_cmd , stdout = True , stderr = True ) ( out , err ) = finish_subprocess ( query_proc , query_cmd , ok_exit_codes = [ 0 , 22 ] ) first_line = out . splitlines ( ) [ 0 ] . strip ( ) if first_line . endswith ( '.vhd' ) : return first_line elif ( 'has no parent' in first_line ) : return None elif ( 'query failed' in first_line ) : raise Exception ( ( "VDI '%(path)s' not present which breaks the VDI chain, bailing out" % locals ( ) ) ) else : raise Exception ( ( "Unexpected output '%(out)s' from vhd-util" % locals ( ) ) ) cur_path = vdi_path while cur_path : _validate_footer_timestamp ( cur_path ) cur_path = get_parent_path ( cur_path )
this check ensures that the parent pointers on the vhds are valid before we move the vdi chain to the sr .