Class: Fog::Compute::Ovirt::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/ovirt/models/compute/server.rb

Instance Method Summary collapse

Instance Method Details

#add_interface(attrs) ⇒ Object



55
56
57
58
# File 'lib/fog/ovirt/models/compute/server.rb', line 55

def add_interface attrs
  wait_for { stopped? } if attrs[:blocking]
  service.add_interface(id, attrs)
end

#add_volume(attrs) ⇒ Object



77
78
79
80
# File 'lib/fog/ovirt/models/compute/server.rb', line 77

def add_volume attrs
  wait_for { stopped? } if attrs[:blocking]
  service.add_volume(id, attrs)
end

#destroy(options = {}) ⇒ Object



113
114
115
116
117
# File 'lib/fog/ovirt/models/compute/server.rb', line 113

def destroy(options = {})
  (stop unless stopped?) rescue nil #ignore failure, destroy the machine anyway.
  wait_for { stopped? }
  service.destroy_vm(:id => id)
end

#destroy_interface(attrs) ⇒ Object



65
66
67
68
# File 'lib/fog/ovirt/models/compute/server.rb', line 65

def destroy_interface attrs
  wait_for { stopped? } if attrs[:blocking]
  service.destroy_interface(id, attrs)
end

#destroy_volume(attrs) ⇒ Object



87
88
89
90
# File 'lib/fog/ovirt/models/compute/server.rb', line 87

def destroy_volume attrs
  wait_for { stopped? } if attrs[:blocking]
  service.destroy_volume(id, attrs)
end

#interfacesObject



48
49
50
51
52
53
# File 'lib/fog/ovirt/models/compute/server.rb', line 48

def interfaces
  @interfaces ||= id.nil? ? [] : Fog::Compute::Ovirt::Interfaces.new(
      :service => service,
      :vm => self
  )
end

#locked?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/fog/ovirt/models/compute/server.rb', line 35

def locked?
  @volumes = nil # force reload volumes
  !!(status =~ /locked/i) || (attributes[:volumes]=nil) || volumes.any?{|v| !!(v.status =~ /locked/i)}
end

#macObject



44
45
46
# File 'lib/fog/ovirt/models/compute/server.rb', line 44

def mac
  interfaces.first.mac unless interfaces.empty?
end

#ready?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fog/ovirt/models/compute/server.rb', line 31

def ready?
  !(status =~ /down/i)
end

#reboot(options = {}) ⇒ Object



103
104
105
106
# File 'lib/fog/ovirt/models/compute/server.rb', line 103

def reboot(options = {})
  stop unless stopped?
  start options.merge(:blocking => true)
end

#saveObject



124
125
126
127
128
129
130
131
# File 'lib/fog/ovirt/models/compute/server.rb', line 124

def save
  if persisted?
    service.update_vm(attributes)
  else
    self.id = service.create_vm(attributes).id
  end
  reload
end

#start(options = {}) ⇒ Object



92
93
94
95
96
# File 'lib/fog/ovirt/models/compute/server.rb', line 92

def start(options = {})
  wait_for { !locked? } if options[:blocking]
  service.vm_action(:id =>id, :action => :start)
  reload
end

#stop(options = {}) ⇒ Object



98
99
100
101
# File 'lib/fog/ovirt/models/compute/server.rb', line 98

def stop(options = {})
  service.vm_action(:id =>id, :action => :stop)
  reload
end

#stopped?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fog/ovirt/models/compute/server.rb', line 40

def stopped?
  !!(status =~ /down/i)
end

#suspend(options = {}) ⇒ Object



108
109
110
111
# File 'lib/fog/ovirt/models/compute/server.rb', line 108

def suspend(options = {})
  service.vm_action(:id =>id, :action => :suspend)
  reload
end

#ticket(options = {}) ⇒ Object



119
120
121
122
# File 'lib/fog/ovirt/models/compute/server.rb', line 119

def ticket(options = {})
  raise "Can not set console ticket, Server is not ready. Server status: #{status}" unless ready?
  service.vm_ticket(id, options)
end

#to_sObject



133
134
135
# File 'lib/fog/ovirt/models/compute/server.rb', line 133

def to_s
  name
end

#update_interface(attrs) ⇒ Object



60
61
62
63
# File 'lib/fog/ovirt/models/compute/server.rb', line 60

def update_interface attrs
  wait_for { stopped? } if attrs[:blocking]
  service.update_interface(id, attrs)
end

#update_volume(attrs) ⇒ Object



82
83
84
85
# File 'lib/fog/ovirt/models/compute/server.rb', line 82

def update_volume attrs
  wait_for { stopped? } if attrs[:blocking]
  service.update_volume(id, attrs)
end

#volumesObject



70
71
72
73
74
75
# File 'lib/fog/ovirt/models/compute/server.rb', line 70

def volumes
  @volumes ||= id.nil? ? [] : Fog::Compute::Ovirt::Volumes.new(
      :service => service,
      :vm => self
  )
end