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

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

Instance Method Summary collapse

Instance Method Details

#add_interface(attrs) ⇒ Object



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

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

#add_to_affinity_group(attrs) ⇒ Object



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

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

#add_volume(attrs) ⇒ Object



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

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

#attach_volume(attrs) ⇒ Object



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

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

#destroy(_options = {}) ⇒ Object



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

def destroy(_options = {})
  begin
    (stop unless stopped?)
  rescue StandardError
    nil
  end
  wait_for { stopped? }
  service.destroy_vm(:id => id)
end

#destroy_interface(attrs) ⇒ Object



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

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

#destroy_volume(attrs) ⇒ Object



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

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

#detach_volume(attrs) ⇒ Object



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

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

#interfacesObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/fog/ovirt/models/compute/server.rb', line 55

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

#locked?Boolean

Returns:

  • (Boolean)


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

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

#macObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  status !~ /down/i
end

#reboot(options = {}) ⇒ Object



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

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

#remove_from_affinity_group(attrs) ⇒ Object



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

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

#saveObject



181
182
183
184
185
186
187
188
# File 'lib/fog/ovirt/models/compute/server.rb', line 181

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

#start(options = {}) ⇒ Object



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

def start(options = {})
  wait_for { !locked? } if options[:blocking]
  vm_power_action(:start)
end

#start_with_cloudinit(options = {}) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/fog/ovirt/models/compute/server.rb', line 132

def start_with_cloudinit(options = {})
  wait_for { !locked? } if options[:blocking]
  user_data = if options[:use_custom_script]
                { :custom_script => options[:user_data] }
              else
                YAML.safe_load(options[:user_data]).to_h { |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 = {}) ⇒ Object



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

def stop(_options = {})
  vm_power_action(:stop)
end

#stopped?Boolean

Returns:

  • (Boolean)


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

def stopped?
  status.casecmp("down").zero?
end

#suspend(_options = {}) ⇒ Object



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

def suspend(_options = {})
  vm_power_action(:suspend)
end

#ticket(options = {}) ⇒ Object



176
177
178
179
# File 'lib/fog/ovirt/models/compute/server.rb', line 176

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_sObject



190
191
192
# File 'lib/fog/ovirt/models/compute/server.rb', line 190

def to_s
  name
end

#update_interface(attrs) ⇒ Object



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

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

#update_volume(attrs) ⇒ Object



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

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

#vm_power_action(action) ⇒ Object



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

def vm_power_action(action)
  action_status = service.vm_action(:id => id, :action => action)
  reload
  action_status
end

#volumesObject



81
82
83
84
85
86
87
88
89
90
# File 'lib/fog/ovirt/models/compute/server.rb', line 81

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