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



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

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

#add_to_affinity_group(attrs) ⇒ Object



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

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

#add_volume(attrs) ⇒ Object



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

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

#attach_volume(attrs) ⇒ Object



95
96
97
98
# File 'lib/fog/ovirt/models/compute/server.rb', line 95

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

#destroy(options = {}) ⇒ Object



143
144
145
146
147
# File 'lib/fog/ovirt/models/compute/server.rb', line 143

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



68
69
70
71
# File 'lib/fog/ovirt/models/compute/server.rb', line 68

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

#destroy_volume(attrs) ⇒ Object



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

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

#detach_volume(attrs) ⇒ Object



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

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

#interfacesObject



51
52
53
54
55
56
# File 'lib/fog/ovirt/models/compute/server.rb', line 51

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

#locked?Boolean

Returns:

  • (Boolean)


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

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

#macObject



47
48
49
# File 'lib/fog/ovirt/models/compute/server.rb', line 47

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#reboot(options = {}) ⇒ Object



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

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

#remove_from_affinity_group(attrs) ⇒ Object



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

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

#saveObject



154
155
156
157
158
159
160
161
# File 'lib/fog/ovirt/models/compute/server.rb', line 154

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

#start(options = {}) ⇒ Object



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

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

#start_with_cloudinit(options = {}) ⇒ Object



121
122
123
124
125
126
# File 'lib/fog/ovirt/models/compute/server.rb', line 121

def start_with_cloudinit(options = {})
  wait_for { !locked? } if options[:blocking]
  user_data = Hash[YAML.load(options[:user_data]).map{|a| [a.first.to_sym, a.last]}]
  service.vm_start_with_cloudinit(:id =>id, :user_data =>user_data)
  reload
end

#stop(options = {}) ⇒ Object



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

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

#stopped?Boolean

Returns:

  • (Boolean)


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

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

#suspend(options = {}) ⇒ Object



138
139
140
141
# File 'lib/fog/ovirt/models/compute/server.rb', line 138

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

#ticket(options = {}) ⇒ Object



149
150
151
152
# File 'lib/fog/ovirt/models/compute/server.rb', line 149

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



163
164
165
# File 'lib/fog/ovirt/models/compute/server.rb', line 163

def to_s
  name
end

#update_interface(attrs) ⇒ Object



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

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

#update_volume(attrs) ⇒ Object



90
91
92
93
# File 'lib/fog/ovirt/models/compute/server.rb', line 90

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

#volumesObject



73
74
75
76
77
78
# File 'lib/fog/ovirt/models/compute/server.rb', line 73

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