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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#private_key=, #scp, #scp_download, #ssh, #ssh_port, #sshable?

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



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

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

#add_volume(attrs) ⇒ Object



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

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

#destroy(options = {}) ⇒ Object



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

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



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

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

#destroy_volume(attrs) ⇒ Object



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

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

#interfacesObject



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

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

#locked?Boolean

Returns:

  • (Boolean)


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

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

#macObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#reboot(options = {}) ⇒ Object



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

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

#saveObject



118
119
120
121
122
123
124
125
# File 'lib/rackspace-fog/ovirt/models/compute/server.rb', line 118

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

#start(options = {}) ⇒ Object



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

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

#stop(options = {}) ⇒ Object



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

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

#stopped?Boolean

Returns:

  • (Boolean)


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

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

#suspend(options = {}) ⇒ Object



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

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

#ticket(options = {}) ⇒ Object



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

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



127
128
129
# File 'lib/rackspace-fog/ovirt/models/compute/server.rb', line 127

def to_s
  name
end

#update_interface(attrs) ⇒ Object



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

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

#volumesObject



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

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