Class: Foreman::Model::Rackspace

Inherits:
ComputeResource show all
Defined in:
lib/foreman/model/rackspace.rb

Constant Summary

Constants inherited from ComputeResource

ComputeResource::PROVIDERS, ComputeResource::STI_PREFIX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComputeResource

#as_json, #console, #hardware_profile, #hardware_profiles, #new_interface, new_provider, #new_vm, #ping, #provider, #provider=, #save_vm, #start_vm, #stop_vm, #supports_update?, #to_label, #to_param, #vms

Methods included from Authorization

#enforce_create_permissions, #enforce_destroy_permissions, #enforce_edit_permissions, #enforce_permissions, included, #permission_failed?

Methods included from Taxonomix

included

Class Method Details

.model_nameObject


10
11
12
# File 'lib/foreman/model/rackspace.rb', line 10

def self.model_name
  ComputeResource.model_name
end

Instance Method Details

#available_imagesObject


59
60
61
# File 'lib/foreman/model/rackspace.rb', line 59

def available_images
  client.images
end

#capabilitiesObject


14
15
16
# File 'lib/foreman/model/rackspace.rb', line 14

def capabilities
  [:image]
end

#create_vm(args = { }) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/foreman/model/rackspace.rb', line 24

def create_vm args = { }
  super(args)
rescue Exception => e
  logger.debug "Unhandled Rackspace error: #{e.class}:#{e.message}\n " + e.backtrace.join("\n ")
  errors.add(:base, e.message.to_s)
  false
end

#destroy_vm(uuid) ⇒ Object


79
80
81
82
83
# File 'lib/foreman/model/rackspace.rb', line 79

def destroy_vm(uuid)
  vm = find_vm_by_uuid(uuid)
  vm.destroy if vm
  true
end

#endpointObject


40
41
42
43
44
45
46
47
48
49
# File 'lib/foreman/model/rackspace.rb', line 40

def endpoint
  case region
    when 'DFW'
      'https://dfw.servers.api.rackspacecloud.com/v2'
    when 'LON'
      'https://lon.servers.api.rackspacecloud.com/v2'
    else
      'https://ord.servers.api.rackspacecloud.com/v2'
  end
end

#find_vm_by_uuid(uuid) ⇒ Object


18
19
20
21
22
# File 'lib/foreman/model/rackspace.rb', line 18

def find_vm_by_uuid uuid
  client.servers.get(uuid)
rescue Fog::Compute::Rackspace::Error
  raise(ActiveRecord::RecordNotFound)
end

#flavorsObject


55
56
57
# File 'lib/foreman/model/rackspace.rb', line 55

def flavors
  client.flavors
end

#provided_attributesObject


6
7
8
# File 'lib/foreman/model/rackspace.rb', line 6

def provided_attributes
  super.merge({ :ip => :public_ip_address })
end

#provider_friendly_nameObject


90
91
92
# File 'lib/foreman/model/rackspace.rb', line 90

def provider_friendly_name
  "Rackspace"
end

#regionObject


75
76
77
# File 'lib/foreman/model/rackspace.rb', line 75

def region
  uuid
end

#region=(value) ⇒ Object


71
72
73
# File 'lib/foreman/model/rackspace.rb', line 71

def region= value
  self.uuid = value
end

#regionsObject


36
37
38
# File 'lib/foreman/model/rackspace.rb', line 36

def regions
  ['ORD', 'DFW', 'LON']
end

#security_groupsObject


32
33
34
# File 'lib/foreman/model/rackspace.rb', line 32

def security_groups
  ["default"]
end

#test_connection(options = {}) ⇒ Object


63
64
65
66
67
68
69
# File 'lib/foreman/model/rackspace.rb', line 63

def test_connection options = {}
  super and flavors
rescue Excon::Errors::Unauthorized => e
  errors[:base] << e.response.body
rescue Fog::Compute::Rackspace::Error => e
  errors[:base] << e.message
end

#update_required?(old_attrs, new_attrs) ⇒ Boolean

not supporting update at the moment


86
87
88
# File 'lib/foreman/model/rackspace.rb', line 86

def update_required?(old_attrs, new_attrs)
  false
end

#zonesObject


51
52
53
# File 'lib/foreman/model/rackspace.rb', line 51

def zones
  ["rackspace"]
end