On Fri, Aug 12, 2011 at 10:20:52AM -0400, Ben Lipton wrote:
> Otherwise there will be an error when paramiko tries to write the
> known_hosts file back
> 
> Signed-off-by: Ben Lipton <[email protected]>
> ---
>  p2v-transfer/p2v_transfer.py |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/p2v-transfer/p2v_transfer.py b/p2v-transfer/p2v_transfer.py
> index fdbb335..5a35a85 100755
> --- a/p2v-transfer/p2v_transfer.py
> +++ b/p2v-transfer/p2v_transfer.py
> @@ -142,7 +142,12 @@ def EstablishConnection(user, host, key):
>      # Load from the known_hosts file. Additional keys will be saved back 
> there.
>      client.load_host_keys(known_hosts_filename)
>    except IOError:
> -    pass
> +    # Error is ok, file will be created as long as parent directory exists.
> +    # So, make sure it exists:
> +    try:
> +      os.mkdir(os.path.dirname(known_hosts_filename))
> +    except OSError:
> +      pass  # probably already exists

except OSError, err:
  if err.errno != errno.EEXIST:
    raise # re-raise the exception, or a custom one

thanks,
iustin

Reply via email to