foreman/app/models/compute_resources/foreman/model/rackspace.rb @ 9d43fc71
8d3aa73e | Romain Vrignaud | module Foreman::Model
|
|
class Rackspace < ComputeResource
|
|||
27e31470 | Michael Moll | validates :url, :format => { :with => URI::DEFAULT_PARSER.make_regexp }, :presence => true
|
|
f2c78d4a | Joseph Magen | validates :user, :password, :region, :presence => true
|
|
79c4c238 | Sam Kottler | validate :ensure_valid_region
|
|
8d3aa73e | Romain Vrignaud | ||
9a9ec5b1 | Daniel Lobato | delegate :flavors, :to => :client
|
|
8d3aa73e | Romain Vrignaud | def provided_attributes
|
|
acf4b687 | Dominic Cleal | super.merge(:ip => :ipv4_address, :ip6 => :ipv6_address)
|
|
8d3aa73e | Romain Vrignaud | end
|
|
bd95cda6 | Dominic Cleal | def self.available?
|
|
Fog::Compute.providers.include?(:rackspace)
|
|||
end
|
|||
8d3aa73e | Romain Vrignaud | def self.model_name
|
|
ComputeResource.model_name
|
|||
end
|
|||
def capabilities
|
|||
[:image]
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def find_vm_by_uuid(uuid)
|
|
4269abbd | Tomas Strachota | super
|
|
8d3aa73e | Romain Vrignaud | rescue Fog::Compute::Rackspace::Error
|
|
raise(ActiveRecord::RecordNotFound)
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def create_vm(args = { })
|
|
8d3aa73e | Romain Vrignaud | super(args)
|
|
c67f9c5e | Greg Sutcliffe | rescue Fog::Errors::Error => e
|
|
01e78260 | Ivan Nečas | Foreman::Logging.exception("Unhandled Rackspace error", e)
|
|
c67f9c5e | Greg Sutcliffe | raise e
|
|
8d3aa73e | Romain Vrignaud | end
|
|
def security_groups
|
|||
["default"]
|
|||
end
|
|||
def regions
|
|||
ac2321f4 | Lukas Zapletal | ['IAD', 'ORD', 'DFW', 'LON', 'SYD', 'HKG']
|
|
8d3aa73e | Romain Vrignaud | end
|
|
def zones
|
|||
["rackspace"]
|
|||
end
|
|||
def available_images
|
|||
client.images
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def test_connection(options = {})
|
|
e263719a | David Davis | super && flavors
|
|
8d3aa73e | Romain Vrignaud | rescue Excon::Errors::Unauthorized => e
|
|
errors[:base] << e.response.body
|
|||
9d43fc71 | Michael Moll | rescue Fog::Compute::Rackspace::Error, Excon::Errors::SocketError => e
|
|
8d3aa73e | Romain Vrignaud | errors[:base] << e.message
|
|
end
|
|||
5f029ed6 | Daniel Lobato | def region=(value)
|
|
8d3aa73e | Romain Vrignaud | self.uuid = value
|
|
end
|
|||
def region
|
|||
uuid
|
|||
end
|
|||
def destroy_vm(uuid)
|
|||
vm = find_vm_by_uuid(uuid)
|
|||
b03dcd1b | Michael Moll | vm&.destroy
|
|
8d3aa73e | Romain Vrignaud | true
|
|
end
|
|||
# not supporting update at the moment
|
|||
def update_required?(old_attrs, new_attrs)
|
|||
false
|
|||
end
|
|||
ddce3dc1 | Amos Benari | def self.provider_friendly_name
|
|
8d3aa73e | Romain Vrignaud | "Rackspace"
|
|
end
|
|||
79c4c238 | Sam Kottler | def ensure_valid_region
|
|
18439248 | Swapnil Abnave | errors.add(:region, 'is not valid') unless regions.include?(region.to_s.upcase)
|
|
79c4c238 | Sam Kottler | end
|
|
805358df | Jason Montleon | def associated_host(vm)
|
|
81a02cde | Tom Caspy | associate_by("ip", [vm.public_ip_address, vm.private_ip_address])
|
|
805358df | Jason Montleon | end
|
|
d21103bc | Shlomi Zadok | def user_data_supported?
|
|
true
|
|||
end
|
|||
56de025f | Tomas Strachota | def normalize_vm_attrs(vm_attrs)
|
|
normalized = slice_vm_attributes(vm_attrs, ['flavor_id', 'image_id'])
|
|||
normalized['flavor_name'] = self.flavors.detect { |f| f.id == normalized['flavor_id'] }.try(:name)
|
|||
normalized['image_name'] = self.images.find_by(:uuid => normalized['image_id']).try(:name)
|
|||
normalized
|
|||
end
|
|||
8d3aa73e | Romain Vrignaud | private
|
|
def client
|
|||
96144a47 | Daniel Lobato | @client ||= Fog::Compute.new(
|
|
8ea76e64 | Sam Kottler | :provider => "Rackspace",
|
|
:version => 'v2',
|
|||
:rackspace_api_key => password,
|
|||
:rackspace_username => user,
|
|||
:rackspace_auth_url => url,
|
|||
79c4c238 | Sam Kottler | :rackspace_region => region.downcase.to_sym
|
|
8ea76e64 | Sam Kottler | )
|
|
8d3aa73e | Romain Vrignaud | end
|
|
def vm_instance_defaults
|
|||
68388bc2 | Michael Moll | # 256 server
|
|
557b8543 | Joseph Mitchell Magen | super.merge(
|
|
9f19765b | Dominic Cleal | :flavor_id => 1,
|
|
:config_drive => true
|
|||
557b8543 | Joseph Mitchell Magen | )
|
|
8d3aa73e | Romain Vrignaud | end
|
|
end
|
|||
end
|