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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#add_interface(attrs) ⇒ Object



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

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

#destroy(options = {}) ⇒ Object



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

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

#destroy_interface(attrs) ⇒ Object



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

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

#interfacesObject



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

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

#locked?Boolean

Returns:

  • (Boolean)


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

def locked?
  !!(status =~ /locked/i)
end

#macObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#reboot(options = {}) ⇒ Object



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

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

#saveObject



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

def save
  if identity
    connection.update_vm(attributes)
  else
    self.id = connection.create_vm(attributes).id
  end
  reload
end

#start(options = {}) ⇒ Object



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

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

#stop(options = {}) ⇒ Object



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

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

#stopped?Boolean

Returns:

  • (Boolean)


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

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

#suspend(options = {}) ⇒ Object



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

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

#ticket(options = {}) ⇒ Object



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

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

#to_sObject



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

def to_s
  name
end

#update_interface(attrs) ⇒ Object



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

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