Class: Deltacloud::Drivers::Rackspace::RackspaceDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Deltacloud::Drivers::Rackspace::RackspaceDriver
show all
- Defined in:
- lib/deltacloud/drivers/rackspace/rackspace_driver.rb
Instance Method Summary
collapse
Methods inherited from BaseDriver
#catched_exceptions_list, declare_feature, define_hardware_profile, define_instance_states, feature, feature_decl_for, feature_decls, #features, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #hardware_profile, hardware_profiles, #has_collection?, #image, #instance, #instance_actions_for, instance_state_machine, #instance_state_machine, #realm, #start_instance, #storage_snapshot, #storage_snapshots, #storage_volume, #storage_volumes, #supported_collections
Instance Method Details
#convert_srv_to_instance(srv) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 135
def convert_srv_to_instance(srv)
inst = Instance.new(:id => srv["id"].to_s,
:owner_id => "root",
:realm_id => "us")
inst.name = srv["name"]
inst.state = srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING"
inst.actions = instance_actions_for(inst.state)
inst.image_id = srv["imageId"].to_s
inst.instance_profile = InstanceProfile.new(srv["flavorId"].to_s)
if srv["addresses"]
inst.public_addresses = srv["addresses"]["public"]
inst.private_addresses = srv["addresses"]["private"]
end
inst
end
|
#create_instance(credentials, image_id, opts) ⇒ Object
create instance. Default to flavor 1 - really need a name though… In rackspace, all flavors work with all images.
104
105
106
107
108
109
110
111
112
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 104
def create_instance(credentials, image_id, opts)
racks = new_client( credentials )
hwp_id = opts[:hwp_id] || 1
name = Time.now.to_s
if (opts[:name]) then name = opts[:name] end
safely do
return convert_srv_to_instance(racks.start_server(image_id, hwp_id, name))
end
end
|
#destroy_instance(credentials, id) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 87
def destroy_instance(credentials, id)
racks = new_client(credentials)
safely do
racks.delete_server(id)
end
Instance.new( {
:id => id,
:state => "STOPPED",
:actions => instance_actions_for( "STOPPED" ),
} )
end
|
#hardware_profiles(credentials, opts = nil) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 30
def hardware_profiles(credentials, opts = nil)
racks = new_client( credentials )
safely do
results = racks.list_flavors.map do |flav|
HardwareProfile.new(flav["id"].to_s) do
architecture 'x86_64'
memory flav["ram"].to_i
storage flav["disk"].to_i
end
end
end
filter_hardware_profiles(results, opts)
end
|
#images(credentials, opts = nil) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 44
def images(credentials, opts=nil)
racks = new_client( credentials )
safely do
results = racks.list_images.map do |img|
Image.new( {
:id=>img["id"].to_s,
:name=>img["name"],
:description => img["name"] + " " + img["status"] + "",
:owner_id=>"root",
:architecture=>'x86_64'
} )
end
end
results.sort_by{|e| [e.description]}
results = filter_on( results, :id, opts )
results
end
|
#instances(credentials, opts = nil) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 117
def instances(credentials, opts=nil)
racks = new_client(credentials)
instances = []
safely do
if (opts.nil?)
instances = racks.list_servers.map do |srv|
convert_srv_to_instance(srv)
end
else
instances << convert_srv_to_instance(racks.load_server_details(opts[:id]))
end
end
instances = filter_on( instances, :id, opts )
instances = filter_on( instances, :state, opts )
instances
end
|
#new_client(credentials) ⇒ Object
151
152
153
154
155
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 151
def new_client(credentials)
safely do
return RackspaceClient.new(credentials.user, credentials.password)
end
end
|
#realms(credentials, opts = nil) ⇒ Object
rackspace does not at this stage have realms… its all US/TX, all the time (at least at time of writing)
63
64
65
66
67
68
69
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 63
def realms(credentials, opts=nil)
[Realm.new( {
:id=>"us",
:name=>"United States",
:state=> "AVAILABLE"
} )]
end
|
#reboot_instance(credentials, id) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 71
def reboot_instance(credentials, id)
racks = new_client(credentials)
safely do
racks.reboot_server(id)
end
Instance.new( {
:id => id,
:state => "REBOOT",
:actions => instance_actions_for( state ),
} )
end
|
#safely(&block) ⇒ Object
170
171
172
173
174
175
176
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 170
def safely(&block)
begin
block.call
rescue Exception => e
raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
end
end
|
#stop_instance(credentials, id) ⇒ Object
83
84
85
|
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 83
def stop_instance(credentials, id)
destroy_instance(credentials, id)
end
|