Revision 1aaf04e4

View differences:

src/vmm_mad/remotes/vcenter/attach_disk
49 49
    vm.attach_disk
50 50

  
51 51
rescue Exception => e
52
    STDERR.puts "Attach image for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
53
                "failed due to \"#{e.message}\"\n#{e.backtrace}"
52
    message = "Attach image for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
53
              "failed due to \"#{e.message}\"\n#{e.backtrace}"
54
    STDERR.puts error_message(message)
54 55
    exit -1
55 56
ensure
56 57
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/attach_nic
49 49
    vm.attach_nic
50 50

  
51 51
rescue Exception => e
52
    STDERR.puts "Attach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
53
                "failed due to \"#{e.message}\"\n#{e.backtrace}"
54
    exit(-1)
52
    message = "Attach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
53
              "failed due to \"#{e.message}\"\n#{e.backtrace}"
54
    STDERR.puts error_message(message)
55
    exit -1
55 56
ensure
56 57
    vi_client.close_connection if vi_client
57 58
end
src/vmm_mad/remotes/vcenter/cancel
49 49
    vm.poweroff_hard
50 50

  
51 51
rescue Exception => e
52
    STDERR.puts "Cancel VM #{vm_ref} failed due to "\
53
                "\"#{e.message}\"\n#{e.backtrace}"
54
    exit(-1)
52
    message = "Cancel VM #{vm_ref} failed due to "\
53
              "\"#{e.message}\"\n#{e.backtrace}"
54
    STDERR.puts error_message(message)
55
    exit -1
55 56
ensure
56 57
    vi_client.close_connection if vi_client
57 58
end
src/vmm_mad/remotes/vcenter/deploy
68 68
    # Resize unmanaged disks
69 69
    vm.resize_unmanaged_disks
70 70

  
71

  
72

  
73 71
    vm.reconfigure
74 72
    vm.poweron
75 73
    vm.set_running(true)
......
77 75
    puts vm['_ref']
78 76

  
79 77
rescue Exception => e
80
    STDERR.puts "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " +
81
                "with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
78
    message   =  "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " +
79
                 "with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
80
    STDERR.puts error_message(message)
82 81
    exit -1
83 82
ensure
84 83
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/detach_disk
47 47
          "snapshot of the virtual machine." if vm.has_snapshots?
48 48

  
49 49
rescue Exception => e
50
    STDERR.puts "Detach DISK for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
51
                "failed due to \"#{e.message}\"\n#{e.backtrace}"
50
    message = "Detach DISK for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
51
              "failed due to \"#{e.message}\"\n#{e.backtrace}"
52
    STDERR.puts error_message(message)
52 53
    exit -1
53 54
ensure
54 55
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/detach_nic
49 49
    vm.detach_nic
50 50

  
51 51
rescue Exception => e
52
    STDERR.puts "Detach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
53
                "failed due to \"#{e.message}\"\n#{e.backtrace}"
52
    message = "Detach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
53
              "failed due to \"#{e.message}\"\n#{e.backtrace}"
54
    STDERR.puts error_message(message)
54 55
    exit -1
55 56
ensure
56 57
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/poll
46 46
    puts vm.info
47 47

  
48 48
rescue Exception => e
49
    STDERR.puts "Cannot poll info for VM #{vm_ref} on vCenter cluster "\
50
                "#{vc_cluster_name} failed due to "\
51
                "\"#{e.message}\"\n#{e.backtrace}"
49
    message = "Cannot poll info for VM #{vm_ref} on vCenter cluster "\
50
              "#{vc_cluster_name} failed due to "\
51
              "\"#{e.message}\"\n#{e.backtrace}"
52
    STDERR.puts error_message(message)
52 53
    exit -1
53 54
ensure
54 55
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/reboot
43 43
    vm.reboot
44 44

  
45 45
rescue Exception => e
46
    STDERR.puts "Guest reboot of VM #{vm_ref} on vCenter cluster "\
47
                "#{vc_cluster_name} failed due to "\
48
                "\"#{e.message}\"\n#{e.backtrace}"
46
    message = "Guest reboot of VM #{vm_ref} on vCenter cluster "\
47
              "#{vc_cluster_name} failed due to "\
48
              "\"#{e.message}\"\n#{e.backtrace}"
49
    STDERR.puts error_message(message)
49 50
    exit -1
50 51
ensure
51 52
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/reconfigure
43 43
    vm.regenerate_context
44 44

  
45 45
rescue Exception => e
46
    STDERR.puts "Reconfiguration of VM #{vm_ref} on vCenter cluster "\
47
                "#{vc_cluster_name} failed due to "\
48
                "\"#{e.message}\"\n#{e.backtrace}"
46
    message = "Reconfiguration of VM #{vm_ref} on vCenter cluster "\
47
              "#{vc_cluster_name} failed due to "\
48
              "\"#{e.message}\"\n#{e.backtrace}"
49
    STDERR.puts error_message(message)
49 50
    exit -1
50 51
ensure
51 52
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/reset
43 43
    vm.reset
44 44

  
45 45
rescue Exception => e
46
    STDERR.puts "Reset of VM #{vm_ref} on vCenter cluster "\
47
                "#{vc_cluster_name} failed due to "\
48
                "\"#{e.message}\"\n#{e.backtrace}"
46
    message = "Reset of VM #{vm_ref} on vCenter cluster "\
47
              "#{vc_cluster_name} failed due to "\
48
              "\"#{e.message}\"\n#{e.backtrace}"
49
    STDERR.puts error_message(message)
49 50
    exit -1
50 51
ensure
51 52
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/restore
45 45
    vm.set_running(true)
46 46

  
47 47
rescue Exception => e
48
    STDERR.puts "Restore of VM #{vm_ref} on vCenter cluster "\
49
                "#{vc_cluster_name} failed due to "\
50
                "\"#{e.message}\"\n#{e.backtrace}"
48
    message = "Restore of VM #{vm_ref} on vCenter cluster "\
49
              "#{vc_cluster_name} failed due to "\
50
              "\"#{e.message}\"\n#{e.backtrace}"
51
    STDERR.puts error_message(message)
51 52
    exit -1
52 53
ensure
53 54
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/save
62 62
    vm.suspend
63 63

  
64 64
rescue Exception => e
65
    STDERR.puts "Save of VM #{vm_ref} on vCenter cluster "\
66
                "#{vc_cluster_name} failed due to "\
67
                "\"#{e.message}\"\n#{e.backtrace}"
65
    message = "Save of VM #{vm_ref} on vCenter cluster "\
66
              "#{vc_cluster_name} failed due to "\
67
              "\"#{e.message}\"\n#{e.backtrace}"
68
    STDERR.puts error_message(message)
68 69
    exit -1
69 70
ensure
70 71
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/shutdown
59 59
    vm.shutdown #Undeploy, Poweroff or Terminate
60 60

  
61 61
rescue Exception => e
62
    STDERR.puts "Shutdown of VM #{vm_ref} on vCenter cluster "\
63
                "#{vc_cluster_name} failed due to "\
64
                "\"#{e.message}\"\n#{e.backtrace}"
62
    message = "Shutdown of VM #{vm_ref} on vCenter cluster "\
63
              "#{vc_cluster_name} failed due to "\
64
              "\"#{e.message}\"\n#{e.backtrace}"
65
    STDERR.puts error_message(message)
65 66
    exit -1
66 67
ensure
67 68
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/snapshot_create
62 62
    puts vm.create_snapshot(snap_id, snap_name)
63 63

  
64 64
rescue Exception => e
65
    STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
66
                "#{vc_cluster_name} failed due to "\
67
                "\"#{e.message}\"\n#{e.backtrace}"
65
    message = "Snapshot of VM #{vm_ref} on vCenter cluster "\
66
              "#{vc_cluster_name} failed due to "\
67
              "\"#{e.message}\"\n#{e.backtrace}"
68
    STDERR.puts error_message(message)
68 69
    exit -1
69 70
ensure
70 71
    vi_client.close_connection if vi_client
src/vmm_mad/remotes/vcenter/snapshot_delete
44 44
    vm.delete_snapshot(snap_id)
45 45

  
46 46
rescue Exception => e
47
    STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
48
                "#{vc_cluster_name} could not be deleted due to "\
49
                "\"#{e.message}\"\n#{e.backtrace}"
50
    exit(-1)
47
    message = "Snapshot of VM #{vm_ref} on vCenter cluster "\
48
              "#{vc_cluster_name} could not be deleted due to "\
49
              "\"#{e.message}\"\n#{e.backtrace}"
50
    STDERR.puts error_message(message)
51
    exit -1
51 52
ensure
52 53
    vi_client.close_connection if vi_client
53 54
end
src/vmm_mad/remotes/vcenter/snapshot_revert
44 44
    vm.revert_snapshot(snap_id)
45 45

  
46 46
rescue Exception => e
47
    STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
48
                "#{vc_cluster_name} could not be reverted due "\
49
                "to \"#{e.message}\"\n#{e.backtrace}"
50
    exit(-1)
47
    message = "Snapshot of VM #{vm_ref} on vCenter cluster "\
48
              "#{vc_cluster_name} could not be reverted due "\
49
              "to \"#{e.message}\"\n#{e.backtrace}"
50
    STDERR.puts error_message(message)
51
    exit -1
51 52
ensure
52 53
    vi_client.close_connection if vi_client
53 54
end
src/vmm_mad/remotes/vcenter/vcenter_driver.rb
63 63
# Helper functions                                                             #
64 64
# ---------------------------------------------------------------------------- #
65 65

  
66
def error_message(message)
67
    error_str = "ERROR MESSAGE --8<------\n"
68
    error_str << message
69
    error_str << "\nERROR MESSAGE ------>8--"
70

  
71
    return error_str
72
end
73

  
66 74
def check_valid(parameter, label)
67 75
    if parameter.nil? || parameter.empty?
68
        STDERR.puts "The parameter '#{label}' is required for this action."
76
        STDERR.puts error_message("The parameter '#{label}' is required for this action.")
69 77
        exit -1
70 78
    end
71 79
end

Also available in: Unified diff