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



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

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

#add_to_affinity_group(attrs) ⇒ Object



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

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

#add_volume(attrs) ⇒ Object



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

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

#attach_volume(attrs) ⇒ Object



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

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

#destroy(options = {}) ⇒ Object



153
154
155
156
157
# File 'lib/fog/ovirt/models/compute/server.rb', line 153

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



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

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

#destroy_volume(attrs) ⇒ Object



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

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

#detach_volume(attrs) ⇒ Object



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

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

#interfacesObject



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

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

#locked?Boolean

Returns:

  • (Boolean)


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

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

#macObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#reboot(options = {}) ⇒ Object



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

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

#remove_from_affinity_group(attrs) ⇒ Object



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

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

#saveObject



164
165
166
167
168
169
170
171
# File 'lib/fog/ovirt/models/compute/server.rb', line 164

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

#start(options = {}) ⇒ Object



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

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

#start_with_cloudinit(options = {}) ⇒ Object



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

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

#stop(options = {}) ⇒ Object



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

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

#stopped?Boolean

Returns:

  • (Boolean)


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

def stopped?
  status.downcase == 'down'
end

#suspend(options = {}) ⇒ Object



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

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

#ticket(options = {}) ⇒ Object



159
160
161
162
# File 'lib/fog/ovirt/models/compute/server.rb', line 159

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



173
174
175
# File 'lib/fog/ovirt/models/compute/server.rb', line 173

def to_s
  name
end

#update_interface(attrs) ⇒ Object



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

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

#update_volume(attrs) ⇒ Object



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

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

#volumesObject



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

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