class Fog::Compute::Ovirt::Server

Public Instance Methods

add_interface(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 62
def add_interface(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.add_interface(id, attrs)
end
add_to_affinity_group(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 109
def add_to_affinity_group(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.add_to_affinity_group(id, attrs)
end
add_volume(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 84
def add_volume(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.add_volume(id, attrs)
end
attach_volume(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 99
def attach_volume(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.attach_volume(id, attrs)
end
destroy(_options = {}) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 160
def destroy(_options = {})
  begin
    (stop unless stopped?)
  rescue StandardError
    nil
  end # ignore failure, destroy the machine anyway.
  wait_for { stopped? }
  service.destroy_vm(:id => id)
end
destroy_interface(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 72
def destroy_interface(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.destroy_interface(id, attrs)
end
destroy_volume(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 89
def destroy_volume(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.destroy_volume(id, attrs)
end
detach_volume(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 104
def detach_volume(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.detach_volume(id, attrs)
end
interfaces() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 55
def interfaces
  @interfaces ||= id.nil? ? [] : Fog::Compute::Ovirt::Interfaces.new(
    :service => service,
    :vm => self
  )
end
locked?() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 42
def locked?
  @volumes = nil # force reload volumes
  !!(status =~ /locked/) || (attributes[:volumes] = nil) || volumes.any? { |v| !!(v.status =~ /locked/) }
end
mac() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 51
def mac
  interfaces.first.mac unless interfaces.empty?
end
ready?() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 38
def ready?
  status !~ /down/
end
reboot(options = {}) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 142
def reboot(options = {})
  unless stopped?
    stop
    wait_for { stopped? }
  end
  start options.merge(:blocking => true)
end
remove_from_affinity_group(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 114
def remove_from_affinity_group(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.remove_from_affinity_group(id, attrs)
end
save() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 175
def save
  if persisted?
    service.update_vm(attributes)
  else
    self.id = service.create_vm(attributes).id
  end
  reload
end
start(options = {}) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 119
def start(options = {})
  wait_for { !locked? } if options[:blocking]
  vm_power_action(:start)
end
start_with_cloudinit(options = {}) click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/fog/ovirt/models/compute/server.rb, line 125
def start_with_cloudinit(options = {})
  wait_for { !locked? } if options[:blocking]
  user_data = if options[:use_custom_script]
                { :custom_script => options[:user_data] }
              else
                Hash[YAML.safe_load(options[:user_data]).map { |a| [a.first.to_sym, a.last] }]
              end
  action_status = service.vm_start_with_cloudinit(:id => id, :user_data => user_data)
  reload
  action_status
end
stop(_options = {}) click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/fog/ovirt/models/compute/server.rb, line 138
def stop(_options = {})
  vm_power_action(:stop)
end
stopped?() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 47
def stopped?
  status.casecmp("down").zero?
end
suspend(_options = {}) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 150
def suspend(_options = {})
  vm_power_action(:suspend)
end
ticket(options = {}) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 170
def ticket(options = {})
  raise ::Fog::Ovirt::Errors::OvirtError, "Can not set console ticket, Server is not ready. Server status: #{status}" unless ready?
  service.vm_ticket(id, options)
end
to_s() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 184
def to_s
  name
end
update_interface(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 67
def update_interface(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.update_interface(id, attrs)
end
update_volume(attrs) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 94
def update_volume(attrs)
  wait_for { stopped? } if attrs[:blocking]
  service.update_volume(id, attrs)
end
vm_power_action(action) click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 154
def vm_power_action(action)
  action_status = service.vm_action(:id => id, :action => action)
  reload
  action_status
end
volumes() click to toggle source
# File lib/fog/ovirt/models/compute/server.rb, line 77
def volumes
  @volumes ||= id.nil? ? [] : Fog::Compute::Ovirt::Volumes.new(
    :service => service,
    :vm => self
  )
end